From ef5a1525149b8f9cfc6806fdb46217d912025195 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 16 Jun 2016 23:04:10 +0200 Subject: MACVENTURE: Add main loop --- engines/macventure/macventure.cpp | 157 +++++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 21 deletions(-) (limited to 'engines/macventure/macventure.cpp') diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 383832b80e..8466c1bf2d 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -53,10 +53,11 @@ MacVentureEngine::~MacVentureEngine() { delete _rnd; delete _debugger; delete _gui; + delete _scriptEngine; - if (_filenames) + if (_filenames) delete _filenames; - + if (_textHuffman) delete _textHuffman; } @@ -80,18 +81,42 @@ Common::Error MacVentureEngine::run() { error("Could not load the engine settings"); _oldTextEncoding = !loadTextHuffman(); - + _filenames = new StringTable(this, _resourceManager, kFilenamesStringTableID); - + // Big class instantiation _gui = new Gui(this, _resourceManager); _world = new World(this, _resourceManager); + _scriptEngine = new ScriptEngine(); - _shouldQuit = false; + _paused = false; + _halted = true; + _cmdReady = false; + _haltedAtEnd = false; + _haltedInSelection = false; while (!(_gameState == kGameStateQuitting)) { processEvents(); - - _gui->draw(); + + if (!_halted) { + _gui->draw(); + } + + if (_cmdReady || _halted) { + _halted = false; + if (runScriptEngine()) { + _halted = true; + _paused = true; + } else { + _paused = false; + if (!updateState()) { + updateControls(); + } + } + } + + if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { + endGame(); + } g_system->updateScreen(); g_system->delayMillis(50); @@ -101,29 +126,34 @@ Common::Error MacVentureEngine::run() { } void MacVentureEngine::requestQuit() { - _shouldQuit = true; + // TODO: Display save game dialog and such _gameState = kGameStateQuitting; } void MacVentureEngine::requestUnpause() { _paused = false; - _gameState = kGameStatePlaying; + _gameState = kGameStatePlaying; } -const GlobalSettings& MacVentureEngine::getGlobalSettings() const { - return _globalSettings; +void MacVentureEngine::enqueueObject(ObjID id) { + QueuedObject obj; + obj.parent = _world->getObjAttr(id, kAttrParentObject); + obj.x = _world->getObjAttr(id, kAttrPosX); + obj.y = _world->getObjAttr(id, kAttrPosY); + obj.exitx = _world->getObjAttr(id, kAttrExitX); + obj.exity = _world->getObjAttr(id, kAttrExitY); + obj.hidden = _world->getObjAttr(id, kAttrHiddenExit); + obj.offsecreen = _world->getObjAttr(id, kAttrInvisible); + obj.invisible = _world->getObjAttr(id, kAttrUnclickable); + _objQueue.push_back(obj); } -// Data retrieval - -bool MacVentureEngine::isPaused() { - return _paused; +const GlobalSettings& MacVentureEngine::getGlobalSettings() const { + return _globalSettings; } -Common::String MacVentureEngine::getCommandsPausedString() const { - return Common::String("Click to continue"); -} +// Private engine methods void MacVentureEngine::processEvents() { Common::Event event; @@ -132,7 +162,7 @@ void MacVentureEngine::processEvents() { continue; switch (event.type) { - case Common::EVENT_QUIT: + case Common::EVENT_QUIT: _gameState = kGameStateQuitting; break; default: @@ -141,6 +171,91 @@ void MacVentureEngine::processEvents() { } } +bool MacVenture::MacVentureEngine::runScriptEngine() { + debug(5, "MAIN: Running script engine"); + if (_haltedAtEnd) { + _haltedAtEnd = false; + if (_scriptEngine->resume()) { + _haltedAtEnd = true; + return true; + } + return false; + } + + if (_haltedInSelection) { + _haltedInSelection = false; + if (_scriptEngine->resume()) { + _haltedInSelection = true; + return true; + } + if (updateState()) + return true; + } + + while (!_currentSelection.empty()) { + ObjID obj = _currentSelection.front(); + _currentSelection.pop_front(); + if ((_gameState == kGameStateInit || _gameState == kGameStatePlaying) && _world->isObjActive(obj)) { + if (_scriptEngine->runControl(_selectedControl, obj, _destObject, _deltaPoint)) { + _haltedInSelection = true; + return true; + } + if (updateState()) { + return true; + } + } + } + if (_selectedControl == 1) + _gameChanged = false; + + else if (_gameState == kGameStateInit || _gameState == kGameStatePlaying){ + if (_scriptEngine->runControl(kTick, _selectedControl, _destObject, _deltaPoint)) { + _haltedAtEnd = true; + return true; + } + } + return false; +} + +void MacVentureEngine::endGame() { + requestQuit(); +} + +bool MacVentureEngine::updateState() { + runObjQueue(); + return true; +} + +void MacVentureEngine::runObjQueue() { + +} + +void MacVentureEngine::updateControls() { + if (_activeControl) + _activeControl = kNoCommand; + // toggleExits(); + // resetVars(); +} + +void MacVentureEngine::resetVars() { + _selectedControl = kNoCommand; + _activeControl = kNoCommand; + _currentSelection.clear(); + _destObject = 0; + _deltaPoint = Common::Point(0, 0); + _cmdReady = false; +} + +// Data retrieval + +bool MacVentureEngine::isPaused() { + return _paused; +} + +Common::String MacVentureEngine::getCommandsPausedString() const { + return Common::String("Click to continue"); +} + Common::String MacVentureEngine::getFilePath(FilePathID id) const { const Common::Array *names = _filenames->getStrings(); if (id <= 3) { // We don't want a file in the subdirectory @@ -226,8 +341,8 @@ bool MacVentureEngine::loadTextHuffman() { _textHuffman = new Common::Huffman(0, numEntries, masks, lengths, values); debug(5, "Text is huffman-encoded"); return true; - } - return false; + } + return false; } -- cgit v1.2.3