@ -51,6 +51,7 @@ struct Maps::Private
Server : : Maps : : maps_offsets offsets ;
APIPrivate * d ;
Process * owner ;
bool Inited ;
bool Started ;
vector < uint16_t > v_geology [ eBiomeCount ] ;
@ -60,9 +61,10 @@ Maps::Maps(APIPrivate* _d)
{
d = new Private ;
d - > d = _d ;
Process * p = d - > owner = _d - > p ;
d - > Inited = d - > Started = false ;
DFHack : : memory_info * mem = d- > d - > offset_descriptor ;
DFHack : : memory_info * mem = p- > getDescriptor ( ) ;
Server : : Maps : : maps_offsets & off = d - > offsets ;
// get the offsets once here
@ -87,14 +89,14 @@ Maps::Maps(APIPrivate* _d)
// upload offsets to SHM server if possible
d - > maps_module = 0 ;
if ( g_ pProcess - > getModuleIndex ( " Maps2010 " , 1 , d - > maps_module ) )
if ( p- > getModuleIndex ( " Maps2010 " , 1 , d - > maps_module ) )
{
// supply the module with offsets so it can work with them
Server : : Maps : : maps_offsets * off2 = SHMDATA ( Server : : Maps : : maps_offsets ) ;
memcpy ( off2 , & ( d - > offsets ) , sizeof ( Server : : Maps : : maps_offsets ) ) ;
full_barrier
const uint32_t cmd = Server : : Maps : : MAP_INIT + ( d - > maps_module < < 16 ) ;
g_ pProcess - > SetAndWait ( cmd ) ;
p- > SetAndWait ( cmd ) ;
}
d - > Inited = true ;
}
@ -114,9 +116,10 @@ bool Maps::Start()
return false ;
if ( d - > Started )
Finish ( ) ;
Process * p = d - > owner ;
Server : : Maps : : maps_offsets & off = d - > offsets ;
// get the map pointer
uint32_t x_array_loc = g_ pProcess - > readDWord ( off . map_offset ) ;
uint32_t x_array_loc = p- > readDWord ( off . map_offset ) ;
if ( ! x_array_loc )
{
return false ;
@ -124,9 +127,9 @@ bool Maps::Start()
// get the size
uint32_t mx , my , mz ;
mx = d - > x_block_count = g_ pProcess - > readDWord ( off . x_count_offset ) ;
my = d - > y_block_count = g_ pProcess - > readDWord ( off . y_count_offset ) ;
mz = d - > z_block_count = g_ pProcess - > readDWord ( off . z_count_offset ) ;
mx = d - > x_block_count = p- > readDWord ( off . x_count_offset ) ;
my = d - > y_block_count = p- > readDWord ( off . y_count_offset ) ;
mz = d - > z_block_count = p- > readDWord ( off . z_count_offset ) ;
// test for wrong map dimensions
if ( mx = = 0 | | mx > 48 | | my = = 0 | | my > 48 | | mz = = 0 )
@ -141,14 +144,14 @@ bool Maps::Start()
uint32_t * temp_y = new uint32_t [ my ] ;
uint32_t * temp_z = new uint32_t [ mz ] ;
g_ pProcess - > read ( x_array_loc , mx * sizeof ( uint32_t ) , ( uint8_t * ) temp_x ) ;
p- > read ( x_array_loc , mx * sizeof ( uint32_t ) , ( uint8_t * ) temp_x ) ;
for ( uint32_t x = 0 ; x < mx ; x + + )
{
g_ pProcess - > read ( temp_x [ x ] , my * sizeof ( uint32_t ) , ( uint8_t * ) temp_y ) ;
p- > read ( temp_x [ x ] , my * sizeof ( uint32_t ) , ( uint8_t * ) temp_y ) ;
// y -> map column
for ( uint32_t y = 0 ; y < my ; y + + )
{
g_ pProcess - > read ( temp_y [ y ] ,
p- > read ( temp_y [ y ] ,
mz * sizeof ( uint32_t ) ,
( uint8_t * ) ( d - > block + x * my * mz + y * mz ) ) ;
}
@ -197,13 +200,14 @@ uint32_t Maps::getBlockPtr (uint32_t x, uint32_t y, uint32_t z)
bool Maps : : ReadBlock40d ( uint32_t x , uint32_t y , uint32_t z , mapblock40d * buffer )
{
Process * p = d - > owner ;
if ( d - > d - > shm_start & & d - > maps_module ) // ACCELERATE!
{
SHMMAPSHDR - > x = x ;
SHMMAPSHDR - > y = y ;
SHMMAPSHDR - > z = z ;
volatile uint32_t cmd = Server : : Maps : : MAP_READ_BLOCK_BY_COORDS + ( d - > maps_module < < 16 ) ;
if ( ! g_ pProcess - > SetAndWait ( cmd ) )
if ( ! p- > SetAndWait ( cmd ) )
return false ;
memcpy ( buffer , SHMDATA ( mapblock40d ) , sizeof ( mapblock40d ) ) ;
return true ;
@ -213,13 +217,13 @@ bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
g_ pProcess - > read ( addr + d - > offsets . tile_type_offset , sizeof ( buffer - > tiletypes ) , ( uint8_t * ) buffer - > tiletypes ) ;
g_ pProcess - > read ( addr + d - > offsets . designation_offset , sizeof ( buffer - > designation ) , ( uint8_t * ) buffer - > designation ) ;
g_ pProcess - > read ( addr + d - > offsets . occupancy_offset , sizeof ( buffer - > occupancy ) , ( uint8_t * ) buffer - > occupancy ) ;
g_ pProcess - > read ( addr + d - > offsets . biome_stuffs , sizeof ( biome_indices40d ) , ( uint8_t * ) buffer - > biome_indices ) ;
p- > read ( addr + d - > offsets . tile_type_offset , sizeof ( buffer - > tiletypes ) , ( uint8_t * ) buffer - > tiletypes ) ;
p- > read ( addr + d - > offsets . designation_offset , sizeof ( buffer - > designation ) , ( uint8_t * ) buffer - > designation ) ;
p- > read ( addr + d - > offsets . occupancy_offset , sizeof ( buffer - > occupancy ) , ( uint8_t * ) buffer - > occupancy ) ;
p- > read ( addr + d - > offsets . biome_stuffs , sizeof ( biome_indices40d ) , ( uint8_t * ) buffer - > biome_indices ) ;
buffer - > origin = addr ;
uint32_t addr_of_struct = g_ pProcess - > readDWord ( addr ) ;
buffer - > blockflags . whole = g_ pProcess - > readDWord ( addr_of_struct ) ;
uint32_t addr_of_struct = p- > readDWord ( addr ) ;
buffer - > blockflags . whole = p- > readDWord ( addr_of_struct ) ;
return true ;
}
return false ;
@ -235,7 +239,7 @@ bool Maps::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buff
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
g_pProcess - > read ( addr + d - > offsets . tile_type_offset , sizeof ( tiletypes40d ) , ( uint8_t * ) buffer ) ;
d- > owner - > read ( addr + d - > offsets . tile_type_offset , sizeof ( tiletypes40d ) , ( uint8_t * ) buffer ) ;
return true ;
}
return false ;
@ -246,7 +250,7 @@ bool Maps::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buf
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
g_pProcess - > write ( addr + d - > offsets . tile_type_offset , sizeof ( tiletypes40d ) , ( uint8_t * ) buffer ) ;
d- > owner - > write ( addr + d - > offsets . tile_type_offset , sizeof ( tiletypes40d ) , ( uint8_t * ) buffer ) ;
return true ;
}
return false ;
@ -261,8 +265,9 @@ bool Maps::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit)
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
uint32_t addr_of_struct = g_pProcess - > readDWord ( addr ) ;
dirtybit = g_pProcess - > readDWord ( addr_of_struct ) & 1 ;
Process * p = d - > owner ;
uint32_t addr_of_struct = p - > readDWord ( addr ) ;
dirtybit = p - > readDWord ( addr_of_struct ) & 1 ;
return true ;
}
return false ;
@ -273,11 +278,12 @@ bool Maps::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
uint32_t addr_of_struct = g_pProcess - > readDWord ( addr ) ;
uint32_t dirtydword = g_pProcess - > readDWord ( addr_of_struct ) ;
Process * p = d - > owner ;
uint32_t addr_of_struct = p - > readDWord ( addr ) ;
uint32_t dirtydword = p - > readDWord ( addr_of_struct ) ;
dirtydword & = 0xFFFFFFFE ;
dirtydword | = ( uint32_t ) dirtybit ;
g_ pProcess - > writeDWord ( addr_of_struct , dirtydword ) ;
p- > writeDWord ( addr_of_struct , dirtydword ) ;
return true ;
}
return false ;
@ -289,8 +295,9 @@ bool Maps::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &bloc
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
uint32_t addr_of_struct = g_pProcess - > readDWord ( addr ) ;
blockflags . whole = g_pProcess - > readDWord ( addr_of_struct ) ;
Process * p = d - > owner ;
uint32_t addr_of_struct = p - > readDWord ( addr ) ;
blockflags . whole = p - > readDWord ( addr_of_struct ) ;
return true ;
}
return false ;
@ -300,8 +307,9 @@ bool Maps::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags bloc
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
uint32_t addr_of_struct = g_pProcess - > readDWord ( addr ) ;
g_pProcess - > writeDWord ( addr_of_struct , blockflags . whole ) ;
Process * p = d - > owner ;
uint32_t addr_of_struct = p - > readDWord ( addr ) ;
p - > writeDWord ( addr_of_struct , blockflags . whole ) ;
return true ;
}
return false ;
@ -316,7 +324,7 @@ bool Maps::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
g_pProcess - > read ( addr + d - > offsets . designation_offset , sizeof ( designations40d ) , ( uint8_t * ) buffer ) ;
d- > owner - > read ( addr + d - > offsets . designation_offset , sizeof ( designations40d ) , ( uint8_t * ) buffer ) ;
return true ;
}
return false ;
@ -327,7 +335,7 @@ bool Maps::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
g_pProcess - > write ( addr + d - > offsets . designation_offset , sizeof ( designations40d ) , ( uint8_t * ) buffer ) ;
d- > owner - > write ( addr + d - > offsets . designation_offset , sizeof ( designations40d ) , ( uint8_t * ) buffer ) ;
return true ;
}
return false ;
@ -342,7 +350,7 @@ bool Maps::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *bu
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
g_pProcess - > read ( addr + d - > offsets . occupancy_offset , sizeof ( occupancies40d ) , ( uint8_t * ) buffer ) ;
d- > owner - > read ( addr + d - > offsets . occupancy_offset , sizeof ( occupancies40d ) , ( uint8_t * ) buffer ) ;
return true ;
}
return false ;
@ -353,7 +361,7 @@ bool Maps::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *b
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
g_pProcess - > write ( addr + d - > offsets . occupancy_offset , sizeof ( tiletypes40d ) , ( uint8_t * ) buffer ) ;
d- > owner - > write ( addr + d - > offsets . occupancy_offset , sizeof ( tiletypes40d ) , ( uint8_t * ) buffer ) ;
return true ;
}
return false ;
@ -368,9 +376,9 @@ bool Maps::ReadTemperatures(uint32_t x, uint32_t y, uint32_t z, t_temperatures *
if ( addr )
{
if ( temp1 )
g_pProcess - > read ( addr + d - > offsets . temperature1_offset , sizeof ( t_temperatures ) , ( uint8_t * ) temp1 ) ;
d- > owner - > read ( addr + d - > offsets . temperature1_offset , sizeof ( t_temperatures ) , ( uint8_t * ) temp1 ) ;
if ( temp2 )
g_pProcess - > read ( addr + d - > offsets . temperature2_offset , sizeof ( t_temperatures ) , ( uint8_t * ) temp2 ) ;
d- > owner - > read ( addr + d - > offsets . temperature2_offset , sizeof ( t_temperatures ) , ( uint8_t * ) temp2 ) ;
return true ;
}
return false ;
@ -381,9 +389,9 @@ bool Maps::WriteTemperatures (uint32_t x, uint32_t y, uint32_t z, t_temperatures
if ( addr )
{
if ( temp1 )
g_pProcess - > write ( addr + d - > offsets . temperature1_offset , sizeof ( t_temperatures ) , ( uint8_t * ) temp1 ) ;
d- > owner - > write ( addr + d - > offsets . temperature1_offset , sizeof ( t_temperatures ) , ( uint8_t * ) temp1 ) ;
if ( temp2 )
g_pProcess - > write ( addr + d - > offsets . temperature2_offset , sizeof ( t_temperatures ) , ( uint8_t * ) temp2 ) ;
d- > owner - > write ( addr + d - > offsets . temperature2_offset , sizeof ( t_temperatures ) , ( uint8_t * ) temp2 ) ;
return true ;
}
return false ;
@ -397,7 +405,7 @@ bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices4
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( addr )
{
g_pProcess - > read ( addr + d - > offsets . biome_stuffs , sizeof ( biome_indices40d ) , ( uint8_t * ) buffer ) ;
d- > owner - > read ( addr + d - > offsets . biome_stuffs , sizeof ( biome_indices40d ) , ( uint8_t * ) buffer ) ;
return true ;
}
return false ;
@ -411,6 +419,7 @@ bool Maps::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein>* veins,
t_vein v ;
t_frozenliquidvein fv ;
t_spattervein sv ;
Process * p = d - > owner ;
uint32_t addr = d - > block [ x * d - > y_block_count * d - > z_block_count + y * d - > z_block_count + z ] ;
if ( veins ) veins - > clear ( ) ;
@ -422,19 +431,19 @@ bool Maps::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein>* veins,
{
// veins are stored as a vector of pointers to veins
/*pointer is 4 bytes! we work with a 32bit program here, no matter what architecture we compile khazad for*/
DfVector < uint32_t > p_veins ( d- > d - > p, addr + off . veinvector ) ;
DfVector < uint32_t > p_veins ( p, addr + off . veinvector ) ;
uint32_t size = p_veins . size ( ) ;
// read all veins
for ( uint32_t i = 0 ; i < size ; i + + )
{
// read the vein pointer from the vector
uint32_t temp = p_veins [ i ] ;
uint32_t type = g_ pProcess - > readDWord ( temp ) ;
uint32_t type = p- > readDWord ( temp ) ;
try_again :
if ( veins & & type = = off . vein_mineral_vptr )
{
// read the vein data (dereference pointer)
g_ pProcess - > read ( temp , sizeof ( t_vein ) , ( uint8_t * ) & v ) ;
p- > read ( temp , sizeof ( t_vein ) , ( uint8_t * ) & v ) ;
v . address_of = temp ;
// store it in the vector
veins - > push_back ( v ) ;
@ -442,7 +451,7 @@ try_again:
else if ( ices & & type = = off . vein_ice_vptr )
{
// read the ice vein data (dereference pointer)
g_ pProcess - > read ( temp , sizeof ( t_frozenliquidvein ) , ( uint8_t * ) & fv ) ;
p- > read ( temp , sizeof ( t_frozenliquidvein ) , ( uint8_t * ) & fv ) ;
fv . address_of = temp ;
// store it in the vector
ices - > push_back ( fv ) ;
@ -450,14 +459,14 @@ try_again:
else if ( splatter & & type = = off . vein_spatter_vptr )
{
// read the splatter vein data (dereference pointer)
g_ pProcess - > read ( temp , sizeof ( t_spattervein ) , ( uint8_t * ) & sv ) ;
p- > read ( temp , sizeof ( t_spattervein ) , ( uint8_t * ) & sv ) ;
sv . address_of = temp ;
// store it in the vector
splatter - > push_back ( sv ) ;
}
else
{
string cname = g_ pProcess - > readClassName ( type ) ;
string cname = p- > readClassName ( type ) ;
if ( ices & & cname = = " block_square_event_frozen_liquidst " )
{
off . vein_ice_vptr = type ;
@ -548,6 +557,7 @@ __int16 __userpurge GetGeologicalRegion<ax>(__int16 block_X<cx>, int X<ebx>, __i
bool Maps : : ReadGeology ( vector < vector < uint16_t > > & assign )
{
memory_info * minfo = d - > d - > offset_descriptor ;
Process * p = d - > owner ;
// get needed addresses and offsets. Now this is what I call crazy.
int region_x_offset = minfo - > getAddress ( " region_x " ) ;
int region_y_offset = minfo - > getAddress ( " region_y " ) ;
@ -566,16 +576,16 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
uint16_t worldSizeX , worldSizeY ;
// read position of the region inside DF world
g_ pProcess - > readDWord ( region_x_offset , regionX ) ;
g_ pProcess - > readDWord ( region_y_offset , regionY ) ;
g_ pProcess - > readDWord ( region_z_offset , regionZ ) ;
p- > readDWord ( region_x_offset , regionX ) ;
p- > readDWord ( region_y_offset , regionY ) ;
p- > readDWord ( region_z_offset , regionZ ) ;
// get world size
g_ pProcess - > readWord ( world_size_x , worldSizeX ) ;
g_ pProcess - > readWord ( world_size_y , worldSizeY ) ;
p- > readWord ( world_size_x , worldSizeX ) ;
p- > readWord ( world_size_y , worldSizeY ) ;
// get pointer to first part of 2d array of regions
uint32_t regions = g_ pProcess - > readDWord ( world_regions ) ;
uint32_t regions = p- > readDWord ( world_regions ) ;
// read the geoblock vector
DfVector < uint32_t > geoblocks ( d - > d - > p , world_geoblocks_vector ) ;
@ -595,11 +605,11 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
/// regions are of region_size size
// get pointer to column of regions
uint32_t geoX ;
g_ pProcess - > readDWord ( regions + bioRX * 4 , geoX ) ;
p- > readDWord ( regions + bioRX * 4 , geoX ) ;
// get index into geoblock vector
uint16_t geoindex ;
g_ pProcess - > readWord ( geoX + bioRY * region_size + region_geo_index_offset , geoindex ) ;
p- > readWord ( geoX + bioRY * region_size + region_geo_index_offset , geoindex ) ;
/// geology blocks are assigned to regions from a vector
// get the geoblock from the geoblock vector using the geoindex
@ -608,7 +618,7 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
/// geology blocks have a vector of layer descriptors
// get the vector with pointer to layers
DfVector < uint32_t > geolayers ( d- > d - > p, geoblock_off + geolayer_geoblock_offset ) ; // let's hope
DfVector < uint32_t > geolayers ( p, geoblock_off + geolayer_geoblock_offset ) ; // let's hope
// make sure we don't load crap
assert ( geolayers . size ( ) > 0 & & geolayers . size ( ) < = 16 ) ;
@ -620,7 +630,7 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
// read pointer to a layer
uint32_t geol_offset = geolayers [ j ] ;
// read word at pointer + 2, store in our geology vectors
d - > v_geology [ i ] . push_back ( g_ pProcess - > readWord ( geol_offset + type_inside_geolayer ) ) ;
d - > v_geology [ i ] . push_back ( p- > readWord ( geol_offset + type_inside_geolayer ) ) ;
}
}
assign . clear ( ) ;