Some map module bits

develop
Petr Mrázek 2010-03-05 16:06:02 +01:00
parent 9aedc56186
commit 958ca0e384
3 changed files with 25 additions and 20 deletions

@ -198,7 +198,7 @@ bool API::InitMap()
/*
* --> SHM initialization (if possible) <--
*/
g_pProcess->getModuleIndex("Maps",1,d->maps_module);
g_pProcess->getModuleIndex("Maps",2,d->maps_module);
if(d->maps_module)
{

@ -55,27 +55,11 @@ struct mblock
#define SHMBLOCK ((mapblock40d *)(shm + SHM_HEADER))
void ReadBlockByCoords (void * data)
inline void ReadBlockByAddress (void * data)
{
maps_modulestate * state = (maps_modulestate *) data;
maps_offsets & offsets = state->offsets;
/* map_offset is a pointer to
a pointer to
an X block of pointers to
an Y blocks of pointers to
a Z blocks of pointers to
map blocks
only Z blocks can have NULL pointers? TODO: verify
*/
mblock * *** mapArray = *(mblock * ****)offsets.map_offset;
mblock * block = mapArray[SHMHDR->x][SHMHDR->y][SHMHDR->z];
/*
fprintf(stderr, "map_offset: 0x%x\n", offsets.map_offset);
fprintf(stderr, "x_array: 0x%x\n", mapArray);
fprintf(stderr, "y_array: 0x%x\n", mapArray[SHMHDR->x]);
fprintf(stderr, "z_array: 0x%x\n", mapArray[SHMHDR->x][SHMHDR->y]);
fprintf(stderr, "Readblock: %d %d %d 0x%x\n", SHMHDR->x,SHMHDR->y,SHMHDR->z, block);
*/
mblock * block = (mblock *) SHMHDR->address;
if(block)
{
memcpy(&(SHMBLOCK->tiletypes), ((char *) block) + offsets.tile_type_offset, sizeof(SHMBLOCK->tiletypes));
@ -93,6 +77,23 @@ void ReadBlockByCoords (void * data)
}
}
void ReadBlockByCoords (void * data)
{
maps_modulestate * state = (maps_modulestate *) data;
maps_offsets & offsets = state->offsets;
/* map_offset is a pointer to
a pointer to
an X block of pointers to
an Y blocks of pointers to
a Z blocks of pointers to
map blocks
only Z blocks can have NULL pointers? TODO: verify
*/
mblock * *** mapArray = *(mblock * ****)offsets.map_offset;
SHMHDR->address = (uint32_t) mapArray[SHMHDR->x][SHMHDR->y][SHMHDR->z];
ReadBlockByAddress(data); // I wonder... will this inline properly?
}
DFPP_module InitMaps( void )
{
DFPP_module maps;
@ -108,6 +109,7 @@ DFPP_module InitMaps( void )
maps.set_command(MAP_INIT, FUNCTION, "Supply the module with offsets",InitOffsets,CORE_SUSPENDED);
maps.set_command(MAP_GET_SIZE, FUNCTION, "Get map size in 16x16x1 tile blocks", GetMapSize, CORE_SUSPENDED);
maps.set_command(MAP_READ_BLOCK_BY_COORDS, FUNCTION, "Read the whole block with specified coords", ReadBlockByCoords, CORE_SUSPENDED);
maps.set_command(MAP_READ_BLOCK_BY_ADDRESS, FUNCTION, "Read the whole block from an address", ReadBlockByAddress, CORE_SUSPENDED);
// will it fit into 1MB? We shouldn't assume this is the case
maps.set_command(MAP_READ_BLOCKTREE, FUNCTION,"Get the tree of block pointers as a single structure", NullCommand, CORE_SUSPENDED);

@ -33,7 +33,7 @@ namespace DFHack
namespace Maps
{
#define MAPS_VERSION 1
#define MAPS_VERSION 2
typedef struct
{
uint32_t map_offset;// = d->offset_descriptor->getAddress ("map_data");
@ -89,8 +89,11 @@ enum MAPS_COMMAND
MAP_GET_SIZE, // get the map size in 16x16x1 blocks
MAP_READ_BLOCKTREE, // read the structure of pointers to blocks
MAP_READ_BLOCK_BY_COORDS, // read block by cords
MAP_READ_BLOCK_BY_ADDRESS, // read block by address
MAP_WRITE_BLOCK,
MAP_READ_BLOCKS_3D, // read blocks between two coords (volumetric)
MAP_READ_ALL_BLOCKS, // read the entire map
MAP_REVEAL, // reveal the whole map
NUM_MAPS_CMDS,
};
}