diff options
author | Max Horn | 2009-02-28 06:14:42 +0000 |
---|---|---|
committer | Max Horn | 2009-02-28 06:14:42 +0000 |
commit | a26b3bfde6411a4d9aeee75b9fc952b5a8e0e4c4 (patch) | |
tree | fc1e43f7f1fba05b6d8d0527ddbf6d6382d39dbe | |
parent | c1a712c4e848dd56601c43fc7fdd3c75d83e03df (diff) | |
download | scummvm-rg350-a26b3bfde6411a4d9aeee75b9fc952b5a8e0e4c4.tar.gz scummvm-rg350-a26b3bfde6411a4d9aeee75b9fc952b5a8e0e4c4.tar.bz2 scummvm-rg350-a26b3bfde6411a4d9aeee75b9fc952b5a8e0e4c4.zip |
SCI: Get rid of extra layer around our timer manager
svn-id: r38947
-rw-r--r-- | engines/sci/module.mk | 1 | ||||
-rw-r--r-- | engines/sci/sfx/core.cpp | 46 | ||||
-rw-r--r-- | engines/sci/sfx/sfx_pcm.h | 1 | ||||
-rw-r--r-- | engines/sci/sfx/sfx_timer.h | 56 | ||||
-rw-r--r-- | engines/sci/sfx/timer.cpp | 78 |
5 files changed, 14 insertions, 168 deletions
diff --git a/engines/sci/module.mk b/engines/sci/module.mk index 1babcab4ca..cebd4b87f7 100644 --- a/engines/sci/module.mk +++ b/engines/sci/module.mk @@ -71,7 +71,6 @@ MODULE_OBJS = \ sfx/pcm-iterator.o \ sfx/songlib.o \ sfx/time.o \ - sfx/timer.o \ sfx/device/devices.o \ sfx/mixer/soft.o \ sfx/player/players.o \ diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp index 5d6812711f..a08c0824b5 100644 --- a/engines/sci/sfx/core.cpp +++ b/engines/sci/sfx/core.cpp @@ -26,14 +26,13 @@ /* Sound subsystem core: Event handler, sound player dispatching */ #include "sci/tools.h" -#include "sci/sfx/sfx_timer.h" #include "sci/sfx/sfx_iterator_internal.h" #include "sci/sfx/sfx_player.h" #include "sci/sfx/mixer.h" #include "sci/sfx/sci_midi.h" -#include "common/mutex.h" #include "common/system.h" +#include "common/timer.h" namespace Sci { @@ -46,8 +45,6 @@ int sciprintf(char *msg, ...); static sfx_player_t *player = NULL; sfx_pcm_mixer_t *mixer = NULL; static sfx_pcm_device_t *pcm_device = NULL; -static sfx_timer_t *timer = NULL; -extern sfx_timer_t sfx_timer_scummvm; extern sfx_pcm_device_t sfx_pcm_driver_scummvm; int sfx_pcm_available() { @@ -355,19 +352,19 @@ int sfx_play_iterator_pcm(song_iterator_t *it, song_handle_t handle) { return 0; } -static void _sfx_timer_callback(void *data) { - if (timer) { - /* First run the player, to give it a chance to fill - ** the audio buffer */ +#define FREQ 60 +#define DELAY (1000000 / FREQ) - if (player) - player->maintenance(); - assert(timer); +static void _sfx_timer_callback(void *data) { + /* First run the player, to give it a chance to fill + ** the audio buffer */ - if (mixer) - mixer->process(mixer); - } + if (player) + player->maintenance(); + + if (mixer) + mixer->process(mixer); } void sfx_init(sfx_state_t *self, ResourceManager *resmgr, int flags) { @@ -421,7 +418,7 @@ void sfx_init(sfx_state_t *self, ResourceManager *resmgr, int flags) { if (!resmgr) { sciprintf("[SFX] Warning: No resource manager present, cannot initialise player\n"); player = NULL; - } else if (player->init(resmgr, timer ? timer->delay_ms : 0)) { + } else if (player->init(resmgr, DELAY / 1000)) { sciprintf("[SFX] Song player '%s' reported error, disabled\n", player->name); player = NULL; } @@ -440,21 +437,9 @@ void sfx_init(sfx_state_t *self, ResourceManager *resmgr, int flags) { // still being initialized. if (pcm_device || (player && player->maintenance)) { - timer = &sfx_timer_scummvm; - - if (!timer) { - fprintf(stderr, "[SFX] " __FILE__": Could not find timing mechanism\n"); - fprintf(stderr, "[SFX] Disabled sound support\n"); - pcm_device = NULL; - player = NULL; - mixer = NULL; - return; - } - - if (timer->init(_sfx_timer_callback, NULL)) { + if (!g_system->getTimerManager()->installTimerProc(&_sfx_timer_callback, DELAY, NULL)) { warning("[SFX] " __FILE__": Timer failed to initialize"); warning("[SFX] Disabled sound support"); - timer = NULL; pcm_device = NULL; player = NULL; mixer = NULL; @@ -465,15 +450,12 @@ void sfx_init(sfx_state_t *self, ResourceManager *resmgr, int flags) { } void sfx_exit(sfx_state_t *self) { - if (timer && timer->exit()) - warning("[SFX] Timer reported error on exit"); + g_system->getTimerManager()->removeTimerProc(&_sfx_timer_callback); // The timer API guarantees no more callbacks are running or will be // run from this point onward, so we can now safely exit the mixer and // player. - timer = NULL; - #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Uninitialising\n"); #endif diff --git a/engines/sci/sfx/sfx_pcm.h b/engines/sci/sfx/sfx_pcm.h index 598c99f5b5..89ccee04d9 100644 --- a/engines/sci/sfx/sfx_pcm.h +++ b/engines/sci/sfx/sfx_pcm.h @@ -27,7 +27,6 @@ #define SCI_SFX_SFX_PCM_H #include "sci/sfx/sfx_core.h" -#include "sci/sfx/sfx_timer.h" #include "sci/sfx/sfx_time.h" namespace Sci { diff --git a/engines/sci/sfx/sfx_timer.h b/engines/sci/sfx/sfx_timer.h deleted file mode 100644 index ffeb208a8f..0000000000 --- a/engines/sci/sfx/sfx_timer.h +++ /dev/null @@ -1,56 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#ifndef SCI_SFX_SFX_TIMER_H -#define SCI_SFX_SFX_TIMER_H - -#include "sci/sfx/sfx_core.h" - -namespace Sci { - -struct sfx_timer_t { - int delay_ms; /* Approximate delay (in milliseconds) between calls */ - - int (*init)(void (*callback)(void *data), void *data); - /* Initializes the timer - ** Parameters: (void* -> void) callback: - ** 'data' must contain the next argument: - ** (void *) data: Must always be passed to the callback - ** Returns : (int) SFX_OK on success, SFX_ERROR on failure - ** This does not start the timer yet, it just specifies and initializes it. - ** This function is called exactly once (provided that the timer is used at all). - */ - - int (*exit)(); - /* Stops the timer - ** Returns : (int) SFX_OK on success, SFX_ERROR on failure - ** All resources allocated with the timer should be freed as an effect - ** of this. - */ -}; - -} // End of namespace Sci - -#endif // SCI_SFX_SFX_TIMER_H diff --git a/engines/sci/sfx/timer.cpp b/engines/sci/sfx/timer.cpp deleted file mode 100644 index 334c0e5155..0000000000 --- a/engines/sci/sfx/timer.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#include "common/timer.h" -#include "engines/engine.h" -#include "sci/sfx/sfx_timer.h" - -namespace Sci { - -#define FREQ 60 -#define DELAY (1000000 / FREQ) - -typedef void (*scummvm_timer_callback_t)(void *); -static scummvm_timer_callback_t scummvm_timer_callback = NULL; -static void *scummvm_timer_callback_data = NULL; -extern ::Engine *g_engine; - -void scummvm_timer_update_internal(void *ptr) { - if (scummvm_timer_callback) - scummvm_timer_callback(scummvm_timer_callback_data); -} - -int scummvm_timer_start(void (*func)(void *), void *data) { - if (scummvm_timer_callback) { - fprintf(stderr, - "Error: Attempt to initialize gametick timer more than once\n"); - return SFX_ERROR; - } - - if (!func) { - fprintf(stderr, - "Error: Attempt to initialize gametick timer w/o callback\n"); - return SFX_ERROR; - } - - scummvm_timer_callback = func; - scummvm_timer_callback_data = data; - - ::g_engine->getTimerManager()->installTimerProc(&scummvm_timer_update_internal, DELAY, NULL); - return SFX_OK; -} - -int scummvm_timer_stop() { - ::g_engine->getTimerManager()->removeTimerProc(&scummvm_timer_update_internal); - scummvm_timer_callback = NULL; - return SFX_OK; -} - - -sfx_timer_t sfx_timer_scummvm = { - DELAY / 1000, - &scummvm_timer_start, - &scummvm_timer_stop -}; - -} // End of namespace Sci |