moved sound manager from world to engine (first step of another round of refactoring)

This commit is contained in:
Marc Zinnschlag 2010-07-03 15:17:02 +02:00
parent c12752df4d
commit f8cb4c2502
7 changed files with 35 additions and 18 deletions

View file

@ -13,6 +13,8 @@
#include "mwscript/interpretercontext.hpp" #include "mwscript/interpretercontext.hpp"
#include "mwscript/extensions.hpp" #include "mwscript/extensions.hpp"
#include "mwsound/soundmanager.hpp"
#include "world.hpp" #include "world.hpp"
void OMW::Engine::executeLocalScripts() void OMW::Engine::executeLocalScripts()
@ -20,7 +22,7 @@ void OMW::Engine::executeLocalScripts()
for (World::ScriptList::const_iterator iter (mWorld->getLocalScripts().begin()); for (World::ScriptList::const_iterator iter (mWorld->getLocalScripts().begin());
iter!=mWorld->getLocalScripts().end(); ++iter) iter!=mWorld->getLocalScripts().end(); ++iter)
{ {
MWScript::InterpreterContext interpreterContext (*mWorld, iter->second); MWScript::InterpreterContext interpreterContext (*mWorld, *mSoundManager, iter->second);
mScriptManager->run (iter->first, interpreterContext); mScriptManager->run (iter->first, interpreterContext);
} }
} }
@ -52,7 +54,7 @@ void OMW::Engine::processCommands()
} }
OMW::Engine::Engine() OMW::Engine::Engine()
: mWorld(NULL), mDebug (false), mScriptManager (0), mScriptContext (0) : mWorld(NULL), mDebug (false), mSoundManager (0), mScriptManager (0), mScriptContext (0)
{ {
mspCommandServer.reset( mspCommandServer.reset(
new OMW::CommandServer::Server(&mCommandQueue, kCommandServerPort)); new OMW::CommandServer::Server(&mCommandQueue, kCommandServerPort));
@ -62,6 +64,7 @@ OMW::Engine::~Engine()
{ {
// mspCommandServer->stop(); // mspCommandServer->stop();
delete mWorld; delete mWorld;
delete mSoundManager;
delete mScriptManager; delete mScriptManager;
delete mScriptContext; delete mScriptContext;
} }
@ -162,6 +165,8 @@ void OMW::Engine::go()
// Create the world // Create the world
mWorld = new World (mOgre, mDataDir, mMaster, mCellName); mWorld = new World (mOgre, mDataDir, mMaster, mCellName);
mSoundManager = new MWSound::SoundManager;
MWScript::registerExtensions (mExtensions); MWScript::registerExtensions (mExtensions);
mScriptContext = new MWScript::CompilerContextScript; mScriptContext = new MWScript::CompilerContextScript;

View file

@ -13,8 +13,6 @@
#include "components/commandserver/command.hpp" #include "components/commandserver/command.hpp"
#include <components/compiler/extensions.hpp> #include <components/compiler/extensions.hpp>
#include "mwrender/mwscene.hpp"
namespace Compiler namespace Compiler
{ {
class Context; class Context;
@ -25,6 +23,11 @@ namespace MWScript
class ScriptManager; class ScriptManager;
} }
namespace MWSound
{
class SoundManager;
}
namespace OMW namespace OMW
{ {
class World; class World;
@ -46,6 +49,7 @@ namespace OMW
TsDeque<OMW::Command> mCommandQueue; TsDeque<OMW::Command> mCommandQueue;
std::auto_ptr<OMW::CommandServer::Server> mspCommandServer; std::auto_ptr<OMW::CommandServer::Server> mspCommandServer;
MWSound::SoundManager *mSoundManager;
MWScript::ScriptManager *mScriptManager; MWScript::ScriptManager *mScriptManager;
Compiler::Extensions mExtensions; Compiler::Extensions mExtensions;
Compiler::Context *mScriptContext; Compiler::Context *mScriptContext;

View file

@ -9,8 +9,9 @@
namespace MWScript namespace MWScript
{ {
InterpreterContext::InterpreterContext (OMW::World& world, MWScript::Locals *locals) InterpreterContext::InterpreterContext (OMW::World& world,
: mWorld (world), mLocals (locals) MWSound::SoundManager& soundManager, MWScript::Locals *locals)
: mWorld (world), mSoundManager (soundManager), mLocals (locals)
{} {}
int InterpreterContext::getLocalShort (int index) const int InterpreterContext::getLocalShort (int index) const
@ -74,5 +75,10 @@ namespace MWScript
{ {
return mWorld; return mWorld;
} }
MWSound::SoundManager& InterpreterContext::getSoundManager()
{
return mSoundManager;
}
} }

View file

@ -8,6 +8,11 @@ namespace OMW
class World; class World;
} }
namespace MWSound
{
class SoundManager;
}
namespace MWScript namespace MWScript
{ {
struct Locals; struct Locals;
@ -15,11 +20,13 @@ namespace MWScript
class InterpreterContext : public Interpreter::Context class InterpreterContext : public Interpreter::Context
{ {
OMW::World& mWorld; OMW::World& mWorld;
MWSound::SoundManager& mSoundManager;
Locals *mLocals; Locals *mLocals;
public: 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. ///< The ownership of \a locals is not transferred. 0-pointer allowed.
virtual int getLocalShort (int index) const; virtual int getLocalShort (int index) const;
@ -38,6 +45,8 @@ namespace MWScript
const std::vector<std::string>& buttons); const std::vector<std::string>& buttons);
OMW::World& getWorld(); OMW::World& getWorld();
MWSound::SoundManager& getSoundManager();
}; };
} }

View file

@ -11,6 +11,8 @@
#include "../world.hpp" #include "../world.hpp"
#include "soundmanager.hpp"
namespace MWSound namespace MWSound
{ {
namespace Script namespace Script
@ -24,7 +26,7 @@ namespace MWSound
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (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]; int index = runtime[0];
runtime.pop(); runtime.pop();
runtime.push (context.getWorld().getSoundManager().getSoundPlaying ( runtime.push (context.getSoundManager().getSoundPlaying (
"", runtime.getStringLiteral (index), context)); "", runtime.getStringLiteral (index), context));
} }
}; };

View file

@ -123,9 +123,4 @@ namespace OMW
// Cell change not implemented yet. // Cell change not implemented yet.
return false; return false;
} }
MWSound::SoundManager& World::getSoundManager()
{
return mSoundManager;
}
} }

View file

@ -11,7 +11,6 @@
#include "apps/openmw/mwrender/playerpos.hpp" #include "apps/openmw/mwrender/playerpos.hpp"
#include "apps/openmw/mwrender/mwscene.hpp" #include "apps/openmw/mwrender/mwscene.hpp"
#include "mwsound/soundmanager.hpp"
#include "refdata.hpp" #include "refdata.hpp"
@ -49,7 +48,6 @@ namespace OMW
ESM::ESMReader mEsm; ESM::ESMReader mEsm;
ESMS::ESMStore mStore; ESMS::ESMStore mStore;
std::map<std::string, CellStore> mInteriors; std::map<std::string, CellStore> mInteriors;
MWSound::SoundManager mSoundManager;
ScriptList mLocalScripts; ScriptList mLocalScripts;
// not implemented // not implemented
@ -74,8 +72,6 @@ namespace OMW
bool hasCellChanged() const; bool hasCellChanged() const;
///< Has the player moved to a different cell, since the last frame? ///< Has the player moved to a different cell, since the last frame?
MWSound::SoundManager& getSoundManager();
}; };
} }