diff options
author | Johannes Schickel | 2008-05-10 19:20:38 +0000 |
---|---|---|
committer | Johannes Schickel | 2008-05-10 19:20:38 +0000 |
commit | 7c7e9b831fc8b250942170bc12cd9c54602ded48 (patch) | |
tree | d5f7eb71f396a921f4f72a1473c051afaa7b7a64 /engines/kyra | |
parent | f930fff0d12c55e63140f45f4aee2c933f59aa63 (diff) | |
download | scummvm-rg350-7c7e9b831fc8b250942170bc12cd9c54602ded48.tar.gz scummvm-rg350-7c7e9b831fc8b250942170bc12cd9c54602ded48.tar.bz2 scummvm-rg350-7c7e9b831fc8b250942170bc12cd9c54602ded48.zip |
Implemented pausing of timers, this should fix some minor glitches.
svn-id: r31985
Diffstat (limited to 'engines/kyra')
-rw-r--r-- | engines/kyra/gui_hof.cpp | 2 | ||||
-rw-r--r-- | engines/kyra/gui_mr.cpp | 2 | ||||
-rw-r--r-- | engines/kyra/gui_v1.cpp | 3 | ||||
-rw-r--r-- | engines/kyra/timer.cpp | 49 | ||||
-rw-r--r-- | engines/kyra/timer.h | 15 |
5 files changed, 59 insertions, 12 deletions
diff --git a/engines/kyra/gui_hof.cpp b/engines/kyra/gui_hof.cpp index cc212d28fc..2c333df937 100644 --- a/engines/kyra/gui_hof.cpp +++ b/engines/kyra/gui_hof.cpp @@ -666,6 +666,8 @@ int KyraEngine_HoF::cauldronButton(Button *button) { #pragma mark - int GUI_HoF::optionsButton(Button *button) { + PauseTimer pause(*_vm->_timer); + _restartGame = false; _reloadTemporarySave = false; diff --git a/engines/kyra/gui_mr.cpp b/engines/kyra/gui_mr.cpp index 1e89e50072..a7fc742b6f 100644 --- a/engines/kyra/gui_mr.cpp +++ b/engines/kyra/gui_mr.cpp @@ -789,6 +789,8 @@ int GUI_MR::quitGame(Button *caller) { } int GUI_MR::optionsButton(Button *button) { + PauseTimer pause(*_vm->_timer); + _vm->musicUpdate(0); _screen->hideMouse(); diff --git a/engines/kyra/gui_v1.cpp b/engines/kyra/gui_v1.cpp index 2d2c4f1219..0c66064409 100644 --- a/engines/kyra/gui_v1.cpp +++ b/engines/kyra/gui_v1.cpp @@ -30,6 +30,7 @@ #include "kyra/animator_v1.h" #include "kyra/sound.h" #include "kyra/gui_v1.h" +#include "kyra/timer.h" #include "common/config-manager.h" #include "common/savefile.h" @@ -406,6 +407,8 @@ void GUI_v1::setGUILabels() { } int GUI_v1::buttonMenuCallback(Button *caller) { + PauseTimer pause(*_vm->_timer); + _displayMenu = true; assert(_vm->_guiStrings); diff --git a/engines/kyra/timer.cpp b/engines/kyra/timer.cpp index 1f25f88c97..d9668afa98 100644 --- a/engines/kyra/timer.cpp +++ b/engines/kyra/timer.cpp @@ -62,10 +62,32 @@ struct TimerEqual : public Common::UnaryFunction<const TimerEntry&, bool> { }; } // end of anonymous namespace +void TimerManager::pause(bool pause) { + if (pause) { + ++_isPaused; + + if (_isPaused == 1) { + _isPaused = true; + _pauseStart = _system->getMillis(); + } + } else if (!pause && _isPaused > 0) { + --_isPaused; + + if (_isPaused == 0) { + const uint32 pausedTime = _system->getMillis() - _pauseStart; + _nextRun += pausedTime; + + for (Iterator pos = _timers.begin(); pos != _timers.end(); ++pos) { + pos->lastUpdate += pausedTime; + pos->nextRun += pausedTime; + } + } + } +} + void TimerManager::reset() { - for (Iterator pos = _timers.begin(); pos != _timers.end(); ++pos) { + for (Iterator pos = _timers.begin(); pos != _timers.end(); ++pos) delete pos->func; - } _timers.clear(); } @@ -93,7 +115,7 @@ void TimerManager::addTimer(uint8 id, TimerFunc *func, int countdown, bool enabl void TimerManager::update() { debugC(9, kDebugLevelTimer, "TimerManager::update()"); - if (_system->getMillis() < _nextRun) + if (_system->getMillis() < _nextRun || _isPaused) return; _nextRun += 99999; @@ -121,8 +143,10 @@ void TimerManager::update() { void TimerManager::resync() { debugC(9, kDebugLevelTimer, "TimerManager::resync()"); + const uint32 curTime = _isPaused ? _pauseStart : _system->getMillis(); + _nextRun = 0; // force rerun - Common::for_each(_timers.begin(), _timers.end(), TimerResync(_vm, _system->getMillis())); + Common::for_each(_timers.begin(), _timers.end(), TimerResync(_vm, curTime)); } void TimerManager::resetNextRun() { @@ -225,7 +249,9 @@ void TimerManager::disable(uint8 id) { } void TimerManager::loadDataFromFile(Common::SeekableReadStream &file, int version) { - debugC(9, kDebugLevelTimer, "TimerManager::loadDataFromFile(%p, %d)", (const void*)&file, version); + debugC(9, kDebugLevelTimer, "TimerManager::loadDataFromFile(%p, %d)", (const void *)&file, version); + + const uint32 loadTime = _isPaused ? _pauseStart : _system->getMillis(); if (version <= 7) { _nextRun = 0; @@ -240,12 +266,11 @@ void TimerManager::loadDataFromFile(Common::SeekableReadStream &file, int versio timer->countdown = countdown; if (nextRun) { - timer->nextRun = nextRun + _system->getMillis(); + timer->nextRun = nextRun + loadTime; timer->lastUpdate = timer->nextRun - countdown * _vm->tickLength(); } else { - uint32 curTime = _system->getMillis(); - timer->nextRun = curTime; - timer->lastUpdate = curTime - countdown * _vm->tickLength(); + timer->nextRun = loadTime; + timer->lastUpdate = loadTime - countdown * _vm->tickLength(); } } else { warning("Loading timer data for non existing timer %d", i); @@ -272,14 +297,16 @@ void TimerManager::loadDataFromFile(Common::SeekableReadStream &file, int versio } void TimerManager::saveDataToFile(Common::WriteStream &file) const { - debugC(9, kDebugLevelTimer, "TimerManager::saveDataToFile(%p)", (const void*)&file); + debugC(9, kDebugLevelTimer, "TimerManager::saveDataToFile(%p)", (const void *)&file); + + const uint32 saveTime = _isPaused ? _pauseStart : _system->getMillis(); file.writeByte(count()); for (CIterator pos = _timers.begin(); pos != _timers.end(); ++pos) { file.writeByte(pos->id); file.writeByte(pos->enabled); file.writeSint32BE(pos->countdown); - file.writeSint32BE(pos->lastUpdate - _system->getMillis()); + file.writeSint32BE(pos->lastUpdate - saveTime); } } diff --git a/engines/kyra/timer.h b/engines/kyra/timer.h index 0991f0a1b1..f668a88015 100644 --- a/engines/kyra/timer.h +++ b/engines/kyra/timer.h @@ -49,9 +49,11 @@ struct TimerEntry { class TimerManager { public: - TimerManager(KyraEngine *vm, OSystem *sys) : _vm(vm), _system(sys), _timers(), _nextRun(0) {} + TimerManager(KyraEngine *vm, OSystem *sys) : _vm(vm), _system(sys), _timers(), _nextRun(0), _isPaused(0), _pauseStart(0) {} ~TimerManager() { reset(); } + void pause(bool pause); + void reset(); void addTimer(uint8 id, TimerFunc *func, int countdown, bool enabled); @@ -82,10 +84,21 @@ private: Common::List<TimerEntry> _timers; uint32 _nextRun; + uint _isPaused; + uint32 _pauseStart; + typedef Common::List<TimerEntry>::iterator Iterator; typedef Common::List<TimerEntry>::const_iterator CIterator; }; +class PauseTimer { +public: + PauseTimer(TimerManager &timer) : _timer(timer) { _timer.pause(true); } + ~PauseTimer() { _timer.pause(false); } +private: + TimerManager &_timer; +}; + } // end of namespace Kyra #endif |