diff --git a/engines/dreamweb/dreamweb.cpp b/engines/dreamweb/dreamweb.cpp index 665e5b44de9..435f91b2952 100644 --- a/engines/dreamweb/dreamweb.cpp +++ b/engines/dreamweb/dreamweb.cpp @@ -49,8 +49,6 @@ DreamWebEngine::DreamWebEngine(OSystem *syst, const DreamWebGameDescription *gam DebugMan.addDebugChannel(kDebugAnimation, "Animation", "Animation Debug Flag"); DebugMan.addDebugChannel(kDebugSaveLoad, "SaveLoad", "Track Save/Load Function"); - _vSyncInterrupt = false; - _console = 0; _sound = 0; _speed = 1; @@ -276,26 +274,21 @@ DreamWebEngine::~DreamWebEngine() { delete _sound; } -static void vSyncInterrupt(void *refCon) { - DreamWebEngine *vm = (DreamWebEngine *)refCon; - - if (!vm->isPaused()) { - vm->setVSyncInterrupt(true); - } -} - -void DreamWebEngine::setVSyncInterrupt(bool flag) { - _vSyncInterrupt = flag; -} - void DreamWebEngine::waitForVSync() { + const uint32 previousTicks = _system->getMillis(); + // Originally, this was an interval for a thread that was + // called every 1000000 / 70 nanoseconds. It has been + // adjusted to be a delay instead. + const uint32 delay = 800 / 70 / _speed; + + if (isPaused()) + return; + processEvents(); - if (!_turbo) { - while (!_vSyncInterrupt) { - _system->delayMillis(10); - } - setVSyncInterrupt(false); + while (!_turbo && _system->getMillis() - previousTicks < delay) { + processEvents(false); + _system->delayMillis(10); } doShake(); @@ -308,13 +301,15 @@ void DreamWebEngine::quit() { _lastHardKey = Common::KEYCODE_ESCAPE; } -void DreamWebEngine::processEvents() { +void DreamWebEngine::processEvents(bool processSoundEvents) { if (_eventMan->shouldQuit()) { quit(); return; } - _sound->soundHandler(); + if (processSoundEvents) + _sound->soundHandler(); + Common::Event event; int softKey; while (_eventMan->pollEvent(event)) { @@ -411,21 +406,16 @@ Common::Error DreamWebEngine::run() { _brightPalette = ConfMan.getBool("bright_palette"); _copyProtection = ConfMan.getBool("copy_protection"); - _timer->installTimerProc(vSyncInterrupt, 1000000 / 70, this, "dreamwebVSync"); dreamweb(); dreamwebFinalize(); _quitRequested = false; - _timer->removeTimerProc(vSyncInterrupt); - return Common::kNoError; } void DreamWebEngine::setSpeed(uint speed) { debug(0, "setting speed %u", speed); _speed = speed; - _timer->removeTimerProc(vSyncInterrupt); - _timer->installTimerProc(vSyncInterrupt, 1000000 / 70 / speed, this, "dreamwebVSync"); } Common::String DreamWebEngine::getSavegameFilename(int slot) const { diff --git a/engines/dreamweb/dreamweb.h b/engines/dreamweb/dreamweb.h index d770c20bae3..ee4af33bdd5 100644 --- a/engines/dreamweb/dreamweb.h +++ b/engines/dreamweb/dreamweb.h @@ -102,7 +102,6 @@ class DreamWebEngine : public Engine { private: DreamWebConsole *_console; DreamWebSound *_sound; - bool _vSyncInterrupt; protected: // Engine APIs @@ -115,7 +114,6 @@ public: DreamWebEngine(OSystem *syst, const DreamWebGameDescription *gameDesc); virtual ~DreamWebEngine(); - void setVSyncInterrupt(bool flag); void waitForVSync(); Common::Error loadGameState(int slot); @@ -127,7 +125,7 @@ public: uint8 randomNumber() { return _rnd.getRandomNumber(255); } void mouseCall(uint16 *x, uint16 *y, uint16 *state); //fill mouse pos and button state - void processEvents(); + void processEvents(bool processSoundEvents = true); void blit(const uint8 *src, int pitch, int x, int y, int w, int h); void cls(); bool isCD();