[Scummvm-cvs-logs] scummvm master -> c442295b9fc2367905b9e20382e462e3ae9a7804

wjp wjp at usecode.org
Mon Sep 26 09:37:18 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:
c442295b9f AGI: Clean up save/load String usage


Commit: c442295b9fc2367905b9e20382e462e3ae9a7804
    https://github.com/scummvm/scummvm/commit/c442295b9fc2367905b9e20382e462e3ae9a7804
Author: Willem Jan Palenstijn (wjp at usecode.org)
Date: 2011-09-26T00:27:15-07:00

Commit Message:
AGI: Clean up save/load String usage

Changed paths:
    engines/agi/agi.h
    engines/agi/preagi.h
    engines/agi/saveload.cpp



diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 07729b6..b08b1f1 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -809,8 +809,8 @@ public:
 	virtual void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
 		int16 p4, int16 p5, int16 p6, int16 p7) = 0;
 	virtual void releaseImageStack() = 0;
-	virtual	int saveGame(Common::String fileName, Common::String saveName) = 0;
-	virtual int loadGame(Common::String fileName, bool checkId = true) = 0;
+	virtual	int saveGame(const Common::String& fileName, const Common::String& saveName) = 0;
+	virtual int loadGame(const Common::String& fileName, bool checkId = true) = 0;
 
 	int _soundemu;
 
@@ -881,11 +881,11 @@ public:
 
 	StringData _stringdata;
 
-	Common::String getSavegameFilename(int num);
+	Common::String getSavegameFilename(int num) const;
 	void getSavegameDescription(int num, char *buf, bool showEmpty = true);
 	int selectSlot();
-	int saveGame(Common::String fileName, Common::String saveName);
-	int loadGame(Common::String fileName, bool checkId = true);
+	int saveGame(const Common::String &fileName, const Common::String &saveName);
+	int loadGame(const Common::String &fileName, bool checkId = true);
 	int saveGameDialog();
 	int saveGameSimple();
 	int loadGameDialog();
diff --git a/engines/agi/preagi.h b/engines/agi/preagi.h
index 6f534c3..5d50fb5 100644
--- a/engines/agi/preagi.h
+++ b/engines/agi/preagi.h
@@ -73,8 +73,8 @@ protected:
 	void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
 		int16 p4, int16 p5, int16 p6, int16 p7) {}
 	void releaseImageStack() {}
-	int saveGame(Common::String fileName, Common::String saveName) { return -1; }
-	int loadGame(Common::String fileName, bool checkId = true) { return -1; }
+	int saveGame(const Common::String &fileName, const Common::String &saveName) { return -1; }
+	int loadGame(const Common::String &fileName, bool checkId = true) { return -1; }
 
 	// Game
 	Common::String getTargetName() { return _targetName; }
diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp
index 48d238a..3cebbf5 100644
--- a/engines/agi/saveload.cpp
+++ b/engines/agi/saveload.cpp
@@ -53,7 +53,7 @@ namespace Agi {
 
 static const uint32 AGIflag = MKTAG('A','G','I',':');
 
-int AgiEngine::saveGame(Common::String fileName, Common::String description) {
+int AgiEngine::saveGame(const Common::String &fileName, const Common::String &description) {
 	char gameIDstring[8] = "gameIDX";
 	int i;
 	Common::OutSaveFile *out;
@@ -252,7 +252,7 @@ int AgiEngine::saveGame(Common::String fileName, Common::String description) {
 	return result;
 }
 
-int AgiEngine::loadGame(Common::String fileName, bool checkId) {
+int AgiEngine::loadGame(const Common::String &fileName, bool checkId) {
 	char description[31], saveVersion, loadId[8];
 	int i, vtEntries = MAX_VIEWTABLE;
 	uint8 t;
@@ -546,7 +546,7 @@ int AgiEngine::loadGame(Common::String fileName, bool checkId) {
 #define NUM_SLOTS 100
 #define NUM_VISIBLE_SLOTS 12
 
-Common::String AgiEngine::getSavegameFilename(int num) {
+Common::String AgiEngine::getSavegameFilename(int num) const {
 	Common::String saveLoadSlot = _targetName;
 	saveLoadSlot += Common::String::format(".%.3d", num);
 	return saveLoadSlot;
@@ -858,7 +858,7 @@ int AgiEngine::saveGameDialog() {
 	// #2960567: "AGI: Ego partly erased in Load/Save thumbnails"
 	_gfx->doUpdate();
 
-	int result = saveGame(fileName.c_str(), desc);
+	int result = saveGame(fileName, desc);
 
 	if (result == errOK)
 		messageBox("Game saved.");
@@ -871,7 +871,7 @@ int AgiEngine::saveGameDialog() {
 int AgiEngine::saveGameSimple() {
 	Common::String fileName = getSavegameFilename(0);
 
-	int result = saveGame(fileName.c_str(), "Default savegame");
+	int result = saveGame(fileName, "Default savegame");
 	if (result != errOK)
 		messageBox("Error saving game.");
 	return result;
@@ -906,7 +906,7 @@ int AgiEngine::loadGameDialog() {
 
 	Common::String fileName = getSavegameFilename(_firstSlot + slot);
 
-	if ((rc = loadGame(fileName.c_str())) == errOK) {
+	if ((rc = loadGame(fileName)) == errOK) {
 		messageBox("Game restored.");
 		_game.exitAllLogics = 1;
 		_menu->enableAll();
@@ -926,7 +926,7 @@ int AgiEngine::loadGameSimple() {
 	_sound->stopSound();
 	closeWindow();
 
-	if ((rc = loadGame(fileName.c_str())) == errOK) {
+	if ((rc = loadGame(fileName)) == errOK) {
 		messageBox("Game restored.");
 		_game.exitAllLogics = 1;
 		_menu->enableAll();
@@ -979,12 +979,12 @@ void AgiEngine::releaseImageStack() {
 
 void AgiEngine::checkQuickLoad() {
 	if (ConfMan.hasKey("save_slot")) {
-		Common::String saveNameBuffer = Common::String::format("%s.%03d", _targetName.c_str(), ConfMan.getInt("save_slot"));
+		Common::String saveNameBuffer = getSavegameFilename(ConfMan.getInt("save_slot"));
 
 		_sprites->eraseBoth();
 		_sound->stopSound();
 
-		if (loadGame(saveNameBuffer.c_str(), false) == errOK) {	 // Do not check game id
+		if (loadGame(saveNameBuffer, false) == errOK) {	 // Do not check game id
 			_game.exitAllLogics = 1;
 			_menu->enableAll();
 		}
@@ -992,8 +992,7 @@ void AgiEngine::checkQuickLoad() {
 }
 
 Common::Error AgiEngine::loadGameState(int slot) {
-	char saveLoadSlot[12];
-	sprintf(saveLoadSlot, "%s.%.3d", _targetName.c_str(), slot);
+	Common::String saveLoadSlot = getSavegameFilename(slot);
 
 	_sprites->eraseBoth();
 	_sound->stopSound();
@@ -1008,9 +1007,8 @@ Common::Error AgiEngine::loadGameState(int slot) {
 }
 
 Common::Error AgiEngine::saveGameState(int slot, const Common::String &desc) {
-	char saveLoadSlot[12];
-	sprintf(saveLoadSlot, "%s.%.3d", _targetName.c_str(), slot);
-	if (saveGame(saveLoadSlot, desc.c_str()) == errOK)
+	Common::String saveLoadSlot = getSavegameFilename(slot);
+	if (saveGame(saveLoadSlot, desc) == errOK)
 		return Common::kNoError;
 	else
 		return Common::kUnknownError;






More information about the Scummvm-git-logs mailing list