diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 8c5ee33f7..bcf2de40d 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -106,6 +106,7 @@ OMW::Engine::Engine() : mDebug (false) , mVerboseScripts (false) , mNewGame (false) + , mUseSound (true) , mScriptManager (0) , mScriptContext (0) { @@ -239,7 +240,8 @@ void OMW::Engine::go() mEnvironment.mSoundManager = new MWSound::SoundManager(mOgre.getRoot(), mOgre.getCamera(), mEnvironment.mWorld->getStore(), - (mDataDir / "Sound").file_string()); + (mDataDir / "Sound").file_string(), + mUseSound); // Create script system mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full, diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index bc612d13c..d7420889f 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -59,6 +59,7 @@ namespace OMW bool mDebug; bool mVerboseScripts; bool mNewGame; + bool mUseSound; MWWorld::Environment mEnvironment; MWScript::ScriptManager *mScriptManager; @@ -115,6 +116,9 @@ namespace OMW /// Enable verbose script output void enableVerboseScripts(); + /// Disable all sound + void disableSound() { mUseSound = false; } + /// Start as a new game. void setNewGame(); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index ff3f32e3d..b622b1f27 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -31,6 +31,7 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) ("master", bpo::value()->default_value ("Morrowind"), "master file") ( "debug", "debug mode" ) + ( "nosound", "disable all sound" ) ( "script-verbose", "verbose script output" ) ( "new-game", "activate char gen/new game mechanics" ) ; @@ -64,6 +65,9 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) if (variables.count ("debug")) engine.enableDebugMode(); + + if (variables.count ("nosound")) + engine.disableSound(); if (variables.count ("script-verbose")) engine.enableVerboseScripts(); diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index f8f5eeb00..f9f3dc9cb 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -150,29 +150,37 @@ namespace MWSound SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &store, - const std::string &soundDir) + const std::string &soundDir, + bool useSound) + : mData(NULL) { - mData = new SoundImpl(root, camera, store, soundDir); + if(useSound) + mData = new SoundImpl(root, camera, store, soundDir); } SoundManager::~SoundManager() { - delete mData; + if(mData) + delete mData; } void SoundManager::say (MWWorld::Ptr ptr, const std::string& filename) { // The range values are not tested + if(!mData) return; mData->add(filename, ptr, "_say_sound", 1, 1, 100, 10000, false); } bool SoundManager::sayDone (MWWorld::Ptr ptr) const { + if(!mData) return false; return !mData->isPlaying(ptr, "_say_sound"); } void SoundManager::streamMusic (const std::string& filename) { + if(!mData) return; + // Play the sound and tell it to stream, if possible. TODO: // Store the reference, the jukebox will need to check status, // control volume etc. @@ -184,6 +192,8 @@ namespace MWSound void SoundManager::playSound (const std::string& soundId, float volume, float pitch) { + if(!mData) return; + // Play and forget float min, max; const std::string &file = mData->lookup(soundId, volume, min, max); @@ -199,6 +209,8 @@ namespace MWSound void SoundManager::playSound3D (MWWorld::Ptr ptr, const std::string& soundId, float volume, float pitch, bool loop) { + if(!mData) return; + // Look up the sound in the ESM data float min, max; const std::string &file = mData->lookup(soundId, volume, min, max); @@ -208,21 +220,28 @@ namespace MWSound void SoundManager::stopSound3D (MWWorld::Ptr ptr, const std::string& soundId) { + if(!mData) return; mData->remove(ptr, soundId); } void SoundManager::stopSound (MWWorld::Ptr::CellStore *cell) { + if(!mData) return; mData->removeCell(cell); } bool SoundManager::getSoundPlaying (MWWorld::Ptr ptr, const std::string& soundId) const { + // Mark all sounds as playing, otherwise the scripts will just + // keep trying to play them every frame. + if(!mData) return true; + return mData->isPlaying(ptr, soundId); } void SoundManager::updateObject(MWWorld::Ptr ptr) { + if(!mData) return; mData->updatePositions(ptr); } } diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index 9b4745203..9f99b34b2 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -28,7 +28,7 @@ namespace MWSound public: SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store, - const std::string &soundDir); + const std::string &soundDir, bool useSound); ~SoundManager(); void say (MWWorld::Ptr reference, const std::string& filename);