Permalink
Browse files

XEEN: Implementing savegame code

  • Loading branch information...
dreammaster committed Jan 12, 2018
1 parent ebc3d27 commit 93935a779883131f7f9568153cf29ead2affd833
Showing with 63 additions and 29 deletions.
  1. +2 −1 engines/xeen/events.cpp
  2. +3 −0 engines/xeen/events.h
  3. +9 −2 engines/xeen/files.cpp
  4. +14 −3 engines/xeen/files.h
  5. +35 −18 engines/xeen/saves.cpp
  6. +0 −5 engines/xeen/saves.h
View
@@ -31,7 +31,7 @@
namespace Xeen {
EventsManager::EventsManager(XeenEngine *vm) : _vm(vm),
EventsManager::EventsManager(XeenEngine *vm) : _vm(vm), _playTime(0),
_frameCounter(0), _priorFrameCounterTime(0), _gameCounter(0),
_leftButton(false), _rightButton(false), _sprites("mouse.icn") {
Common::fill(&_gameCounters[0], &_gameCounters[6], 0);
@@ -181,6 +181,7 @@ void EventsManager::waitForPressAnimated() {
void EventsManager::nextFrame() {
++_frameCounter;
++_playTime;
// Allow debugger to update
_vm->_debugger->update();
View
@@ -41,6 +41,7 @@ class EventsManager {
uint32 _priorFrameCounterTime;
uint32 _gameCounter;
uint32 _gameCounters[6];
uint32 _playTime;
Common::Queue<Common::KeyState> _keys;
SpriteResource _sprites;
@@ -107,6 +108,8 @@ class EventsManager {
uint32 timeElapsed4() const { return _frameCounter - _gameCounters[4]; }
uint32 timeElapsed5() const { return _frameCounter - _gameCounters[5]; }
uint32 getTicks() { return _frameCounter; }
uint32 playTime() const { return _playTime; }
void setPlayTime(uint32 time) { _playTime = time; }
bool wait(uint numFrames, bool interruptable = true);
View
@@ -23,6 +23,7 @@
#include "common/scummsys.h"
#include "common/archive.h"
#include "common/memstream.h"
#include "common/substream.h"
#include "common/textconsole.h"
#include "xeen/xeen.h"
#include "xeen/files.h"
@@ -393,9 +394,10 @@ void SaveArchive::load(Common::SeekableReadStream *stream) {
loadIndex(stream);
delete[] _data;
_data = new byte[stream->size()];
_dataSize = stream->size();
_data = new byte[_dataSize];
stream->seek(0);
stream->read(_data, stream->size());
stream->read(_data, _dataSize);
// Load in the character stats and active party
Common::SeekableReadStream *chr = createReadStreamForMember("maze.chr");
@@ -435,6 +437,11 @@ void SaveArchive::reset(CCArchive *src) {
load(&f);
}
void SaveArchive::save(Common::WriteStream &s) {
s.writeUint32LE(_dataSize);
s.write(_data, _dataSize);
}
/*------------------------------------------------------------------------*/
OutFile::OutFile(const Common::String &filename) :
View
@@ -258,9 +258,8 @@ class SaveArchive : public BaseCCArchive {
private:
Party *_party;
byte *_data;
uint32 _dataSize;
Common::HashMap<uint16, Common::MemoryWriteStreamDynamic *> _newData;
void load(Common::SeekableReadStream *stream);
public:
SaveArchive(Party *party);
~SaveArchive();
@@ -270,8 +269,20 @@ class SaveArchive : public BaseCCArchive {
*/
void reset(CCArchive *src);
// Archive implementation
/**
* Archive implementation
*/
virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const;
/**
* Loads a save archive from a stream
*/
void load(Common::SeekableReadStream *stream);
/**
* Saves a save archive to a savegame
*/
void save(Common::WriteStream &s);
};
/**
View
@@ -23,6 +23,7 @@
#include "common/scummsys.h"
#include "common/algorithm.h"
#include "common/memstream.h"
#include "common/substream.h"
#include "graphics/scaler.h"
#include "graphics/thumbnail.h"
#include "xeen/saves.h"
@@ -112,6 +113,9 @@ bool SavesManager::readSavegameHeader(Common::InSaveFile *in, XeenSavegameHeader
}
void SavesManager::writeSavegameHeader(Common::OutSaveFile *out, XeenSavegameHeader &header) {
EventsManager &events = *g_vm->_events;
Screen &screen = *g_vm->_screen;
// Write out a savegame header
out->write(SAVEGAME_STR, SAVEGAME_STR_SIZE + 1);
@@ -122,15 +126,14 @@ void SavesManager::writeSavegameHeader(Common::OutSaveFile *out, XeenSavegameHea
out->writeByte('\0');
// Write a thumbnail of the screen
/*
uint8 thumbPalette[768];
_screen->getPalette(thumbPalette);
screen.getPalette(thumbPalette);
Graphics::Surface saveThumb;
::createThumbnail(&saveThumb, (const byte *)_screen->getPixels(),
_screen->w, _screen->h, thumbPalette);
::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);
@@ -139,7 +142,7 @@ void SavesManager::writeSavegameHeader(Common::OutSaveFile *out, XeenSavegameHea
out->writeSint16LE(td.tm_mday);
out->writeSint16LE(td.tm_hour);
out->writeSint16LE(td.tm_min);
// out->writeUint32LE(_events->getFrameCounter());
out->writeUint32LE(events.playTime());
}
Common::Error SavesManager::saveGameState(int slot, const Common::String &desc) {
@@ -152,8 +155,16 @@ Common::Error SavesManager::saveGameState(int slot, const Common::String &desc)
header._saveName = desc;
writeSavegameHeader(out, header);
Common::Serializer s(nullptr, out);
synchronize(s);
// Loop through saving the sides' save archives
SaveArchive *archives[2] = { File::_xeenSave, File::_darkSave };
for (int idx = 0; idx < 2; ++idx) {
if (archives[idx]) {
archives[idx]->save(*out);
} else {
// Side isn't present
out->writeUint32LE(0);
}
}
out->finalize();
delete out;
@@ -167,8 +178,6 @@ Common::Error SavesManager::loadGameState(int slot) {
if (!saveFile)
return Common::kReadingFailed;
Common::Serializer s(saveFile, nullptr);
// Load the savaegame header
XeenSavegameHeader header;
if (!readSavegameHeader(saveFile, header))
@@ -179,9 +188,22 @@ Common::Error SavesManager::loadGameState(int slot) {
delete header._thumbnail;
}
// Load most of the savegame data
synchronize(s);
delete saveFile;
// Set the total play time
g_vm->_events->setPlayTime(header._totalFrames);
// Loop through loading the sides' save archives
SaveArchive *archives[2] = { File::_xeenSave, File::_darkSave };
for (int idx = 0; idx < 2; ++idx) {
uint fileSize = saveFile->readUint32LE();
if (archives[idx]) {
Common::SeekableSubReadStream arcStream(saveFile, saveFile->pos(),
saveFile->pos() + fileSize);
archives[idx]->load(&arcStream);
} else {
assert(!fileSize);
}
}
return Common::kNoError;
}
@@ -190,9 +212,4 @@ Common::String SavesManager::generateSaveName(int slot) {
return Common::String::format("%s.%03d", _targetName.c_str(), slot);
}
void SavesManager::synchronize(Common::Serializer &s) {
// TODO
}
} // End of namespace Xeen
View
@@ -45,11 +45,6 @@ class SavesManager {
private:
Common::String _targetName;
private:
/**
* Synchronize savegame data
*/
void synchronize(Common::Serializer &s);
/**
* Support method that generates a savegame name
* @param slot Slot number

0 comments on commit 93935a7

Please sign in to comment.