diff options
author | Johannes Schickel | 2010-10-27 22:37:51 +0000 |
---|---|---|
committer | Johannes Schickel | 2010-10-27 22:37:51 +0000 |
commit | 2ad28b8cd53c363f12d920c746795e0d371dc9f9 (patch) | |
tree | f849131b939c148f7843a60dd8d68b36ffb5a772 /engines | |
parent | 8a08ca1f39a0dc5ad6003d8213fe8aec4acb7327 (diff) | |
download | scummvm-rg350-2ad28b8cd53c363f12d920c746795e0d371dc9f9.tar.gz scummvm-rg350-2ad28b8cd53c363f12d920c746795e0d371dc9f9.tar.bz2 scummvm-rg350-2ad28b8cd53c363f12d920c746795e0d371dc9f9.zip |
ENGINE: Generalize SCUMM play time counting and move it into Engine.
This implements Max's idea on -devel
("Re: [Scummvm-devel] ATTN Engine authors: Advanced engine features") from
27.10.2010 on 11:12PM CEST.
Unlike the SCUMM implementation it stores the play time as ms instead of s.
The SCUMM engine was adapted to use this instead to reduce code duplication.
svn-id: r53892
Diffstat (limited to 'engines')
-rw-r--r-- | engines/engine.cpp | 23 | ||||
-rw-r--r-- | engines/engine.h | 25 | ||||
-rw-r--r-- | engines/scumm/saveload.cpp | 6 | ||||
-rw-r--r-- | engines/scumm/scumm.cpp | 10 | ||||
-rw-r--r-- | engines/scumm/scumm.h | 3 |
5 files changed, 52 insertions, 15 deletions
diff --git a/engines/engine.cpp b/engines/engine.cpp index 965dcca485..78e431aa09 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -94,6 +94,8 @@ Engine::Engine(OSystem *syst) _saveFileMan(_system->getSavefileManager()), _targetName(ConfMan.getActiveDomainName()), _pauseLevel(0), + _pauseStartTime(0), + _engineStartTime(_system->getMillis()), _mainMenuDialog(NULL) { g_engine = this; @@ -380,9 +382,12 @@ void Engine::pauseEngine(bool pause) { _pauseLevel--; if (_pauseLevel == 1 && pause) { + _pauseStartTime = _system->getMillis(); pauseEngineIntern(true); } else if (_pauseLevel == 0) { pauseEngineIntern(false); + _engineStartTime += _system->getMillis() - _pauseStartTime; + _pauseStartTime = 0; } } @@ -398,6 +403,24 @@ void Engine::openMainMenuDialog() { syncSoundSettings(); } +uint32 Engine::getTotalPlayTime() const { + if (!_pauseLevel) + return _system->getMillis() - _engineStartTime; + else + return _pauseStartTime - _engineStartTime; +} + +void Engine::resetTotalPlayTime(uint32 time) { + const uint32 currentTime = _system->getMillis(); + + // We need to reset the pause start time here in case the engine is already + // paused to avoid any incorrect play time counting. + if (_pauseLevel > 0) + _pauseStartTime = currentTime; + + _engineStartTime = currentTime - time; +} + int Engine::runDialog(GUI::Dialog &dialog) { pauseEngine(true); int result = dialog.runModal(); diff --git a/engines/engine.h b/engines/engine.h index ead1526d72..b1575962ff 100644 --- a/engines/engine.h +++ b/engines/engine.h @@ -74,6 +74,17 @@ private: */ int _pauseLevel; + /** + * The time when the pause was started. + */ + uint32 _pauseStartTime; + + /** + * The time when the engine was started. This value is used to calculate + * the current play time of the game running. + */ + int32 _engineStartTime; + public: @@ -234,6 +245,20 @@ public: */ void openMainMenuDialog(); + /** + * Get the total play time. + * + * @return How long the player has been playing in ms. + */ + uint32 getTotalPlayTime() const; + + /** + * Reset the game time counter to the specified time. + * + * @param time Play time to set up in ms. + */ + void resetTotalPlayTime(uint32 time = 0); + inline Common::TimerManager *getTimerManager() { return _timer; } inline Common::EventManager *getEventManager() { return _eventMan; } inline Common::SaveFileManager *getSaveFileManager() { return _saveFileMan; } diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 28ec6c182f..b9cb0ae10f 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -378,10 +378,10 @@ bool ScummEngine::loadState(int slot, bool compat) { return false; } - _engineStartTime = _system->getMillis() / 1000 - infos.playtime; + resetTotalPlayTime(infos.playtime * 1000); } else { // start time counting - _engineStartTime = _system->getMillis() / 1000; + resetTotalPlayTime(); } // Due to a bug in scummvm up to and including 0.3.0, save games could be saved @@ -797,7 +797,7 @@ void ScummEngine::saveInfos(Common::WriteStream* file) { // still save old format for older versions section.timeTValue = 0; - section.playtime = _system->getMillis() / 1000 - _engineStartTime; + section.playtime = getTotalPlayTime() / 1000; TimeDate curTime; _system->getTimeAndDate(curTime); diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp index d711888c2c..2c654402fa 100644 --- a/engines/scumm/scumm.cpp +++ b/engines/scumm/scumm.cpp @@ -1927,7 +1927,7 @@ int ScummEngine::getTalkSpeed() { #pragma mark - Common::Error ScummEngine::go() { - _engineStartTime = _system->getMillis() / 1000; + resetTotalPlayTime(); // If requested, load a save game instead of running the boot script if (_saveLoadFlag != 2 || !loadState(_saveLoadSlot, _saveTemporaryState)) { @@ -2505,10 +2505,6 @@ void ScummEngine::startManiac() { void ScummEngine::pauseEngineIntern(bool pause) { if (pause) { - // Record start of the pause, so that we can later - // adjust _engineStartTime accordingly. - _pauseStartTime = _system->getMillis(); - // Pause sound & video _oldSoundsPaused = _sound->_soundsPaused; _sound->pauseSounds(true); @@ -2526,10 +2522,6 @@ void ScummEngine::pauseEngineIntern(bool pause) { // Resume sound & video _sound->pauseSounds(_oldSoundsPaused); - - // Adjust engine start time - _engineStartTime += (_system->getMillis() - _pauseStartTime) / 1000; - _pauseStartTime = 0; } } diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h index 346d8fb79a..0a513b6068 100644 --- a/engines/scumm/scumm.h +++ b/engines/scumm/scumm.h @@ -700,9 +700,6 @@ protected: void saveInfos(Common::WriteStream* file); static bool loadInfos(Common::SeekableReadStream *file, InfoStuff *stuff); - int32 _engineStartTime; - int32 _pauseStartTime; - protected: /* Script VM - should be in Script class */ uint32 _localScriptOffsets[1024]; |