diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 3e6a9ecc0..7fc9d88d6 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -418,6 +418,16 @@ namespace MWBase End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it possible to check whether a cell is active + */ + virtual bool isCellActive(MWWorld::CellStore* cell) = 0; + /* + End of tes3mp addition + */ + virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if the player is standing on \a object virtual bool getActorStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if any actor is standing on \a object virtual bool getPlayerCollidingWith(const MWWorld::ConstPtr& object) = 0; ///< @return true if the player is colliding with \a object diff --git a/apps/openmw/mwmp/CellController.cpp b/apps/openmw/mwmp/CellController.cpp index dc309e10e..725edecb9 100644 --- a/apps/openmw/mwmp/CellController.cpp +++ b/apps/openmw/mwmp/CellController.cpp @@ -8,6 +8,10 @@ #include "CellController.hpp" #include "Main.hpp" #include "LocalPlayer.hpp" +using namespace mwmp; + +std::map CellController::localActors; +std::map CellController::dedicatedActors; mwmp::CellController::CellController() { @@ -19,6 +23,53 @@ mwmp::CellController::~CellController() } +void CellController::update() +{ + for (std::map::iterator it = localActors.begin(); it != localActors.end();) + { + LocalActor *actor = it->second; + + if (!MWBase::Environment::get().getWorld()->isCellActive(getCell(actor->cell))) + { + localActors.erase(it++); + } + else + { + printf("Updating %s\n", it->first.c_str()); + ++it; + } + } +} + +void CellController::initializeLocalActors(const ESM::Cell& cell) +{ + MWWorld::CellStore *cellStore = getCell(cell); + + if (!cellStore) return; + + MWWorld::CellRefList *npcList = cellStore->getNpcs(); + + for (typename MWWorld::CellRefList::List::iterator listIter(npcList->mList.begin()); + listIter != npcList->mList.end(); ++listIter) + { + MWWorld::Ptr ptr(&*listIter, 0); + + std::string mapIndex = generateMapIndex(ptr); + localActors[mapIndex] = new LocalActor(); + localActors[mapIndex]->cell = cell; + printf("Initialized local actor %s\n", mapIndex.c_str()); + } +} + +std::string CellController::generateMapIndex(MWWorld::Ptr ptr) +{ + std::string mapIndex = ""; + mapIndex += ptr.getCellRef().getRefId(); + mapIndex += "-" + std::to_string(ptr.getCellRef().getRefNum().mIndex); + mapIndex += "-" + std::to_string(ptr.getCellRef().getMpNum()); + return mapIndex; +} + int mwmp::CellController::getCellSize() const { return 8192; diff --git a/apps/openmw/mwmp/CellController.hpp b/apps/openmw/mwmp/CellController.hpp index bf59fd05f..dc72e9dfc 100644 --- a/apps/openmw/mwmp/CellController.hpp +++ b/apps/openmw/mwmp/CellController.hpp @@ -1,6 +1,8 @@ #ifndef OPENMW_CELLCONTROLLER_HPP #define OPENMW_CELLCONTROLLER_HPP +#include "LocalActor.hpp" +#include "DedicatedActor.hpp" #include "../mwworld/cellstore.hpp" namespace mwmp @@ -12,12 +14,19 @@ namespace mwmp CellController(); ~CellController(); + void update(); + void initializeLocalActors(const ESM::Cell& cell); + + std::string generateMapIndex(MWWorld::Ptr ptr); int getCellSize() const; - virtual MWWorld::CellStore *getCell(const ESM::Cell& cell); void openContainer(const MWWorld::Ptr& container, bool loot); void closeContainer(const MWWorld::Ptr& container); + + private: + static std::map localActors; + static std::map dedicatedActors; }; } diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index 9d2464b1c..0755340d2 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -210,6 +210,7 @@ void Main::updateWorld(float dt) const else { mLocalPlayer->update(); + mCellController->update(); } } diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index f227390aa..f6f9226c4 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -857,11 +857,10 @@ void Networking::processWorldPacket(RakNet::Packet *packet) } case ID_ACTOR_AUTHORITY: { - MWWorld::CellStore *ptrCellStore = Main::get().getCellController()->getCell(worldEvent.cell); + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_AUTHORITY about %s", worldEvent.cell.getDescription().c_str()); - if (!ptrCellStore) return; + Main::get().getCellController()->initializeLocalActors(worldEvent.cell); - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_AUTHORITY about %s", worldEvent.cell.getDescription().c_str()); break; } case ID_ACTOR_FRAME: diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 5ae907923..8451f11e1 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2368,6 +2368,19 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it possible to check whether a cell is active + */ + bool World::isCellActive(MWWorld::CellStore* cell) + { + return mWorldScene->isCellActive(*cell); + } + /* + End of tes3mp addition + */ + bool World::getPlayerStandingOn (const MWWorld::ConstPtr& object) { MWWorld::Ptr player = getPlayerPtr(); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index ee566595a..cf25c0ebb 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -534,6 +534,16 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it possible to check whether a cell is active + */ + virtual bool isCellActive(MWWorld::CellStore* cell); + /* + End of tes3mp addition + */ + virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object); ///< @return true if the player is standing on \a object virtual bool getActorStandingOn (const MWWorld::ConstPtr& object); ///< @return true if any actor is standing on \a object virtual bool getPlayerCollidingWith(const MWWorld::ConstPtr& object); ///< @return true if the player is colliding with \a object