diff --git a/doomsday/apps/client/include/audio/s_main.h b/doomsday/apps/client/include/audio/s_main.h index 78d3b9bfb8..124710b100 100644 --- a/doomsday/apps/client/include/audio/s_main.h +++ b/doomsday/apps/client/include/audio/s_main.h @@ -67,11 +67,6 @@ void S_Shutdown(void); */ void S_SetupForChangedMap(void); -/** - * Stop all channels and music, delete the entire sample cache. - */ -void S_Reset(void); - void S_StartFrame(void); void S_EndFrame(void); diff --git a/doomsday/apps/client/include/audio/system.h b/doomsday/apps/client/include/audio/system.h index ebd496c526..415ef91446 100644 --- a/doomsday/apps/client/include/audio/system.h +++ b/doomsday/apps/client/include/audio/system.h @@ -41,6 +41,11 @@ class System : public de::System // Systems observe the passage of time. void timeChanged(de::Clock const &) override; + /** + * Stop all channels and music, delete the entire sample cache. + */ + void reset(); + private: DENG2_PRIVATE(d) }; diff --git a/doomsday/apps/client/src/audio/s_main.cpp b/doomsday/apps/client/src/audio/s_main.cpp index bb0a3f0eae..4db9c9bda7 100644 --- a/doomsday/apps/client/src/audio/s_main.cpp +++ b/doomsday/apps/client/src/audio/s_main.cpp @@ -145,14 +145,6 @@ void S_SetupForChangedMap() #endif } -void S_Reset() -{ -#ifdef __CLIENT__ - Sfx_Reset(); -#endif - _api_S.StopMusic(); -} - void S_StartFrame() { #ifdef DD_PROFILE diff --git a/doomsday/apps/client/src/audio/system.cpp b/doomsday/apps/client/src/audio/system.cpp index f251ec707a..f26d67ffc7 100644 --- a/doomsday/apps/client/src/audio/system.cpp +++ b/doomsday/apps/client/src/audio/system.cpp @@ -16,8 +16,17 @@ * http://www.gnu.org/licenses */ +#define DENG_NO_API_MACROS_SOUND + #include "audio/system.h" +#include "api_sound.h" + +#ifdef __CLIENT__ +# include "audio/audiodriver.h" +#endif +#include "audio/s_mus.h" +#include "audio/s_sfx.h" #include using namespace de; @@ -27,15 +36,25 @@ namespace audio { static audio::System *theAudioSystem = nullptr; DENG2_PIMPL(System) +, DENG2_OBSERVES(App, GameUnload) { Instance(Public *i) : Base(i) { theAudioSystem = thisPublic; + + App::app().audienceForGameUnload() += this; } ~Instance() { + App::app().audienceForGameUnload() -= this; + theAudioSystem = nullptr; } + + void aboutToUnloadGame(game::Game const &) + { + self.reset(); + } }; System::System() : d(new Instance(this)) @@ -52,4 +71,12 @@ audio::System &System::get() return *theAudioSystem; } +void System::reset() +{ +#ifdef __CLIENT__ + Sfx_Reset(); +#endif + _api_S.StopMusic(); +} + } // namespace audio diff --git a/doomsday/apps/client/src/dd_main.cpp b/doomsday/apps/client/src/dd_main.cpp index 58e29497b1..c18f30ebb8 100644 --- a/doomsday/apps/client/src/dd_main.cpp +++ b/doomsday/apps/client/src/dd_main.cpp @@ -1364,8 +1364,6 @@ bool App_ChangeGame(Game &game, bool allowReload) } #endif - S_Reset(); - #ifdef __CLIENT__ Demo_StopPlayback(); @@ -2214,7 +2212,7 @@ void DD_UpdateEngineState() LOG_MSG("Updating engine state..."); // Stop playing sounds and music. - S_Reset(); + App_AudioSystem().reset(); #ifdef __CLIENT__ BusyMode_FreezeGameForBusyMode();