1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #4485 from kaja47/opto-isinthemap

Optimize CMap::isInTheMap
This commit is contained in:
Ivan Savenko 2024-08-24 16:06:44 +03:00 committed by GitHub
commit 51fafe66cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View File

@ -332,11 +332,6 @@ bool CMap::isCoastalTile(const int3 & pos) const
return false;
}
bool CMap::isInTheMap(const int3 & pos) const
{
return pos.x >= 0 && pos.y >= 0 && pos.z >= 0 && pos.x < width && pos.y < height && pos.z <= (twoLevel ? 1 : 0);
}
TerrainTile & CMap::getTile(const int3 & tile)
{
assert(isInTheMap(tile));

View File

@ -84,8 +84,15 @@ public:
TerrainTile & getTile(const int3 & tile);
const TerrainTile & getTile(const int3 & tile) const;
bool isCoastalTile(const int3 & pos) const;
bool isInTheMap(const int3 & pos) const;
bool isWaterTile(const int3 & pos) const;
inline bool isInTheMap(const int3 & pos) const
{
// Check whether coord < 0 is done implicitly. Negative signed int overflows to unsigned number larger than all signed ints.
return
static_cast<uint32_t>(pos.x) < static_cast<uint32_t>(width) &&
static_cast<uint32_t>(pos.y) < static_cast<uint32_t>(height) &&
static_cast<uint32_t>(pos.z) <= (twoLevel ? 1 : 0);
}
bool canMoveBetween(const int3 &src, const int3 &dst) const;
bool checkForVisitableDir(const int3 & src, const TerrainTile * pom, const int3 & dst) const;