[Client] Update CellController to C++11

This commit is contained in:
Koncord 2017-06-27 21:56:40 +08:00
parent 7d4dd2ad1c
commit 7499777b3a

View file

@ -22,6 +22,7 @@ mwmp::CellController::CellController()
{ {
} }
void CellController::updateLocal(bool forceUpdate) void CellController::updateLocal(bool forceUpdate)
{ {
// Loop through Cells, deleting inactive ones and updating LocalActors in active ones // Loop through Cells, deleting inactive ones and updating LocalActors in active ones
@ -47,9 +48,9 @@ void CellController::updateLocal(bool forceUpdate)
// //
// Note: This cannot be combined with the above loop because initializing LocalActors in a Cell before they are // Note: This cannot be combined with the above loop because initializing LocalActors in a Cell before they are
// deleted from their previous one can make their records stay deleted // deleted from their previous one can make their records stay deleted
for (std::map<std::string, mwmp::Cell *>::iterator it = cellsInitialized.begin(); it != cellsInitialized.end(); ++it) for(auto &cell : cellsInitialized)
{ {
mwmp::Cell *mpCell = it->second; mwmp::Cell *mpCell = cell.second;
if (mpCell->shouldInitializeActors == true) if (mpCell->shouldInitializeActors == true)
{ {
mpCell->shouldInitializeActors = false; mpCell->shouldInitializeActors = false;
@ -60,10 +61,8 @@ void CellController::updateLocal(bool forceUpdate)
void CellController::updateDedicated(float dt) void CellController::updateDedicated(float dt)
{ {
for (std::map<std::string, mwmp::Cell *>::iterator it = cellsInitialized.begin(); it != cellsInitialized.end(); ++it) for(const auto &cell : cellsInitialized)
{ cell.second->updateDedicated(dt);
it->second->updateDedicated(dt);
}
} }
void CellController::initializeCell(const ESM::Cell& cell) void CellController::initializeCell(const ESM::Cell& cell)
@ -92,9 +91,7 @@ void CellController::readPositions(ActorList& actorList)
// If this now exists, send it the data // If this now exists, send it the data
if (cellsInitialized.count(mapIndex) > 0) if (cellsInitialized.count(mapIndex) > 0)
{
cellsInitialized[mapIndex]->readPositions(actorList); cellsInitialized[mapIndex]->readPositions(actorList);
}
} }
void CellController::readAnimFlags(ActorList& actorList) void CellController::readAnimFlags(ActorList& actorList)
@ -105,9 +102,7 @@ void CellController::readAnimFlags(ActorList& actorList)
// If this now exists, send it the data // If this now exists, send it the data
if (cellsInitialized.count(mapIndex) > 0) if (cellsInitialized.count(mapIndex) > 0)
{
cellsInitialized[mapIndex]->readAnimFlags(actorList); cellsInitialized[mapIndex]->readAnimFlags(actorList);
}
} }
void CellController::readAnimPlay(ActorList& actorList) void CellController::readAnimPlay(ActorList& actorList)
@ -118,9 +113,7 @@ void CellController::readAnimPlay(ActorList& actorList)
// If this now exists, send it the data // If this now exists, send it the data
if (cellsInitialized.count(mapIndex) > 0) if (cellsInitialized.count(mapIndex) > 0)
{
cellsInitialized[mapIndex]->readAnimPlay(actorList); cellsInitialized[mapIndex]->readAnimPlay(actorList);
}
} }
void CellController::readStatsDynamic(ActorList& actorList) void CellController::readStatsDynamic(ActorList& actorList)
@ -131,9 +124,7 @@ void CellController::readStatsDynamic(ActorList& actorList)
// If this now exists, send it the data // If this now exists, send it the data
if (cellsInitialized.count(mapIndex) > 0) if (cellsInitialized.count(mapIndex) > 0)
{
cellsInitialized[mapIndex]->readStatsDynamic(actorList); cellsInitialized[mapIndex]->readStatsDynamic(actorList);
}
} }
void CellController::readEquipment(ActorList& actorList) void CellController::readEquipment(ActorList& actorList)
@ -144,9 +135,7 @@ void CellController::readEquipment(ActorList& actorList)
// If this now exists, send it the data // If this now exists, send it the data
if (cellsInitialized.count(mapIndex) > 0) if (cellsInitialized.count(mapIndex) > 0)
{
cellsInitialized[mapIndex]->readEquipment(actorList); cellsInitialized[mapIndex]->readEquipment(actorList);
}
} }
void CellController::readSpeech(ActorList& actorList) void CellController::readSpeech(ActorList& actorList)
@ -157,9 +146,7 @@ void CellController::readSpeech(ActorList& actorList)
// If this now exists, send it the data // If this now exists, send it the data
if (cellsInitialized.count(mapIndex) > 0) if (cellsInitialized.count(mapIndex) > 0)
{
cellsInitialized[mapIndex]->readSpeech(actorList); cellsInitialized[mapIndex]->readSpeech(actorList);
}
} }
void CellController::readAttack(ActorList& actorList) void CellController::readAttack(ActorList& actorList)
@ -170,9 +157,7 @@ void CellController::readAttack(ActorList& actorList)
// If this now exists, send it the data // If this now exists, send it the data
if (cellsInitialized.count(mapIndex) > 0) if (cellsInitialized.count(mapIndex) > 0)
{
cellsInitialized[mapIndex]->readAttack(actorList); cellsInitialized[mapIndex]->readAttack(actorList);
}
} }
void CellController::readCellChange(ActorList& actorList) void CellController::readCellChange(ActorList& actorList)
@ -183,9 +168,7 @@ void CellController::readCellChange(ActorList& actorList)
// If this now exists, send it the data // If this now exists, send it the data
if (cellsInitialized.count(mapIndex) > 0) if (cellsInitialized.count(mapIndex) > 0)
{
cellsInitialized[mapIndex]->readCellChange(actorList); cellsInitialized[mapIndex]->readCellChange(actorList);
}
} }
void CellController::setLocalActorRecord(std::string actorIndex, std::string cellIndex) void CellController::setLocalActorRecord(std::string actorIndex, std::string cellIndex)
@ -292,9 +275,7 @@ std::string CellController::generateMapIndex(BaseActor baseActor)
bool CellController::hasLocalAuthority(const ESM::Cell& cell) bool CellController::hasLocalAuthority(const ESM::Cell& cell)
{ {
if (isInitializedCell(cell) && isActiveWorldCell(cell)) if (isInitializedCell(cell) && isActiveWorldCell(cell))
{
return getCell(cell)->hasLocalAuthority(); return getCell(cell)->hasLocalAuthority();
}
return false; return false;
} }
@ -357,15 +338,14 @@ void CellController::openContainer(const MWWorld::Ptr &container, bool loot)
// Record this as the player's current open container // Record this as the player's current open container
Main::get().getLocalPlayer()->storeCurrentContainer(container, loot); Main::get().getLocalPlayer()->storeCurrentContainer(container, loot);
const auto &cellRef = container.getCellRef();
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is opened. Loot: %s", LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is opened. Loot: %s",
container.getCellRef().getRefId().c_str(), container.getCellRef().getRefNum().mIndex, cellRef.getRefId().c_str(), cellRef.getRefNum().mIndex, loot ? "true" : "false");
loot ? "true" : "false");
MWWorld::ContainerStore &cont = container.getClass().getContainerStore(container); for(const auto &ptr : container.getClass().getContainerStore(container))
for (MWWorld::ContainerStoreIterator iter = cont.begin(); iter != cont.end(); iter++)
{ {
int count = iter->getRefData().getCount(); int count = ptr.getRefData().getCount();
const std::string &name = iter->getCellRef().getRefId(); const std::string &name = ptr.getCellRef().getRefId();
LOG_APPEND(Log::LOG_VERBOSE, " - Item. Refid: \"%s\" Count: %d", name.c_str(), count); LOG_APPEND(Log::LOG_VERBOSE, " - Item. Refid: \"%s\" Count: %d", name.c_str(), count);
@ -386,10 +366,10 @@ void CellController::closeContainer(const MWWorld::Ptr &container)
container.getCellRef().getRefNum().mIndex); container.getCellRef().getRefNum().mIndex);
MWWorld::ContainerStore &cont = container.getClass().getContainerStore(container); MWWorld::ContainerStore &cont = container.getClass().getContainerStore(container);
for (MWWorld::ContainerStoreIterator iter = cont.begin(); iter != cont.end(); iter++) for(const auto &ptr : cont)
{ {
LOG_APPEND(Log::LOG_VERBOSE, " - Item. Refid: \"%s\" Count: %d", iter->getCellRef().getRefId().c_str(), LOG_APPEND(Log::LOG_VERBOSE, " - Item. Refid: \"%s\" Count: %d", ptr.getCellRef().getRefId().c_str(),
iter->getRefData().getCount()); ptr.getRefData().getCount());
} }
} }