diff options
author | Paul Gilbert | 2011-07-10 09:44:46 +1000 |
---|---|---|
committer | Paul Gilbert | 2011-07-10 09:44:46 +1000 |
commit | 989e071bb9d101696f5498d1eeea5e32c7291e5d (patch) | |
tree | 4391491dcb98c027bd867330044be27436f2a4c7 | |
parent | cf1a45f8a8ecfe758dfb6a420b004821528a19cc (diff) | |
download | scummvm-rg350-989e071bb9d101696f5498d1eeea5e32c7291e5d.tar.gz scummvm-rg350-989e071bb9d101696f5498d1eeea5e32c7291e5d.tar.bz2 scummvm-rg350-989e071bb9d101696f5498d1eeea5e32c7291e5d.zip |
CGE: Implemented code for saving games, removing the need for the SavTab array
-rw-r--r-- | engines/cge/cge.cpp | 51 | ||||
-rw-r--r-- | engines/cge/cge.h | 5 | ||||
-rw-r--r-- | engines/cge/cge_main.cpp | 83 |
3 files changed, 57 insertions, 82 deletions
diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 2c173b8990..25fc4f7c00 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -116,57 +116,6 @@ void CGEEngine::setup() { _volume[0] = 0; _volume[1] = 0; - _savTab[0]._ptr = &_now; - _savTab[0]._len = sizeof(_now); - _savTab[0]._flag = true; - _savTab[1]._ptr = &_oldLev; - _savTab[1]._len = sizeof(_oldLev); - _savTab[1]._flag = true; - _savTab[2]._ptr = &_demoText; - _savTab[2]._len = sizeof(_demoText); - _savTab[2]._flag = true; - _savTab[3]._ptr = &_game; - _savTab[3]._len = sizeof(_game); - _savTab[3]._flag = true; - _savTab[4]._ptr = &_game; - _savTab[4]._len = sizeof(_game); - _savTab[4]._flag = true; - _savTab[5]._ptr = &_game; - _savTab[5]._len = sizeof(_game); - _savTab[5]._flag = true; - _savTab[6]._ptr = &_game; - _savTab[6]._len = sizeof(_game); - _savTab[6]._flag = true; - _savTab[7]._ptr = &_game; - _savTab[7]._len = sizeof(_game); - _savTab[7]._flag = true; - _savTab[8]._ptr = &_vga->_mono; - _savTab[8]._len = sizeof(_vga->_mono); - _savTab[8]._flag = false; - _savTab[9]._ptr = &_music; - _savTab[9]._len = sizeof(_music); - _savTab[9]._flag = true; - _savTab[10]._ptr = _volume; - _savTab[10]._len = sizeof(_volume); - _savTab[10]._flag = true; - _savTab[11]._ptr = _flag; - _savTab[11]._len = sizeof(_flag); - _savTab[11]._flag = true; - _savTab[12]._ptr = _heroXY; -// _savTab[12]._len = sizeof(_heroXY); FIXME: illegal sizeof - _savTab[12]._len = 0; - _savTab[12]._flag = true; - _savTab[13]._ptr = _barriers; -// _savTab[13]._len = sizeof(_barriers); FIXME: illegal sizeof - _savTab[13]._len = 0; - _savTab[13]._flag = true; - _savTab[14]._ptr = _pocref; - _savTab[14]._len = sizeof(_pocref); - _savTab[14]._flag = true; - _savTab[15]._ptr = NULL; - _savTab[15]._len = 0; - _savTab[15]._flag = false; - if (_isDemo) { _maxCaveArr[0] = CAVE_MAX; _maxCaveArr[1] = -1; diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 4f6b452850..49f2c46e40 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -25,6 +25,7 @@ #include "cge/general.h" #include "common/random.h" +#include "common/serializer.h" #include "engines/engine.h" #include "gui/debugger.h" #include "graphics/surface.h" @@ -58,6 +59,7 @@ class CGEEngine : public Engine { private: uint32 _lastFrame; void tick(); + void syncHeader(Common::Serializer &s); public: CGEEngine(OSystem *syst, const ADGameDescription *gameDescription); ~CGEEngine(); @@ -69,7 +71,6 @@ public: int _oldLev; bool _jbw; int _pocPtr; - SavTab _savTab[16]; bool _music; int _pocref[POCKET_NX]; uint8 _volume[2]; @@ -124,7 +125,7 @@ public: void setIRQ(); void setDMA(); void mainLoop(); - void saveGame(XFile &file); + void saveGame(Common::WriteStream *file); void switchMusic(); void selectPocket(int n); void expandSprite(Sprite *spr); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 0135b0441a..256cee6795 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -27,6 +27,7 @@ #include "common/scummsys.h" #include "common/memstream.h" +#include "common/savefile.h" #include "common/serializer.h" #include "cge/general.h" #include "cge/sound.h" @@ -176,18 +177,9 @@ Cluster XZ(Couple xy) { return XZ(x, y); } -void CGEEngine::loadGame(XFile &file, bool tiny = false) { - Sprite *spr; +void CGEEngine::syncHeader(Common::Serializer &s) { int i; - // Read the data into a data buffer - int size = file.size() - file.mark(); - byte *dataBuffer = new byte[size]; - file.read(dataBuffer, size); - Common::MemoryReadStream readStream(dataBuffer, size, DisposeAfterUse::YES); - Common::Serializer s(&readStream, NULL); - - // Synchronise header data s.syncAsUint16LE(_now); s.syncAsUint16LE(_oldLev); s.syncAsUint16LE(_demoText); @@ -210,10 +202,32 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { for (i = 0; i < POCKET_NX; ++i) s.syncAsUint16LE(_pocref[i]); - uint16 checksum; - s.syncAsUint16LE(checksum); - if (checksum != SVGCHKSUM) - error("%s", _text->getText(BADSVG_TEXT)); + if (s.isSaving()) { + // Write checksum + int checksum = SVGCHKSUM; + s.syncAsUint16LE(checksum); + } else { + // Read checksum and validate it + uint16 checksum; + s.syncAsUint16LE(checksum); + if (checksum != SVGCHKSUM) + error("%s", _text->getText(BADSVG_TEXT)); + } +} + +void CGEEngine::loadGame(XFile &file, bool tiny = false) { + Sprite *spr; + int i; + + // Read the data into a data buffer + int size = file.size() - file.mark(); + byte *dataBuffer = new byte[size]; + file.read(dataBuffer, size); + Common::MemoryReadStream readStream(dataBuffer, size, DisposeAfterUse::YES); + Common::Serializer s(&readStream, NULL); + + // Synchronise header data + syncHeader(s); if (Startup::_core < CORE_HIG) _music = false; @@ -253,7 +267,7 @@ void CGEEngine::saveSound() { } -void CGEEngine::saveGame(XFile &file) { +void CGEEngine::saveGame(Common::WriteStream *file) { SavTab *st; Sprite *spr; int i; @@ -266,18 +280,19 @@ void CGEEngine::saveGame(XFile &file) { _volume[0] = _sndDrvInfo.Vol2._d; _volume[1] = _sndDrvInfo.Vol2._m; - for (st = _savTab; st->_ptr; st++) { - if (file._error) - error("Bad SVG"); - file.write((uint8 *) st->_ptr, st->_len); - } + Common::Serializer s(NULL, file); + + // Synchronise header data + syncHeader(s); - file.write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); + // Loop through saving the sprite data + for (spr = _vga->_spareQ->first(); spr; spr = spr->_next) { + if ((spr->_ref >= 1000) && !s.err()) + spr->sync(s); + } - for (spr = _vga->_spareQ->first(); spr; spr = spr->_next) - if (spr->_ref >= 1000) - if (!file._error) - file.write((uint8 *)spr, sizeof(*spr)); + // Finish writing out game data + file->finalize(); } void CGEEngine::heroCover(int cvr) { @@ -715,8 +730,12 @@ void CGEEngine::qGame() { caveDown(); _oldLev = _lev; saveSound(); - CFile file = CFile(usrPath(_usrFnam), WRI, RCrypt); - saveGame(file); + + // Write out the user's progress + Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(Common::String(_usrFnam)); + saveGame(saveFile); + delete saveFile; + _vga->sunset(); _finis = true; } @@ -1531,10 +1550,16 @@ void CGEEngine::loadUser() { SVG0FILE file = SVG0FILE(SVG0NAME); loadGame(file); } else { + // TODO: I think this was only used by the original developers to create the initial + // game state savegame. Verify this is the case, and if so remove this block loadScript(progName(INI_EXT)); _music = true; - CFile file = CFile(SVG0NAME, WRI); - saveGame(file); + + Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving( + Common::String(SVG0NAME)); + saveGame(saveFile); + delete saveFile; + error("Ok [%s]", SVG0NAME); } } |