diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp index 0178d30ec..95130ed6e 100644 --- a/apps/openmw/mwmp/Cell.cpp +++ b/apps/openmw/mwmp/Cell.cpp @@ -117,6 +117,16 @@ void Cell::uninitializeLocalActors() localActors.clear(); } +void Cell::uninitializeDedicatedActors() +{ + for (std::map::iterator it = dedicatedActors.begin(); it != dedicatedActors.end(); ++it) + { + Main::get().getCellController()->removeDedicatedActorRecord(it->first); + } + + dedicatedActors.clear(); +} + void Cell::readCellFrame(WorldEvent& worldEvent) { WorldObject worldObject; @@ -138,6 +148,8 @@ void Cell::readCellFrame(WorldEvent& worldEvent) actor->setPtr(ptrFound); dedicatedActors[mapIndex] = actor; + Main::get().getCellController()->setDedicatedActorRecord(mapIndex, getDescription()); + LOG_APPEND(Log::LOG_INFO, "- Initialized DedicatedActor %s", mapIndex.c_str()); } @@ -158,6 +170,11 @@ LocalActor *Cell::getLocalActor(std::string actorIndex) return localActors.at(actorIndex); } +DedicatedActor *Cell::getDedicatedActor(std::string actorIndex) +{ + return dedicatedActors.at(actorIndex); +} + MWWorld::CellStore *Cell::getCellStore() { return store; diff --git a/apps/openmw/mwmp/Cell.hpp b/apps/openmw/mwmp/Cell.hpp index e75b706e1..1a75b7163 100644 --- a/apps/openmw/mwmp/Cell.hpp +++ b/apps/openmw/mwmp/Cell.hpp @@ -17,11 +17,15 @@ namespace mwmp void updateLocal(); void updateDedicated(float dt); + void initializeLocalActors(); void uninitializeLocalActors(); + void uninitializeDedicatedActors(); + void readCellFrame(mwmp::WorldEvent& worldEvent); virtual LocalActor *getLocalActor(std::string actorIndex); + virtual DedicatedActor *getDedicatedActor(std::string actorIndex); MWWorld::CellStore* getCellStore(); std::string getDescription(); diff --git a/apps/openmw/mwmp/CellController.cpp b/apps/openmw/mwmp/CellController.cpp index 3130a5908..e398255e2 100644 --- a/apps/openmw/mwmp/CellController.cpp +++ b/apps/openmw/mwmp/CellController.cpp @@ -14,6 +14,7 @@ using namespace mwmp; std::map CellController::cellsActive; std::map CellController::localActorsToCells; +std::map CellController::dedicatedActorsToCells; mwmp::CellController::CellController() { @@ -34,6 +35,7 @@ void CellController::updateLocal() if (!MWBase::Environment::get().getWorld()->isCellActive(mpCell->getCellStore())) { mpCell->uninitializeLocalActors(); + mpCell->uninitializeDedicatedActors(); cellsActive.erase(it++); } else @@ -116,6 +118,31 @@ LocalActor *CellController::getLocalActor(MWWorld::Ptr ptr) return cellsActive.at(cellIndex)->getLocalActor(actorIndex); } +void CellController::setDedicatedActorRecord(std::string actorIndex, std::string cellIndex) +{ + dedicatedActorsToCells[actorIndex] = cellIndex; +} + +void CellController::removeDedicatedActorRecord(std::string actorIndex) +{ + dedicatedActorsToCells.erase(actorIndex); +} + +bool CellController::hasDedicatedActorRecord(MWWorld::Ptr ptr) +{ + std::string mapIndex = generateMapIndex(ptr); + + return (dedicatedActorsToCells.count(mapIndex) > 0); +} + +DedicatedActor *CellController::getDedicatedActor(MWWorld::Ptr ptr) +{ + std::string actorIndex = generateMapIndex(ptr); + std::string cellIndex = dedicatedActorsToCells.at(actorIndex); + + return cellsActive.at(cellIndex)->getDedicatedActor(actorIndex); +} + std::string CellController::generateMapIndex(MWWorld::Ptr ptr) { std::string mapIndex = ""; diff --git a/apps/openmw/mwmp/CellController.hpp b/apps/openmw/mwmp/CellController.hpp index 670c902a5..151a880ed 100644 --- a/apps/openmw/mwmp/CellController.hpp +++ b/apps/openmw/mwmp/CellController.hpp @@ -25,9 +25,13 @@ namespace mwmp void setLocalActorRecord(std::string actorIndex, std::string cellIndex); void removeLocalActorRecord(std::string actorIndex); bool hasLocalActorRecord(MWWorld::Ptr ptr); - virtual LocalActor *getLocalActor(MWWorld::Ptr ptr); + void setDedicatedActorRecord(std::string actorIndex, std::string cellIndex); + void removeDedicatedActorRecord(std::string actorIndex); + bool hasDedicatedActorRecord(MWWorld::Ptr ptr); + virtual DedicatedActor *getDedicatedActor(MWWorld::Ptr ptr); + std::string generateMapIndex(MWWorld::Ptr ptr); std::string generateMapIndex(mwmp::WorldObject object); @@ -40,6 +44,7 @@ namespace mwmp private: static std::map cellsActive; static std::map localActorsToCells; + static std::map dedicatedActorsToCells; }; }