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

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sun Oct 31 02:45:24 CET 2010


Revision: 53974
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53974&view=rev
Author:   thebluegr
Date:     2010-10-31 01:45:24 +0000 (Sun, 31 Oct 2010)

Log Message:
-----------
SCI: Play time related changes

- Added support for savegame play time
- Removed obsolete variables for calculating the play time (EngineState::gameStartTime and Console::_enterTime)
- Renamed some variables to camelCase

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/console.h
    scummvm/trunk/engines/sci/detection.cpp
    scummvm/trunk/engines/sci/engine/kfile.cpp
    scummvm/trunk/engines/sci/engine/kmisc.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/savegame.h
    scummvm/trunk/engines/sci/engine/state.h
    scummvm/trunk/engines/sci/graphics/frameout.cpp
    scummvm/trunk/engines/sci/sci.cpp

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2010-10-31 00:20:30 UTC (rev 53973)
+++ scummvm/trunk/engines/sci/console.cpp	2010-10-31 01:45:24 UTC (rev 53974)
@@ -68,7 +68,7 @@
 static int parse_reg_t(EngineState *s, const char *str, reg_t *dest, bool mayBeValue);
 
 Console::Console(SciEngine *engine) : GUI::Debugger(),
-	_engine(engine), _debugState(engine->_debugState), _enterTime(0) {
+	_engine(engine), _debugState(engine->_debugState) {
 
 	// Variables
 	DVar_Register("sleeptime_factor",	&g_debug_sleeptime_factor, DVAR_INT, 0);
@@ -222,7 +222,6 @@
 
 void Console::preEnter() {
 	_engine->pauseEngine(true);
-	_enterTime = g_system->getMillis();
 }
 
 void Console::postEnter() {
@@ -283,8 +282,6 @@
 	}
 
 	_engine->pauseEngine(false);
-	// Subtract the time we were running the debugger from the game running time
-	_engine->_gamestate->gameStartTime += g_system->getMillis() - _enterTime;
 }
 
 bool Console::cmdHelp(int argc, const char **argv) {

Modified: scummvm/trunk/engines/sci/console.h
===================================================================
--- scummvm/trunk/engines/sci/console.h	2010-10-31 00:20:30 UTC (rev 53973)
+++ scummvm/trunk/engines/sci/console.h	2010-10-31 01:45:24 UTC (rev 53974)
@@ -168,7 +168,6 @@
 	bool _mouseVisible;
 	Common::String _videoFile;
 	int _videoFrameDelay;
-	uint32 _enterTime;
 };
 
 } // End of namespace Sci

Modified: scummvm/trunk/engines/sci/detection.cpp
===================================================================
--- scummvm/trunk/engines/sci/detection.cpp	2010-10-31 00:20:30 UTC (rev 53973)
+++ scummvm/trunk/engines/sci/detection.cpp	2010-10-31 01:45:24 UTC (rev 53974)
@@ -624,7 +624,8 @@
 		(f == kSupportsDeleteSave) ||
 		(f == kSavesSupportMetaInfo) ||
 		(f == kSavesSupportThumbnail) ||
-		(f == kSavesSupportCreationDate);
+		(f == kSavesSupportCreationDate) ||
+		(f == kSavesSupportPlayTime);
 }
 
 bool SciEngine::hasFeature(EngineFeature f) const {
@@ -665,7 +666,7 @@
 					delete in;
 					continue;
 				}
-				saveList.push_back(SaveStateDescriptor(slotNum, meta.savegame_name));
+				saveList.push_back(SaveStateDescriptor(slotNum, meta.name));
 				delete in;
 			}
 		}
@@ -688,7 +689,7 @@
 			return desc;
 		}
 
-		SaveStateDescriptor desc(slot, meta.savegame_name);
+		SaveStateDescriptor desc(slot, meta.name);
 
 		Graphics::Surface *thumbnail = new Graphics::Surface();
 		assert(thumbnail);
@@ -702,18 +703,18 @@
 		desc.setDeletableFlag(true);
 		desc.setWriteProtectedFlag(false);
 
-		int day = (meta.savegame_date >> 24) & 0xFF;
-		int month = (meta.savegame_date >> 16) & 0xFF;
-		int year = meta.savegame_date & 0xFFFF;
+		int day = (meta.saveDate >> 24) & 0xFF;
+		int month = (meta.saveDate >> 16) & 0xFF;
+		int year = meta.saveDate & 0xFFFF;
 
 		desc.setSaveDate(year, month, day);
 
-		int hour = (meta.savegame_time >> 16) & 0xFF;
-		int minutes = (meta.savegame_time >> 8) & 0xFF;
+		int hour = (meta.saveTime >> 16) & 0xFF;
+		int minutes = (meta.saveTime >> 8) & 0xFF;
 
 		desc.setSaveTime(hour, minutes);
 
-		// TODO: played time
+		desc.setPlayTime(meta.playTime * 1000);
 
 		delete in;
 

Modified: scummvm/trunk/engines/sci/engine/kfile.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kfile.cpp	2010-10-31 00:20:30 UTC (rev 53973)
+++ scummvm/trunk/engines/sci/engine/kfile.cpp	2010-10-31 01:45:24 UTC (rev 53974)
@@ -422,7 +422,7 @@
 		Common::SeekableReadStream *in;
 		if ((in = saveFileMan->openForLoading(filename))) {
 			SavegameMetadata meta;
-			if (!get_savegame_metadata(in, &meta) || meta.savegame_name.empty()) {
+			if (!get_savegame_metadata(in, &meta) || meta.name.empty()) {
 				// invalid
 				delete in;
 				continue;
@@ -431,17 +431,17 @@
 
 			SavegameDesc desc;
 			desc.id = strtol(filename.end() - 3, NULL, 10);
-			desc.date = meta.savegame_date;
+			desc.date = meta.saveDate;
 			// We need to fix date in here, because we save DDMMYYYY instead of
 			// YYYYMMDD, so sorting wouldn't work
 			desc.date = ((desc.date & 0xFFFF) << 16) | ((desc.date & 0xFF0000) >> 8) | ((desc.date & 0xFF000000) >> 24);
-			desc.time = meta.savegame_time;
-			desc.version = meta.savegame_version;
+			desc.time = meta.saveTime;
+			desc.version = meta.version;
 
-			if (meta.savegame_name.lastChar() == '\n')
-				meta.savegame_name.deleteLastChar();
+			if (meta.name.lastChar() == '\n')
+				meta.name.deleteLastChar();
 
-			Common::strlcpy(desc.name, meta.savegame_name.c_str(), SCI_MAX_SAVENAME_LENGTH);
+			Common::strlcpy(desc.name, meta.name.c_str(), SCI_MAX_SAVENAME_LENGTH);
 
 			debug(3, "Savegame in file %s ok, id %d", filename.c_str(), desc.id);
 

Modified: scummvm/trunk/engines/sci/engine/kmisc.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kmisc.cpp	2010-10-31 00:20:30 UTC (rev 53973)
+++ scummvm/trunk/engines/sci/engine/kmisc.cpp	2010-10-31 01:45:24 UTC (rev 53974)
@@ -180,11 +180,10 @@
 
 reg_t kGetTime(EngineState *s, int argc, reg_t *argv) {
 	TimeDate loc_time;
-	uint32 elapsedTime;
+	uint32 elapsedTime = g_engine->getTotalPlayTime();
 	int retval = 0; // Avoid spurious warning
 
 	g_system->getTimeAndDate(loc_time);
-	elapsedTime = g_system->getMillis() - s->gameStartTime;
 
 	int mode = (argc > 0) ? argv[0].toUint16() : 0;
 

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2010-10-31 00:20:30 UTC (rev 53973)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2010-10-31 01:45:24 UTC (rev 53974)
@@ -178,24 +178,34 @@
 	// TODO: It would be a good idea to store a magic number & a header size here,
 	// so that we can implement backward compatibility if the savegame format changes.
 
-	s.syncString(obj.savegame_name);
+	s.syncString(obj.name);
 	s.syncVersion(CURRENT_SAVEGAME_VERSION);
-	obj.savegame_version = s.getVersion();
-	s.syncString(obj.game_version);
-	s.syncAsSint32LE(obj.savegame_date);
-	s.syncAsSint32LE(obj.savegame_time);
+	obj.version = s.getVersion();
+	s.syncString(obj.gameVersion);
+	s.syncAsSint32LE(obj.saveDate);
+	s.syncAsSint32LE(obj.saveTime);
 	if (s.getVersion() < 22) {
-		obj.game_object_offset = 0;
-		obj.script0_size = 0;
+		obj.gameObjectOffset = 0;
+		obj.script0Size = 0;
 	} else {
-		s.syncAsUint16LE(obj.game_object_offset);
-		s.syncAsUint16LE(obj.script0_size);
+		s.syncAsUint16LE(obj.gameObjectOffset);
+		s.syncAsUint16LE(obj.script0Size);
 	}
+
+	// Playtime
+	obj.playTime = 0;
+	if (s.isLoading()) {
+		if (s.getVersion() >= 26)
+			s.syncAsUint32LE(obj.playTime);
+	} else {
+		obj.playTime = g_engine->getTotalPlayTime() / 1000;
+		s.syncAsUint32LE(obj.playTime);
+	}
 }
 
 void EngineState::saveLoadWithSerializer(Common::Serializer &s) {
 	Common::String tmp;
-	s.syncString(tmp, VER(14), VER(23));			// OBSOLETE: Used to be game_version
+	s.syncString(tmp, VER(14), VER(23));			// OBSOLETE: Used to be gameVersion
 
 	if (getSciVersion() <= SCI_VERSION_1_1) {
 		// Save/Load picPort as well for SCI0-SCI1.1. Necessary for Castle of Dr. Brain,
@@ -520,7 +530,7 @@
 	_music->saveLoadWithSerializer(s);
 }
 
-void SoundCommandParser::reconstructPlayList(int savegame_version) {
+void SoundCommandParser::reconstructPlayList(int version) {
 	Common::StackLock lock(_music->_mutex);
 
 	const MusicList::iterator end = _music->getPlayListEnd();
@@ -681,15 +691,15 @@
 	g_system->getTimeAndDate(curTime);
 
 	SavegameMetadata meta;
-	meta.savegame_version = CURRENT_SAVEGAME_VERSION;
-	meta.savegame_name = savename;
-	meta.game_version = version;
-	meta.savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
-	meta.savegame_time = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
+	meta.version = CURRENT_SAVEGAME_VERSION;
+	meta.name = savename;
+	meta.gameVersion = version;
+	meta.saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
+	meta.saveTime = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
 
 	Resource *script0 = g_sci->getResMan()->findResource(ResourceId(kResourceTypeScript, 0), false);
-	meta.script0_size = script0->size;
-	meta.game_object_offset = g_sci->getGameObject().offset;
+	meta.script0Size = script0->size;
+	meta.gameObjectOffset = g_sci->getGameObject().offset;
 
 	// Checking here again
 	if (s->executionStackBase) {
@@ -718,13 +728,13 @@
 		return;
 	}
 
-	if ((meta.savegame_version < MINIMUM_SAVEGAME_VERSION) ||
-	    (meta.savegame_version > CURRENT_SAVEGAME_VERSION)) {
+	if ((meta.version < MINIMUM_SAVEGAME_VERSION) ||
+	    (meta.version > CURRENT_SAVEGAME_VERSION)) {
 		/*
-		if (meta.savegame_version < MINIMUM_SAVEGAME_VERSION)
+		if (meta.version < MINIMUM_SAVEGAME_VERSION)
 			warning("Old savegame version detected, unable to load it");
 		else
-			warning("Savegame version is %d, maximum supported is %0d", meta.savegame_version, CURRENT_SAVEGAME_VERSION);
+			warning("Savegame version is %d, maximum supported is %0d", meta.version, CURRENT_SAVEGAME_VERSION);
 		*/
 
 		showScummVMDialog("The format of this saved game is obsolete, unable to load it");
@@ -733,9 +743,9 @@
 		return;
 	}
 
-	if (meta.game_object_offset > 0 && meta.script0_size > 0) {
+	if (meta.gameObjectOffset > 0 && meta.script0Size > 0) {
 		Resource *script0 = g_sci->getResMan()->findResource(ResourceId(kResourceTypeScript, 0), false);
-		if (script0->size != meta.script0_size || g_sci->getGameObject().offset != meta.game_object_offset) {
+		if (script0->size != meta.script0Size || g_sci->getGameObject().offset != meta.gameObjectOffset) {
 			//warning("This saved game was created with a different version of the game, unable to load it");
 
 			showScummVMDialog("This saved game was created with a different version of the game, unable to load it");
@@ -761,13 +771,13 @@
 
 	// Time state:
 	s->lastWaitTime = g_system->getMillis();
-	s->gameStartTime = g_system->getMillis();
 	s->_screenUpdateTime = g_system->getMillis();
+	g_engine->setTotalPlayTime(meta.playTime * 1000);
 
 	if (g_sci->_gfxPorts)
 		g_sci->_gfxPorts->reset();
 
-	g_sci->_soundCmd->reconstructPlayList(meta.savegame_version);
+	g_sci->_soundCmd->reconstructPlayList(meta.version);
 
 	// Message state:
 	delete s->_msgState;
@@ -789,12 +799,12 @@
 	if (stream->eos())
 		return false;
 
-	if ((meta->savegame_version < MINIMUM_SAVEGAME_VERSION) ||
-	    (meta->savegame_version > CURRENT_SAVEGAME_VERSION)) {
-		if (meta->savegame_version < MINIMUM_SAVEGAME_VERSION)
+	if ((meta->version < MINIMUM_SAVEGAME_VERSION) ||
+	    (meta->version > CURRENT_SAVEGAME_VERSION)) {
+		if (meta->version < MINIMUM_SAVEGAME_VERSION)
 			warning("Old savegame version detected- can't load");
 		else
-			warning("Savegame version is %d- maximum supported is %0d", meta->savegame_version, CURRENT_SAVEGAME_VERSION);
+			warning("Savegame version is %d- maximum supported is %0d", meta->version, CURRENT_SAVEGAME_VERSION);
 
 		return false;
 	}

Modified: scummvm/trunk/engines/sci/engine/savegame.h
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.h	2010-10-31 00:20:30 UTC (rev 53973)
+++ scummvm/trunk/engines/sci/engine/savegame.h	2010-10-31 01:45:24 UTC (rev 53974)
@@ -36,19 +36,20 @@
 struct EngineState;
 
 enum {
-	CURRENT_SAVEGAME_VERSION = 25,
+	CURRENT_SAVEGAME_VERSION = 26,
 	MINIMUM_SAVEGAME_VERSION = 14
 };
 
 // Savegame metadata
 struct SavegameMetadata {
-	Common::String savegame_name;
-	int savegame_version;
-	Common::String game_version;
-	int savegame_date;
-	int savegame_time;
-	uint16 game_object_offset;
-	uint16 script0_size;
+	Common::String name;
+	int version;
+	Common::String gameVersion;
+	int saveDate;
+	int saveTime;
+	uint32 playTime;
+	uint16 gameObjectOffset;
+	uint16 script0Size;
 };
 
 

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2010-10-31 00:20:30 UTC (rev 53973)
+++ scummvm/trunk/engines/sci/engine/state.h	2010-10-31 01:45:24 UTC (rev 53974)
@@ -125,7 +125,6 @@
 
 	/* Non-VM information */
 
-	uint32 gameStartTime; /**< The time at which the interpreter was started */
 	uint32 lastWaitTime; /**< The last time the game invoked Wait() */
 	uint32 _screenUpdateTime;	/**< The last time the game updated the screen */
 

Modified: scummvm/trunk/engines/sci/graphics/frameout.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/frameout.cpp	2010-10-31 00:20:30 UTC (rev 53973)
+++ scummvm/trunk/engines/sci/graphics/frameout.cpp	2010-10-31 01:45:24 UTC (rev 53974)
@@ -44,6 +44,8 @@
 
 namespace Sci {
 
+// TODO/FIXME: This is all guesswork
+
 GfxFrameout::GfxFrameout(SegManager *segMan, ResourceManager *resMan, GfxCoordAdjuster *coordAdjuster, GfxCache *cache, GfxScreen *screen, GfxPalette *palette, GfxPaint32 *paint32)
 	: _segMan(segMan), _resMan(resMan), _cache(cache), _screen(screen), _palette(palette), _paint32(paint32) {
 
@@ -249,7 +251,7 @@
 	return readSelectorValue(g_sci->getEngineState()->_segMan, _planes.back().object, SELECTOR(priority));
 }
 
-// No idea yet how to implement this
+// TODO: No idea yet how to implement this
 void GfxFrameout::kernelAddPicAt(reg_t planeObj, int16 forWidth, GuiResourceId pictureId) {
 	addPlanePicture(planeObj, pictureId, forWidth);
 }

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2010-10-31 00:20:30 UTC (rev 53973)
+++ scummvm/trunk/engines/sci/sci.cpp	2010-10-31 01:45:24 UTC (rev 53974)
@@ -554,7 +554,7 @@
 		_vocabulary->reset();
 	}
 
-	_gamestate->gameStartTime = _gamestate->lastWaitTime = _gamestate->_screenUpdateTime = g_system->getMillis();
+	_gamestate->lastWaitTime = _gamestate->_screenUpdateTime = g_system->getMillis();
 
 	// Load game language into printLang property of game object
 	setSciLanguage();
@@ -650,6 +650,8 @@
 }
 
 void SciEngine::runGame() {
+	setTotalPlayTime(0);
+
 	initStackBaseWithSelector(SELECTOR(play)); // Call the play selector
 
 	// Attach the debug console on game startup, if requested


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