Skip to content

Commit

Permalink
Refactor|Audio|Client: audio::System is responsible for sound/music r…
Browse files Browse the repository at this point in the history
…esets
  • Loading branch information
danij-deng committed Aug 6, 2015
1 parent 47053fa commit 53d36b3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
5 changes: 0 additions & 5 deletions doomsday/apps/client/include/audio/s_main.h
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions doomsday/apps/client/include/audio/system.h
Expand Up @@ -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)
};
Expand Down
8 changes: 0 additions & 8 deletions doomsday/apps/client/src/audio/s_main.cpp
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions doomsday/apps/client/src/audio/system.cpp
Expand Up @@ -16,8 +16,17 @@
* http://www.gnu.org/licenses</small>
*/

#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 <de/App>

using namespace de;
Expand All @@ -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))
Expand All @@ -52,4 +71,12 @@ audio::System &System::get()
return *theAudioSystem;
}

void System::reset()
{
#ifdef __CLIENT__
Sfx_Reset();
#endif
_api_S.StopMusic();
}

} // namespace audio
4 changes: 1 addition & 3 deletions doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -1364,8 +1364,6 @@ bool App_ChangeGame(Game &game, bool allowReload)
}
#endif

S_Reset();

#ifdef __CLIENT__
Demo_StopPlayback();

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 53d36b3

Please sign in to comment.