aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2014-08-30 08:45:42 -0400
committerPaul Gilbert2014-08-30 08:45:42 -0400
commit83528083228ea45ec3105b7dbcb720a1ac0dba55 (patch)
tree32969a892aa1f7a675a3bc783582fafc69fa4fae
parent8b9faf7de563b5c3a00cc9935eccb5e60b816632 (diff)
downloadscummvm-rg350-83528083228ea45ec3105b7dbcb720a1ac0dba55.tar.gz
scummvm-rg350-83528083228ea45ec3105b7dbcb720a1ac0dba55.tar.bz2
scummvm-rg350-83528083228ea45ec3105b7dbcb720a1ac0dba55.zip
ACCESS: Added code for reading/writing savegame headers and list saves
-rw-r--r--engines/access/access.cpp69
-rw-r--r--engines/access/access.h16
-rw-r--r--engines/access/detection.cpp26
-rw-r--r--engines/access/events.h5
-rw-r--r--engines/access/room.cpp2
-rw-r--r--engines/access/screen.cpp3
-rw-r--r--engines/access/screen.h2
7 files changed, 122 insertions, 1 deletions
diff --git a/engines/access/access.cpp b/engines/access/access.cpp
index 9525608b2b..f6382262fd 100644
--- a/engines/access/access.cpp
+++ b/engines/access/access.cpp
@@ -25,6 +25,8 @@
#include "common/debug-channels.h"
#include "common/events.h"
#include "engines/util.h"
+#include "graphics/scaler.h"
+#include "graphics/thumbnail.h"
#include "access/access.h"
namespace Access {
@@ -417,4 +419,71 @@ void AccessEngine::synchronize(Common::Serializer &s) {
_player->synchronize(s);
}
+const char *const SAVEGAME_STR = "ACCESS";
+#define SAVEGAME_STR_SIZE 6
+
+bool AccessEngine::readSavegameHeader(Common::InSaveFile *in, AccessSavegameHeader &header) {
+ char saveIdentBuffer[SAVEGAME_STR_SIZE + 1];
+ header._thumbnail = nullptr;
+
+ // Validate the header Id
+ in->read(saveIdentBuffer, SAVEGAME_STR_SIZE + 1);
+ if (strncmp(saveIdentBuffer, SAVEGAME_STR, SAVEGAME_STR_SIZE))
+ return false;
+
+ header._version = in->readByte();
+ if (header._version > ACCESS_SAVEGAME_VERSION)
+ return false;
+
+ // Read in the string
+ header._saveName.clear();
+ char ch;
+ while ((ch = (char)in->readByte()) != '\0') header._saveName += ch;
+
+ // Get the thumbnail
+ header._thumbnail = Graphics::loadThumbnail(*in);
+ if (!header._thumbnail)
+ return false;
+
+ // Read in save date/time
+ header._year = in->readSint16LE();
+ header._month = in->readSint16LE();
+ header._day = in->readSint16LE();
+ header._hour = in->readSint16LE();
+ header._minute = in->readSint16LE();
+ header._totalFrames = in->readUint32LE();
+
+ return true;
+}
+
+void AccessEngine::writeSavegameHeader(Common::OutSaveFile *out, AccessSavegameHeader &header) {
+ // Write out a savegame header
+ out->write(SAVEGAME_STR, SAVEGAME_STR_SIZE + 1);
+
+ out->writeByte(ACCESS_SAVEGAME_VERSION);
+
+ // Write savegame name
+ out->write(header._saveName.c_str(), header._saveName.size());
+ out->writeByte('\0');
+
+ // Write a thumbnail of the screen
+ uint8 thumbPalette[PALETTE_SIZE];
+ _screen->getPalette(thumbPalette);
+ Graphics::Surface saveThumb;
+ ::createThumbnail(&saveThumb, (const byte *)_screen->getPixels(),
+ _screen->w, _screen->h, thumbPalette);
+ Graphics::saveThumbnail(*out, saveThumb);
+ saveThumb.free();
+
+ // Write out the save date/time
+ TimeDate td;
+ g_system->getTimeAndDate(td);
+ out->writeSint16LE(td.tm_year + 1900);
+ out->writeSint16LE(td.tm_mon + 1);
+ out->writeSint16LE(td.tm_mday);
+ out->writeSint16LE(td.tm_hour);
+ out->writeSint16LE(td.tm_min);
+ out->writeUint32LE(_events->getFrameCounter());
+}
+
} // End of namespace Access
diff --git a/engines/access/access.h b/engines/access/access.h
index 7d76be9039..a192da3904 100644
--- a/engines/access/access.h
+++ b/engines/access/access.h
@@ -27,6 +27,7 @@
#include "common/system.h"
#include "common/error.h"
#include "common/random.h"
+#include "common/savefile.h"
#include "common/serializer.h"
#include "common/util.h"
#include "engines/engine.h"
@@ -77,6 +78,17 @@ struct AccessGameDescription;
extern const char *const _estTable[];
+#define ACCESS_SAVEGAME_VERSION 1
+
+struct AccessSavegameHeader {
+ uint8 _version;
+ Common::String _saveName;
+ Graphics::Surface *_thumbnail;
+ int _year, _month, _day;
+ int _hour, _minute;
+ int _totalFrames;
+};
+
class AccessEngine : public Engine {
private:
uint32 _lastTime, _curTime;
@@ -248,6 +260,10 @@ public:
void doLoadSave();
void freeChar();
+
+ static bool readSavegameHeader(Common::InSaveFile *in, AccessSavegameHeader &header);
+
+ void writeSavegameHeader(Common::OutSaveFile *out, AccessSavegameHeader &header);
};
} // End of namespace Access
diff --git a/engines/access/detection.cpp b/engines/access/detection.cpp
index dd75b28177..293cd3dccb 100644
--- a/engines/access/detection.cpp
+++ b/engines/access/detection.cpp
@@ -136,7 +136,33 @@ bool AccessMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGa
}
SaveStateList AccessMetaEngine::listSaves(const char *target) const {
+ Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
+ Common::StringArray filenames;
+ Common::String saveDesc;
+ Common::String pattern = Common::String::format("%s.0??", target);
+ Access::AccessSavegameHeader header;
+
+ filenames = saveFileMan->listSavefiles(pattern);
+ sort(filenames.begin(), filenames.end()); // Sort to get the files in numerical order
+
SaveStateList saveList;
+ for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
+ const char *ext = strrchr(file->c_str(), '.');
+ int slot = ext ? atoi(ext + 1) : -1;
+
+ if (slot >= 0 && slot < MAX_SAVES) {
+ Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file);
+
+ if (in) {
+ Access::AccessEngine::readSavegameHeader(in, header);
+ saveList.push_back(SaveStateDescriptor(slot, header._saveName));
+
+ header._thumbnail->free();
+ delete header._thumbnail;
+ delete in;
+ }
+ }
+ }
return saveList;
}
diff --git a/engines/access/events.h b/engines/access/events.h
index fdfb0a5043..014ff239b9 100644
--- a/engines/access/events.h
+++ b/engines/access/events.h
@@ -71,6 +71,11 @@ public:
~EventsManager();
/**
+ * Return frame counter
+ */
+ uint32 getFrameCounter() { return _frameCounter; }
+
+ /**
* Sets the cursor
*/
void setCursor(CursorType cursorId);
diff --git a/engines/access/room.cpp b/engines/access/room.cpp
index b9a07ea2ed..c9e150f8ea 100644
--- a/engines/access/room.cpp
+++ b/engines/access/room.cpp
@@ -433,7 +433,7 @@ void Room::handleCommand(int commandId) {
--commandId;
if (commandId == 9)
- _vm->doLoadSave();
+ _vm->openMainMenuDialog();
else if (commandId == _selectCommand) {
_vm->_events->debounceLeft();
commandOff();
diff --git a/engines/access/screen.cpp b/engines/access/screen.cpp
index 4b1c6d824d..26dd2e93ae 100644
--- a/engines/access/screen.cpp
+++ b/engines/access/screen.cpp
@@ -141,6 +141,9 @@ void Screen::restorePalette() {
&_savedPalettes[_savedPaletteCount][PALETTE_SIZE], &_rawPalette[0]);
}
+void Screen::getPalette(byte *pal) {
+ g_system->getPaletteManager()->grabPalette(pal, 0, 256);
+}
void Screen::forceFadeOut() {
const int FADE_AMOUNT = 2;
diff --git a/engines/access/screen.h b/engines/access/screen.h
index a166fded5e..47e03de2b8 100644
--- a/engines/access/screen.h
+++ b/engines/access/screen.h
@@ -131,6 +131,8 @@ public:
void restorePalette();
+ void getPalette(byte *pal);
+
/**
* Copy a buffer to the screen
*/