aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2011-09-26 09:27:15 +0200
committerWillem Jan Palenstijn2011-09-26 09:27:15 +0200
commitc442295b9fc2367905b9e20382e462e3ae9a7804 (patch)
treeca906f3de4d11229eb726dd334a01d0cf523fd7a
parentcfb12c8f91932f88a96caabdb1d52f5945c78fec (diff)
downloadscummvm-rg350-c442295b9fc2367905b9e20382e462e3ae9a7804.tar.gz
scummvm-rg350-c442295b9fc2367905b9e20382e462e3ae9a7804.tar.bz2
scummvm-rg350-c442295b9fc2367905b9e20382e462e3ae9a7804.zip
AGI: Clean up save/load String usage
-rw-r--r--engines/agi/agi.h10
-rw-r--r--engines/agi/preagi.h4
-rw-r--r--engines/agi/saveload.cpp26
3 files changed, 19 insertions, 21 deletions
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 07729b6ca1..b08b1f1eba 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 6f534c37f6..5d50fb5af8 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 48d238a047..3cebbf50c8 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;