From 8b8216bf2cfbaa016aa20a15eb7ac9069d8f9f21 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 4 Jul 2014 18:39:03 +0200 Subject: CGE2: Fully implement the save/load system. Now the toolbar is working too after loading. --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 65 +++++++++++++++++++++++++--------------------- engines/cge2/saveload.cpp | 23 +++++----------- engines/cge2/spare.cpp | 2 +- 4 files changed, 44 insertions(+), 47 deletions(-) diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index dddf0c3e23..f126da591f 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -149,6 +149,7 @@ public: void inf(const char *text, ColorBank col = kCBInf); void movie(const char *ext); void runGame(); + void initToolbar(); void loadHeroes(); void loadScript(const char *fname); void loadSprite(const char *fname, int ref, int scene, V3D &pos); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 804294d478..935a3c94e3 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -672,40 +672,11 @@ void CGE2Engine::runGame() { if (_quitFlag) return; - selectPocket(-1); - loadUser(); - _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, _music, nullptr); - if (!_music) - _midiPlayer->killMidi(); - - checkSaySwitch(); - - _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); - _infoLine->setText(nullptr); - _vga->_showQ->insert(_infoLine); + initToolbar(); sceneUp(_now); - _startupMode = 0; - _mouse->center(); - _mouse->off(); - _mouse->on(); - - _keyboard->setClient(_sys); - _commandHandler->addCommand(kCmdSeq, kPowerRef, 1, nullptr); - - _busyPtr = _vga->_showQ->locate(kBusyRef); - - _vol[0] = _vga->_showQ->locate(kDvolRef); - _vol[1] = _vga->_showQ->locate(kMvolRef); - - // these sprites are loaded with SeqPtr==0 (why?!) - if (_vol[0]) - _vol[0]->step((/*(int)SNDDrvInfo.VOL4.DL * */ _vol[0]->_seqCnt + _vol[0]->_seqCnt / 2) >> 4); - if (_vol[1]) - _vol[1]->step((/*(int)SNDDrvInfo.VOL4.ML * */ _vol[1]->_seqCnt + _vol[1]->_seqCnt / 2) >> 4); - // TODO: Recheck these! ^ // main loop while (!_endGame && !_quitFlag) { @@ -795,6 +766,40 @@ void CGE2Engine::loadPos() { error("Missing file: CGE.HXY"); } +void CGE2Engine::initToolbar() { + selectPocket(-1); + + _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, _music, nullptr); + if (!_music) + _midiPlayer->killMidi(); + + checkSaySwitch(); + + _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); + _infoLine->setText(nullptr); + _vga->_showQ->insert(_infoLine); + + _startupMode = 0; + _mouse->center(); + _mouse->off(); + _mouse->on(); + + _keyboard->setClient(_sys); + _commandHandler->addCommand(kCmdSeq, kPowerRef, 1, nullptr); + + _busyPtr = _vga->_showQ->locate(kBusyRef); + + _vol[0] = _vga->_showQ->locate(kDvolRef); + _vol[1] = _vga->_showQ->locate(kMvolRef); + + // these sprites are loaded with SeqPtr==0 (why?!) + if (_vol[0]) + _vol[0]->step((/*(int)SNDDrvInfo.VOL4.DL * */ _vol[0]->_seqCnt + _vol[0]->_seqCnt / 2) >> 4); + if (_vol[1]) + _vol[1]->step((/*(int)SNDDrvInfo.VOL4.ML * */ _vol[1]->_seqCnt + _vol[1]->_seqCnt / 2) >> 4); + // TODO: Recheck these! ^ +} + void CGE2Engine::releasePocket(Sprite *spr) { for (int i = 0; i < 2; i++) { for (int j = 0; j < kPocketMax; j++) { diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index f6cbbf93e1..0ea957f9e1 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -38,6 +38,7 @@ #include "cge2/hero.h" #include "cge2/text.h" #include "cge2/sound.h" +#include "cge2/cge2_main.h" namespace CGE2 { @@ -260,8 +261,7 @@ void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteS // Save the references of the items in the heroes pockets: for (int i = 0; i < 2; i++) { for (int j = 0; j < kPocketMax; j++) { - Sprite *spr = _heroTab[i]->_pocket[j]; - int ref = (spr) ? spr->_ref : -1; + int ref = _heroTab[i]->_downPocketId[j]; s.syncAsSint16LE(ref); } } @@ -271,7 +271,7 @@ void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteS for (int j = 0; j < kPocketMax; j++) { int ref = 0; s.syncAsSint16LE(ref); - _heroTab[i]->_pocket[j] = _spare->locate(ref); + _heroTab[i]->_downPocketId[j] = ref; } } } @@ -310,25 +310,13 @@ void CGE2Engine::syncHeader(Common::Serializer &s) { } Common::Error CGE2Engine::loadGameState(int slot) { - // Clear current game activity sceneDown(); resetGame(); - // If music is playing, kill it. - if (_music) - _midiPlayer->killMidi(); - if (!loadGame(slot)) return Common::kReadingFailed; - + initToolbar(); loadHeroes(); - sceneUp(_now); - - _busyPtr = _vga->_showQ->locate(kBusyRef); - - _vol[0] = _vga->_showQ->locate(kDvolRef); - _vol[1] = _vga->_showQ->locate(kMvolRef); - return Common::kNoError; } @@ -338,6 +326,9 @@ void CGE2Engine::resetGame() { _spare->clear(); _vga->_showQ->clear(); _commandHandler->reset(); + loadScript("CGE.INI"); + delete _infoLine; + _infoLine = new InfoLine(this, kInfoW); } bool CGE2Engine::loadGame(int slotNumber) { diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index a0c3f741eb..93c8a2674d 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -47,7 +47,7 @@ void Spare::sync(Common::Serializer &s) { for (int i = 0; i < size; i++) { Sprite *sprite = new Sprite(_vm); sprite->sync(s); - store(sprite); + update(sprite); } } } -- cgit v1.2.3