From fe3b6230fc2229fa6f474c872244163c5617ad17 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 21 Aug 2010 11:43:07 +0200 Subject: [PATCH] refactored cell unloading --- apps/openmw/mwworld/world.cpp | 37 +++++++++++++++++++++++------------ apps/openmw/mwworld/world.hpp | 6 +++++- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 38f21d9bc..f6476799f 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -250,6 +250,29 @@ namespace MWWorld throw std::runtime_error ("month out of range"); } + void World::removeScripts (Ptr::CellStore *cell) + { + ScriptList::iterator iter = mLocalScripts.begin(); + + while (iter!=mLocalScripts.end()) + { + if (iter->second.getCell()==cell) + mLocalScripts.erase (iter++); + else + ++iter; + } + } + + void World::unloadCell (CellRenderCollection::iterator iter) + { + removeScripts (iter->first); + mEnvironment.mMechanicsManager->dropActors (iter->first); + iter->second->destroy(); + mEnvironment.mSoundManager->stopSound (iter->first); + delete iter->second; + mActiveCells.erase (iter); + } + World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir, const std::string& master, bool newGame, Environment& environment) : mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0), @@ -532,15 +555,10 @@ namespace MWWorld if (active!=mActiveCells.end()) { - mEnvironment.mMechanicsManager->dropActors (active->first); - active->second->destroy(); - mEnvironment.mSoundManager->stopSound (active->first); - delete active->second; - mActiveCells.erase (active); + unloadCell (active); } // register local scripts - mLocalScripts.clear(); // FIXME won't work with exteriors insertInteriorScripts (*cell); // adjust player @@ -585,15 +603,10 @@ namespace MWWorld if (active!=mActiveCells.end()) { - mEnvironment.mMechanicsManager->dropActors (active->first); - active->second->destroy(); - mEnvironment.mSoundManager->stopSound (active->first); - delete active->second; - mActiveCells.erase (active); + unloadCell (active); } // register local scripts - mLocalScripts.clear(); // FIXME won't work with exteriors insertInteriorScripts (*cell); // adjust player diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 1839ef271..c61ea12ad 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -41,7 +41,7 @@ namespace MWWorld { public: - typedef std::vector > ScriptList; + typedef std::list > ScriptList; private: @@ -77,6 +77,10 @@ namespace MWWorld int getDaysPerMonth (int month) const; + void removeScripts (Ptr::CellStore *cell); + + void unloadCell (CellRenderCollection::iterator iter); + public: World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& master,