BACKENDS: Move MixerManager code into ModularMixerBackend

This commit is contained in:
Cameron Cawley 2019-11-30 20:22:19 +00:00 committed by Eugene Sandulenko
parent d1bfa2c4ec
commit b9d2b87085
4 changed files with 52 additions and 22 deletions

View File

@ -22,7 +22,9 @@
#include "backends/modular-backend.h"
#include "backends/audiocd/audiocd.h"
#include "backends/graphics/graphics.h"
#include "backends/mixer/mixer.h"
#include "backends/mutex/mutex.h"
#include "gui/EventRecorder.h"
@ -250,6 +252,31 @@ void ModularGraphicsBackend::displayActivityIconOnOSD(const Graphics::Surface *i
}
ModularMixerBackend::ModularMixerBackend()
:
_mixerManager(0) {
}
ModularMixerBackend::~ModularMixerBackend() {
// _audiocdManager needs to be deleted before _mixerManager to avoid a crash.
delete _audiocdManager;
_audiocdManager = 0;
delete _mixerManager;
_mixerManager = 0;
}
MixerManager *ModularMixerBackend::getMixerManager() {
assert(_mixerManager);
return _mixerManager;
}
Audio::Mixer *ModularMixerBackend::getMixer() {
assert(_mixerManager);
return getMixerManager()->getMixer();
}
ModularMutexBackend::ModularMutexBackend()
:
_mutexManager(0) {

View File

@ -26,6 +26,7 @@
#include "backends/base-backend.h"
class GraphicsManager;
class MixerManager;
class MutexManager;
/**
@ -40,7 +41,6 @@ class MutexManager;
* OSystem::getMillis()
* OSystem::delayMillis()
* OSystem::getTimeAndDate()
* OSystem::getMixer()
* OSystem::quit()
*
* And, it should also initialize all the managers variables
@ -133,6 +133,28 @@ protected:
//@}
};
class ModularMixerBackend : virtual public BaseBackend {
public:
ModularMixerBackend();
virtual ~ModularMixerBackend();
/** @name Sound */
//@{
virtual MixerManager *getMixerManager();
virtual Audio::Mixer *getMixer() override final;
//@}
protected:
/** @name Managers variables */
//@{
MixerManager *_mixerManager;
//@}
};
class ModularMutexBackend : virtual public BaseBackend {
public:
ModularMutexBackend();

View File

@ -81,7 +81,6 @@ OSystem_SDL::OSystem_SDL()
_initedSDLnet(false),
#endif
_logger(0),
_mixerManager(0),
_eventSource(0),
_eventSourceWrapper(nullptr),
_window(0) {
@ -541,11 +540,6 @@ void OSystem_SDL::getTimeAndDate(TimeDate &td) const {
td.tm_wday = t.tm_wday;
}
Audio::Mixer *OSystem_SDL::getMixer() {
assert(_mixerManager);
return getMixerManager()->getMixer();
}
MixerManager *OSystem_SDL::getMixerManager() {
assert(_mixerManager);

View File

@ -36,7 +36,7 @@
/**
* Base OSystem class for all SDL ports.
*/
class OSystem_SDL : public ModularMutexBackend, public ModularGraphicsBackend {
class OSystem_SDL : public ModularMutexBackend, public ModularMixerBackend, public ModularGraphicsBackend {
public:
OSystem_SDL();
virtual ~OSystem_SDL();
@ -48,13 +48,6 @@ public:
*/
virtual void init() override;
/**
* Get the Mixer Manager instance. Not to confuse with getMixer(),
* that returns Audio::Mixer. The Mixer Manager is a SDL wrapper class
* for the Audio::Mixer. Used by other managers.
*/
virtual MixerManager *getMixerManager();
virtual bool hasFeature(Feature f) override;
// Override functions from ModularBackend and OSystem
@ -83,7 +76,7 @@ public:
virtual uint32 getMillis(bool skipRecord = false) override;
virtual void delayMillis(uint msecs) override;
virtual void getTimeAndDate(TimeDate &td) const override;
virtual Audio::Mixer *getMixer() override;
virtual MixerManager *getMixerManager() override;
virtual Common::TimerManager *getTimerManager() override;
virtual Common::SaveFileManager *getSavefileManager() override;
@ -107,12 +100,6 @@ protected:
*/
Common::String _logFilePath;
/**
* Mixer manager that configures and setups SDL for
* the wrapped Audio::Mixer, the true mixer.
*/
MixerManager *_mixerManager;
/**
* The event source we use for obtaining SDL events.
*/