[Scummvm-cvs-logs] CVS: scummvm/scumm dialogs.cpp,1.149,1.150 saveload.cpp,1.233,1.234 saveload.h,1.63,1.64 scumm.cpp,1.590,1.591 scumm.h,1.643,1.644

Max Horn fingolfin at users.sourceforge.net
Sun Oct 2 13:15:01 CEST 2005


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21636

Modified Files:
	dialogs.cpp saveload.cpp saveload.h scumm.cpp scumm.h 
Log Message:
Patch #1259034 (Scumm Savegame Informations)

Index: dialogs.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/dialogs.cpp,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -d -r1.149 -r1.150
--- dialogs.cpp	30 Jul 2005 21:11:24 -0000	1.149
+++ dialogs.cpp	1 Oct 2005 21:13:38 -0000	1.150
@@ -21,6 +21,7 @@
 #include "common/stdafx.h"
 
 #include "common/config-manager.h"
+#include "common/savefile.h"
 #include "common/system.h"
 #include "common/scaler.h"
 
@@ -193,6 +194,8 @@
 
 #pragma mark -
 
+Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode);
+
 enum {
 	kSaveCmd = 'SAVE',
 	kLoadCmd = 'LOAD',
@@ -271,6 +274,9 @@
 	GUI::ListWidget		*_list;
 	GUI::ButtonWidget	*_chooseButton;
 	GUI::GraphicsWidget	*_gfxWidget;
+	GUI::StaticTextWidget	*_date;
+	GUI::StaticTextWidget	*_time;
+	GUI::StaticTextWidget	*_playtime;
 	ScummEngine			*_scumm;
 
 public:
@@ -300,6 +306,39 @@
 			((_scumm->_system->getHeight() % 200 && _scumm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8);
 	_gfxWidget->setFlags(GUI::WIDGET_BORDER);
 
+	int height = 18 + ((_scumm->_system->getHeight() % 200 && _scumm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8;
+
+	_date = new StaticTextWidget(this,
+					_w - (kThumbnailWidth + 22),
+					height,
+					kThumbnailWidth + 8,
+					kLineHeight,
+					"No date saved",
+					kTextAlignCenter);
+	_date->setFlags(GUI::WIDGET_CLEARBG);
+
+	height += kLineHeight;
+
+	_time = new StaticTextWidget(this,
+					_w - (kThumbnailWidth + 22),
+					height,
+					kThumbnailWidth + 8,
+					kLineHeight,
+					"No time saved",
+					kTextAlignCenter);
+	_time->setFlags(GUI::WIDGET_CLEARBG);
+
+	height += kLineHeight;
+
+	_playtime = new StaticTextWidget(this,
+					_w - (kThumbnailWidth + 22),
+					height,
+					kThumbnailWidth + 8,
+					kLineHeight,
+					"No playtime saved",
+					kTextAlignCenter);
+	_playtime->setFlags(GUI::WIDGET_CLEARBG);
+
 	// Buttons
 	addButton(this, _w - 2 * (kBigButtonWidth + 10), _h - kBigButtonHeight - 8, "Cancel", kCloseCmd, 0, GUI::kBigWidgetSize);
 	_chooseButton = addButton(this, _w - (kBigButtonWidth + 10), _h - kBigButtonHeight - 8, buttonLabel, kChooseCmd, 0, GUI::kBigWidgetSize);
@@ -342,9 +381,48 @@
 		Graphics::Surface *thumb;
 		thumb = _scumm->loadThumbnailFromSlot(_saveMode ? selItem + 1 : selItem);
 		_gfxWidget->setGfx(thumb);
+		if (thumb)
+			thumb->free();
 		delete thumb;
 		_gfxWidget->draw();
 
+		InfoStuff infos;
+		memset(&infos, 0, sizeof(InfoStuff));
+		char buffer[32];
+		if (_scumm->loadInfosFromSlot(_saveMode ? selItem + 1 : selItem, &infos)) {
+			snprintf(buffer, 32, "Date: %.2d.%.2d.%.4d",
+				(infos.date >> 24) & 0xFF, (infos.date >> 16) & 0xFF,
+				infos.date & 0xFFFF);
+			_date->setLabel(buffer);
+			_date->draw();
+			
+			snprintf(buffer, 32, "Time: %.2d:%.2d",
+				(infos.time >> 8) & 0xFF, infos.time & 0xFF);
+			_time->setLabel(buffer);
+			_time->draw();
+
+			int minutes = infos.playtime / 60;
+			int hours = minutes / 60;
+			minutes %= 60;
+
+			snprintf(buffer, 32, "Playtime: %.2d:%.2d",
+				hours & 0xFF, minutes & 0xFF);
+			_playtime->setLabel(buffer);
+			_playtime->draw();
+		} else {
+			snprintf(buffer, 32, "No date saved");
+			_date->setLabel(buffer);
+			_date->draw();
+			
+			snprintf(buffer, 32, "No time saved");
+			_time->setLabel(buffer);
+			_time->draw();
+
+			snprintf(buffer, 32, "No playtime saved");
+			_playtime->setLabel(buffer);
+			_playtime->draw();
+		}
+
 		if (_saveMode) {
 			_list->startEditMode();
 		}

Index: saveload.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/saveload.cpp,v
retrieving revision 1.233
retrieving revision 1.234
diff -u -d -r1.233 -r1.234
--- saveload.cpp	2 Sep 2005 11:24:16 -0000	1.233
+++ saveload.cpp	1 Oct 2005 21:13:38 -0000	1.234
@@ -51,6 +51,24 @@
 	char name[32];
 };
 
+#if !defined(__GNUC__)
+	#pragma START_PACK_STRUCTS
+#endif
+
+struct SaveInfoSection {
+	uint32 type;
+	uint32 version;
+	uint32 size;
+	
+	uint32 timeTValue;
+	uint32 playtime;
+} GCC_PACK;
+
+#if !defined(__GNUC__)
+	#pragma END_PACK_STRUCTS
+#endif
+
+#define INFOSECTION_VERSION 1
 
 void ScummEngine::requestSave(int slot, const char *name, bool temporary) {
 	_saveLoadSlot = slot;
@@ -84,6 +102,7 @@
 
 	out->write(&hdr, sizeof(hdr));
 	saveThumbnail(out);
+	saveInfos(out);
 
 	Serializer ser(0, out, CURRENT_VER);
 	saveOrLoad(&ser, CURRENT_VER);
@@ -144,6 +163,23 @@
 		in->skip(size - 8);
 	}
 
+	// Since version 56 we have informations about the creation of the save game and the save time here
+	if (hdr.ver >= VER(56)) {
+		InfoStuff infos;
+		if (!loadInfos(in, &infos)) {
+			warning("Info section could not be found");
+			delete in;
+			return false;
+		}
+
+		_engineStartTime = _system->getMillis() / 1000 - infos.playtime;
+	} else {
+		// start time counting
+		_engineStartTime = _system->getMillis() / 1000;
+	}
+
+	_dialogStartTime = _system->getMillis() / 1000;
+
 	// Due to a bug in scummvm up to and including 0.3.0, save games could be saved
 	// in the V8/V9 format but were tagged with a V7 mark. Ouch. So we just pretend V7 == V8 here
 	if (hdr.ver == VER(7))
@@ -359,6 +395,9 @@
 
 	_sound->pauseSounds(false);
 
+	_engineStartTime += _system->getMillis() / 1000 - _dialogStartTime;
+	_dialogStartTime = 0;
+
 	return true;
 }
 
@@ -440,6 +479,115 @@
 	return thumb;
 }
 
+bool ScummEngine::loadInfosFromSlot(int slot, InfoStuff *stuff) {
+	char filename[256];
+	Common::InSaveFile *in;
+	SaveGameHeader hdr;
+	int len;
+
+	makeSavegameName(filename, slot, false);
+	if (!(in = _saveFileMan->openForLoading(filename))) {
+		return false;
+	}
+	len = in->read(&hdr, sizeof(hdr));
+
+	if (len != sizeof(hdr) || hdr.type != MKID('SCVM')) {
+		delete in;
+		return false;
+	}
+
+	if (hdr.ver > CURRENT_VER)
+		hdr.ver = TO_LE_32(hdr.ver);
+	if (hdr.ver < VER(56)) {
+		delete in;
+		return false;
+	}
+
+	uint32 type;
+	in->read(&type, 4);
+
+	// Check for the THMB header. Also, work around a bug which caused
+	// the chunk type (incorrectly) to be written in LE on LE machines.
+	if (! (type == MKID('THMB') || (hdr.ver < VER(55) && type == MKID('BMHT')))){
+		delete in;
+		return false;
+	}
+	uint32 size = in->readUint32BE();
+	in->skip(size - 8);
+
+	if (!loadInfos(in, stuff)) {
+		delete in;
+		return false;
+	}
+	
+	delete in;	
+	return true;
+}
+
+bool ScummEngine::loadInfos(Common::InSaveFile *file, InfoStuff *stuff) {
+	memset(stuff, 0, sizeof(InfoStuff));
+
+	SaveInfoSection section;
+	file->read(&section.type, 4);
+	if (section.type != MKID('INFO')) {
+		return false;
+	}
+
+	section.version = file->readUint32BE();
+	section.size = file->readUint32BE();
+
+	// if we extend this we should add a table for the special sizes at the versions to check it
+	if (section.version == INFOSECTION_VERSION && section.size != sizeof(SaveInfoSection)) {
+		warning("Info section is corrupt");
+		file->skip(section.size);
+		return false;
+	}
+
+	section.timeTValue = file->readUint32BE();
+	section.playtime = file->readUint32BE();
+
+	time_t curTime_ = section.timeTValue;
+	tm *curTime = localtime(&curTime_);	
+	stuff->date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF;
+	stuff->time = (curTime->tm_hour & 0xFF) << 8 | (curTime->tm_min) & 0xFF;
+	stuff->playtime = section.playtime;
+
+	// if we extend the header we should check here for the version
+	// e.g.:
+	// if (header.version == 2) {
+	//	// load some things here
+	// }
+	//
+	// if (header.version == 3) {
+	//	// ...
+	// }
+	// and so on...
+
+	// skip all newer features, this could make problems if some older version uses more space for
+	// saving informations, but this should NOT happen
+	if (section.size > sizeof(SaveInfoSection)) {
+		file->skip(section.size - sizeof(SaveInfoSection));
+	}
+
+	return true;
+}
+
+void ScummEngine::saveInfos(Common::OutSaveFile* file) {
+	SaveInfoSection section;
+	section.type = MKID('INFO');
+	section.version = INFOSECTION_VERSION;
+	section.size = sizeof(SaveInfoSection);
+
+	section.timeTValue = time(0);
+	section.playtime = _system->getMillis() / 1000 - _engineStartTime;
+
+	file->write(&section.type, 4);
+	file->writeUint32BE(section.version);
+	file->writeUint32BE(section.size);
+	file->writeUint32BE(section.timeTValue);
+	file->writeUint32BE(section.playtime);
+}
+
 void ScummEngine::saveOrLoad(Serializer *s, uint32 savegameVersion) {
 	const SaveLoadEntry objectEntries[] = {
 		MKLINE(ObjectData, OBIMoffset, sleUint32, VER(8)),

Index: saveload.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/saveload.h,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- saveload.h	30 Jul 2005 21:11:27 -0000	1.63
+++ saveload.h	1 Oct 2005 21:13:38 -0000	1.64
@@ -45,7 +45,7 @@
  * only saves/loads those which are valid for the version of the savegame
  * which is being loaded/saved currently.
  */
-#define CURRENT_VER 55
+#define CURRENT_VER 56
 
 /**
  * An auxillary macro, used to specify savegame versions. We use this instead

Index: scumm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.cpp,v
retrieving revision 1.590
retrieving revision 1.591
diff -u -d -r1.590 -r1.591
--- scumm.cpp	30 Sep 2005 18:51:08 -0000	1.590
+++ scumm.cpp	1 Oct 2005 21:13:38 -0000	1.591
@@ -2109,6 +2109,8 @@
 #pragma mark -
 
 int ScummEngine::go() {
+	_engineStartTime = _system->getMillis() / 1000;
+
 	// If requested, load a save game instead of running the boot script
 	if (_saveLoadFlag != 2 || !loadState(_saveLoadSlot, _saveTemporaryState)) {
 		int args[16];
@@ -2550,6 +2552,8 @@
 #pragma mark -
 
 int ScummEngine::runDialog(Dialog &dialog) {
+	_dialogStartTime = _system->getMillis() / 1000;
+
 	// Pause sound & video
 	bool old_soundsPaused = _sound->_soundsPaused;
 	_sound->pauseSounds(true);
@@ -2566,6 +2570,9 @@
 	_sound->pauseSounds(old_soundsPaused);
 	_smushPaused = oldSmushPaused;
 
+	_engineStartTime += (_system->getMillis() / 1000) - _dialogStartTime;
+	_dialogStartTime = 0;
+
 	// Return the result
 	return result;
 }

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.643
retrieving revision 1.644
diff -u -d -r1.643 -r1.644
--- scumm.h	1 Oct 2005 13:02:35 -0000	1.643
+++ scumm.h	1 Oct 2005 21:13:38 -0000	1.644
@@ -309,6 +309,12 @@
 	int subIndex;
 };
 
+struct InfoStuff {
+	uint32 date;
+	uint16 time;
+	uint32 playtime;
+};
+
 class ResourceManager {
 	friend class ScummDebugger;
 	friend class ScummEngine;
@@ -583,13 +589,19 @@
 	void requestSave(int slot, const char *name, bool temporary = false);
 	void requestLoad(int slot);
 
-// thumbnail stuff
+// thumbnail + info stuff
 public:
 	Graphics::Surface *loadThumbnailFromSlot(int slot);
+	bool loadInfosFromSlot(int slot, InfoStuff *stuff);
 
 protected:
 	Graphics::Surface *loadThumbnail(Common::InSaveFile *file);
+	bool loadInfos(Common::InSaveFile *file, InfoStuff *stuff);
 	void saveThumbnail(Common::OutSaveFile *file);
+	void saveInfos(Common::OutSaveFile* file);
+
+	int32 _engineStartTime;
+	int32 _dialogStartTime;
 
 protected:
 	/* Script VM - should be in Script class */





More information about the Scummvm-git-logs mailing list