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

hkz at users.sourceforge.net hkz at users.sourceforge.net
Mon Mar 2 23:37:10 CET 2009


Revision: 39083
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39083&view=rev
Author:   hkz
Date:     2009-03-02 22:37:09 +0000 (Mon, 02 Mar 2009)

Log Message:
-----------
Add playtime feature support to sword1

Modified Paths:
--------------
    scummvm/trunk/engines/sword1/control.cpp
    scummvm/trunk/engines/sword1/control.h
    scummvm/trunk/engines/sword1/detection.cpp
    scummvm/trunk/engines/sword1/sword1.cpp
    scummvm/trunk/engines/sword1/sword1.h

Modified: scummvm/trunk/engines/sword1/control.cpp
===================================================================
--- scummvm/trunk/engines/sword1/control.cpp	2009-03-02 22:16:44 UTC (rev 39082)
+++ scummvm/trunk/engines/sword1/control.cpp	2009-03-02 22:37:09 UTC (rev 39083)
@@ -1117,8 +1117,10 @@
 
 	outf->writeUint32BE(saveDate);
 	outf->writeUint16BE(saveTime);
-	// TODO: played time
 
+	uint32 currentTime = _system->getMillis() / 1000;
+	outf->writeUint32BE(currentTime - SwordEngine::_systemVars.engineStartTime);
+
 	_objMan->saveLiveList(liveBuf);
 	for (cnt = 0; cnt < TOTAL_SECTIONS; cnt++)
 		outf->writeUint16LE(liveBuf[cnt]);
@@ -1165,7 +1167,7 @@
 	inf->skip(40);		// skip description
 	uint8 saveVersion = inf->readByte();
 
-	if (saveVersion != SAVEGAME_VERSION) {
+	if (saveVersion > SAVEGAME_VERSION) {
 		warning("Different save game version");
 		return false;
 	}
@@ -1183,8 +1185,14 @@
 
 	inf->readUint32BE();	// save date
 	inf->readUint16BE();	// save time
-	// TODO: played time
 
+	if (saveVersion < 2) { // Before version 2 we didn't had play time feature
+		SwordEngine::_systemVars.engineStartTime = 	_system->getMillis() / 1000; // Start counting
+	} else {
+		uint32 currentTime = _system->getMillis() / 1000;
+		SwordEngine::_systemVars.engineStartTime = currentTime - inf->readUint32BE(); // Engine start time
+	}
+
 	_restoreBuf = (uint8*)malloc(
 		TOTAL_SECTIONS * 2 +
 		NUM_SCRIPT_VARS * 4 +
@@ -1281,7 +1289,7 @@
 
 	newSave->writeUint32BE(saveDate);
 	newSave->writeUint16BE(saveTime);
-	// TODO: played time
+	newSave->writeUint32BE(0); // We don't have playtime info when converting, so we start from 0.
 
 	newSave->write(saveData, dataSize);
 

Modified: scummvm/trunk/engines/sword1/control.h
===================================================================
--- scummvm/trunk/engines/sword1/control.h	2009-03-02 22:16:44 UTC (rev 39082)
+++ scummvm/trunk/engines/sword1/control.h	2009-03-02 22:37:09 UTC (rev 39083)
@@ -44,7 +44,7 @@
 class Sound;
 
 #define SAVEGAME_HEADER MKID_BE('BS_1')
-#define SAVEGAME_VERSION 1
+#define SAVEGAME_VERSION 2 
 #define HAS_THUMBNAIL 1
 #define NO_THUMBNAIL 0
 

Modified: scummvm/trunk/engines/sword1/detection.cpp
===================================================================
--- scummvm/trunk/engines/sword1/detection.cpp	2009-03-02 22:16:44 UTC (rev 39082)
+++ scummvm/trunk/engines/sword1/detection.cpp	2009-03-02 22:37:09 UTC (rev 39083)
@@ -102,7 +102,8 @@
 		(f == kSupportsDeleteSave) ||
 		(f == kSavesSupportMetaInfo) ||
 		(f == kSavesSupportThumbnail) ||
-		(f == kSavesSupportCreationDate);
+		(f == kSavesSupportCreationDate) ||
+		(f == kSavesSupportPlayTime);
 }
 
 bool Sword1::SwordEngine::hasFeature(EngineFeature f) const {
@@ -244,13 +245,15 @@
 	char fileName[12];
 	snprintf(fileName, 12, "sword1.%03d", slot);
 	char name[40];
+	uint32 playTime;
+	byte versionSave;
 
 	Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(fileName);
 
 	if (in) {
 		in->skip(4);		// header
 		in->read(name, sizeof(name));
-		in->skip(1);		// version
+		in->read(&versionSave, 1);		// version
 
 		SaveStateDescriptor desc(slot, name);
 
@@ -271,6 +274,8 @@
 
 		uint32 saveDate = in->readUint32BE();
 		uint16 saveTime = in->readUint16BE();
+		if (versionSave > 1) // Previous versions did not have playtime data
+			playTime = in->readUint32BE();
 
 		int day = (saveDate >> 24) & 0xFF;
 		int month = (saveDate >> 16) & 0xFF;
@@ -283,7 +288,14 @@
 
 		desc.setSaveTime(hour, minutes);
 
-		// TODO: played time
+		if (versionSave > 1) {
+			minutes = playTime / 60;
+			hour = minutes / 60;
+			minutes %= 60;
+			desc.setPlayTime(hour, minutes);
+		} else { //We have no playtime data
+			desc.setPlayTime(0, 0);
+		}
 
 		delete in;
 

Modified: scummvm/trunk/engines/sword1/sword1.cpp
===================================================================
--- scummvm/trunk/engines/sword1/sword1.cpp	2009-03-02 22:16:44 UTC (rev 39082)
+++ scummvm/trunk/engines/sword1/sword1.cpp	2009-03-02 22:37:09 UTC (rev 39083)
@@ -546,6 +546,7 @@
 
 Common::Error SwordEngine::go() {
 	_control->checkForOldSaveGames();
+	SwordEngine::_systemVars.engineStartTime = _system->getMillis() / 1000;
 
 	uint16 startPos = ConfMan.getInt("boot_param");
 	_control->readSavegameDescriptions();

Modified: scummvm/trunk/engines/sword1/sword1.h
===================================================================
--- scummvm/trunk/engines/sword1/sword1.h	2009-03-02 22:16:44 UTC (rev 39082)
+++ scummvm/trunk/engines/sword1/sword1.h	2009-03-02 22:37:09 UTC (rev 39083)
@@ -66,6 +66,7 @@
 	uint8	showText;
 	uint8	language;
 	bool    isDemo;
+	uint32	engineStartTime;    // Used for playtime 
 	Common::Platform platform;
 };
 
@@ -75,7 +76,7 @@
 	virtual ~SwordEngine();
 	static SystemVars _systemVars;
 	void reinitialize(void);
-
+	
 	uint32 _features;
 
 	bool mouseIsActive();
@@ -96,6 +97,7 @@
 	}
 	virtual bool hasFeature(EngineFeature f) const;
 	virtual void syncSoundSettings();
+
 	// FIXME: Loading a game through the GMM crashes the game
 #if 0
 	Common::Error loadGameState(int slot);


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