diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/dreamweb/dreamweb.cpp | 16 | ||||
-rw-r--r-- | engines/dreamweb/dreamweb.h | 4 | ||||
-rw-r--r-- | engines/dreamweb/saveload.cpp | 40 |
3 files changed, 24 insertions, 36 deletions
diff --git a/engines/dreamweb/dreamweb.cpp b/engines/dreamweb/dreamweb.cpp index 2e2d993d0a..12fea56202 100644 --- a/engines/dreamweb/dreamweb.cpp +++ b/engines/dreamweb/dreamweb.cpp @@ -51,7 +51,6 @@ DreamWebEngine::DreamWebEngine(OSystem *syst, const DreamWebGameDescription *gam _console = 0; DebugMan.addDebugChannel(kDebugAnimation, "Animation", "Animation Debug Flag"); DebugMan.addDebugChannel(kDebugSaveLoad, "SaveLoad", "Track Save/Load Function"); - _outSaveFile = 0; _inSaveFile = 0; _speed = 1; _turbo = false; @@ -260,8 +259,6 @@ void DreamWebEngine::closeFile() { _file.close(); delete _inSaveFile; _inSaveFile = 0; - delete _outSaveFile; - _outSaveFile = 0; } Common::String DreamWebEngine::getSavegameFilename(int slot) const { @@ -273,12 +270,6 @@ Common::String DreamWebEngine::getSavegameFilename(int slot) const { return filename; } -void DreamWebEngine::openSaveFileForWriting(const Common::String &name) { - processEvents(); - delete _outSaveFile; - _outSaveFile = _saveFileMan->openForSaving(name); -} - bool DreamWebEngine::openSaveFileForReading(const Common::String &name) { processEvents(); delete _inSaveFile; @@ -286,13 +277,6 @@ bool DreamWebEngine::openSaveFileForReading(const Common::String &name) { return _inSaveFile != 0; } -uint DreamWebEngine::writeToSaveFile(const uint8 *data, uint size) { - processEvents(); - if (!_outSaveFile) - error("save file was not opened for writing"); - return _outSaveFile->write(data, size); -} - uint DreamWebEngine::readFromSaveFile(uint8 *data, uint size) { processEvents(); if (!_inSaveFile) diff --git a/engines/dreamweb/dreamweb.h b/engines/dreamweb/dreamweb.h index 28ca021896..f296f051a4 100644 --- a/engines/dreamweb/dreamweb.h +++ b/engines/dreamweb/dreamweb.h @@ -106,9 +106,6 @@ public: Common::String getSavegameFilename(int slot) const; - void openSaveFileForWriting(const Common::String &name); - uint writeToSaveFile(const uint8 *data, uint size); - bool openSaveFileForReading(const Common::String &name); uint readFromSaveFile(uint8 *data, uint size); @@ -151,7 +148,6 @@ private: Common::RandomSource _rnd; Common::File _file; - Common::OutSaveFile *_outSaveFile; Common::InSaveFile *_inSaveFile; uint _speed; diff --git a/engines/dreamweb/saveload.cpp b/engines/dreamweb/saveload.cpp index ad95f318c1..95dc353d5e 100644 --- a/engines/dreamweb/saveload.cpp +++ b/engines/dreamweb/saveload.cpp @@ -31,12 +31,6 @@ namespace DreamGen { // Temporary storage for loading the room from a savegame Room g_madeUpRoomDat; -void DreamGenContext::openForSave(unsigned int slot) { - Common::String filename = engine->getSavegameFilename(slot); - debug(1, "openForSave(%s)", filename.c_str()); - engine->openSaveFileForWriting(filename); -} - bool DreamGenContext::openForLoad(unsigned int slot) { Common::String filename = engine->getSavegameFilename(slot); debug(1, "openForLoad(%s)", filename.c_str()); @@ -323,7 +317,14 @@ void DreamGenContext::savePosition(unsigned int slot, const uint8 *descbuf) { madeUpRoom.facing = data.byte(kFacing); madeUpRoom.b27 = 255; - openForSave(slot); + + engine->processEvents(); // TODO: Is this necessary? + + Common::String filename = engine->getSavegameFilename(slot); + debug(1, "openForSave(%s)", filename.c_str()); + Common::OutSaveFile *outSaveFile = engine->getSaveFileManager()->openForSaving(filename); + if (!outSaveFile) // TODO: Do proper error handling! + error("save could not be opened for writing"); // Initialize new header FileHeader header; @@ -341,18 +342,25 @@ void DreamGenContext::savePosition(unsigned int slot, const uint8 *descbuf) { for (int i = 0; i < 6; ++i) header.setLen(i, len[i]); - engine->writeToSaveFile((const uint8 *)&header, sizeof(FileHeader)); - engine->writeToSaveFile(descbuf, len[0]); - engine->writeToSaveFile(data.ptr(kStartvars, len[1]), len[1]); - engine->writeToSaveFile(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]); - engine->writeToSaveFile(getSegment(data.word(kBuffers)).ptr(kListofchanges, len[3]), len[3]); + outSaveFile->write((const uint8 *)&header, sizeof(FileHeader)); + outSaveFile->write(descbuf, len[0]); + outSaveFile->write(data.ptr(kStartvars, len[1]), len[1]); + outSaveFile->write(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]); + outSaveFile->write(getSegment(data.word(kBuffers)).ptr(kListofchanges, len[3]), len[3]); // len[4] == 48, which is sizeof(Room) plus 16 for 'Roomscango' - engine->writeToSaveFile((const uint8 *)&madeUpRoom, sizeof(Room)); - engine->writeToSaveFile(data.ptr(kRoomscango, 16), 16); + outSaveFile->write((const uint8 *)&madeUpRoom, sizeof(Room)); + outSaveFile->write(data.ptr(kRoomscango, 16), 16); - engine->writeToSaveFile(data.ptr(kReelroutines, len[5]), len[5]); - engine->closeFile(); + outSaveFile->write(data.ptr(kReelroutines, len[5]), len[5]); + + outSaveFile->finalize(); + if (outSaveFile->err()) { + // TODO: Do proper error handling + warning("an error occurred while writing the savegame"); + } + + delete outSaveFile; } void DreamGenContext::loadPosition(unsigned int slot) { |