Permalink
Browse files

TOON: Add playtime to saved game

Supports saved games made in the current version or the the last saved game version.
  • Loading branch information...
dafioram authored and sev- committed Aug 18, 2018
1 parent 16ee8aa commit e2e0f9f5289a56031f9427040a4615264eeb9851
Showing with 23 additions and 8 deletions.
  1. +12 −6 engines/toon/detection.cpp
  2. +9 −1 engines/toon/toon.cpp
  3. +2 −1 engines/toon/toon.h
@@ -160,6 +160,7 @@ bool ToonMetaEngine::hasFeature(MetaEngineFeature f) const {
(f == kSavesSupportMetaInfo) ||
(f == kSavesSupportThumbnail) ||
(f == kSavesSupportCreationDate) ||
(f == kSavesSupportPlayTime) ||
(f == kSimpleSavesNames);
}

@@ -168,7 +169,7 @@ void ToonMetaEngine::removeSaveState(const char *target, int slot) const {
g_system->getSavefileManager()->removeSavefile(fileName);
}

int ToonMetaEngine::getMaximumSaveSlot() const { return 99; }
int ToonMetaEngine::getMaximumSaveSlot() const { return MAX_SAVE_SLOT; }

SaveStateList ToonMetaEngine::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
@@ -183,11 +184,11 @@ SaveStateList ToonMetaEngine::listSaves(const char *target) const {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNum = atoi(filename->c_str() + filename->size() - 3);

if (slotNum >= 0 && slotNum <= 99) {
if (slotNum >= 0 && slotNum <= MAX_SAVE_SLOT) {
Common::InSaveFile *file = saveFileMan->openForLoading(*filename);
if (file) {
int32 version = file->readSint32BE();
if (version != TOON_SAVEGAME_VERSION) {
if ( (version < 4) || (version > TOON_SAVEGAME_VERSION) ) {
delete file;
continue;
}
@@ -220,7 +221,7 @@ SaveStateDescriptor ToonMetaEngine::querySaveMetaInfos(const char *target, int s
if (file) {

int32 version = file->readSint32BE();
if (version != TOON_SAVEGAME_VERSION) {
if ( (version < 4) || (version > TOON_SAVEGAME_VERSION) ) {
delete file;
return SaveStateDescriptor();
}
@@ -232,8 +233,8 @@ SaveStateDescriptor ToonMetaEngine::querySaveMetaInfos(const char *target, int s

SaveStateDescriptor desc(slot, saveName);

Graphics::Surface *thumbnail;
if (!Graphics::loadThumbnail(*file, thumbnail)) {
Graphics::Surface *thumbnail = nullptr;
if (!Graphics::loadThumbnail(*file, thumbnail, false)) {
delete file;
return SaveStateDescriptor();
}
@@ -253,6 +254,11 @@ SaveStateDescriptor ToonMetaEngine::querySaveMetaInfos(const char *target, int s

desc.setSaveTime(hour, minutes);

if (version >= 5) {
uint32 playTimeMsec = file->readUint32BE();
desc.setPlayTime(playTimeMsec);
}

delete file;
return desc;
}
@@ -3378,6 +3378,8 @@ bool ToonEngine::saveGame(int32 slot, const Common::String &saveGameDesc) {

saveFile->writeUint32BE(saveDate);
saveFile->writeUint16BE(saveTime);
uint32 playTime = getTotalPlayTime();
saveFile->writeUint32BE(playTime);

// save global state
_gameState->save(saveFile);
@@ -3444,7 +3446,7 @@ bool ToonEngine::loadGame(int32 slot) {
return false;

int32 saveGameVersion = loadFile->readSint32BE();
if (saveGameVersion != TOON_SAVEGAME_VERSION) {
if ( (saveGameVersion < 4) || (saveGameVersion > TOON_SAVEGAME_VERSION) ) {
delete loadFile;
return false;
}
@@ -3456,6 +3458,12 @@ bool ToonEngine::loadGame(int32 slot) {

loadFile->skip(6); // date & time skip

uint32 playTimeMsec = 0;
if (saveGameVersion >= 5) {
playTimeMsec = loadFile->readUint32BE();
}
setTotalPlayTime(playTimeMsec);

if (_gameState->_currentScene != -1) {
exitScene();
}
@@ -47,8 +47,9 @@ struct ADGameDescription;

#define TOON_DAT_VER_MAJ 0 // 1 byte
#define TOON_DAT_VER_MIN 3 // 1 byte
#define TOON_SAVEGAME_VERSION 4
#define TOON_SAVEGAME_VERSION 5
#define DATAALIGNMENT 4
#define MAX_SAVE_SLOT 99

#define TOON_SCREEN_WIDTH 640
#define TOON_SCREEN_HEIGHT 400

0 comments on commit e2e0f9f

Please sign in to comment.