diff options
author | Adrian Frühwirth | 2018-04-06 00:06:38 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2018-04-07 09:26:20 +0200 |
commit | 00e59a312211c0b49433ad3e9923460ed85edc50 (patch) | |
tree | d604e3f19249c6a6436a83cc868fda9d12e57165 /engines/draci | |
parent | 07775ca71723ddb02de32b840b90742a173dca35 (diff) | |
download | scummvm-rg350-00e59a312211c0b49433ad3e9923460ed85edc50.tar.gz scummvm-rg350-00e59a312211c0b49433ad3e9923460ed85edc50.tar.bz2 scummvm-rg350-00e59a312211c0b49433ad3e9923460ed85edc50.zip |
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
Diffstat (limited to 'engines/draci')
-rw-r--r-- | engines/draci/detection.cpp | 10 | ||||
-rw-r--r-- | engines/draci/saveload.cpp | 11 | ||||
-rw-r--r-- | engines/draci/saveload.h | 2 |
3 files changed, 9 insertions, 14 deletions
diff --git a/engines/draci/detection.cpp b/engines/draci/detection.cpp index 65427bd8cd..9a76e3890c 100644 --- a/engines/draci/detection.cpp +++ b/engines/draci/detection.cpp @@ -132,10 +132,6 @@ SaveStateList DraciMetaEngine::listSaves(const char *target) const { Draci::DraciSavegameHeader header; if (Draci::readSavegameHeader(in, header)) { saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); - if (header.thumbnail) { - header.thumbnail->free(); - delete header.thumbnail; - } } delete in; } @@ -157,7 +153,11 @@ SaveStateDescriptor DraciMetaEngine::querySaveMetaInfos(const char *target, int if (f) { Draci::DraciSavegameHeader header; - Draci::readSavegameHeader(f, header); + if (!Draci::readSavegameHeader(f, header, false)) { + delete f; + return SaveStateDescriptor(); + } + delete f; // Create the return descriptor diff --git a/engines/draci/saveload.cpp b/engines/draci/saveload.cpp index 3e7f8651c1..e30af5375e 100644 --- a/engines/draci/saveload.cpp +++ b/engines/draci/saveload.cpp @@ -35,9 +35,8 @@ namespace Draci { static const char *const draciIdentString = "DRACI"; -bool readSavegameHeader(Common::InSaveFile *in, DraciSavegameHeader &header) { +WARN_UNUSED_RESULT bool readSavegameHeader(Common::InSaveFile *in, DraciSavegameHeader &header, bool skipThumbnail) { char saveIdentBuffer[6]; - header.thumbnail = NULL; // Validate the header Id in->read(saveIdentBuffer, 6); @@ -59,9 +58,9 @@ bool readSavegameHeader(Common::InSaveFile *in, DraciSavegameHeader &header) { header.playtime = in->readUint32LE(); // Get the thumbnail - header.thumbnail = Graphics::loadThumbnail(*in); - if (!header.thumbnail) + if (!Graphics::loadThumbnail(*in, header.thumbnail, skipThumbnail)) { return false; + } return true; } @@ -130,10 +129,6 @@ Common::Error loadSavegameData(int saveGameIdx, DraciEngine *vm) { if (!readSavegameHeader(f, header)) { return Common::kNoGameDataFoundError; } - if (header.thumbnail) { - header.thumbnail->free(); - delete header.thumbnail; - } // Pre-processing vm->_game->rememberRoomNumAsPrevious(); diff --git a/engines/draci/saveload.h b/engines/draci/saveload.h index 6f951a3409..bceaebb468 100644 --- a/engines/draci/saveload.h +++ b/engines/draci/saveload.h @@ -42,7 +42,7 @@ struct DraciSavegameHeader { class DraciEngine; -bool readSavegameHeader(Common::InSaveFile *in, DraciSavegameHeader &header); +WARN_UNUSED_RESULT bool readSavegameHeader(Common::InSaveFile *in, DraciSavegameHeader &header, bool skipThumbnail = true); void writeSavegameHeader(Common::OutSaveFile *out, const DraciSavegameHeader &header); Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName, DraciEngine &vm); Common::Error loadSavegameData(int saveGameIdx, DraciEngine *vm); |