diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 8e7071f50..455ce5f4e 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -13,6 +13,8 @@ #include "mwscript/interpretercontext.hpp" #include "mwscript/extensions.hpp" +#include "mwsound/soundmanager.hpp" + #include "world.hpp" void OMW::Engine::executeLocalScripts() @@ -20,7 +22,7 @@ void OMW::Engine::executeLocalScripts() for (World::ScriptList::const_iterator iter (mWorld->getLocalScripts().begin()); iter!=mWorld->getLocalScripts().end(); ++iter) { - MWScript::InterpreterContext interpreterContext (*mWorld, iter->second); + MWScript::InterpreterContext interpreterContext (*mWorld, *mSoundManager, iter->second); mScriptManager->run (iter->first, interpreterContext); } } @@ -52,7 +54,7 @@ void OMW::Engine::processCommands() } OMW::Engine::Engine() -: mWorld(NULL), mDebug (false), mScriptManager (0), mScriptContext (0) +: mWorld(NULL), mDebug (false), mSoundManager (0), mScriptManager (0), mScriptContext (0) { mspCommandServer.reset( new OMW::CommandServer::Server(&mCommandQueue, kCommandServerPort)); @@ -62,6 +64,7 @@ OMW::Engine::~Engine() { // mspCommandServer->stop(); delete mWorld; + delete mSoundManager; delete mScriptManager; delete mScriptContext; } @@ -162,6 +165,8 @@ void OMW::Engine::go() // Create the world mWorld = new World (mOgre, mDataDir, mMaster, mCellName); + mSoundManager = new MWSound::SoundManager; + MWScript::registerExtensions (mExtensions); mScriptContext = new MWScript::CompilerContextScript; diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 406cf2358..9217835a7 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -13,8 +13,6 @@ #include "components/commandserver/command.hpp" #include -#include "mwrender/mwscene.hpp" - namespace Compiler { class Context; @@ -25,6 +23,11 @@ namespace MWScript class ScriptManager; } +namespace MWSound +{ + class SoundManager; +} + namespace OMW { class World; @@ -46,6 +49,7 @@ namespace OMW TsDeque mCommandQueue; std::auto_ptr mspCommandServer; + MWSound::SoundManager *mSoundManager; MWScript::ScriptManager *mScriptManager; Compiler::Extensions mExtensions; Compiler::Context *mScriptContext; diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 7acd3822e..8edfbf580 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -9,8 +9,9 @@ namespace MWScript { - InterpreterContext::InterpreterContext (OMW::World& world, MWScript::Locals *locals) - : mWorld (world), mLocals (locals) + InterpreterContext::InterpreterContext (OMW::World& world, + MWSound::SoundManager& soundManager, MWScript::Locals *locals) + : mWorld (world), mSoundManager (soundManager), mLocals (locals) {} int InterpreterContext::getLocalShort (int index) const @@ -74,5 +75,10 @@ namespace MWScript { return mWorld; } + + MWSound::SoundManager& InterpreterContext::getSoundManager() + { + return mSoundManager; + } } diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index 983897087..ac5863f1a 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -8,6 +8,11 @@ namespace OMW class World; } +namespace MWSound +{ + class SoundManager; +} + namespace MWScript { struct Locals; @@ -15,11 +20,13 @@ namespace MWScript class InterpreterContext : public Interpreter::Context { OMW::World& mWorld; + MWSound::SoundManager& mSoundManager; Locals *mLocals; public: - InterpreterContext (OMW::World& world, MWScript::Locals *locals); + InterpreterContext (OMW::World& world, MWSound::SoundManager& soundManager, + MWScript::Locals *locals); ///< The ownership of \a locals is not transferred. 0-pointer allowed. virtual int getLocalShort (int index) const; @@ -38,6 +45,8 @@ namespace MWScript const std::vector& buttons); OMW::World& getWorld(); + + MWSound::SoundManager& getSoundManager(); }; } diff --git a/apps/openmw/mwsound/extensions.cpp b/apps/openmw/mwsound/extensions.cpp index 2cf6eb5dc..83177b102 100644 --- a/apps/openmw/mwsound/extensions.cpp +++ b/apps/openmw/mwsound/extensions.cpp @@ -11,6 +11,8 @@ #include "../world.hpp" +#include "soundmanager.hpp" + namespace MWSound { namespace Script @@ -24,7 +26,7 @@ namespace MWSound MWScript::InterpreterContext& context = static_cast (runtime.getContext()); - runtime.push (context.getWorld().getSoundManager().sayDone ("", context)); + runtime.push (context.getSoundManager().sayDone ("", context)); } }; @@ -40,7 +42,7 @@ namespace MWSound int index = runtime[0]; runtime.pop(); - runtime.push (context.getWorld().getSoundManager().getSoundPlaying ( + runtime.push (context.getSoundManager().getSoundPlaying ( "", runtime.getStringLiteral (index), context)); } }; diff --git a/apps/openmw/world.cpp b/apps/openmw/world.cpp index f8c416375..59db2ea9a 100644 --- a/apps/openmw/world.cpp +++ b/apps/openmw/world.cpp @@ -123,9 +123,4 @@ namespace OMW // Cell change not implemented yet. return false; } - - MWSound::SoundManager& World::getSoundManager() - { - return mSoundManager; - } } diff --git a/apps/openmw/world.hpp b/apps/openmw/world.hpp index a5862dec2..fc466cdc6 100644 --- a/apps/openmw/world.hpp +++ b/apps/openmw/world.hpp @@ -11,7 +11,6 @@ #include "apps/openmw/mwrender/playerpos.hpp" #include "apps/openmw/mwrender/mwscene.hpp" -#include "mwsound/soundmanager.hpp" #include "refdata.hpp" @@ -49,7 +48,6 @@ namespace OMW ESM::ESMReader mEsm; ESMS::ESMStore mStore; std::map mInteriors; - MWSound::SoundManager mSoundManager; ScriptList mLocalScripts; // not implemented @@ -74,8 +72,6 @@ namespace OMW bool hasCellChanged() const; ///< Has the player moved to a different cell, since the last frame? - - MWSound::SoundManager& getSoundManager(); }; }