aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
Diffstat (limited to 'backends')
-rw-r--r--backends/platform/PalmOS/Src/be_base.cpp2
-rw-r--r--backends/platform/ds/arm9/source/osystem_ds.cpp2
-rw-r--r--backends/platform/gp2x/gp2x.cpp2
-rw-r--r--backends/platform/sdl/sdl-common.h22
-rw-r--r--backends/platform/sdl/sdl.cpp51
-rw-r--r--backends/platform/wince/wince-sdl.cpp6
-rw-r--r--backends/platform/x11/x11.cpp3
-rw-r--r--backends/timer/default/default-timer.cpp43
-rw-r--r--backends/timer/default/default-timer.h6
9 files changed, 96 insertions, 41 deletions
diff --git a/backends/platform/PalmOS/Src/be_base.cpp b/backends/platform/PalmOS/Src/be_base.cpp
index ea3f28a45f..ad28299193 100644
--- a/backends/platform/PalmOS/Src/be_base.cpp
+++ b/backends/platform/PalmOS/Src/be_base.cpp
@@ -83,6 +83,8 @@ void OSystem_PalmBase::initBackend() {
int_initBackend();
_keyMouseMask = (_keyMouse.bitUp | _keyMouse.bitDown | _keyMouse.bitLeft | _keyMouse.bitRight | _keyMouse.bitButLeft);
+
+ OSystem::initBackend();
}
uint32 OSystem_PalmBase::getMillis() {
diff --git a/backends/platform/ds/arm9/source/osystem_ds.cpp b/backends/platform/ds/arm9/source/osystem_ds.cpp
index 0d3e1fdd75..12d3b0ad01 100644
--- a/backends/platform/ds/arm9/source/osystem_ds.cpp
+++ b/backends/platform/ds/arm9/source/osystem_ds.cpp
@@ -52,6 +52,8 @@ OSystem_DS::~OSystem_DS() {
void OSystem_DS::initBackend() {
ConfMan.setInt("autosave_period", 0);
ConfMan.setBool("FM_low_quality", true);
+
+ OSystem::initBackend();
}
bool OSystem_DS::hasFeature(Feature f) {
diff --git a/backends/platform/gp2x/gp2x.cpp b/backends/platform/gp2x/gp2x.cpp
index 4ecbb928ca..975c64a7ab 100644
--- a/backends/platform/gp2x/gp2x.cpp
+++ b/backends/platform/gp2x/gp2x.cpp
@@ -145,6 +145,8 @@ void OSystem_GP2X::initBackend() {
SDL_ShowCursor(SDL_DISABLE);
+ OSystem::initBackend();
+
_inited = true;
}
diff --git a/backends/platform/sdl/sdl-common.h b/backends/platform/sdl/sdl-common.h
index 093e7950f9..aeb9c5bf37 100644
--- a/backends/platform/sdl/sdl-common.h
+++ b/backends/platform/sdl/sdl-common.h
@@ -33,6 +33,15 @@
#include "backends/intern.h"
+namespace Audio {
+ class Mixer;
+}
+
+namespace Common {
+ class SaveFileManager;
+ class TimerManager;
+}
+
#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
// Uncomment this to enable the 'on screen display' code.
#define USE_OSD 1
@@ -124,9 +133,10 @@ public:
virtual bool pollEvent(Event &event); // overloaded by CE backend
// Set function that generates samples
+ typedef void (*SoundProc)(void *param, byte *buf, int len);
virtual bool setSoundCallback(SoundProc proc, void *param); // overloaded by CE backend
-
void clearSoundCallback();
+ virtual Audio::Mixer *getMixer();
// Poll CD status
// Returns true if cd audio is playing
@@ -146,7 +156,9 @@ public:
// Add a callback timer
+ typedef int (*TimerProc)(int interval);
void setTimerCallback(TimerProc callback, int timer);
+ virtual Common::TimerManager *getTimerManager();
// Mutex handling
MutexRef createMutex();
@@ -187,6 +199,8 @@ public:
void displayMessageOnOSD(const char *msg);
#endif
+ virtual Common::SaveFileManager *getSavefileManager();
+
protected:
bool _inited;
@@ -357,6 +371,12 @@ protected:
MutexRef _graphicsMutex;
+ Common::SaveFileManager *_savefile;
+ Audio::Mixer *_mixer;
+ Common::TimerManager *_timer;
+
+
+
void addDirtyRgnAuto(const byte *buf);
void makeChecksums(const byte *buf);
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 21f5935c58..b4677eac0f 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -27,6 +27,10 @@
#include "common/util.h"
#include "base/main.h"
+#include "backends/saves/default/default-saves.h"
+#include "backends/timer/default/default-timer.h"
+#include "sound/mixer.h"
+
#include "icons/scummvm.xpm"
#if defined(__SYMBIAN32__)
@@ -42,6 +46,11 @@ int __stdcall WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpC
}
#endif
+static int timer_handler(int t) {
+ DefaultTimerManager *tm = (DefaultTimerManager *)g_system->getTimerManager();
+ return tm->handler(t);
+}
+
int main(int argc, char *argv[]) {
#if defined(__SYMBIAN32__)
@@ -169,6 +178,29 @@ void OSystem_SDL::initBackend() {
printf("Using joystick: %s\n", SDL_JoystickName(0));
_joystick = SDL_JoystickOpen(joystick_num);
}
+
+
+ // Create the savefile manager, if none exists yet (we check for this to
+ // allow subclasses to provide their own).
+ if (_savefile == 0) {
+ _savefile = new DefaultSaveFileManager();
+ }
+
+ // Create and hook up the mixer, if none exists yet (we check for this to
+ // allow subclasses to provide their own).
+ if (_mixer == 0) {
+ _mixer = new Audio::Mixer();
+ setSoundCallback(Audio::Mixer::mixCallback, _mixer);
+ }
+
+ // Create and hook up the timer manager, if none exists yet (we check for
+ // this to allow subclasses to provide their own).
+ if (_timer == 0) {
+ _timer = new DefaultTimerManager();
+ setTimerCallback(&timer_handler, 10);
+ }
+
+ OSystem::initBackend();
_inited = true;
}
@@ -189,6 +221,9 @@ OSystem_SDL::OSystem_SDL()
_joystick(0),
_currentShakePos(0), _newShakePos(0),
_paletteDirtyStart(0), _paletteDirtyEnd(0),
+ _savefile(0),
+ _mixer(0),
+ _timer(0),
_graphicsMutex(0), _transactionMode(kTransactionNone) {
// allocate palette storage
@@ -223,6 +258,16 @@ void OSystem_SDL::setTimerCallback(TimerProc callback, int timer) {
SDL_SetTimer(timer, (SDL_TimerCallback) callback);
}
+Common::TimerManager *OSystem_SDL::getTimerManager() {
+ assert(_timer);
+ return _timer;
+}
+
+Common::SaveFileManager *OSystem_SDL::getSavefileManager() {
+ assert(_savefile);
+ return _savefile;
+}
+
void OSystem_SDL::setWindowCaption(const char *caption) {
SDL_WM_SetCaption(caption, caption);
}
@@ -395,6 +440,7 @@ bool OSystem_SDL::setSoundCallback(SoundProc proc, void *param) {
// least on some platforms SDL will lie and claim it did get the rate
// even if it didn't. Probably only happens for "weird" rates, though.
_samplesPerSec = obtained.freq;
+ debug(1, "Output sample rate: %d Hz", _samplesPerSec);
SDL_PauseAudio(0);
return true;
}
@@ -407,6 +453,11 @@ int OSystem_SDL::getOutputSampleRate() const {
return _samplesPerSec;
}
+Audio::Mixer *OSystem_SDL::getMixer() {
+ assert(_mixer);
+ return _mixer;
+}
+
#pragma mark -
#pragma mark --- CD Audio ---
#pragma mark -
diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp
index 4dc7d7c410..d41fe5eba6 100644
--- a/backends/platform/wince/wince-sdl.cpp
+++ b/backends/platform/wince/wince-sdl.cpp
@@ -246,6 +246,12 @@ void OSystem_WINCE3::initBackend()
GUI_Actions::Instance()->loadMapping();
loadDeviceConfiguration();
+
+ // FIXME: We are currently not calling OSystem_SDL::initBackend() here.
+ // Maybe on purpose, but this is possibly a bit risky... E.g. _inited
+ // won't be set correctly due to this... Can we change this? Maybe after
+ // some changes to the base SDL backend?
+ //OSystem_SDL::initBackend();
}
int OSystem_WINCE3::getScreenWidth() {
diff --git a/backends/platform/x11/x11.cpp b/backends/platform/x11/x11.cpp
index 7db5066c44..a16fbe8adc 100644
--- a/backends/platform/x11/x11.cpp
+++ b/backends/platform/x11/x11.cpp
@@ -205,7 +205,8 @@ out_of_loop:
/* And finally start the local timer */
gettimeofday(&_start_time, NULL);
-
+
+ OSystem::initBackend();
}
#undef CAPTURE_SOUND
diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp
index 907c715a07..245291c06c 100644
--- a/backends/timer/default/default-timer.cpp
+++ b/backends/timer/default/default-timer.cpp
@@ -25,61 +25,34 @@
#include "common/util.h"
#include "common/system.h"
-namespace Common {
-// FIXME: Hack: This global variable shouldn't be declared here; in fact it
-// probably shouldn't be declared at all but rather a different method to
-// query the TimerManager object should be invented.
-TimerManager *g_timer = NULL;
-}
-
-DefaultTimerManager::DefaultTimerManager(OSystem *system) :
- _system(system),
+DefaultTimerManager::DefaultTimerManager() :
_timerHandler(0),
_lastTime(0) {
- Common::g_timer = this;
-
for (int i = 0; i < MAX_TIMERS; i++) {
_timerSlots[i].procedure = NULL;
_timerSlots[i].interval = 0;
_timerSlots[i].counter = 0;
}
- _thisTime = _system->getMillis();
-
- // Set the timer last, after everything has been initialised
- _system->setTimerCallback(&timer_handler, 10);
-
+ _thisTime = g_system->getMillis();
}
DefaultTimerManager::~DefaultTimerManager() {
- // Remove the timer callback.
- // Note: backends *must* gurantee that after this method call returns,
- // the handler is not in use anymore; else race condtions could occur.
- _system->setTimerCallback(0, 0);
-
- {
- Common::StackLock lock(_mutex);
- for (int i = 0; i < MAX_TIMERS; i++) {
- _timerSlots[i].procedure = NULL;
- _timerSlots[i].interval = 0;
- _timerSlots[i].counter = 0;
- }
+ Common::StackLock lock(_mutex);
+ for (int i = 0; i < MAX_TIMERS; i++) {
+ _timerSlots[i].procedure = NULL;
+ _timerSlots[i].interval = 0;
+ _timerSlots[i].counter = 0;
}
}
-int DefaultTimerManager::timer_handler(int t) {
- if (Common::g_timer)
- return ((DefaultTimerManager *)Common::g_timer)->handler(t);
- return 0;
-}
-
int DefaultTimerManager::handler(int t) {
Common::StackLock lock(_mutex);
uint32 interval, l;
_lastTime = _thisTime;
- _thisTime = _system->getMillis();
+ _thisTime = g_system->getMillis();
interval = 1000 * (_thisTime - _lastTime);
for (l = 0; l < MAX_TIMERS; l++) {
diff --git a/backends/timer/default/default-timer.h b/backends/timer/default/default-timer.h
index 12779cc59c..8c16122b02 100644
--- a/backends/timer/default/default-timer.h
+++ b/backends/timer/default/default-timer.h
@@ -32,7 +32,6 @@ private:
enum {
MAX_TIMERS = 8
};
- OSystem *_system;
Common::Mutex _mutex;
void *_timerHandler;
int32 _thisTime;
@@ -46,13 +45,12 @@ private:
} _timerSlots[MAX_TIMERS];
public:
- DefaultTimerManager(OSystem *system);
+ DefaultTimerManager();
~DefaultTimerManager();
bool installTimerProc(TimerProc proc, int32 interval, void *refCon);
void removeTimerProc(TimerProc proc);
-protected:
- static int timer_handler(int t);
+ // Timer callback, to be invoked at regular time intervals by the backend.
int handler(int t);
};