From 0d62e964ecfc9e518a7dea0517c1ae2f5e2861d9 Mon Sep 17 00:00:00 2001 From: Chris Apers Date: Sat, 28 Oct 2006 14:30:42 +0000 Subject: New modular backend implementation svn-id: r24559 --- backends/platform/PalmOS/Src/be_base.cpp | 51 ++++++++++++++++++++++++++++ backends/platform/PalmOS/Src/be_base.h | 26 ++++++++++++-- backends/platform/PalmOS/Src/be_os5.h | 5 ++- backends/platform/PalmOS/Src/be_save.cpp | 4 --- backends/platform/PalmOS/Src/os5ex_sound.cpp | 2 +- 5 files changed, 77 insertions(+), 11 deletions(-) diff --git a/backends/platform/PalmOS/Src/be_base.cpp b/backends/platform/PalmOS/Src/be_base.cpp index ad28299193..503f9fe8a4 100644 --- a/backends/platform/PalmOS/Src/be_base.cpp +++ b/backends/platform/PalmOS/Src/be_base.cpp @@ -26,6 +26,10 @@ #include "common/config-file.h" #include "common/config-manager.h" +#include "backends/saves/default/default-saves.h" +#include "backends/timer/default/default-timer.h" +#include "sound/mixer.h" + OSystem_PalmBase::OSystem_PalmBase() { _overlayVisible = false; @@ -57,6 +61,10 @@ OSystem_PalmBase::OSystem_PalmBase() { _batCheckTicks = SysTicksPerSecond() * 15; _batCheckLast = TimGetTicks(); + _saveMgr = 0; + _timerMgr = 0; + _mixerMgr = 0; + _mouseDataP = NULL; _mouseVisible = false; _mouseDrawn = false; @@ -70,6 +78,12 @@ OSystem_PalmBase::OSystem_PalmBase() { _keyMouseDelay = (gVars->arrowKeys) ? computeMsecs(125) : computeMsecs(25); } +static int timer_handler(int t) { + DefaultTimerManager *tm = (DefaultTimerManager *)g_system->getTimerManager(); + tm->handler(); + return t; +} + void OSystem_PalmBase::initBackend() { if (gVars->autoSave != -1) ConfMan.setInt("autosave_period", gVars->autoSave); @@ -84,6 +98,26 @@ void OSystem_PalmBase::initBackend() { int_initBackend(); _keyMouseMask = (_keyMouse.bitUp | _keyMouse.bitDown | _keyMouse.bitLeft | _keyMouse.bitRight | _keyMouse.bitButLeft); + // Create the savefile manager, if none exists yet (we check for this to + // allow subclasses to provide their own). + if (_saveMgr == 0) { + _saveMgr = new DefaultSaveFileManager(); + } + + // Create and hook up the mixer, if none exists yet (we check for this to + // allow subclasses to provide their own). + if (_mixerMgr == 0) { + _mixerMgr = new Audio::Mixer(); + setSoundCallback(Audio::Mixer::mixCallback, _mixerMgr); + } + + // Create and hook up the timer manager, if none exists yet (we check for + // this to allow subclasses to provide their own). + if (_timerMgr == 0) { + _timerMgr = new DefaultTimerManager(); + setTimerCallback(::timer_handler, 10); + } + OSystem::initBackend(); } @@ -113,5 +147,22 @@ void OSystem_PalmBase::quit() { int_quit(); clearSoundCallback(); unload_gfx_mode(); + + delete _saveMgr; + delete _timerMgr; + delete _mixerMgr; + exit(0); } + +Common::SaveFileManager *OSystem_PalmBase::getSavefileManager() { + return _saveMgr; +} + +Audio::Mixer * OSystem_PalmBase::getMixer() { + return _mixerMgr; +} + +Common::TimerManager * OSystem_PalmBase::getTimerManager() { + return _timerMgr; +} diff --git a/backends/platform/PalmOS/Src/be_base.h b/backends/platform/PalmOS/Src/be_base.h index 87f9b2ded0..7dd289525c 100644 --- a/backends/platform/PalmOS/Src/be_base.h +++ b/backends/platform/PalmOS/Src/be_base.h @@ -29,6 +29,15 @@ #include "common/scummsys.h" #include "common/system.h" +namespace Audio { + class Mixer; +} + +namespace Common { + class SaveFileManager; + class TimerManager; +} + enum { GFX_NORMAL = 0, GFX_WIDE, @@ -51,10 +60,14 @@ enum { #define computeMsecs(x) ((SysTicksPerSecond() * x) / 1000) + +typedef void (*SoundProc)(void *param, byte *buf, int len); +typedef int (*TimerProc)(int interval); + typedef struct { UInt32 duration, nextExpiry; Boolean active; - OSystem::TimerProc callback; + TimerProc callback; } TimerType, *TimerPtr; typedef struct { @@ -88,7 +101,10 @@ private: void battery_handler(); virtual void get_coordinates(EventPtr ev, Coord &x, Coord &y) = 0; void simulate_mouse(Event &event, Int8 iHoriz, Int8 iVert, Coord *xr, Coord *yr); + virtual void sound_handler() = 0; + virtual bool setSoundCallback(SoundProc proc, void *param) = 0; + virtual void clearSoundCallback() = 0; protected: virtual void draw_osd(UInt16 id, Int32 x, Int32 y, Boolean show, UInt8 color = 0); @@ -112,6 +128,10 @@ protected: TimerType _timer; SoundType _sound; + Common::SaveFileManager *_saveMgr; + Audio::Mixer *_mixerMgr; + Common::TimerManager *_timerMgr; + RGBColorType _currentPalette[256]; uint _paletteDirtyStart, _paletteDirtyEnd; @@ -233,14 +253,14 @@ public: virtual void unlockMutex(MutexRef mutex) {} virtual void deleteMutex(MutexRef mutex) {} - virtual bool setSoundCallback(SoundProc proc, void *param) = 0; - virtual void clearSoundCallback() = 0; int getOutputSampleRate() const { return _samplesPerSec; } + virtual Audio::Mixer *getMixer(); void quit(); virtual void setWindowCaption(const char *caption) = 0; Common::SaveFileManager *getSavefileManager(); + Common::TimerManager *getTimerManager(); }; #endif diff --git a/backends/platform/PalmOS/Src/be_os5.h b/backends/platform/PalmOS/Src/be_os5.h index e6067fc6ff..68e9e1af1d 100644 --- a/backends/platform/PalmOS/Src/be_os5.h +++ b/backends/platform/PalmOS/Src/be_os5.h @@ -132,6 +132,8 @@ private: virtual SndStreamVariableBufferCallback sound_callback(); virtual void sound_handler(); + virtual bool setSoundCallback(SoundProc proc, void *param); + void clearSoundCallback(); protected: UInt16 _sysOldCoord, _sysOldOrientation; @@ -158,9 +160,6 @@ public: virtual OverlayColor RGBToColor(uint8 r, uint8 g, uint8 b); virtual void colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b); - virtual bool setSoundCallback(SoundProc proc, void *param); - void clearSoundCallback(); - void setWindowCaption(const char *caption); }; diff --git a/backends/platform/PalmOS/Src/be_save.cpp b/backends/platform/PalmOS/Src/be_save.cpp index a96770f437..074e13347d 100644 --- a/backends/platform/PalmOS/Src/be_save.cpp +++ b/backends/platform/PalmOS/Src/be_save.cpp @@ -157,7 +157,3 @@ Common::SaveFile *PalmSaveFileManager::makeSaveFile(const char *filename, bool s } return sf; } - -Common::SaveFileManager *OSystem_PalmBase::getSavefileManager() { - return new PalmSaveFileManager(); -} diff --git a/backends/platform/PalmOS/Src/os5ex_sound.cpp b/backends/platform/PalmOS/Src/os5ex_sound.cpp index 1cbd5f7f14..797f5d5e24 100644 --- a/backends/platform/PalmOS/Src/os5ex_sound.cpp +++ b/backends/platform/PalmOS/Src/os5ex_sound.cpp @@ -27,7 +27,7 @@ static SYSTEM_CALLBACK Err sndCallbackEx(void* UserDataP, SndStreamRef stream, void* bufferP, UInt32 *bufferSizeP) { CALLBACK_PROLOGUE SoundType *_sound = ((SoundExType *)UserDataP)->sound; - ((OSystem::SoundProc)_sound->proc)(_sound->param, (byte *)bufferP, *bufferSizeP); + ((SoundProc)_sound->proc)(_sound->param, (byte *)bufferP, *bufferSizeP); CALLBACK_EPILOGUE return errNone; } -- cgit v1.2.3