From 08666cabdbe24e3d4b673b69c6f0bc25729411e7 Mon Sep 17 00:00:00 2001 From: Koncord Date: Tue, 27 Jun 2017 22:24:34 +0800 Subject: [PATCH] [Client] Update PlayerList to C++11 --- apps/openmw/mwmp/PlayerList.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwmp/PlayerList.cpp b/apps/openmw/mwmp/PlayerList.cpp index 448002046..0586693b9 100644 --- a/apps/openmw/mwmp/PlayerList.cpp +++ b/apps/openmw/mwmp/PlayerList.cpp @@ -25,9 +25,9 @@ std::map PlayerList::players; void PlayerList::update(float dt) { - for (std::map ::iterator it = players.begin(); it != players.end(); it++) + for (auto &p : players) { - DedicatedPlayer *player = it->second; + DedicatedPlayer *player = p.second; if (player == 0) continue; player->update(dt); @@ -165,8 +165,6 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid) LOG_APPEND(Log::LOG_INFO, "- Deleting NPC record"); npc_store->erase(npc.mId); npc.mId.clear(); - - } creature.mId = players[guid]->ptr.get()->mBase->mId; creature_store->insert(creature); @@ -233,8 +231,8 @@ void PlayerList::disconnectPlayer(RakNet::RakNetGUID guid) void PlayerList::cleanUp() { - for (std::map ::iterator it = players.begin(); it != players.end(); it++) - delete it->second; + for (auto &p : players) + delete p.second; } DedicatedPlayer *PlayerList::getPlayer(RakNet::RakNetGUID guid) @@ -244,15 +242,13 @@ DedicatedPlayer *PlayerList::getPlayer(RakNet::RakNetGUID guid) DedicatedPlayer *PlayerList::getPlayer(const MWWorld::Ptr &ptr) { - std::map ::iterator it = players.begin(); - - for (; it != players.end(); it++) + for (auto &p : players) { - if (it->second == 0 || it->second->getPtr().mRef == 0) + if (p.second == 0 || p.second->getPtr().mRef == 0) continue; string refid = ptr.getCellRef().getRefId(); - if (it->second->getPtr().getCellRef().getRefId() == refid) - return it->second; + if (p.second->getPtr().getCellRef().getRefId() == refid) + return p.second; } return 0; } @@ -273,14 +269,14 @@ bool PlayerList::isDedicatedPlayer(const MWWorld::Ptr &ptr) */ void PlayerList::clearHitAttemptActorId(int actorId) { - for (std::map ::iterator it = players.begin(); it != players.end(); it++) + for (auto &p : players) { - if (it->second == 0 || it->second->getPtr().mRef == 0) + if (p.second == 0 || p.second->getPtr().mRef == 0) continue; - MWMechanics::CreatureStats *playerCreatureStats = &it->second->getPtr().getClass().getCreatureStats(it->second->getPtr()); + MWMechanics::CreatureStats &playerCreatureStats = p.second->getPtr().getClass().getCreatureStats(p.second->getPtr()); - if (playerCreatureStats->getHitAttemptActorId() == actorId) - playerCreatureStats->setHitAttemptActorId(-1); + if (playerCreatureStats.getHitAttemptActorId() == actorId) + playerCreatureStats.setHitAttemptActorId(-1); } }