From 8067d6280093b5a7534cf6fec3d3d33ab8374e53 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Thu, 12 Aug 2010 16:29:22 +0200 Subject: [PATCH] Decoupled SoundManager from Interpreter::Context --- apps/openmw/mwscript/interpretercontext.hpp | 1 + apps/openmw/mwscript/soundextensions.cpp | 37 ++++++++++----------- apps/openmw/mwsound/soundmanager.cpp | 20 ++++------- apps/openmw/mwsound/soundmanager.hpp | 22 ++++-------- 4 files changed, 33 insertions(+), 47 deletions(-) diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index e63c4838c..ec3c9eb87 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -51,6 +51,7 @@ namespace MWScript virtual void setLocalFloat (int index, float value); + using Interpreter::Context::messageBox; virtual void messageBox (const std::string& message, const std::vector& buttons); diff --git a/apps/openmw/mwscript/soundextensions.cpp b/apps/openmw/mwscript/soundextensions.cpp index 40229475e..c177a87e3 100644 --- a/apps/openmw/mwscript/soundextensions.cpp +++ b/apps/openmw/mwscript/soundextensions.cpp @@ -25,15 +25,15 @@ namespace MWScript { MWScript::InterpreterContext& context = static_cast (runtime.getContext()); - + std::string file = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); std::string text = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - - context.getSoundManager().say (context.getReference(), file, text, - context); + + context.getSoundManager().say (context.getReference(), file, text); + context.messageBox (text); } }; @@ -46,8 +46,7 @@ namespace MWScript MWScript::InterpreterContext& context = static_cast (runtime.getContext()); - runtime.push (context.getSoundManager().sayDone (context.getReference(), - context)); + runtime.push (context.getSoundManager().sayDone (context.getReference())); } }; @@ -63,7 +62,7 @@ namespace MWScript std::string sound = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - context.getSoundManager().streamMusic (sound, context); + context.getSoundManager().streamMusic (sound); } }; @@ -79,7 +78,7 @@ namespace MWScript std::string sound = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - context.getSoundManager().playSound (sound, 1.0, 1.0, context); + context.getSoundManager().playSound (sound, 1.0, 1.0); } }; @@ -101,7 +100,7 @@ namespace MWScript Interpreter::Type_Float pitch = runtime[0].mFloat; runtime.pop(); - context.getSoundManager().playSound (sound, volume, pitch, context); + context.getSoundManager().playSound (sound, volume, pitch); } }; @@ -122,7 +121,7 @@ namespace MWScript runtime.pop(); context.getSoundManager().playSound3D (context.getReference(), sound, - 1.0, 1.0, mLoop, context); + 1.0, 1.0, mLoop); } }; @@ -149,7 +148,7 @@ namespace MWScript runtime.pop(); context.getSoundManager().playSound3D (context.getReference(), sound, volume, - pitch, mLoop, context); + pitch, mLoop); } }; @@ -166,7 +165,7 @@ namespace MWScript std::string sound = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - context.getSoundManager().stopSound3D (context.getReference(), sound, context); + context.getSoundManager().stopSound3D (context.getReference(), sound); } }; @@ -183,7 +182,7 @@ namespace MWScript runtime.pop(); runtime.push (context.getSoundManager().getSoundPlaying ( - context.getReference(), runtime.getStringLiteral (index), context)); + context.getReference(), runtime.getStringLiteral (index))); } }; @@ -206,7 +205,7 @@ namespace MWScript runtime.pop(); context.getSoundManager().say (context.getWorld().getPtr (id, true), - file, text, context); + file, text); } }; @@ -223,7 +222,7 @@ namespace MWScript runtime.pop(); runtime.push (context.getSoundManager().sayDone ( - context.getWorld().getPtr (id, true), context)); + context.getWorld().getPtr (id, true))); } }; @@ -247,7 +246,7 @@ namespace MWScript runtime.pop(); context.getSoundManager().playSound3D ( - context.getWorld().getPtr (id, true), sound, 1.0, 1.0, mLoop, context); + context.getWorld().getPtr (id, true), sound, 1.0, 1.0, mLoop); } }; @@ -277,7 +276,7 @@ namespace MWScript runtime.pop(); context.getSoundManager().playSound3D ( - context.getWorld().getPtr (id, true), sound, volume, pitch, mLoop, context); + context.getWorld().getPtr (id, true), sound, volume, pitch, mLoop); } }; @@ -298,7 +297,7 @@ namespace MWScript runtime.pop(); context.getSoundManager().stopSound3D ( - context.getWorld().getPtr (id, true), sound, context); + context.getWorld().getPtr (id, true), sound); } }; @@ -319,7 +318,7 @@ namespace MWScript runtime.push (context.getSoundManager().getSoundPlaying ( context.getWorld().getPtr (id, true), - runtime.getStringLiteral (index), context)); + runtime.getStringLiteral (index))); } }; diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 87f6b9bdd..b1a1b54e6 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -1,8 +1,6 @@ #include "soundmanager.hpp" -#include - #include /* Set up the sound manager to use Audiere for input (reading sound @@ -63,25 +61,23 @@ namespace MWSound } void SoundManager::say (MWWorld::Ptr reference, const std::string& filename, - const std::string& text, Interpreter::Context& context) + const std::string& text) { std::cout << "sound effect: " << reference.getRefData().getHandle() << " is speaking" << std::endl; - context.messageBox (text); } - bool SoundManager::sayDone (MWWorld::Ptr reference, Interpreter::Context& context) const + bool SoundManager::sayDone (MWWorld::Ptr reference) const { return false; } - void SoundManager::streamMusic (const std::string& filename, Interpreter::Context& context) + void SoundManager::streamMusic (const std::string& filename) { std::cout << "sound effect: playing music" << filename << std::endl; } - void SoundManager::playSound (const std::string& soundId, float volume, float pitch, - Interpreter::Context& context) + void SoundManager::playSound (const std::string& soundId, float volume, float pitch) { std::cout << "sound effect: playing sound " << soundId @@ -90,7 +86,7 @@ namespace MWSound } void SoundManager::playSound3D (MWWorld::Ptr reference, const std::string& soundId, - float volume, float pitch, bool loop, Interpreter::Context& context) + float volume, float pitch, bool loop) { std::cout << "sound effect: playing sound " << soundId @@ -101,8 +97,7 @@ namespace MWSound mData->mSounds[reference.getRefData().getHandle()] = soundId; } - void SoundManager::stopSound3D (MWWorld::Ptr reference, const std::string& soundId, - Interpreter::Context& context) + void SoundManager::stopSound3D (MWWorld::Ptr reference, const std::string& soundId) { std::cout << "sound effect : stop playing sound " << soundId @@ -111,8 +106,7 @@ namespace MWSound mData->mSounds[reference.getRefData().getHandle()] = ""; } - bool SoundManager::getSoundPlaying (MWWorld::Ptr reference, const std::string& soundId, - Interpreter::Context& context) const + bool SoundManager::getSoundPlaying (MWWorld::Ptr reference, const std::string& soundId) const { std::map::const_iterator iter = mData->mSounds.find (reference.getRefData().getHandle()); diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index e42331223..294804d10 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -6,11 +6,6 @@ #include "../mwworld/ptr.hpp" -namespace Interpreter -{ - class Context; -} - namespace Ogre { class Root; @@ -35,32 +30,29 @@ namespace MWSound ~SoundManager(); void say (MWWorld::Ptr reference, const std::string& filename, - const std::string& text, Interpreter::Context& context); + const std::string& text); ///< Make an actor say some text. /// \param filename name of a sound file in "Sound/Vo/" in the data directory. /// \param text Subtitle - bool sayDone (MWWorld::Ptr reference, Interpreter::Context& context) const; + bool sayDone (MWWorld::Ptr reference) const; ///< Is actor not speaking? - void streamMusic (const std::string& filename, Interpreter::Context& context); + void streamMusic (const std::string& filename); ///< Play a soundifle /// \param filename name of a sound file in "Music/" in the data directory. - void playSound (const std::string& soundId, float volume, float pitch, - Interpreter::Context& context); + void playSound (const std::string& soundId, float volume, float pitch); ///< Play a sound, independently of 3D-position void playSound3D (MWWorld::Ptr reference, const std::string& soundId, - float volume, float pitch, bool loop, Interpreter::Context& context); + float volume, float pitch, bool loop); ///< Play a sound from an object - void stopSound3D (MWWorld::Ptr reference, const std::string& soundId, - Interpreter::Context& context); + void stopSound3D (MWWorld::Ptr reference, const std::string& soundId); ///< Stop the given object from playing the given sound. - bool getSoundPlaying (MWWorld::Ptr reference, const std::string& soundId, - Interpreter::Context& context) const; + bool getSoundPlaying (MWWorld::Ptr reference, const std::string& soundId) const; ///< Is the given sound currently playing on the given object? }; }