Skip to content

Commit

Permalink
AGI: Clean up save/load String usage
Browse files Browse the repository at this point in the history
  • Loading branch information
wjp committed Sep 26, 2011
1 parent cfb12c8 commit c442295
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
10 changes: 5 additions & 5 deletions engines/agi/agi.h
Expand Up @@ -809,8 +809,8 @@ class AgiBase : public ::Engine {
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;

This comment has been minimized.

Copy link
@lordhoto

lordhoto Sep 26, 2011

Contributor

It's "const Common::String &fileName" instead of "const Common::String& fileName".

This comment has been minimized.

Copy link
@wjp

wjp Sep 26, 2011

Author Contributor

Thanks. I seem to be having trouble with this specific rule in the case of references... I did get most of them right this time, though :-)


int _soundemu;

Expand Down Expand Up @@ -881,11 +881,11 @@ class AgiEngine : public AgiBase {

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();
Expand Down
4 changes: 2 additions & 2 deletions engines/agi/preagi.h
Expand Up @@ -73,8 +73,8 @@ class PreAgiEngine : public AgiBase {
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; }
Expand Down
26 changes: 12 additions & 14 deletions engines/agi/saveload.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -979,21 +979,20 @@ 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();
}
}
}

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();
Expand All @@ -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;
Expand Down

0 comments on commit c442295

Please sign in to comment.