aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/xeen/events.cpp3
-rw-r--r--engines/xeen/events.h3
-rw-r--r--engines/xeen/files.cpp11
-rw-r--r--engines/xeen/files.h17
-rw-r--r--engines/xeen/saves.cpp53
-rw-r--r--engines/xeen/saves.h5
6 files changed, 63 insertions, 29 deletions
diff --git a/engines/xeen/events.cpp b/engines/xeen/events.cpp
index cc58edda89..babfdcb397 100644
--- a/engines/xeen/events.cpp
+++ b/engines/xeen/events.cpp
@@ -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();
diff --git a/engines/xeen/events.h b/engines/xeen/events.h
index cf74a641c6..e6018f6a87 100644
--- a/engines/xeen/events.h
+++ b/engines/xeen/events.h
@@ -41,6 +41,7 @@ private:
uint32 _priorFrameCounterTime;
uint32 _gameCounter;
uint32 _gameCounters[6];
+ uint32 _playTime;
Common::Queue<Common::KeyState> _keys;
SpriteResource _sprites;
@@ -107,6 +108,8 @@ public:
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);
diff --git a/engines/xeen/files.cpp b/engines/xeen/files.cpp
index 375b9df65a..0ed6dbd8a2 100644
--- a/engines/xeen/files.cpp
+++ b/engines/xeen/files.cpp
@@ -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) :
diff --git a/engines/xeen/files.h b/engines/xeen/files.h
index 34a96906cf..b5636b17ae 100644
--- a/engines/xeen/files.h
+++ b/engines/xeen/files.h
@@ -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 @@ public:
*/
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);
};
/**
diff --git a/engines/xeen/saves.cpp b/engines/xeen/saves.cpp
index 504bb18dd7..0bc41293f7 100644
--- a/engines/xeen/saves.cpp
+++ b/engines/xeen/saves.cpp
@@ -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
diff --git a/engines/xeen/saves.h b/engines/xeen/saves.h
index 2711cc7f2c..334ea3de8a 100644
--- a/engines/xeen/saves.h
+++ b/engines/xeen/saves.h
@@ -46,11 +46,6 @@ private:
Common::String _targetName;
private:
/**
- * Synchronize savegame data
- */
- void synchronize(Common::Serializer &s);
-
- /**
* Support method that generates a savegame name
* @param slot Slot number
*/