Permalink
Browse files

WINTERMUTE: Refactor getSaveSlot* function family

  • Loading branch information...
lolbot-iichan committed Aug 28, 2018
1 parent b956156 commit b32cff29312d9bd657eefc24b2094e89410060be
Showing with 24 additions and 40 deletions.
  1. +4 −8 engines/wintermute/base/base_game.cpp
  2. +18 −30 engines/wintermute/base/saveload.cpp
  3. +2 −2 engines/wintermute/base/saveload.h
@@ -1350,10 +1350,8 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
else if (strcmp(name, "GetSaveSlotDescription") == 0) {
stack->correctParams(1);
int slot = stack->pop()->getInt();
char desc[512];
desc[0] = '\0';
SaveLoad::getSaveSlotDescription(slot, desc);
stack->pushString(desc);
Common::String desc = SaveLoad::getSaveSlotDescription(slot);
stack->pushString(desc.c_str());
return STATUS_OK;
}

@@ -1368,10 +1366,8 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
stack->correctParams(1);
int slot = stack->pop()->getInt();

char desc[512];
desc[0] = '\0';
SaveLoad::getSaveSlotDescription(slot, desc);
stack->pushString(desc);
Common::String desc = SaveLoad::getSaveSlotDescription(slot);
stack->pushString(desc.c_str());

TimeDate time;
SaveLoad::getSaveSlotTimestamp(slot, &time);
@@ -158,53 +158,41 @@ void SaveLoad::afterLoadScript(void *script, void *data) {
}

Common::String SaveLoad::getSaveSlotFilename(int slot) {
Common::String filename;
BasePersistenceManager *pm = new BasePersistenceManager();
Common::String filename = pm->getFilenameForSlot(slot);
delete pm;
if (pm) {
filename = pm->getFilenameForSlot(slot);
delete pm;
}
debugC(kWintermuteDebugSaveGame, "getSaveSlotFileName(%d) = %s", slot, filename.c_str());
return filename;
}

bool SaveLoad::getSaveSlotDescription(int slot, char *buffer) {
buffer[0] = '\0';

Common::String SaveLoad::getSaveSlotDescription(int slot) {
Common::String description;
Common::String filename = getSaveSlotFilename(slot);
BasePersistenceManager *pm = new BasePersistenceManager();
if (!pm) {
return false;
}

if (!(pm->initLoad(filename))) {
if (pm) {
if ((pm->initLoad(filename))) {
description = pm->_savedDescription;
}
delete pm;
return false;
}

strcpy(buffer, pm->_savedDescription);
delete pm;

return true;
return description;
}

#ifdef ENABLE_FOXTAIL
bool SaveLoad::getSaveSlotTimestamp(int slot, TimeDate *time) {
void SaveLoad::getSaveSlotTimestamp(int slot, TimeDate *time) {
memset(time, 0, sizeof(TimeDate));

Common::String filename = getSaveSlotFilename(slot);
BasePersistenceManager *pm = new BasePersistenceManager();
if (!pm) {
return false;
}

if (!(pm->initLoad(filename))) {
if (pm) {
if ((pm->initLoad(filename))) {
const TimeDate *timestamp = &(pm->_savedTimestamp);
memcpy(time, timestamp, sizeof(TimeDate));
}
delete pm;
return false;
}

const TimeDate *timestamp = &(pm->_savedTimestamp);
memcpy(time, timestamp, sizeof(TimeDate));
delete pm;

return true;
}
#endif

@@ -37,9 +37,9 @@ class SaveLoad {
public:
static bool emptySaveSlot(int slot);
static bool isSaveSlotUsed(int slot);
static bool getSaveSlotDescription(int slot, char *buffer);
static Common::String getSaveSlotDescription(int slot);
#ifdef ENABLE_FOXTAIL
static bool getSaveSlotTimestamp(int slot, TimeDate *time);
static void getSaveSlotTimestamp(int slot, TimeDate *time);
#endif
static Common::String getSaveSlotFilename(int slot);

0 comments on commit b32cff2

Please sign in to comment.