diff --git a/apps/openmw/mwmp/CellController.cpp b/apps/openmw/mwmp/CellController.cpp index e398255e2..2e2f79258 100644 --- a/apps/openmw/mwmp/CellController.cpp +++ b/apps/openmw/mwmp/CellController.cpp @@ -55,36 +55,43 @@ void CellController::updateDedicated(float dt) } } -void CellController::initializeCellLocal(const ESM::Cell& cell) +void CellController::initializeCell(const ESM::Cell& cell) { - MWWorld::CellStore *cellStore = getCell(cell); + std::string mapIndex = cell.getDescription(); - if (!cellStore) return; - - mwmp::Cell *mpCell = new mwmp::Cell(cellStore); + // If this key doesn't exist, create it + if (cellsActive.count(mapIndex) == 0) + { + MWWorld::CellStore *cellStore = getCell(cell); - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Initialized mwmp::Cell %s", mpCell->getDescription().c_str()); + if (!cellStore) return; - mpCell->initializeLocalActors(); + mwmp::Cell *mpCell = new mwmp::Cell(cellStore); + cellsActive[mapIndex] = mpCell; - std::string mapIndex = mpCell->getDescription(); - cellsActive[mapIndex] = mpCell; + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "- Initialized mwmp::Cell %s", mpCell->getDescription().c_str()); + } } -void CellController::readCellFrame(WorldEvent& worldEvent) +void CellController::initializeLocalActors(const ESM::Cell& cell) { - std::string mapIndex = worldEvent.cell.getDescription(); + std::string mapIndex = cell.getDescription(); - // If this key doesn't exist, create it - if (cellsActive.count(mapIndex) == 0) + initializeCell(cell); + + // If this now exists, initialize local actors in it + if (cellsActive.count(mapIndex) > 0) { - MWWorld::CellStore *cellStore = getCell(worldEvent.cell); + cellsActive[mapIndex]->uninitializeDedicatedActors(); + cellsActive[mapIndex]->initializeLocalActors(); + } +} - if (!cellStore) return; +void CellController::readCellFrame(WorldEvent& worldEvent) +{ + std::string mapIndex = worldEvent.cell.getDescription(); - mwmp::Cell *mpCell = new mwmp::Cell(cellStore); - cellsActive[mapIndex] = mpCell; - } + initializeCell(worldEvent.cell); // If this now exists, send it the data if (cellsActive.count(mapIndex) > 0) diff --git a/apps/openmw/mwmp/CellController.hpp b/apps/openmw/mwmp/CellController.hpp index 151a880ed..b85e52136 100644 --- a/apps/openmw/mwmp/CellController.hpp +++ b/apps/openmw/mwmp/CellController.hpp @@ -19,7 +19,8 @@ namespace mwmp void updateLocal(); void updateDedicated(float dt); - void initializeCellLocal(const ESM::Cell& cell); + void initializeCell(const ESM::Cell& cell); + void initializeLocalActors(const ESM::Cell& cell); void readCellFrame(mwmp::WorldEvent& worldEvent); void setLocalActorRecord(std::string actorIndex, std::string cellIndex); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index cab2a11ab..b31a71711 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -859,7 +859,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet) { LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_AUTHORITY about %s", worldEvent.cell.getDescription().c_str()); - //Main::get().getCellController()->initializeCellLocal(worldEvent.cell); + //Main::get().getCellController()->initializeLocalActors(worldEvent.cell); break; }