Skip to content

Commit

Permalink
BACKENDS: Unify AudioCD manager instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jun 6, 2011
1 parent 338a859 commit afb06b5
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 65 deletions.
9 changes: 0 additions & 9 deletions backends/base-backend.cpp
Expand Up @@ -25,7 +25,6 @@

#include "backends/base-backend.h"
#include "backends/events/default/default-events.h"
#include "backends/audiocd/default/default-audiocd.h"
#include "gui/message.h"

void BaseBackend::displayMessageOnOSD(const char *msg) {
Expand Down Expand Up @@ -69,11 +68,9 @@ void BaseBackend::fillScreen(uint32 col) {
#endif

BaseBackend::BaseBackend() {
_audiocdManager = 0;
}

BaseBackend::~BaseBackend() {
delete _audiocdManager;
}

Common::SeekableReadStream *BaseBackend::createConfigReadStream() {
Expand All @@ -90,11 +87,5 @@ Common::WriteStream *BaseBackend::createConfigWriteStream() {
#endif
}

AudioCDManager *BaseBackend::getAudioCDManager() {
if (!_audiocdManager)
_audiocdManager = new DefaultAudioCDManager();
return _audiocdManager;
}

void BaseBackend::resetGraphicsScale() {
}
5 changes: 0 additions & 5 deletions backends/base-backend.h
Expand Up @@ -38,12 +38,7 @@ class BaseBackend : public OSystem, Common::EventSource {
virtual Common::SeekableReadStream *createConfigReadStream();
virtual Common::WriteStream *createConfigWriteStream();

virtual AudioCDManager *getAudioCDManager();

virtual void resetGraphicsScale();

protected:
AudioCDManager *_audiocdManager;
};


Expand Down
11 changes: 1 addition & 10 deletions backends/modular-backend.cpp
Expand Up @@ -25,7 +25,6 @@
#include "backends/modular-backend.h"

#include "backends/fs/fs-factory.h"
#include "backends/audiocd/audiocd.h"
#include "backends/graphics/graphics.h"
#include "backends/mutex/mutex.h"

Expand All @@ -42,8 +41,7 @@ ModularBackend::ModularBackend()
_timerManager(0),
_mutexManager(0),
_graphicsManager(0),
_mixer(0),
_audiocdManager(0) {
_mixer(0) {

}

Expand All @@ -56,8 +54,6 @@ ModularBackend::~ModularBackend() {
_eventManager = 0;
delete _mixer;
_mixer = 0;
delete _audiocdManager;
_audiocdManager = 0;
delete _savefileManager;
_savefileManager = 0;
delete _timerManager;
Expand Down Expand Up @@ -257,11 +253,6 @@ Audio::Mixer *ModularBackend::getMixer() {
return (Audio::Mixer *)_mixer;
}

AudioCDManager *ModularBackend::getAudioCDManager() {
assert(_audiocdManager);
return _audiocdManager;
}

void ModularBackend::displayMessageOnOSD(const char *msg) {
_graphicsManager->displayMessageOnOSD(msg);
}
Expand Down
8 changes: 0 additions & 8 deletions backends/modular-backend.h
Expand Up @@ -135,13 +135,6 @@ class ModularBackend : public OSystem {

//@}

/** @name Audio CD */
//@{

virtual AudioCDManager *getAudioCDManager();

//@}

/** @name Miscellaneous */
//@{

Expand All @@ -163,7 +156,6 @@ class ModularBackend : public OSystem {
MutexManager *_mutexManager;
GraphicsManager *_graphicsManager;
Audio::Mixer *_mixer;
AudioCDManager *_audiocdManager;

//@}
};
Expand Down
2 changes: 2 additions & 0 deletions backends/platform/android/android.cpp
Expand Up @@ -388,6 +388,8 @@ void OSystem_Android::initBackend() {
warning("couldn't renice the main thread");

JNI::setReadyForEvents(true);

BaseBackend::initBackend();
}

void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const {
Expand Down
3 changes: 0 additions & 3 deletions backends/platform/dc/dc.h
Expand Up @@ -161,8 +161,6 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Palette
// Returns true if an event was retrieved.
bool pollEvent(Common::Event &event);

AudioCDManager *getAudioCDManager() { return _cdManager; }

// Quit
void quit();

Expand Down Expand Up @@ -206,7 +204,6 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Palette
Audio::MixerImpl *_mixer;
DefaultTimerManager *_timer;
SoftKeyboard _softkbd;
DCCDManager *_cdManager;

int _ms_cur_x, _ms_cur_y, _ms_cur_w, _ms_cur_h, _ms_old_x, _ms_old_y;
int _ms_hotspot_x, _ms_hotspot_y, _ms_visible, _devpoll, _last_screen_refresh;
Expand Down
4 changes: 3 additions & 1 deletion backends/platform/dc/dcmain.cpp
Expand Up @@ -63,7 +63,9 @@ void OSystem_Dreamcast::initBackend()
_mixer = new Audio::MixerImpl(this, sampleRate);
_mixer->setReady(true);

_cdManager = new DCCDManager();
_audiocdManager = new DCCDManager();

BaseBackend::initBackend();
}


Expand Down
9 changes: 8 additions & 1 deletion backends/platform/ds/arm9/source/osystem_ds.cpp
Expand Up @@ -41,6 +41,8 @@
#include "touchkeyboard.h"
#include "backends/fs/ds/ds-fs-factory.h"

#include "backends/audiocd/default/default-audiocd.h"

#ifdef ENABLE_AGI
#include "wordcompletion.h"
#endif
Expand Down Expand Up @@ -118,7 +120,12 @@ void OSystem_DS::initBackend() {
_mixer = new Audio::MixerImpl(this, DS::getSoundFrequency());
_mixer->setReady(true);

OSystem::initBackend();
/* TODO/FIXME: The NDS should use a custom AudioCD manager instance!
if (!_audiocdManager)
_audiocdManager = new DSAudioCDManager();
*/

BaseBackend::initBackend();
}

bool OSystem_DS::hasFeature(Feature f) {
Expand Down
2 changes: 1 addition & 1 deletion backends/platform/iphone/osys_main.cpp
Expand Up @@ -101,7 +101,7 @@ void OSystem_IPHONE::initBackend() {

setTimerCallback(&OSystem_IPHONE::timerHandler, 10);

OSystem::initBackend();
BaseBackend::initBackend();
}

bool OSystem_IPHONE::hasFeature(Feature f) {
Expand Down
3 changes: 1 addition & 2 deletions backends/platform/n64/osys_n64_base.cpp
Expand Up @@ -194,8 +194,7 @@ void OSystem_N64::initBackend() {

setupMixer();

OSystem::initBackend();

BaseBackend::initBackend();
}

bool OSystem_N64::hasFeature(Feature f) {
Expand Down
3 changes: 1 addition & 2 deletions backends/platform/null/null.cpp
Expand Up @@ -78,7 +78,6 @@ void OSystem_NULL::initBackend() {
_eventManager = new DefaultEventManager(this);
_savefileManager = new DefaultSaveFileManager();
_graphicsManager = new NullGraphicsManager();
_audiocdManager = new DefaultAudioCDManager();
_mixer = new Audio::MixerImpl(this, 22050);

((Audio::MixerImpl *)_mixer)->setReady(false);
Expand All @@ -87,7 +86,7 @@ void OSystem_NULL::initBackend() {
// this way; they need to be hooked into the system somehow to
// be functional. Of course, can't do that in a NULL backend :).

OSystem::initBackend();
BaseBackend::initBackend();
}

bool OSystem_NULL::pollEvent(Common::Event &event) {
Expand Down
43 changes: 25 additions & 18 deletions backends/platform/ps2/systemps2.cpp
Expand Up @@ -33,36 +33,42 @@
#include <assert.h>
#include <iopcontrol.h>
#include <iopheap.h>
#include "common/scummsys.h"
#include "engines/engine.h"
#include "backends/platform/ps2/systemps2.h"
#include "backends/platform/ps2/Gs2dScreen.h"
#include "backends/platform/ps2/ps2input.h"
#include "backends/platform/ps2/irxboot.h"

#include <sjpcm.h>
#include <libhdd.h>
#include "backends/platform/ps2/savefilemgr.h"
#include "common/file.h"
#include "backends/platform/ps2/sysdefs.h"
#include "backends/platform/ps2/fileio.h"
#include <libmc.h>
#include <libpad.h>
#include "backends/platform/ps2/cd.h"
#include <fileXio_rpc.h>
#include "backends/platform/ps2/asyncfio.h"
#include "eecodyvdfs.h"
#include "graphics/surface.h"
#include "graphics/font.h"
#include "backends/timer/default/default-timer.h"
#include "audio/mixer_intern.h"

#include "common/config-manager.h"
#include "common/events.h"
#include "common/file.h"
#include "common/scummsys.h"

#include "backends/platform/ps2/asyncfio.h"
#include "backends/platform/ps2/cd.h"
#include "backends/platform/ps2/fileio.h"
#include "backends/platform/ps2/Gs2dScreen.h"
#include "backends/platform/ps2/irxboot.h"
#include "backends/platform/ps2/ps2debug.h"
#include "backends/fs/ps2/ps2-fs-factory.h"
#include "backends/platform/ps2/ps2input.h"
#include "backends/platform/ps2/savefilemgr.h"
#include "backends/platform/ps2/sysdefs.h"
#include "backends/platform/ps2/systemps2.h"

#include "backends/fs/ps2/ps2-fs-factory.h"
#include "backends/plugins/ps2/ps2-provider.h"

#include "backends/saves/default/default-saves.h"
#include "common/config-manager.h"
#include "backends/timer/default/default-timer.h"

#include "audio/mixer_intern.h"

#include "engines/engine.h"

#include "graphics/font.h"
#include "graphics/surface.h"

#include "icon.h"
#include "ps2temp.h"
Expand Down Expand Up @@ -345,6 +351,7 @@ void OSystem_PS2::init(void) {
_scummTimerManager = new DefaultTimerManager();
_scummMixer = new Audio::MixerImpl(this, 48000);
_scummMixer->setReady(true);

initTimer();

sioprintf("Starting SavefileManager\n");
Expand Down
2 changes: 1 addition & 1 deletion backends/platform/psp/osys_psp.cpp
Expand Up @@ -100,7 +100,7 @@ void OSystem_PSP::initBackend() {

setupMixer();

OSystem::initBackend();
BaseBackend::initBackend();
}

// Let's us know an engine
Expand Down
2 changes: 2 additions & 0 deletions backends/platform/sdl/sdl.cpp
Expand Up @@ -206,6 +206,8 @@ void OSystem_SDL::initBackend() {
setupIcon();

_inited = true;

ModularBackend::initBackend();
}

void OSystem_SDL::initSDL() {
Expand Down
2 changes: 1 addition & 1 deletion backends/platform/wii/osystem.cpp
Expand Up @@ -150,7 +150,7 @@ void OSystem_Wii::initBackend() {
initSfx();
initEvents();

OSystem::initBackend();
BaseBackend::initBackend();
}

void OSystem_Wii::quit() {
Expand Down
14 changes: 14 additions & 0 deletions common/system.cpp
Expand Up @@ -26,6 +26,9 @@

#include "common/system.h"
#include "common/str.h"
#include "common/textconsole.h"

#include "backends/audiocd/default/default-audiocd.h"

#ifdef __PLAYSTATION2__
// for those replaced fopen/fread/etc functions
Expand All @@ -45,9 +48,20 @@
OSystem *g_system = 0;

OSystem::OSystem() {
_audiocdManager = 0;
}

OSystem::~OSystem() {
delete _audiocdManager;
}

void OSystem::initBackend() {
#ifndef DISABLE_DEFAULT_AUDIOCD_MANAGER
if (!_audiocdManager)
_audiocdManager = new DefaultAudioCDManager();
#endif
if (!_audiocdManager)
error("Backend failed to instantiate AudioCD manager");
}

bool OSystem::setGraphicsMode(const char *name) {
Expand Down
23 changes: 21 additions & 2 deletions common/system.h
Expand Up @@ -96,6 +96,23 @@ class OSystem : Common::NonCopyable {
OSystem();
virtual ~OSystem();

protected:
/**
* For backend authors only, this pointer may be set by OSystem
* subclasses to an AudioCDManager instance. This is only useful
* if your backend does not want to use the DefaultAudioCDManager.
*
* This instance is returned by OSystem::getAudioCDManager(),
* and it is deleted by the OSystem destructor.
*
* A backend may set this pointer in its initBackend() method,
* its constructor or somewhere in between; but it must
* set it no later than in its initBackend() implementation, because
* OSystem::initBackend() will by default create a DefaultAudioCDManager
* instance if _audiocdManager has not yet been set.
*/
AudioCDManager *_audiocdManager;

public:

/**
Expand All @@ -106,7 +123,7 @@ class OSystem : Common::NonCopyable {
* parent class. They should do so near the end of their own
* implementation.
*/
virtual void initBackend() { }
virtual void initBackend();

/**
* Allows the backend to perform engine specific init.
Expand Down Expand Up @@ -921,7 +938,9 @@ class OSystem : Common::NonCopyable {
* Return the audio cd manager. For more information, refer to the
* AudioCDManager documentation.
*/
virtual AudioCDManager *getAudioCDManager() = 0;
inline AudioCDManager *getAudioCDManager() {
return _audiocdManager;
}

//@}

Expand Down
2 changes: 1 addition & 1 deletion test/module.mk
Expand Up @@ -6,7 +6,7 @@
######################################################################

TESTS := $(srcdir)/test/common/*.h $(srcdir)/test/audio/*.h
TEST_LIBS := audio/libaudio.a common/libcommon.a
TEST_LIBS := backends/libbackends.a audio/libaudio.a common/libcommon.a

#
TEST_FLAGS := --runner=StdioPrinter --no-std --no-eh
Expand Down

0 comments on commit afb06b5

Please sign in to comment.