SDL backend: got rid of setTimerCallback and clearSoundCallback

svn-id: r24446
This commit is contained in:
Max Horn 2006-10-22 16:05:07 +00:00
parent b635a2fb84
commit f4d8920f2b
2 changed files with 20 additions and 17 deletions

View File

@ -135,7 +135,6 @@ public:
// Set function that generates samples // Set function that generates samples
typedef void (*SoundProc)(void *param, byte *buf, int len); typedef void (*SoundProc)(void *param, byte *buf, int len);
virtual bool setSoundCallback(SoundProc proc, void *param); // overloaded by CE backend virtual bool setSoundCallback(SoundProc proc, void *param); // overloaded by CE backend
void clearSoundCallback();
virtual Audio::Mixer *getMixer(); virtual Audio::Mixer *getMixer();
// Poll CD status // Poll CD status
@ -154,10 +153,6 @@ public:
// Quit // Quit
virtual void quit(); // overloaded by CE backend virtual void quit(); // overloaded by CE backend
// Add a callback timer
typedef int (*TimerProc)(int interval);
void setTimerCallback(TimerProc callback, int timer);
virtual Common::TimerManager *getTimerManager(); virtual Common::TimerManager *getTimerManager();
// Mutex handling // Mutex handling
@ -373,6 +368,8 @@ protected:
Common::SaveFileManager *_savefile; Common::SaveFileManager *_savefile;
Audio::Mixer *_mixer; Audio::Mixer *_mixer;
SDL_TimerID _timerID;
Common::TimerManager *_timer; Common::TimerManager *_timer;

View File

@ -46,9 +46,9 @@ int __stdcall WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpC
} }
#endif #endif
static int timer_handler(int t) { static Uint32 timer_handler(Uint32 interval, void *param) {
DefaultTimerManager *tm = (DefaultTimerManager *)g_system->getTimerManager(); ((DefaultTimerManager *)param)->handler();
return tm->handler(t); return interval;
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -196,8 +196,15 @@ void OSystem_SDL::initBackend() {
// Create and hook up the timer manager, if none exists yet (we check for // Create and hook up the timer manager, if none exists yet (we check for
// this to allow subclasses to provide their own). // this to allow subclasses to provide their own).
if (_timer == 0) { if (_timer == 0) {
// TODO: We could implement a custom SDLTimerManager by using
// SDL_AddTimer. That might yield better timer resolution, but it would
// also change the semantics of a timer: Right now, ScummVM timers
// *never* run in parallel, due to the way they are implemented. If we
// switched to SDL_AddTimer, each timer might run in a separate thread.
// Unfortunately, not all our code is prepared for that, so we can't just
// switch. But it's a long term goal to do just that!
_timer = new DefaultTimerManager(); _timer = new DefaultTimerManager();
setTimerCallback(&timer_handler, 10); _timerID = SDL_AddTimer(10, &timer_handler, _timer);
} }
OSystem::initBackend(); OSystem::initBackend();
@ -240,10 +247,17 @@ OSystem_SDL::OSystem_SDL()
} }
OSystem_SDL::~OSystem_SDL() { OSystem_SDL::~OSystem_SDL() {
SDL_RemoveTimer(_timerID);
SDL_CloseAudio();
free(_dirtyChecksums); free(_dirtyChecksums);
free(_currentPalette); free(_currentPalette);
free(_cursorPalette); free(_cursorPalette);
free(_mouseData); free(_mouseData);
delete _savefile;
delete _mixer;
delete _timer;
} }
uint32 OSystem_SDL::getMillis() { uint32 OSystem_SDL::getMillis() {
@ -254,10 +268,6 @@ void OSystem_SDL::delayMillis(uint msecs) {
SDL_Delay(msecs); SDL_Delay(msecs);
} }
void OSystem_SDL::setTimerCallback(TimerProc callback, int timer) {
SDL_SetTimer(timer, (SDL_TimerCallback) callback);
}
Common::TimerManager *OSystem_SDL::getTimerManager() { Common::TimerManager *OSystem_SDL::getTimerManager() {
assert(_timer); assert(_timer);
return _timer; return _timer;
@ -445,10 +455,6 @@ bool OSystem_SDL::setSoundCallback(SoundProc proc, void *param) {
return true; return true;
} }
void OSystem_SDL::clearSoundCallback() {
SDL_CloseAudio();
}
int OSystem_SDL::getOutputSampleRate() const { int OSystem_SDL::getOutputSampleRate() const {
return _samplesPerSec; return _samplesPerSec;
} }