[Scummvm-cvs-logs] SF.net SVN: scummvm:[53892] scummvm/trunk/engines

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Thu Oct 28 00:37:52 CEST 2010


Revision: 53892
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53892&view=rev
Author:   lordhoto
Date:     2010-10-27 22:37:51 +0000 (Wed, 27 Oct 2010)

Log Message:
-----------
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.

Modified Paths:
--------------
    scummvm/trunk/engines/engine.cpp
    scummvm/trunk/engines/engine.h
    scummvm/trunk/engines/scumm/saveload.cpp
    scummvm/trunk/engines/scumm/scumm.cpp
    scummvm/trunk/engines/scumm/scumm.h

Modified: scummvm/trunk/engines/engine.cpp
===================================================================
--- scummvm/trunk/engines/engine.cpp	2010-10-27 21:46:21 UTC (rev 53891)
+++ scummvm/trunk/engines/engine.cpp	2010-10-27 22:37:51 UTC (rev 53892)
@@ -94,6 +94,8 @@
 		_saveFileMan(_system->getSavefileManager()),
 		_targetName(ConfMan.getActiveDomainName()),
 		_pauseLevel(0),
+		_pauseStartTime(0),
+		_engineStartTime(_system->getMillis()),
 		_mainMenuDialog(NULL) {
 
 	g_engine = this;
@@ -380,9 +382,12 @@
 		_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 @@
 	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();

Modified: scummvm/trunk/engines/engine.h
===================================================================
--- scummvm/trunk/engines/engine.h	2010-10-27 21:46:21 UTC (rev 53891)
+++ scummvm/trunk/engines/engine.h	2010-10-27 22:37:51 UTC (rev 53892)
@@ -74,6 +74,17 @@
 	 */
 	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 @@
 	 */
 	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; }

Modified: scummvm/trunk/engines/scumm/saveload.cpp
===================================================================
--- scummvm/trunk/engines/scumm/saveload.cpp	2010-10-27 21:46:21 UTC (rev 53891)
+++ scummvm/trunk/engines/scumm/saveload.cpp	2010-10-27 22:37:51 UTC (rev 53892)
@@ -378,10 +378,10 @@
 			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 @@
 
 	// 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);

Modified: scummvm/trunk/engines/scumm/scumm.cpp
===================================================================
--- scummvm/trunk/engines/scumm/scumm.cpp	2010-10-27 21:46:21 UTC (rev 53891)
+++ scummvm/trunk/engines/scumm/scumm.cpp	2010-10-27 22:37:51 UTC (rev 53892)
@@ -1927,7 +1927,7 @@
 #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::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 @@
 
 		// Resume sound & video
 		_sound->pauseSounds(_oldSoundsPaused);
-
-		// Adjust engine start time
-		_engineStartTime += (_system->getMillis() - _pauseStartTime) / 1000;
-		_pauseStartTime = 0;
 	}
 }
 

Modified: scummvm/trunk/engines/scumm/scumm.h
===================================================================
--- scummvm/trunk/engines/scumm/scumm.h	2010-10-27 21:46:21 UTC (rev 53891)
+++ scummvm/trunk/engines/scumm/scumm.h	2010-10-27 22:37:51 UTC (rev 53892)
@@ -700,9 +700,6 @@
 	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];


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list