diff options
author | Max Horn | 2011-12-09 16:04:45 +0100 |
---|---|---|
committer | Willem Jan Palenstijn | 2011-12-11 10:02:50 +0100 |
commit | 6b226d5943b61e700a8ec7a3099c99f654f13b89 (patch) | |
tree | 1354d866876ea7c9c9f5463fe6878bf1cc6b0cdd /engines | |
parent | 3d753794e6c266e7ee7bd1858a6175d34707e140 (diff) | |
download | scummvm-rg350-6b226d5943b61e700a8ec7a3099c99f654f13b89.tar.gz scummvm-rg350-6b226d5943b61e700a8ec7a3099c99f654f13b89.tar.bz2 scummvm-rg350-6b226d5943b61e700a8ec7a3099c99f654f13b89.zip |
DREAMWEB: Do savefile reading directly in loadPosition() / scanForNames()
Diffstat (limited to 'engines')
-rw-r--r-- | engines/dreamweb/dreamweb.cpp | 17 | ||||
-rw-r--r-- | engines/dreamweb/dreamweb.h | 3 | ||||
-rw-r--r-- | engines/dreamweb/saveload.cpp | 51 | ||||
-rw-r--r-- | engines/dreamweb/stubs.h | 2 |
4 files changed, 29 insertions, 44 deletions
diff --git a/engines/dreamweb/dreamweb.cpp b/engines/dreamweb/dreamweb.cpp index 12fea56202..b4fc1b7b77 100644 --- a/engines/dreamweb/dreamweb.cpp +++ b/engines/dreamweb/dreamweb.cpp @@ -232,6 +232,9 @@ void DreamWebEngine::openFile(const Common::String &name) { closeFile(); if (_file.open(name)) return; + // File not found? See if there is a save state with this name + // FIXME: Is this really needed? If yes, document why; if not, + // remove all traces of _inSaveFile. _inSaveFile = _saveFileMan->openForLoading(name); if (_inSaveFile) return; @@ -270,20 +273,6 @@ Common::String DreamWebEngine::getSavegameFilename(int slot) const { return filename; } -bool DreamWebEngine::openSaveFileForReading(const Common::String &name) { - processEvents(); - delete _inSaveFile; - _inSaveFile = _saveFileMan->openForLoading(name); - return _inSaveFile != 0; -} - -uint DreamWebEngine::readFromSaveFile(uint8 *data, uint size) { - processEvents(); - if (!_inSaveFile) - error("save file was not opened for reading"); - return _inSaveFile->read(data, size); -} - void DreamWebEngine::keyPressed(uint16 ascii) { debug(2, "key pressed = %04x", ascii); uint16 in = (_base.data.word(DreamGen::kBufferin) + 1) & 0x0f; diff --git a/engines/dreamweb/dreamweb.h b/engines/dreamweb/dreamweb.h index f296f051a4..7ff0005fa4 100644 --- a/engines/dreamweb/dreamweb.h +++ b/engines/dreamweb/dreamweb.h @@ -106,9 +106,6 @@ public: Common::String getSavegameFilename(int slot) const; - bool openSaveFileForReading(const Common::String &name); - uint readFromSaveFile(uint8 *data, uint size); - void setShakePos(int pos) { _system->setShakePos(pos); } void printUnderMonitor(); diff --git a/engines/dreamweb/saveload.cpp b/engines/dreamweb/saveload.cpp index 95dc353d5e..40b645154e 100644 --- a/engines/dreamweb/saveload.cpp +++ b/engines/dreamweb/saveload.cpp @@ -31,13 +31,6 @@ namespace DreamGen { // Temporary storage for loading the room from a savegame Room g_madeUpRoomDat; -bool DreamGenContext::openForLoad(unsigned int slot) { - Common::String filename = engine->getSavegameFilename(slot); - debug(1, "openForLoad(%s)", filename.c_str()); - return engine->openSaveFileForReading(filename); -} - - void DreamGenContext::loadGame() { if (data.byte(kCommandtype) != 246) { data.byte(kCommandtype) = 246; @@ -321,7 +314,7 @@ void DreamGenContext::savePosition(unsigned int slot, const uint8 *descbuf) { engine->processEvents(); // TODO: Is this necessary? Common::String filename = engine->getSavegameFilename(slot); - debug(1, "openForSave(%s)", filename.c_str()); + debug(1, "savePosition: slot %d filename %s", slot, 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"); @@ -367,11 +360,15 @@ void DreamGenContext::loadPosition(unsigned int slot) { data.word(kTimecount) = 0; clearChanges(); - openForLoad(slot); + Common::String filename = engine->getSavegameFilename(slot); + debug(1, "loadPosition: slot %d filename %s", slot, filename.c_str()); + Common::InSaveFile *inSaveFile = engine->getSaveFileManager()->openForLoading(filename); + if (!inSaveFile) // TODO: Do proper error handling! + error("save could not be opened for reading"); FileHeader header; - engine->readFromSaveFile((uint8 *)&header, sizeof(FileHeader)); + inSaveFile->read((uint8 *)&header, sizeof(FileHeader)); // read segment lengths from savegame file header int len[6]; @@ -381,25 +378,25 @@ void DreamGenContext::loadPosition(unsigned int slot) { ::error("Error loading save: description buffer isn't 17 bytes"); if (slot < 7) { - engine->readFromSaveFile(data.ptr(kSavenames + 17*slot, len[0]), len[0]); + inSaveFile->read(data.ptr(kSavenames + 17*slot, len[0]), len[0]); } else { // The savenames buffer only has room for 7 descriptions uint8 namebuf[17]; - engine->readFromSaveFile(namebuf, 17); + inSaveFile->read(namebuf, 17); } - engine->readFromSaveFile(data.ptr(kStartvars, len[1]), len[1]); - engine->readFromSaveFile(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]); - engine->readFromSaveFile(getSegment(data.word(kBuffers)).ptr(kListofchanges, len[3]), len[3]); + inSaveFile->read(data.ptr(kStartvars, len[1]), len[1]); + inSaveFile->read(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]); + inSaveFile->read(getSegment(data.word(kBuffers)).ptr(kListofchanges, len[3]), len[3]); // len[4] == 48, which is sizeof(Room) plus 16 for 'Roomscango' // Note: the values read into g_madeUpRoomDat are only used in actualLoad, // which is (almost) immediately called after this function - engine->readFromSaveFile((uint8 *)&g_madeUpRoomDat, sizeof(Room)); - engine->readFromSaveFile(data.ptr(kRoomscango, 16), 16); + inSaveFile->read((uint8 *)&g_madeUpRoomDat, sizeof(Room)); + inSaveFile->read(data.ptr(kRoomscango, 16), 16); - engine->readFromSaveFile(data.ptr(kReelroutines, len[5]), len[5]); + inSaveFile->read(data.ptr(kReelroutines, len[5]), len[5]); - engine->closeFile(); + delete inSaveFile; } // Count number of save files, and load their descriptions into kSavenames @@ -408,24 +405,28 @@ unsigned int DreamGenContext::scanForNames() { FileHeader header; + // TODO: Change this to use SaveFileManager::listSavefiles() for (unsigned int slot = 0; slot < 7; ++slot) { - - if (!openForLoad(slot)) continue; + // Try opening savegame with the given slot id + Common::String filename = engine->getSavegameFilename(slot); + Common::InSaveFile *inSaveFile = engine->getSaveFileManager()->openForLoading(filename); + if (!inSaveFile) + continue; ++count; - engine->readFromSaveFile((uint8 *)&header, sizeof(FileHeader)); + inSaveFile->read((uint8 *)&header, sizeof(FileHeader)); if (header.len(0) != 17) { ::warning("Error loading save: description buffer isn't 17 bytes"); - engine->closeFile(); + delete inSaveFile; continue; } // NB: Only possible if slot < 7 - engine->readFromSaveFile(data.ptr(kSavenames + 17*slot, 17), 17); + inSaveFile->read(data.ptr(kSavenames + 17*slot, 17), 17); - engine->closeFile(); + delete inSaveFile; } al = (uint8)count; diff --git a/engines/dreamweb/stubs.h b/engines/dreamweb/stubs.h index 58d0ce0d28..5d99e231dc 100644 --- a/engines/dreamweb/stubs.h +++ b/engines/dreamweb/stubs.h @@ -306,8 +306,6 @@ void actualLoad(); void loadPosition(unsigned int slot); void savePosition(unsigned int slot, const uint8 *descbuf); - void openForSave(unsigned int slot); - bool openForLoad(unsigned int slot); uint16 allocateAndLoad(unsigned int size); void clearAndLoad(uint8 *buf, uint8 c, unsigned int size, unsigned int maxSize); void clearAndLoad(uint16 seg, uint8 c, unsigned int size, unsigned int maxSize); |