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

megath at users.sourceforge.net megath at users.sourceforge.net
Sun Oct 18 14:13:58 CEST 2009


Revision: 45219
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45219&view=rev
Author:   megath
Date:     2009-10-18 12:13:58 +0000 (Sun, 18 Oct 2009)

Log Message:
-----------
added thumbnails for the save states. removed snprintf's. 

Modified Paths:
--------------
    scummvm/trunk/engines/teenagent/detection.cpp
    scummvm/trunk/engines/teenagent/scene.cpp
    scummvm/trunk/engines/teenagent/teenagent.cpp

Modified: scummvm/trunk/engines/teenagent/detection.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/detection.cpp	2009-10-18 11:44:17 UTC (rev 45218)
+++ scummvm/trunk/engines/teenagent/detection.cpp	2009-10-18 12:13:58 UTC (rev 45219)
@@ -24,11 +24,13 @@
 
 #include "common/system.h"
 #include "common/savefile.h"
+#include "common/algorithm.h"
 
 #include "base/plugins.h"
 
 #include "engines/advancedDetector.h"
 #include "teenagent/teenagent.h"
+#include "graphics/thumbnail.h"
 
 static const PlainGameDescriptor teenAgentGames[] = {
 	{ "teenagent", "Teen Agent" },
@@ -91,7 +93,8 @@
 		case kSupportsListSaves:
 		case kSupportsDeleteSave:
 		case kSupportsLoadingDuringStartup:
-			//case kSavesSupportThumbnail:
+		case kSavesSupportMetaInfo:
+		case kSavesSupportThumbnail:
 			return true;
 		default:
 			return false;
@@ -110,9 +113,7 @@
 //	}
 
 	static Common::String generateGameStateFileName(const char *target, int slot) {
-		char slotStr[16];
-		snprintf(slotStr, sizeof(slotStr), ".%d", slot);
-		return slotStr;
+		return Common::String::printf("%s.%02d", target, slot);
 	}
 
 	virtual SaveStateList listSaves(const char *target) const {
@@ -120,8 +121,8 @@
 		pattern += ".*";
 
 		Common::StringList filenames = g_system->getSavefileManager()->listSavefiles(pattern);
-		bool slotsTable[MAX_SAVES];
-		memset(slotsTable, 0, sizeof(slotsTable));
+		Common::sort(filenames.begin(), filenames.end());
+
 		SaveStateList saveList;
 		for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
 			int slot;
@@ -129,18 +130,17 @@
 			if (ext && (slot = atoi(ext + 1)) >= 0 && slot < MAX_SAVES) {
 				Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file);
 				if (in) {
-					slotsTable[slot] = true;
+					char buf[25];
+					in->seek(0);
+					in->read(buf, 24);
+					buf[24] = 0;
+					Common::String description = buf;
+					saveList.push_back(SaveStateDescriptor(slot, description));
+					
 					delete in;
 				}
 			}
 		}
-		for (int slot = 0; slot < MAX_SAVES; ++slot) {
-			if (slotsTable[slot]) {
-				char description[64];
-				snprintf(description, sizeof(description), "teenagent.%02d", slot);
-				saveList.push_back(SaveStateDescriptor(slot, description));
-			}
-		}
 		return saveList;
 	}
 
@@ -152,6 +152,35 @@
 		Common::String filename = generateGameStateFileName(target, slot);
 		g_system->getSavefileManager()->removeSavefile(filename);
 	}
+
+	virtual SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const {
+		Common::String filename = generateGameStateFileName(target, slot);
+		Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename);
+		if (in == NULL)
+			return SaveStateDescriptor();
+
+		char buf[25];
+		in->seek(0);
+		in->read(buf, 24);
+		buf[24] = 0;
+
+		Common::String desc = buf;
+
+		in->seek(0x777a);
+		if (!Graphics::checkThumbnailHeader(*in))
+			return SaveStateDescriptor(slot, desc);
+
+		Graphics::Surface *thumb = new Graphics::Surface;
+		if (!Graphics::loadThumbnail(*in, *thumb)) {
+			delete thumb;
+			return SaveStateDescriptor(slot, desc);
+		}
+
+		SaveStateDescriptor ssd(slot, desc);
+		ssd.setThumbnail(thumb);
+
+		return ssd;
+	}
 };
 
 #if PLUGIN_ENABLED_DYNAMIC(TEENAGENT)

Modified: scummvm/trunk/engines/teenagent/scene.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/scene.cpp	2009-10-18 11:44:17 UTC (rev 45218)
+++ scummvm/trunk/engines/teenagent/scene.cpp	2009-10-18 12:13:58 UTC (rev 45219)
@@ -86,7 +86,7 @@
 	destination = point;
 	orientation = orient;
 	position0 = position;
-	progress_total = 1 + (int)(sqrt((float)position.sqrDist(destination)) / 10);
+	progress_total = 1 + (int)(0.5f + sqrt((float)position.sqrDist(destination)) / 10);
 	progress = 0;
 }
 

Modified: scummvm/trunk/engines/teenagent/teenagent.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/teenagent.cpp	2009-10-18 11:44:17 UTC (rev 45218)
+++ scummvm/trunk/engines/teenagent/teenagent.cpp	2009-10-18 12:13:58 UTC (rev 45219)
@@ -33,6 +33,7 @@
 #include "teenagent/scene.h"
 #include "teenagent/objects.h"
 #include "teenagent/music.h"
+#include "graphics/thumbnail.h"
 
 namespace TeenAgent {
 
@@ -162,16 +163,18 @@
 
 Common::Error TeenAgentEngine::loadGameState(int slot) {
 	debug(0, "loading from slot %d", slot);
-	char slotStr[16];
-	snprintf(slotStr, sizeof(slotStr), "teenagent.%d", slot);
-	Common::InSaveFile *in = _saveFileMan->openForLoading(slotStr);
+	Common::InSaveFile *in = _saveFileMan->openForLoading(Common::String::printf("teenagent.%02d", slot));
 	if (in == NULL)
+		in = _saveFileMan->openForLoading(Common::String::printf("teenagent.%d", slot));
+
+	if (in == NULL)
 		return Common::kReadPermissionDenied;
 
 	Resources *res = Resources::instance();
 
 	assert(res->dseg.size() >= 0x6478 + 0x777a);
 	char data[0x777a];
+	in->seek(0);
 	if (in->read(data, 0x777a) != 0x777a) {
 		delete in;
 		return Common::kReadingFailed;
@@ -193,9 +196,7 @@
 
 Common::Error TeenAgentEngine::saveGameState(int slot, const char *desc) {
 	debug(0, "saving to slot %d", slot);
-	char slotStr[16];
-	snprintf(slotStr, sizeof(slotStr), "teenagent.%d", slot);
-	Common::OutSaveFile *out = _saveFileMan->openForSaving(slotStr);
+	Common::OutSaveFile *out = _saveFileMan->openForSaving(Common::String::printf("teenagent.%02d", slot));
 	if (out == NULL)
 		return Common::kWritePermissionDenied;
 
@@ -208,7 +209,10 @@
 	assert(res->dseg.size() >= 0x6478 + 0x777a);
 	strncpy((char *)res->dseg.ptr(0x6478), desc, 0x16);
 	out->write(res->dseg.ptr(0x6478), 0x777a);
+	if (!Graphics::saveThumbnail(*out))
+		warning("saveThumbnail failed");
 	delete out;
+
 	return Common::kNoError;
 }
 


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