Adds consistent interface signatures for Maps module

develop
Josh Cooper 2022-04-21 18:13:23 -07:00 committed by Myk
parent ba5aaf897a
commit 9c9a7ef99a
2 changed files with 62 additions and 19 deletions

@ -233,7 +233,8 @@ extern DFHACK_EXPORT bool ReadGeology(std::vector<std::vector<int16_t> > *layer_
/**
* Get pointers to features of a block
*/
extern DFHACK_EXPORT bool ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature * local, t_feature * global);
extern DFHACK_EXPORT bool ReadFeatures(int32_t x, int32_t y, int32_t z, t_feature * local, t_feature * global);
extern DFHACK_EXPORT bool ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature * local, t_feature * global); // todo: deprecate me
/**
* Get pointers to features of an already read block
*/
@ -261,9 +262,11 @@ extern DFHACK_EXPORT bool GetGlobalFeature(t_feature &feature, int32_t index);
*/
/// get size of the map in blocks
extern DFHACK_EXPORT void getSize(uint32_t& x, uint32_t& y, uint32_t& z);
extern DFHACK_EXPORT void getSize(int32_t& x, int32_t& y, int32_t& z);
extern DFHACK_EXPORT void getSize(uint32_t& x, uint32_t& y, uint32_t& z); // todo: deprecate me
/// get size of the map in tiles
extern DFHACK_EXPORT void getTileSize(uint32_t& x, uint32_t& y, uint32_t& z);
extern DFHACK_EXPORT void getTileSize(int32_t& x, int32_t& y, int32_t& z);
extern DFHACK_EXPORT void getTileSize(uint32_t& x, uint32_t& y, uint32_t& z); // todo: deprecate me
/// get the position of the map on world map
extern DFHACK_EXPORT void getPosition(int32_t& x, int32_t& y, int32_t& z);
@ -333,7 +336,8 @@ extern DFHACK_EXPORT bool SortBlockEvents(df::map_block *block,
);
/// remove a block event from the block by address
extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which );
extern DFHACK_EXPORT bool RemoveBlockEvent(int32_t x, int32_t y, int32_t z, df::block_square_event * which );
extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which ); // todo: deprecate me
DFHACK_EXPORT bool canWalkBetween(df::coord pos1, df::coord pos2);
DFHACK_EXPORT bool canStepBetween(df::coord pos1, df::coord pos2);

@ -107,9 +107,9 @@ bool Maps::IsValid ()
}
// getter for map size in blocks
void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
inline void getSizeInline (int32_t& x, int32_t& y, int32_t& z)
{
if (!IsValid())
if (!Maps::IsValid())
{
x = y = z = 0;
return;
@ -118,14 +118,38 @@ void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
y = world->map.y_count_block;
z = world->map.z_count_block;
}
void Maps::getSize (int32_t& x, int32_t& y, int32_t& z)
{
getSizeInline(x, y, z);
}
void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z) //todo: deprecate me
{
int32_t sx, sy, sz;
getSizeInline(sx, sy, sz);
x = uint32_t(sx);
y = uint32_t(sy);
z = uint32_t(sz);
}
// getter for map size in tiles
void Maps::getTileSize (uint32_t& x, uint32_t& y, uint32_t& z)
inline void getTileSizeInline (int32_t& x, int32_t& y, int32_t& z)
{
getSize(x, y, z);
getSizeInline(x, y, z);
x *= 16;
y *= 16;
}
void Maps::getTileSize (int32_t& x, int32_t& y, int32_t& z)
{
getTileSizeInline(x, y, z);
}
void Maps::getTileSize (uint32_t& x, uint32_t& y, uint32_t& z) //todo: deprecate me
{
int32_t sx, sy, sz;
getTileSizeInline(sx, sy, sz);
x = uint32_t(sx);
y = uint32_t(sy);
z = uint32_t(sz);
}
// getter for map position
void Maps::getPosition (int32_t& x, int32_t& y, int32_t& z)
@ -375,12 +399,20 @@ bool GetLocalFeature(t_feature &feature, df::coord2d rgn_pos, int32_t index)
return true;
}
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature *local, t_feature *global)
inline bool ReadFeaturesInline(int32_t x, int32_t y, int32_t z, t_feature *local, t_feature *global)
{
df::map_block *block = getBlock(x,y,z);
df::map_block* block = Maps::getBlock(x, y, z);
if (!block)
return false;
return ReadFeatures(block, local, global);
return Maps::ReadFeatures(block, local, global);
}
bool Maps::ReadFeatures(int32_t x, int32_t y, int32_t z, t_feature *local, t_feature *global)
{
return ReadFeaturesInline(x, y, z, local, global);
}
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, t_feature *local, t_feature *global) //todo: deprecate me
{
return ReadFeaturesInline(int32_t(x), int32_t(y), int32_t(z), local, global);
}
bool Maps::ReadFeatures(df::map_block * block, t_feature * local, t_feature * global)
@ -477,12 +509,11 @@ bool Maps::SortBlockEvents(df::map_block *block,
return true;
}
bool Maps::RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which)
inline bool RemoveBlockEventInline(int32_t x, int32_t y, int32_t z, df::block_square_event * which)
{
df::map_block * block = getBlock(x,y,z);
df::map_block* block = Maps::getBlock(x, y, z);
if (!block)
return false;
int idx = linear_index(block->block_events, which);
if (idx >= 0)
{
@ -493,6 +524,14 @@ bool Maps::RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square
else
return false;
}
inline bool Maps::RemoveBlockEvent(int32_t x, int32_t y, int32_t z, df::block_square_event * which)
{
return RemoveBlockEventInline(x, y, z, which);
}
bool Maps::RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, df::block_square_event * which) //todo: deprecate me
{
return RemoveBlockEventInline(int32_t(x), int32_t(y), int32_t(z), which);
}
static df::coord2d biome_offsets[9] = {
df::coord2d(-1,-1), df::coord2d(0,-1), df::coord2d(1,-1),
@ -658,8 +697,8 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2)
if ( x == 0 && y == 0 )
continue;
df::tiletype* type = Maps::getTileType(df::coord(pos1.x+x,pos1.y+y,pos1.z));
df::tiletype_shape shape1 = ENUM_ATTR(tiletype,shape,*type);
if ( shape1 == tiletype_shape::WALL ) {
df::tiletype_shape shape3 = ENUM_ATTR(tiletype,shape,*type);
if ( shape3 == tiletype_shape::WALL ) {
foundWall = true;
x = 2;
break;
@ -695,8 +734,8 @@ bool Maps::canStepBetween(df::coord pos1, df::coord pos2)
if ( x == 0 && y == 0 )
continue;
df::tiletype* type = Maps::getTileType(df::coord(pos1.x+x,pos1.y+y,pos1.z));
df::tiletype_shape shape1 = ENUM_ATTR(tiletype,shape,*type);
if ( shape1 == tiletype_shape::WALL ) {
df::tiletype_shape shape3 = ENUM_ATTR(tiletype,shape,*type);
if ( shape3 == tiletype_shape::WALL ) {
foundWall = true;
x = 2;
break;