diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-22 13:02:26 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-22 14:32:45 +0100 |
commit | 81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08 (patch) | |
tree | e2619b16a5331e5760d94be389d0a3a01427293f /src/actorspritemanager.cpp | |
parent | d047db79f7034e0e75a85a656d18f40716d197b9 (diff) | |
download | mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.gz mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.bz2 mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.xz mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.zip |
General code cleanups
* Use default member initializers
* Use range-based loops
* Don't use 'else' after 'return'
* Removed some unused includes
* Construct empty strings with std::string() instead of ""
* Clear strings with .clear() instead of assigning ""
* Check whether strings are empty with .empty() instead of comparing to ""
* Removed redundant initializations
Diffstat (limited to 'src/actorspritemanager.cpp')
-rw-r--r-- | src/actorspritemanager.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 0ecc731d..75e3fcc2 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -29,7 +29,7 @@ class FindBeingFunctor { public: - bool operator() (ActorSprite *actor) + bool operator() (ActorSprite *actor) const { if (actor->getType() == ActorSprite::FLOOR_ITEM) return false; @@ -37,7 +37,7 @@ class FindBeingFunctor if (!game) return false; - auto* b = static_cast<Being*>(actor); + auto *b = static_cast<Being*>(actor); uint16_t other_y = y + ((b->getType() == ActorSprite::NPC) ? 1 : 0); const Vector &pos = b->getPosition(); @@ -50,7 +50,7 @@ class FindBeingFunctor uint16_t x, y; ActorSprite::Type type; -} beingFinder; +}; class PlayerNamesLister : public AutoCompleteLister { @@ -63,7 +63,7 @@ class PlayerNamesLister : public AutoCompleteLister continue; auto *being = static_cast<Being *>(actor); - if (being->getType() == Being::PLAYER && being->getName() != "") + if (being->getType() == Being::PLAYER && !being->getName().empty()) names.push_back(being->getName()); } } @@ -82,8 +82,7 @@ class PlayerNPCNamesLister : public AutoCompleteLister auto *being = static_cast<Being *>(actor); if ((being->getType() == Being::PLAYER || - being->getType() == Being::NPC) && - being->getName() != "") + being->getType() == Being::NPC) && !being->getName().empty()) names.push_back(being->getName()); } } @@ -157,12 +156,12 @@ Being *ActorSpriteManager::findBeing(int id) const Being *ActorSpriteManager::findBeing(int x, int y, ActorSprite::Type type) const { + FindBeingFunctor beingFinder; beingFinder.x = x; beingFinder.y = y; beingFinder.type = type; - auto it = find_if(mActors.begin(), mActors.end(), - beingFinder); + auto it = find_if(mActors.begin(), mActors.end(), beingFinder); return (it == mActors.end()) ? nullptr : static_cast<Being*>(*it); } @@ -355,7 +354,7 @@ void ActorSpriteManager::updatePlayerNames() continue; auto *being = static_cast<Being *>(actor); - if (being->getType() == ActorSprite::PLAYER && being->getName() != "") + if (being->getType() == ActorSprite::PLAYER && !being->getName().empty()) being->updateName(); } } |