diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-02-04 00:13:47 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-02-04 00:13:47 +0300 |
commit | 8d969b8b7a4178d6a72795a9446ddc7f8e398a00 (patch) | |
tree | bce7f22bf9477cad46488235a497a50a69ce8d08 /src | |
parent | 0d7d3fd2888cf59ed41bc16c3305582ca64e7596 (diff) | |
download | plus-8d969b8b7a4178d6a72795a9446ddc7f8e398a00.tar.gz plus-8d969b8b7a4178d6a72795a9446ddc7f8e398a00.tar.bz2 plus-8d969b8b7a4178d6a72795a9446ddc7f8e398a00.tar.xz plus-8d969b8b7a4178d6a72795a9446ddc7f8e398a00.zip |
Improve search being by id.
Diffstat (limited to 'src')
-rw-r--r-- | src/actormanager.cpp | 48 | ||||
-rw-r--r-- | src/actormanager.h | 4 |
2 files changed, 39 insertions, 13 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp index f305fae8f..98e8ef008 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -192,6 +192,7 @@ class SortBeingFunctor final ActorManager::ActorManager() : mActors(), mDeleteActors(), + mActorsIdMap(), mIdName(), mBlockedBeings(), #ifdef EATHENA_SUPPORT @@ -254,6 +255,8 @@ void ActorManager::setPlayer(LocalPlayer *const player) { localPlayer = player; mActors.insert(player); + if (player) + mActorsIdMap[player->getId()] = player; if (socialWindow) socialWindow->updateAttackFilter(); if (socialWindow) @@ -267,6 +270,9 @@ Being *ActorManager::createBeing(const BeingId id, Being *const being = new Being(id, type, subtype, mMap); mActors.insert(being); + + mActorsIdMap[being->getId()] = being; + if (type == ActorType::Player #ifdef EATHENA_SUPPORT || type == ActorType::Mercenary @@ -334,6 +340,7 @@ FloorItem *ActorManager::createItem(const BeingId id, if (!checkForPickup(floorItem)) floorItem->disableHightlight(); mActors.insert(floorItem); + mActorsIdMap[floorItem->getId()] = floorItem; return floorItem; } @@ -351,6 +358,9 @@ void ActorManager::erase(ActorSprite *const actor) return; mActors.erase(actor); + ActorSpritesMapIterator it = mActorsIdMap.find(actor->getId()); + if (it != mActorsIdMap.end() && (*it).second == actor) + mActorsIdMap.erase(it); } void ActorManager::undelete(const ActorSprite *const actor) @@ -370,16 +380,17 @@ void ActorManager::undelete(const ActorSprite *const actor) Being *ActorManager::findBeing(const BeingId id) const { - for_actors + ActorSpritesMapConstIterator it = mActorsIdMap.find(id); + if (it != mActorsIdMap.end()) { - ActorSprite *const actor = *it; - if (actor->getId() == id && + ActorSprite *const actor = (*it).second; + if (actor && + actor->getId() == id && actor->getType() != ActorType::FloorItem) { return static_cast<Being*>(actor); } } - return nullptr; } @@ -585,18 +596,17 @@ Being *ActorManager::findPortalByTile(const int x, const int y) const FloorItem *ActorManager::findItem(const BeingId id) const { - for_actorsm + ActorSpritesMapConstIterator it = mActorsIdMap.find(id); + if (it != mActorsIdMap.end()) { - if (!*it) - continue; - - if ((*it)->getId() == id && - (*it)->getType() == ActorType::FloorItem) + ActorSprite *const actor = (*it).second; + if (actor && + actor->getId() == id && + actor->getType() == ActorType::FloorItem) { - return static_cast<FloorItem*>(*it); + return static_cast<FloorItem*>(actor); } } - return nullptr; } @@ -889,7 +899,15 @@ void ActorManager::logic() { ActorSprite *actor = *it; mActors.erase(actor); - delete actor; + + if (actor) + { + ActorSpritesMapIterator itr = mActorsIdMap.find(actor->getId()); + if (itr != mActorsIdMap.end() && (*itr).second == actor) + mActorsIdMap.erase(itr); + + delete actor; + } } mDeleteActors.clear(); @@ -913,9 +931,13 @@ void ActorManager::clear() delete *it; mActors.clear(); mDeleteActors.clear(); + mActorsIdMap.clear(); if (localPlayer) + { mActors.insert(localPlayer); + mActorsIdMap[localPlayer->getId()] = localPlayer; + } #ifdef EATHENA_SUPPORT mChars.clear(); diff --git a/src/actormanager.h b/src/actormanager.h index 2738181f7..59f8552d2 100644 --- a/src/actormanager.h +++ b/src/actormanager.h @@ -55,6 +55,9 @@ struct ChatObject; typedef std::set<ActorSprite*> ActorSprites; typedef ActorSprites::iterator ActorSpritesIterator; typedef ActorSprites::const_iterator ActorSpritesConstIterator; +typedef std::map<BeingId, ActorSprite*> ActorSpritesMap; +typedef ActorSpritesMap::iterator ActorSpritesMapIterator; +typedef ActorSpritesMap::const_iterator ActorSpritesMapConstIterator; typedef std::map<BeingId, std::set<std::string> > IdNameMapping; @@ -396,6 +399,7 @@ class ActorManager final: public ConfigListener ActorSprites mActors; ActorSprites mDeleteActors; + ActorSpritesMap mActorsIdMap; IdNameMapping mIdName; std::set<BeingId> mBlockedBeings; #ifdef EATHENA_SUPPORT |