Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/fix-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Nov 6, 2023
2 parents 4cf85f1 + 4927dfa commit 2c979d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/map/mapcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ std::shared_ptr<Tile> MapCache::getOrCreateTileFromCache(const std::unique_ptr<F
return floor->getTile(x, y);
}

std::unique_lock l(floor->getMutex());

const uint8_t z = floor->getZ();

auto map = static_cast<Map*>(this);
Expand Down
7 changes: 7 additions & 0 deletions src/map/mapcache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct Floor {
z(z) {};

std::shared_ptr<Tile> getTile(uint16_t x, uint16_t y) const {
std::shared_lock sl(mutex);
return tiles[x & FLOOR_MASK][y & FLOOR_MASK].first;
}

Expand All @@ -94,6 +95,7 @@ struct Floor {
}

std::shared_ptr<BasicTile> getTileCache(uint16_t x, uint16_t y) const {
std::shared_lock sl(mutex);
return tiles[x & FLOOR_MASK][y & FLOOR_MASK].second;
}

Expand All @@ -105,8 +107,13 @@ struct Floor {
return z;
}

auto &getMutex() const {
return mutex;
}

private:
std::pair<std::shared_ptr<Tile>, std::shared_ptr<BasicTile>> tiles[FLOOR_SIZE][FLOOR_SIZE] = {};
mutable std::shared_mutex mutex;
uint8_t z { 0 };
};

Expand Down

0 comments on commit 2c979d5

Please sign in to comment.