From 81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Thu, 22 Feb 2024 13:02:26 +0100 Subject: 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 --- src/actorspritemanager.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/actorspritemanager.cpp') 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(actor); + auto *b = static_cast(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(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(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(*it); } @@ -355,7 +354,7 @@ void ActorSpriteManager::updatePlayerNames() continue; auto *being = static_cast(actor); - if (being->getType() == ActorSprite::PLAYER && being->getName() != "") + if (being->getType() == ActorSprite::PLAYER && !being->getName().empty()) being->updateName(); } } -- cgit v1.2.3-70-g09d2