[Scummvm-cvs-logs] scummvm master -> 8755ebc0aa9526966bfa5001e0ce811df91166e5

bluegr md5 at scummvm.org
Wed Aug 24 09:44:16 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8755ebc0aa DRASCULA: Separated the save name syncing code, and added a TODO


Commit: 8755ebc0aa9526966bfa5001e0ce811df91166e5
    https://github.com/scummvm/scummvm/commit/8755ebc0aa9526966bfa5001e0ce811df91166e5
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2011-08-24T00:39:05-07:00

Commit Message:
DRASCULA: Separated the save name syncing code, and added a TODO

Changed paths:
    engines/drascula/drascula.h
    engines/drascula/saveload.cpp



diff --git a/engines/drascula/drascula.h b/engines/drascula/drascula.h
index 5ec4684..6f98c50 100644
--- a/engines/drascula/drascula.h
+++ b/engines/drascula/drascula.h
@@ -495,6 +495,8 @@ public:
 	void updateVolume(Audio::Mixer::SoundType soundType, int prevVolume);
 	void volumeControls();
 	bool saveLoadScreen();
+	void loadSaveNames();
+	void saveSaveNames();
 	void print_abc(const char *, int, int);
 	void delay(int ms);
 	bool confirmExit();
@@ -775,6 +777,7 @@ private:
 	RoomUpdate *_roomPreUpdates, *_roomUpdates;
 	RoomTalkAction *_roomActions;
 	TalkSequenceCommand *_talkSequences;
+	char _saveNames[10][23];
 
 	char **loadTexts(Common::File &in);
 	void freeTexts(char **ptr);
diff --git a/engines/drascula/saveload.cpp b/engines/drascula/saveload.cpp
index 664a082..c8622f3 100644
--- a/engines/drascula/saveload.cpp
+++ b/engines/drascula/saveload.cpp
@@ -26,20 +26,26 @@
 
 namespace Drascula {
 
-bool DrasculaEngine::saveLoadScreen() {
-	char names[10][23];
-	Common::String file;
-	int n, n2, num_sav = 0, y = 27;
+/**
+ * Loads the save names from the EPA index file.
+ *
+ * TODO: We should move the save names in their respective save files and get
+ * rid of this completely. A good example is the sword1 engine, which also used
+ * to have an index file for its saves, that has been removed.
+ * sword1 contains code that converts the old index-based saves into the new
+ * format without the index file, so we could apply this idea to drascula as
+ * well.
+ */
+void DrasculaEngine::loadSaveNames() {
 	Common::InSaveFile *sav;
-
-	clearRoom();
-
 	Common::String fileEpa = Common::String::format("%s.epa", _targetName.c_str());
+
+	// Create and initialize the index file, if it doesn't exist
 	if (!(sav = _saveFileMan->openForLoading(fileEpa))) {
 		Common::OutSaveFile *epa;
 		if (!(epa = _saveFileMan->openForSaving(fileEpa)))
 			error("Can't open %s file", fileEpa.c_str());
-		for (n = 0; n < NUM_SAVES; n++)
+		for (int n = 0; n < NUM_SAVES; n++)
 			epa->writeString("*\n");
 		epa->finalize();
 		delete epa;
@@ -47,11 +53,47 @@ bool DrasculaEngine::saveLoadScreen() {
 			error("Can't open %s file", fileEpa.c_str());
 		}
 	}
-	for (n = 0; n < NUM_SAVES; n++) {
-		strncpy(names[n], sav->readLine().c_str(), 23);
-		names[n][22] = '\0';	// make sure the savegame name is 0-terminated
+
+	// Load the index file
+	for (int n = 0; n < NUM_SAVES; n++) {
+		strncpy(_saveNames[n], sav->readLine().c_str(), 23);
+		_saveNames[n][22] = '\0';	// make sure the savegame name is 0-terminated
 	}
 	delete sav;
+}
+
+/**
+ * Saves the save names into the EPA index file.
+ *
+ * TODO: We should move the save names in their respective save files and get
+ * rid of this completely. A good example is the sword1 engine, which also used
+ * to have an index file for its saves, that has been removed.
+ * sword1 contains code that converts the old index-based saves into the new
+ * format without the index file, so we could apply this idea to drascula as
+ * well.
+ */
+void DrasculaEngine::saveSaveNames() {
+	Common::OutSaveFile *tsav;
+	Common::String fileEpa = Common::String::format("%s.epa", _targetName.c_str());
+
+	if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
+		error("Can't open %s file", fileEpa.c_str());
+	}
+	for (int n = 0; n < NUM_SAVES; n++) {
+		tsav->writeString(_saveNames[n]);
+		tsav->writeString("\n");
+	}
+	tsav->finalize();
+	delete tsav;
+}
+
+bool DrasculaEngine::saveLoadScreen() {
+	Common::String file;
+	int n, n2, num_sav = 0, y = 27;
+
+	clearRoom();
+
+	loadSaveNames();
 
 	loadPic("savescr.alg", bgSurface, HALF_PAL);
 
@@ -66,7 +108,7 @@ bool DrasculaEngine::saveLoadScreen() {
 		y = 27;
 		copyBackground();
 		for (n = 0; n < NUM_SAVES; n++) {
-			print_abc(names[n], 116, y);
+			print_abc(_saveNames[n], 116, y);
 			y = y + 9;
 		}
 		print_abc(select, 117, 15);
@@ -79,33 +121,24 @@ bool DrasculaEngine::saveLoadScreen() {
 			delay(50);
 			for (n = 0; n < NUM_SAVES; n++) {
 				if (mouseX > 115 && mouseY > y + (9 * n) && mouseX < 115 + 175 && mouseY < y + 10 + (9 * n)) {
-					strcpy(select, names[n]);
+					strcpy(select, _saveNames[n]);
 
 					if (strcmp(select, "*"))
 						selectionMade = 1;
 					else {
 						enterName();
-						strcpy(names[n], select);
+						strcpy(_saveNames[n], select);
 						if (selectionMade == 1) {
 							file = Common::String::format("%s%02d", _targetName.c_str(), n + 1);
 							saveGame(file.c_str());
-							Common::OutSaveFile *tsav;
-							if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
-								error("Can't open %s file", fileEpa.c_str());
-							}
-							for (n = 0; n < NUM_SAVES; n++) {
-								tsav->writeString(names[n]);
-								tsav->writeString("\n");
-							}
-							tsav->finalize();
-							delete tsav;
+							saveSaveNames();
 						}
 					}
 
 					print_abc(select, 117, 15);
 					y = 27;
 					for (n2 = 0; n2 < NUM_SAVES; n2++) {
-						print_abc(names[n2], 116, y);
+						print_abc(_saveNames[n2], 116, y);
 						y = y + 9;
 					}
 					if (selectionMade == 1) {
@@ -117,27 +150,18 @@ bool DrasculaEngine::saveLoadScreen() {
 
 			if (mouseX > 117 && mouseY > 15 && mouseX < 295 && mouseY < 24 && selectionMade == 1) {
 				enterName();
-				strcpy(names[num_sav], select);
+				strcpy(_saveNames[num_sav], select);
 				print_abc(select, 117, 15);
 				y = 27;
 				for (n2 = 0; n2 < NUM_SAVES; n2++) {
-					print_abc(names[n2], 116, y);
+					print_abc(_saveNames[n2], 116, y);
 					y = y + 9;
 				}
 
 				if (selectionMade == 1) {
 					file = Common::String::format("%s%02d", _targetName.c_str(), n + 1);
 					saveGame(file.c_str());
-					Common::OutSaveFile *tsav;
-					if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
-						error("Can't open %s file", fileEpa.c_str());
-					}
-					for (n = 0; n < NUM_SAVES; n++) {
-						tsav->writeString(names[n]);
-						tsav->writeString("\n");
-					}
-					tsav->finalize();
-					delete tsav;
+					saveSaveNames();
 				}
 			}
 
@@ -149,16 +173,7 @@ bool DrasculaEngine::saveLoadScreen() {
 				break;
 			} else if (mouseX > 208 && mouseY > 123 && mouseX < 282 && mouseY < 149 && selectionMade == 1) {
 				saveGame(file.c_str());
-				Common::OutSaveFile *tsav;
-				if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
-					error("Can't open %s file", fileEpa.c_str());
-				}
-				for (n = 0; n < NUM_SAVES; n++) {
-					tsav->writeString(names[n]);
-					tsav->writeString("\n");
-				}
-				tsav->finalize();
-				delete tsav;
+				saveSaveNames();
 			} else if (mouseX > 168 && mouseY > 154 && mouseX < 242 && mouseY < 180)
 				break;
 			else if (selectionMade == 0) {






More information about the Scummvm-git-logs mailing list