mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-24 05:01:43 +00:00
ACCESS: Added code for reading/writing savegame headers and list saves
This commit is contained in:
parent
8b9faf7de5
commit
8352808322
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -70,6 +70,11 @@ public:
|
||||
*/
|
||||
~EventsManager();
|
||||
|
||||
/**
|
||||
* Return frame counter
|
||||
*/
|
||||
uint32 getFrameCounter() { return _frameCounter; }
|
||||
|
||||
/**
|
||||
* Sets the cursor
|
||||
*/
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -131,6 +131,8 @@ public:
|
||||
|
||||
void restorePalette();
|
||||
|
||||
void getPalette(byte *pal);
|
||||
|
||||
/**
|
||||
* Copy a buffer to the screen
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user