Add a form of ReadFeature applicable to already read blocks.

develop
Petr Mrázek 2011-03-24 04:39:38 +01:00
parent 4090a378c1
commit d0a171a350
2 changed files with 47 additions and 23 deletions

@ -459,6 +459,7 @@ namespace DFHack
*/
typedef struct
{
DFCoord position;
/// type of the tiles
tiletypes40d tiletypes;
/// flags determining the state of the tiles
@ -552,6 +553,10 @@ namespace DFHack
* Get pointers to features of a block
*/
bool ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature ** local, t_feature ** global);
/**
* Get pointers to features of an already read block
*/
bool ReadFeatures(mapblock40d * block, t_feature ** local, t_feature ** global);
/**
* @deprecated

@ -357,10 +357,6 @@ void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
bool Maps::Finish()
{
if(d->FeaturesStarted)
{
StopFeatures();
}
if (d->block != NULL)
{
delete [] d->block;
@ -396,6 +392,7 @@ 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)
{
buffer->position = DFCoord(x,y,z);
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);
@ -794,13 +791,14 @@ bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature ** local,
{
if(!d->FeaturesStarted) return false;
int16_t loc, glob;
if(ReadFeatures(x,y,z,loc,glob))
{
if(glob != -1)
if(!ReadFeatures(x,y,z,loc,glob)) return false;
if(global && glob != -1)
*global = &(d->v_global_feature[glob]);
else
else if (global)
*global = 0;
if(loc != -1)
if(local && loc != -1)
{
DFCoord foo(x,y,0);
map <DFCoord, std::vector <t_feature* > >::iterator iter = d->m_local_feature.find(foo);
@ -810,13 +808,34 @@ bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature ** local,
}
else *local = 0;
}
else
else if(local)
*local = 0;
return true;
}
bool Maps::ReadFeatures(mapblock40d * block, t_feature ** local, t_feature ** global)
{
if(!block) return false;
if(!d->FeaturesStarted) return false;
DFCoord c = block->position;
c.z = 0;
if(global && block->global_feature != -1)
*global = &(d->v_global_feature[block->global_feature]);
else if (global)
*global = 0;
if(local && block->local_feature != -1)
{
map <DFCoord, std::vector <t_feature* > >::iterator iter = d->m_local_feature.find(c);
if(iter != d->m_local_feature.end())
{
*local = ((*iter).second)[block->local_feature];
}
else *local = 0;
}
else if(local)
*local = 0;
*global = 0;
return false;
return true;
}
bool Maps::SetBlockLocalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t local)