refactored cell unloading

This commit is contained in:
Marc Zinnschlag 2010-08-21 11:43:07 +02:00
parent b8fee8f1ee
commit fe3b6230fc
2 changed files with 30 additions and 13 deletions

View File

@ -250,6 +250,29 @@ namespace MWWorld
throw std::runtime_error ("month out of range"); 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, World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir,
const std::string& master, bool newGame, Environment& environment) const std::string& master, bool newGame, Environment& environment)
: mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0), : mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0),
@ -532,15 +555,10 @@ namespace MWWorld
if (active!=mActiveCells.end()) if (active!=mActiveCells.end())
{ {
mEnvironment.mMechanicsManager->dropActors (active->first); unloadCell (active);
active->second->destroy();
mEnvironment.mSoundManager->stopSound (active->first);
delete active->second;
mActiveCells.erase (active);
} }
// register local scripts // register local scripts
mLocalScripts.clear(); // FIXME won't work with exteriors
insertInteriorScripts (*cell); insertInteriorScripts (*cell);
// adjust player // adjust player
@ -585,15 +603,10 @@ namespace MWWorld
if (active!=mActiveCells.end()) if (active!=mActiveCells.end())
{ {
mEnvironment.mMechanicsManager->dropActors (active->first); unloadCell (active);
active->second->destroy();
mEnvironment.mSoundManager->stopSound (active->first);
delete active->second;
mActiveCells.erase (active);
} }
// register local scripts // register local scripts
mLocalScripts.clear(); // FIXME won't work with exteriors
insertInteriorScripts (*cell); insertInteriorScripts (*cell);
// adjust player // adjust player

View File

@ -41,7 +41,7 @@ namespace MWWorld
{ {
public: public:
typedef std::vector<std::pair<std::string, Ptr> > ScriptList; typedef std::list<std::pair<std::string, Ptr> > ScriptList;
private: private:
@ -77,6 +77,10 @@ namespace MWWorld
int getDaysPerMonth (int month) const; int getDaysPerMonth (int month) const;
void removeScripts (Ptr::CellStore *cell);
void unloadCell (CellRenderCollection::iterator iter);
public: public:
World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& master, World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& master,