diff --git a/apps/openmw/mwbase/mechanicsmanager.hpp b/apps/openmw/mwbase/mechanicsmanager.hpp index 37586ed33a..4883fa2000 100644 --- a/apps/openmw/mwbase/mechanicsmanager.hpp +++ b/apps/openmw/mwbase/mechanicsmanager.hpp @@ -27,11 +27,6 @@ namespace ESM class ESMWriter; } -namespace MWSound -{ - enum class MusicType; -} - namespace MWWorld { class Ptr; @@ -312,9 +307,6 @@ namespace MWBase virtual float getAngleToPlayer(const MWWorld::Ptr& ptr) const = 0; virtual MWMechanics::GreetingState getGreetingState(const MWWorld::Ptr& ptr) const = 0; virtual bool isTurningToPlayer(const MWWorld::Ptr& ptr) const = 0; - - virtual MWSound::MusicType getMusicType() const = 0; - virtual void setMusicType(MWSound::MusicType type) = 0; }; } diff --git a/apps/openmw/mwbase/soundmanager.hpp b/apps/openmw/mwbase/soundmanager.hpp index 9f1412dcbf..5f96a4e095 100644 --- a/apps/openmw/mwbase/soundmanager.hpp +++ b/apps/openmw/mwbase/soundmanager.hpp @@ -115,6 +115,8 @@ namespace MWBase virtual void stopMusic() = 0; ///< Stops music if it's playing + virtual MWSound::MusicType getMusicType() const = 0; + virtual void streamMusic(VFS::Path::NormalizedView filename, MWSound::MusicType type, float fade = 1.f) = 0; ///< Play a soundifle /// \param filename name of a sound file in the data directory. diff --git a/apps/openmw/mwlua/soundbindings.cpp b/apps/openmw/mwlua/soundbindings.cpp index fbae24ae1e..50b693fe32 100644 --- a/apps/openmw/mwlua/soundbindings.cpp +++ b/apps/openmw/mwlua/soundbindings.cpp @@ -157,7 +157,13 @@ namespace MWLua api["isMusicPlaying"] = []() { return MWBase::Environment::get().getSoundManager()->isMusicPlaying(); }; - api["stopMusic"] = []() { MWBase::Environment::get().getSoundManager()->stopMusic(); }; + api["stopMusic"] = []() { + MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); + if (sndMgr->getMusicType() == MWSound::MusicType::MWScript) + return; + + sndMgr->stopMusic(); + }; lua["openmw_ambient"] = LuaUtil::makeReadOnly(api); return lua["openmw_ambient"]; diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index e9c34407e8..a3761e1b64 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -250,7 +250,6 @@ namespace MWMechanics , mClassSelected(false) , mRaceSelected(false) , mAI(true) - , mMusicType(MWSound::MusicType::Normal) { // buildPlayer no longer here, needs to be done explicitly after all subsystems are up and running } diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index 1ef4d9ab19..4b0126cd34 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -38,8 +38,6 @@ namespace MWMechanics typedef std::map StolenItemsMap; StolenItemsMap mStolenItems; - MWSound::MusicType mMusicType; - public: void buildPlayer(); ///< build player according to stored class/race/birthsign information. Will @@ -245,9 +243,6 @@ namespace MWMechanics GreetingState getGreetingState(const MWWorld::Ptr& ptr) const override; bool isTurningToPlayer(const MWWorld::Ptr& ptr) const override; - MWSound::MusicType getMusicType() const override { return mMusicType; } - void setMusicType(MWSound::MusicType type) override { mMusicType = type; } - private: bool canCommitCrimeAgainst(const MWWorld::Ptr& victim, const MWWorld::Ptr& attacker); bool canReportCrime( diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index 38530d859f..8848948c1e 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -16,7 +16,6 @@ #include #include "../mwbase/environment.hpp" -#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/statemanager.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/world.hpp" @@ -115,6 +114,7 @@ namespace MWSound , mOutput(std::make_unique(*this)) , mWaterSoundUpdater(makeWaterSoundUpdaterSettings()) , mSoundBuffers(*mOutput) + , mMusicType(MWSound::MusicType::Normal) , mListenerUnderwater(false) , mListenerPos(0, 0, 0) , mListenerDir(1, 0, 0) @@ -304,13 +304,11 @@ namespace MWSound void SoundManager::streamMusic(VFS::Path::NormalizedView filename, MusicType type, float fade) { - const auto mechanicsManager = MWBase::Environment::get().getMechanicsManager(); - // Can not interrupt scripted music by built-in playlists - if (mechanicsManager->getMusicType() == MusicType::MWScript && type != MusicType::MWScript) + if (mMusicType == MusicType::MWScript && type != MusicType::MWScript) return; - mechanicsManager->setMusicType(type); + mMusicType = type; advanceMusic(filename, fade); } @@ -1072,6 +1070,8 @@ namespace MWSound streamMusicFull(mNextMusic); mNextMusic = VFS::Path::Normalized(); } + else + mMusicType = MusicType::Normal; } else { @@ -1256,7 +1256,8 @@ namespace MWSound void SoundManager::clear() { - SoundManager::stopMusic(); + stopMusic(); + mMusicType = MusicType::Normal; for (SoundMap::value_type& snd : mActiveSounds) { diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index 2e38215e14..a5e5b2c45f 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -86,7 +86,7 @@ namespace MWSound TrackList mActiveTracks; StreamPtr mMusic; - VFS::Path::Normalized mCurrentPlaylist; + MusicType mMusicType; bool mListenerUnderwater; osg::Vec3f mListenerPos; @@ -169,6 +169,8 @@ namespace MWSound void stopMusic() override; ///< Stops music if it's playing + MWSound::MusicType getMusicType() const override { return mMusicType; } + void streamMusic(VFS::Path::NormalizedView filename, MWSound::MusicType type, float fade = 1.f) override; ///< Play a soundifle /// \param filename name of a sound file in the data directory.