diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index c4b3776ed6..a27d5ae751 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -58,6 +58,10 @@ add_openmw_dir (mwmechanics mechanicsmanager stat creaturestats magiceffects movement actors drawstate spells ) +add_openmw_dir (mwbase + environment + ) + # Main executable IF(OGRE_STATIC) IF(WIN32) diff --git a/apps/openmw/mwbase/environment.cpp b/apps/openmw/mwbase/environment.cpp new file mode 100644 index 0000000000..43e726e7c8 --- /dev/null +++ b/apps/openmw/mwbase/environment.cpp @@ -0,0 +1,123 @@ + +#include "environment.hpp" + +#include + +MWBase::Environment *MWBase::Environment::sThis = 0; + +MWBase::Environment::Environment() +: mWorld (0), mSoundManager (0), mGlobalScripts (0), mScriptManager (0), mWindowManager (0), + mMechanicsManager (0), mDialogueManager (0), mJournal (0), mFrameDuration (0) +{ + assert (!sThis); + sThis = this; +} + +MWBase::Environment::~Environment() +{ + sThis = 0; +} + +void MWBase::Environment::setWorld (MWWorld::World *world) +{ + mWorld = world; +} + +void MWBase::Environment::setSoundManager (MWSound::SoundManager *soundManager) +{ + mSoundManager = soundManager; +} + +void MWBase::Environment::setGlobalScripts (MWScript::GlobalScripts *globalScripts) +{ + mGlobalScripts = globalScripts; +} + +void MWBase::Environment::setScriptManager (MWScript::ScriptManager *scriptManager) +{ + mScriptManager = scriptManager; +} + +void MWBase::Environment::setWindowManager (MWGui::WindowManager *windowManager) +{ + mWindowManager = windowManager; +} + +void MWBase::Environment::setMechanicsManager (MWMechanics::MechanicsManager *mechanicsManager) +{ + mMechanicsManager = mechanicsManager; +} + +void MWBase::Environment::setDialogueManager (MWDialogue::DialogueManager *dialogueManager) +{ + mDialogueManager = dialogueManager; +} + +void MWBase::Environment::setJournal (MWDialogue::Journal *journal) +{ + mJournal = journal; +} + +void MWBase::Environment::setFrameDuration (float duration) +{ + mFrameDuration = duration; +} + +MWWorld::World *MWBase::Environment::getWorld() const +{ + assert (mWorld); + return mWorld; +} + +MWSound::SoundManager *MWBase::Environment::getSoundManager() const +{ + assert (mSoundManager); + return mSoundManager; +} + +MWScript::GlobalScripts *MWBase::Environment::getGlobalScripts() const +{ + assert (mGlobalScripts); + return mGlobalScripts; +} + +MWScript::ScriptManager *MWBase::Environment::getScriptManager() const +{ + assert (mScriptManager); + return mScriptManager; +} + +MWGui::WindowManager *MWBase::Environment::getWindowManager() const +{ + assert (mWindowManager); + return mWindowManager; +} + +MWMechanics::MechanicsManager *MWBase::Environment::getMechanicsManager() const +{ + assert (mMechanicsManager); + return mMechanicsManager; +} + +MWDialogue::DialogueManager *MWBase::Environment::getDialogueManager() const +{ + assert (mDialogueManager); + return mDialogueManager; +} + +MWDialogue::Journal *MWBase::Environment::getJournal() const +{ + assert (mJournal); + return mJournal; +} + +float MWBase::Environment::getFrameDuration() const +{ + return mFrameDuration; +} + +const MWBase::Environment& MWBase::Environment::get() +{ + assert (sThis); + return *sThis; +} diff --git a/apps/openmw/mwbase/environment.hpp b/apps/openmw/mwbase/environment.hpp new file mode 100644 index 0000000000..9fca704350 --- /dev/null +++ b/apps/openmw/mwbase/environment.hpp @@ -0,0 +1,117 @@ +#ifndef GAME_BASE_INVIRONMENT_H +#define GAME_BASE_INVIRONMENT_H + +namespace MWSound +{ + class SoundManager; +} + +namespace MWScript +{ + class GlobalScripts; + class ScriptManager; +} + +namespace MWGui +{ + class WindowManager; +} + +namespace MWMechanics +{ + class MechanicsManager; +} + +namespace MWDialogue +{ + class DialogueManager; + class Journal; +} + +namespace MWInput +{ + struct MWInputManager; +} + +namespace MWWorld +{ + class World; +} + +namespace MWBase +{ + /// \brief Central hub for mw-subsystems + /// + /// 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 + /// the set* functions. + class Environment + { + static Environment *sThis; + + MWWorld::World *mWorld; + MWSound::SoundManager *mSoundManager; + MWScript::GlobalScripts *mGlobalScripts; + MWScript::ScriptManager *mScriptManager; + MWGui::WindowManager *mWindowManager; + MWMechanics::MechanicsManager *mMechanicsManager; + MWDialogue::DialogueManager *mDialogueManager; + MWDialogue::Journal *mJournal; + float mFrameDuration; + + Environment (const Environment&); + ///< not implemented + + Environment& operator= (const Environment&); + ///< not implemented + + public: + + Environment(); + + ~Environment(); + + void setWorld (MWWorld::World *world); + + void setSoundManager (MWSound::SoundManager *soundManager); + + void setGlobalScripts (MWScript::GlobalScripts *globalScripts); + + void setScriptManager (MWScript::ScriptManager *scriptManager); + + void setWindowManager (MWGui::WindowManager *windowManager); + + void setMechanicsManager (MWMechanics::MechanicsManager *mechanicsManager); + + void setDialogueManager (MWDialogue::DialogueManager *dialogueManager); + + void setJournal (MWDialogue::Journal *journal); + + void setFrameDuration (float duration); + ///< Set length of current frame in seconds. + + MWWorld::World *getWorld() const; + + MWSound::SoundManager *getSoundManager() const; + + MWScript::GlobalScripts *getGlobalScripts() const; + + MWScript::ScriptManager *getScriptManager() const; + + MWGui::WindowManager *getWindowManager() const; + + MWMechanics::MechanicsManager *getMechanicsManager() const; + + MWDialogue::DialogueManager *getDialogueManager() const; + + MWDialogue::Journal *getJournal() const; + + float getFrameDuration() const; + + static const Environment& get(); + ///< Return instance of this class. + }; +} + +#endif