From 4e232814d5f96a7a0ed8aa2e249497c0d63dbace Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 26 May 2014 10:33:47 +0200 Subject: [PATCH] CGE2: Implement runGame(). --- engines/cge2/cge2.cpp | 6 ++++ engines/cge2/cge2.h | 10 ++++++ engines/cge2/cge2_main.cpp | 69 +++++++++++++++++++++++++++++++++++++- engines/cge2/cge2_main.h | 9 +++++ 4 files changed, 93 insertions(+), 1 deletion(-) diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 88fdfbb74d6..dd2ca16bf42 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -65,6 +65,9 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) for (int i = 0; i < kMaxPoint; i++) _point[i] = nullptr; _sys = nullptr; + _busyPtr = nullptr; + for (int i = 0; i < 2; i++) + _vol[i] = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -81,6 +84,9 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _waitRef = 0; _commandStat = { nullptr, { 0 , 0 } }; _taken = false; + _endGame = false; + for (int i = 0; i < 4; i++) + _flag[i] = false; } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 5275fa7bc8f..8520424ea59 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -68,6 +68,9 @@ class System; #define kPocketMax 4 #define kCaveMax 100 #define kMaxPoint 4 +#define kInfoX 160 +#define kInfoY -11 +#define kInfoW 180 enum CallbackType { kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume @@ -129,6 +132,9 @@ public: void handleFrame(); Sprite *locate(int ref); bool isHero(Sprite *spr); + void loadUser(); + void checkSaySwitch(); + void qGame(); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); @@ -199,6 +205,8 @@ public: int _ref[2]; } _commandStat; bool _taken; + bool _endGame; + bool _flag[4]; ResourceManager *_resman; Vga *_vga; @@ -219,6 +227,8 @@ public: Talk *_talk; V3D *_point[kMaxPoint]; System *_sys; + Sprite *_busyPtr; + Sprite *_vol[2]; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 501fa594cf6..ff80c59669b 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -498,7 +498,74 @@ void CGE2Engine::busy(bool on) { } void CGE2Engine::runGame() { - warning("STUB: 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); + + caveUp(_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) { + if (_flag[3]) // Flag FINIS + _commandHandler->addCallback(kCmdExec, -1, 0, kQGame); + mainLoop(); + } + + // If finishing game due to closing ScummVM window, explicitly save the game + if (!_endGame && canSaveGameStateCurrently()) + qGame(); + + _keyboard->setClient(nullptr); + _commandHandler->addCommand(kCmdClear, -1, 0, nullptr); + _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); + _mouse->off(); + _vga->_showQ->clear(); + _vga->_spareQ->clear(); +} + +void CGE2Engine::loadUser() { + warning("STUB: CGE2Engine::loadUser()"); +} + +void CGE2Engine::checkSaySwitch() { + warning("STUB: CGE2Engine::checkSaySwitch()"); +} + +void CGE2Engine::qGame() { + warning("STUB: CGE2Engine::qGame()"); + _endGame = true; } void CGE2Engine::loadTab() { diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index a37370546b2..98e7fbb1a31 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -40,6 +40,15 @@ namespace CGE2 { #define kGameFrameDelay (750 / 50) #define kGameTickDelay (750 / 62) +#define kMusicRef 122 +#define kPowerRef 123 +#define kDvolRef 124 +#define kMvolRef 125 +#define kRef 126 +#define kBusyRef 127 +#define kCapRef 128 +#define kVoxRef 129 + class System : public Sprite { public: int _funDel;