Skip to content

Commit

Permalink
perf: remove browseField on container destruction (#2677)
Browse files Browse the repository at this point in the history
Instead of checking all the time if there is a browsefield to be
destroyed, why not remove it at the time of its destruction?!

Besides, the linear search of phmap::flat_hash_map is very slow.
  • Loading branch information
mehah committed Jun 15, 2024
1 parent 883c3ff commit 8a2e5f2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
14 changes: 0 additions & 14 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6255,7 +6255,6 @@ void Game::checkCreatureWalk(uint32_t creatureId) {
const auto &creature = getCreatureByID(creatureId);
if (creature && creature->getHealth() > 0) {
creature->onCreatureWalk();
cleanup();
}
}

Expand Down Expand Up @@ -6318,7 +6317,6 @@ void Game::checkCreatures() {
--end;
}
}
cleanup();

index = (index + 1) % EVENT_CREATURECOUNT;
}
Expand Down Expand Up @@ -7967,8 +7965,6 @@ void Game::shutdown() {
map.spawnsNpc.clear();
raids.clear();

cleanup();

if (serviceManager) {
serviceManager->stop();
}
Expand All @@ -7980,16 +7976,6 @@ void Game::shutdown() {
g_logger().info("Done!");
}

void Game::cleanup() {
for (auto it = browseFields.begin(); it != browseFields.end();) {
if (it->second.expired()) {
it = browseFields.erase(it);
} else {
++it;
}
}
}

void Game::addBestiaryList(uint16_t raceid, std::string name) {
auto it = BestiaryList.find(raceid);
if (it != BestiaryList.end()) {
Expand Down
1 change: 0 additions & 1 deletion src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ class Game {

void updatePlayerHelpers(std::shared_ptr<Player> player);

void cleanup();
void shutdown();
void dieSafely(const std::string &errorMsg);
void addBestiaryList(uint16_t raceid, std::string name);
Expand Down
4 changes: 4 additions & 0 deletions src/items/containers/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ std::shared_ptr<Container> Container::create(std::shared_ptr<Tile> tile) {

Container::~Container() {
if (getID() == ITEM_BROWSEFIELD) {
if (getParent() && getParent()->getTile()) {
g_game().browseFields.erase(getParent()->getTile());
}

for (std::shared_ptr<Item> item : itemlist) {
item->setParent(getParent());
}
Expand Down

0 comments on commit 8a2e5f2

Please sign in to comment.