From e762ae9703d245012da4f7eb0ca9541954031b14 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 2 Jun 2024 09:29:28 +0400 Subject: [PATCH 1/3] Move current music from MechanicsManager to SoundManager --- apps/openmw/mwbase/mechanicsmanager.hpp | 8 -------- apps/openmw/mwmechanics/mechanicsmanagerimp.cpp | 1 - apps/openmw/mwmechanics/mechanicsmanagerimp.hpp | 5 ----- apps/openmw/mwsound/soundmanagerimp.cpp | 5 +++-- apps/openmw/mwsound/soundmanagerimp.hpp | 2 +- 5 files changed, 4 insertions(+), 17 deletions(-) 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/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..cb0d6ac331 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -115,6 +115,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) @@ -307,10 +308,10 @@ namespace MWSound 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); } diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index 2e38215e14..fab6489878 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; From 402e725d879389a27e61df7cf6c7f4b574815796 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 2 Jun 2024 09:44:41 +0400 Subject: [PATCH 2/3] Reset music type to Normal when we are done to scripted music --- apps/openmw/mwsound/soundmanagerimp.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index cb0d6ac331..c741dce24e 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" @@ -305,8 +304,6 @@ 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 (mMusicType == MusicType::MWScript && type != MusicType::MWScript) return; @@ -1073,6 +1070,8 @@ namespace MWSound streamMusicFull(mNextMusic); mNextMusic = VFS::Path::Normalized(); } + else + mMusicType = MusicType::Normal; } else { @@ -1257,7 +1256,7 @@ namespace MWSound void SoundManager::clear() { - SoundManager::stopMusic(); + stopMusic(); for (SoundMap::value_type& snd : mActiveSounds) { From 7b5146e824094ffcffe1678a70e1a1b9cbd031fb Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 2 Jun 2024 13:18:06 +0400 Subject: [PATCH 3/3] Do not allow Lua's "stopMusic" to interrupt MWScript's music --- apps/openmw/mwbase/soundmanager.hpp | 2 ++ apps/openmw/mwlua/soundbindings.cpp | 8 +++++++- apps/openmw/mwsound/soundmanagerimp.cpp | 1 + apps/openmw/mwsound/soundmanagerimp.hpp | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) 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/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index c741dce24e..8848948c1e 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -1257,6 +1257,7 @@ namespace MWSound void SoundManager::clear() { 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 fab6489878..a5e5b2c45f 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -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.