aboutsummaryrefslogtreecommitdiff
path: root/engines/toltecs/saveload.cpp
diff options
context:
space:
mode:
authorBenjamin Haisch2008-11-13 00:16:13 +0000
committerWillem Jan Palenstijn2011-11-20 22:43:07 +0100
commit9e78b5d393cadd6ce426f0184e136a38579c819a (patch)
treecd0c6d2352ef4c55849c0cf7763dffbaa1830d0b /engines/toltecs/saveload.cpp
parent47ae9085899a41f5ed5204183b008d4bff7c4a31 (diff)
downloadscummvm-rg350-9e78b5d393cadd6ce426f0184e136a38579c819a.tar.gz
scummvm-rg350-9e78b5d393cadd6ce426f0184e136a38579c819a.tar.bz2
scummvm-rg350-9e78b5d393cadd6ce426f0184e136a38579c819a.zip
TOLTECS: - Listing savestates via command line or Launcher
- Loading/Saving during run time Other savestate functions yet todo. I'll probably remove the "original" in-game menu and move everything to the GMM.
Diffstat (limited to 'engines/toltecs/saveload.cpp')
-rw-r--r--engines/toltecs/saveload.cpp80
1 files changed, 75 insertions, 5 deletions
diff --git a/engines/toltecs/saveload.cpp b/engines/toltecs/saveload.cpp
index b631b1d529..da62da40f4 100644
--- a/engines/toltecs/saveload.cpp
+++ b/engines/toltecs/saveload.cpp
@@ -30,6 +30,8 @@
#include "base/plugins.h"
#include "base/version.h"
+#include "graphics/thumbnail.h"
+
#include "sound/mixer.h"
#include "toltecs/toltecs.h"
@@ -44,14 +46,43 @@ namespace Toltecs {
/* TODO:
- Saveload is working so far but only one slot is supported until the game menu is implemented
- - Save with F6; Load with F9
+ - Save with F7; Load with F9
- Saving during an animation (AnimationPlayer) is not working correctly yet
- Maybe switch to SCUMM/Tinsel serialization approach?
*/
#define SAVEGAME_VERSION 0 // 0 is dev version until in official SVN
-void ToltecsEngine::savegame(const char *filename) {
+ToltecsEngine::kReadSaveHeaderError ToltecsEngine::readSaveHeader(Common::SeekableReadStream *in, bool loadThumbnail, SaveHeader &header) {
+
+ header.version = in->readUint32LE();
+ if (header.version != SAVEGAME_VERSION)
+ return kRSHEInvalidVersion;
+
+ byte descriptionLen = in->readByte();
+ header.description = "";
+ while (descriptionLen--)
+ header.description += (char)in->readByte();
+
+ if (loadThumbnail) {
+ header.thumbnail = new Graphics::Surface();
+ assert(header.thumbnail);
+ if (!Graphics::loadThumbnail(*in, *header.thumbnail)) {
+ delete header.thumbnail;
+ header.thumbnail = 0;
+ }
+ } else {
+ Graphics::skipThumbnailHeader(*in);
+ }
+
+ // Not used yet, reserved for future usage
+ header.gameID = in->readByte();
+ header.flags = in->readUint32LE();
+
+ return (in->ioFailed() ? kRSHEIoError : kRSHENoError);
+}
+
+void ToltecsEngine::savegame(const char *filename, const char *description) {
Common::OutSaveFile *out;
if (!(out = g_system->getSavefileManager()->openForSaving(filename))) {
@@ -61,6 +92,16 @@ void ToltecsEngine::savegame(const char *filename) {
out->writeUint32LE(SAVEGAME_VERSION);
+ byte descriptionLen = strlen(description);
+ out->writeByte(descriptionLen);
+ out->write(description, descriptionLen);
+
+ Graphics::saveThumbnail(*out);
+
+ // Not used yet, reserved for future usage
+ out->writeByte(0);
+ out->writeUint32LE(0);
+
out->writeUint16LE(_cameraX);
out->writeUint16LE(_cameraY);
out->writeUint16LE(_cameraHeight);
@@ -99,10 +140,14 @@ void ToltecsEngine::loadgame(const char *filename) {
warning("Can't open file '%s', game not loaded", filename);
return;
}
+
+ SaveHeader header;
+
+ kReadSaveHeaderError errorCode = readSaveHeader(in, false, header);
- uint32 version = in->readUint32LE();
- if (version != SAVEGAME_VERSION) {
- warning("Savegame '%s' too old, game not loaded (got v%d, need v%d)", filename, version, SAVEGAME_VERSION);
+ if (errorCode != kRSHENoError) {
+ warning("Error loading savegame '%s'", filename);
+ delete in;
return;
}
@@ -145,4 +190,29 @@ void ToltecsEngine::loadgame(const char *filename) {
}
+Common::Error ToltecsEngine::loadGameState(int slot) {
+ const char *fileName = getSavegameFilename(slot);
+ loadgame(fileName);
+}
+
+Common::Error ToltecsEngine::saveGameState(int slot, const char *description) {
+ const char *fileName = getSavegameFilename(slot);
+ savegame(fileName, description);
+}
+
+const char *ToltecsEngine::getSavegameFilename(int num) {
+ static Common::String filename;
+ filename = getSavegameFilename(_targetName, num);
+ return filename.c_str();
+}
+
+Common::String ToltecsEngine::getSavegameFilename(const Common::String &target, int num) {
+ assert(num >= 0 && num <= 999);
+
+ char extension[5];
+ sprintf(extension, "%03d", num);
+
+ return target + "." + extension;
+}
+
} // End of namespace Toltecs