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
This commit is contained in:
parent
8a08ca1f39
commit
2ad28b8cd5
5 changed files with 52 additions and 15 deletions
|
@ -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();
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue