diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 12a5956a9..319c42bbd 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -158,13 +158,7 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager) OMW::Engine::~Engine() { - delete MWBase::Environment::get().getInputManager(); - delete MWBase::Environment::get().getSoundManager(); - delete MWBase::Environment::get().getMechanicsManager(); - delete MWBase::Environment::get().getDialogueManager(); - delete MWBase::Environment::get().getJournal(); - delete MWBase::Environment::get().getScriptManager(); - delete MWBase::Environment::get().getWorld(); + mEnvironment.cleanup(); delete mScriptContext; delete mOgre; } diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 09d6bc820..63464a40d 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -62,6 +62,7 @@ namespace OMW /// \brief Main engine class, that brings together all the components of OpenMW class Engine : private Ogre::FrameListener { + MWBase::Environment mEnvironment; std::string mEncoding; Files::PathContainer mDataDirs; boost::filesystem::path mResDir; @@ -77,7 +78,6 @@ namespace OMW std::string mFocusName; std::map mFallbackMap; - MWBase::Environment mEnvironment; Compiler::Extensions mExtensions; Compiler::Context *mScriptContext; diff --git a/apps/openmw/mwbase/environment.cpp b/apps/openmw/mwbase/environment.cpp index 8e9a9cfce..792e240f4 100644 --- a/apps/openmw/mwbase/environment.cpp +++ b/apps/openmw/mwbase/environment.cpp @@ -3,6 +3,19 @@ #include +#include "../mwinput/inputmanager.hpp" + +#include "../mwscript/scriptmanager.hpp" + +#include "../mwsound/soundmanager.hpp" + +#include "../mwworld/world.hpp" + +#include "../mwdialogue/dialoguemanager.hpp" +#include "../mwdialogue/journal.hpp" + +#include "../mwmechanics/mechanicsmanager.hpp" + MWBase::Environment *MWBase::Environment::sThis = 0; MWBase::Environment::Environment() @@ -15,6 +28,7 @@ MWBase::Environment::Environment() MWBase::Environment::~Environment() { + cleanup(); sThis = 0; } @@ -116,6 +130,30 @@ float MWBase::Environment::getFrameDuration() const return mFrameDuration; } +void MWBase::Environment::cleanup() +{ + delete mInputManager; + mInputManager = 0; + + delete mSoundManager; + mSoundManager = 0; + + delete mMechanicsManager; + mMechanicsManager = 0; + + delete mDialogueManager; + mDialogueManager = 0; + + delete mJournal; + mJournal = 0; + + delete mScriptManager; + mScriptManager = 0; + + delete mWorld; + mWorld = 0; +} + const MWBase::Environment& MWBase::Environment::get() { assert (sThis); diff --git a/apps/openmw/mwbase/environment.hpp b/apps/openmw/mwbase/environment.hpp index a010e7faa..521beee0a 100644 --- a/apps/openmw/mwbase/environment.hpp +++ b/apps/openmw/mwbase/environment.hpp @@ -43,7 +43,7 @@ namespace MWBase /// /// This class allows each mw-subsystem to access any others subsystem's top-level manager class. /// - /// \attention Environment does not take ownership of the manager class instances it is handed over in + /// \attention Environment takes ownership of the manager class instances it is handed over in /// the set* functions. class Environment { @@ -108,6 +108,9 @@ namespace MWBase float getFrameDuration() const; + void cleanup(); + ///< Delete all mw*-subsystems. + static const Environment& get(); ///< Return instance of this class. };