Skip to content

Commit

Permalink
Move spectator caches to anonymous namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ranisalt committed Sep 8, 2024
1 parent 0504a99 commit 1db58b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
13 changes: 11 additions & 2 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

extern Game g_game;

namespace {

using SpectatorCache = boost::unordered_flat_map<Position, Spectators>;

SpectatorCache spectatorCache;
SpectatorCache playersSpectatorCache;

} // namespace

bool Map::loadMap(const std::string& identifier, bool loadHouses)
{
IOMap loader;
Expand Down Expand Up @@ -472,9 +481,9 @@ void Map::getSpectators(Spectators& spectators, const Position& centerPos, bool
}
}

void Map::clearSpectatorCache() { spectatorCache.clear(); }
void tfs::map::clearSpectatorCache() { spectatorCache.clear(); }

void Map::clearPlayersSpectatorCache() { playersSpectatorCache.clear(); }
void tfs::map::clearPlayersSpectatorCache() { playersSpectatorCache.clear(); }

bool Map::canThrowObjectTo(const Position& fromPos, const Position& toPos, bool checkLineOfSight /*= true*/,
bool sameFloor /*= false*/, int32_t rangex /*= Map::maxClientViewportX*/,
Expand Down
15 changes: 7 additions & 8 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class AStarNodes
int_fast32_t closedNodes;
};

using SpectatorCache = boost::unordered_flat_map<Position, Spectators>;

static constexpr int32_t FLOOR_BITS = 3;
static constexpr int32_t FLOOR_SIZE = (1 << FLOOR_BITS);
static constexpr int32_t FLOOR_MASK = (FLOOR_SIZE - 1);
Expand Down Expand Up @@ -206,9 +204,6 @@ class Map
bool onlyPlayers = false, int32_t minRangeX = 0, int32_t maxRangeX = 0, int32_t minRangeY = 0,
int32_t maxRangeY = 0);

void clearSpectatorCache();
void clearPlayersSpectatorCache();

/**
* Checks if you can throw an object to that position
* \param fromPos from Source point
Expand Down Expand Up @@ -257,9 +252,6 @@ class Map
Houses houses;

private:
SpectatorCache spectatorCache;
SpectatorCache playersSpectatorCache;

QTreeNode root;

std::filesystem::path spawnfile;
Expand All @@ -277,4 +269,11 @@ class Map
friend class IOMap;
};

namespace tfs::map {

void clearSpectatorCache();
void clearPlayersSpectatorCache();

} // namespace tfs::map

#endif // FS_MAP_H
12 changes: 6 additions & 6 deletions src/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,9 @@ void Tile::addThing(int32_t, Thing* thing)
{
Creature* creature = thing->getCreature();
if (creature) {
g_game.map.clearSpectatorCache();
tfs::map::clearSpectatorCache();
if (creature->getPlayer()) {
g_game.map.clearPlayersSpectatorCache();
tfs::map::clearPlayersSpectatorCache();
}

creature->setParent(this);
Expand Down Expand Up @@ -1055,9 +1055,9 @@ void Tile::removeThing(Thing* thing, uint32_t count)
if (creatures) {
auto it = std::find(creatures->begin(), creatures->end(), thing);
if (it != creatures->end()) {
g_game.map.clearSpectatorCache();
tfs::map::clearSpectatorCache();
if (creature->getPlayer()) {
g_game.map.clearPlayersSpectatorCache();
tfs::map::clearPlayersSpectatorCache();
}

creatures->erase(it);
Expand Down Expand Up @@ -1429,9 +1429,9 @@ void Tile::internalAddThing(uint32_t, Thing* thing)

Creature* creature = thing->getCreature();
if (creature) {
g_game.map.clearSpectatorCache();
tfs::map::clearSpectatorCache();
if (creature->getPlayer()) {
g_game.map.clearPlayersSpectatorCache();
tfs::map::clearPlayersSpectatorCache();
}

CreatureVector* creatures = makeCreatures();
Expand Down

0 comments on commit 1db58b9

Please sign in to comment.