From 0b85829e38b8356e3898757021993fba32f36ea2 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 28 Sep 2019 13:09:03 +0300 Subject: [PATCH] [Client] Make it possible to unload Cells & clear CellStores from World --- apps/openmw/mwbase/world.hpp | 20 ++++++++++++++++++++ apps/openmw/mwworld/cells.cpp | 21 +++++++++++++++++++++ apps/openmw/mwworld/cells.hpp | 11 +++++++++++ apps/openmw/mwworld/worldimp.cpp | 31 +++++++++++++++++++++++++++++++ apps/openmw/mwworld/worldimp.hpp | 20 ++++++++++++++++++++ 5 files changed, 103 insertions(+) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 488b642a7..c10ee2cd5 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -594,6 +594,26 @@ namespace MWBase End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it possible to unload a cell from elsewhere + */ + virtual void unloadCell(const ESM::Cell& cell) = 0; + /* + End of tes3mp addition + */ + + /* + Start of tes3mp addition + + Clear the CellStore for a specific Cell from elsewhere + */ + virtual void clearCellStore(const ESM::Cell& cell) = 0; + /* + End of tes3mp addition + */ + virtual void getActorsStandingOn (const MWWorld::ConstPtr& object, std::vector &actors) = 0; ///< get a list of actors standing on \a object 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 diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index bea5825da..04f6b9848 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -53,6 +53,27 @@ void MWWorld::Cells::clear() mIdCacheIndex = 0; } +/* + Start of tes3mp addition + + Make it possible to clear the CellStore for a specific Cell, + allowing cells to be replaced from elsewhere in the code +*/ +void MWWorld::Cells::clear(const ESM::Cell& cell) +{ + for (auto it = mInteriors.begin(); it != mInteriors.end(); ++it) + { + if (Misc::StringUtils::ciEqual((*it).first, cell.mName)) + { + mInteriors.erase(it); + break; + } + } +} +/* + End of tes3mp addition +*/ + MWWorld::Ptr MWWorld::Cells::getPtrAndCache (const std::string& name, CellStore& cellStore) { Ptr ptr = getPtr (name, cellStore); diff --git a/apps/openmw/mwworld/cells.hpp b/apps/openmw/mwworld/cells.hpp index dce42d996..f2aa0fd59 100644 --- a/apps/openmw/mwworld/cells.hpp +++ b/apps/openmw/mwworld/cells.hpp @@ -47,6 +47,17 @@ namespace MWWorld void clear(); + /* + Start of tes3mp addition + + Make it possible to clear the CellStore for a specific Cell, + allowing cells to be replaced from elsewhere in the code + */ + void clear(const ESM::Cell& cell); + /* + End of tes3mp addition + */ + Cells (const MWWorld::ESMStore& store, std::vector& reader); CellStore *getExterior (int x, int y); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 360048aa9..9c1e46f3a 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2924,6 +2924,37 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it possible to unload a cell from elsewhere + */ + void World::unloadCell(const ESM::Cell& cell) + { + if (isCellActive(cell)) + { + const Scene::CellStoreCollection& activeCells = mWorldScene->getActiveCells(); + mwmp::CellController *cellController = mwmp::Main::get().getCellController(); + mWorldScene->unloadCell(activeCells.find(cellController->getCellStore(cell))); + } + } + /* + End of tes3mp addition + */ + + /* + Start of tes3mp addition + + Clear the CellStore for a specific Cell from elsewhere + */ + void World::clearCellStore(const ESM::Cell& cell) + { + mCells.clear(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 6ec292f4e..8613036f5 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -702,6 +702,26 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it possible to unload a cell from elsewhere + */ + void unloadCell(const ESM::Cell& cell) override; + /* + End of tes3mp addition + */ + + /* + Start of tes3mp addition + + Clear the CellStore for a specific Cell from elsewhere + */ + virtual void clearCellStore(const ESM::Cell& cell) override; + /* + End of tes3mp addition + */ + void getActorsStandingOn (const MWWorld::ConstPtr& object, std::vector &actors) override; ///< get a list of actors standing on \a object bool getPlayerStandingOn (const MWWorld::ConstPtr& object) override; ///< @return true if the player is standing on \a object bool getActorStandingOn (const MWWorld::ConstPtr& object) override; ///< @return true if any actor is standing on \a object