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 +++++++++++++++++++++++++++++++++----- engines/macventure/macventure.h | 53 ++++++++++++- engines/macventure/script.h | 72 +++++++++++++++++ engines/macventure/world.cpp | 12 +-- engines/macventure/world.h | 30 +++++++- 5 files changed, 294 insertions(+), 30 deletions(-) create mode 100644 engines/macventure/script.h 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; } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index e4cda4e11b..e1a147c28a 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -34,6 +34,7 @@ #include "macventure/gui.h" #include "macventure/world.h" #include "macventure/stringtable.h" +#include "macventure/script.h" struct ADGameDescription; @@ -41,6 +42,9 @@ namespace MacVenture { class Console; class World; +class ScriptEngine; + +typedef uint32 ObjID; enum { kScreenWidth = 512, @@ -108,6 +112,29 @@ enum GameState { kGameStateQuitting }; +enum ObjectQueueID { + kFocusWindow = 2, + kOpenWindow = 3, + kCloseWindow = 4, + kUpdateObject = 7, + kUpdateWindow = 8, + kSetToPlayerParent = 12, + kHightlightExits = 13, + kAnimateBack = 14 +}; + +struct QueuedObject { + ObjectQueueID id; + ObjID object; + ObjID parent; + uint x; + uint y; + uint exitx; + uint exity; + bool hidden; + bool offsecreen; + bool invisible; +}; class MacVentureEngine : public Engine { @@ -120,6 +147,8 @@ public: void requestQuit(); void requestUnpause(); + void enqueueObject(ObjID id); + // Data retrieval bool isPaused(); Common::String getCommandsPausedString() const; @@ -129,6 +158,13 @@ public: private: void processEvents(); + bool runScriptEngine(); + void endGame(); + bool updateState(); + void runObjQueue(); + void updateControls(); + void resetVars(); + // Data loading bool loadGlobalSettings(); bool loadTextHuffman(); @@ -143,6 +179,7 @@ private: // Attributes Console *_debugger; Gui *_gui; World *_world; + ScriptEngine *_scriptEngine; // Engine state GameState _gameState; @@ -150,8 +187,20 @@ private: // Attributes StringTable *_filenames; Common::Huffman *_textHuffman; bool _oldTextEncoding; - bool _shouldQuit; - bool _paused; + bool _paused, _halted, _cmdReady; + bool _haltedAtEnd, _haltedInSelection; + bool _gameChanged; + + Common::List _objQueue; + Common::List _soundQueue; + Common::List _textQueue; + + // Selections + ObjID _destObject; + ControlAction _selectedControl; + ControlAction _activeControl; + Common::List _currentSelection; + Common::Point _deltaPoint; private: // Methods diff --git a/engines/macventure/script.h b/engines/macventure/script.h new file mode 100644 index 0000000000..66376924b0 --- /dev/null +++ b/engines/macventure/script.h @@ -0,0 +1,72 @@ +/* ScummVM - Graphic Adventure Engine +* +* ScummVM is the legal property of its developers, whose names +* are too numerous to list here. Please refer to the COPYRIGHT +* file distributed with this source distribution. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +*/ + +#ifndef MACVENTURE_SCRIPT_H +#define MACVENTURE_SCRIPT_H + +#include "macventure/macventure.h" + +namespace MacVenture { + +enum ControlAction { + kNoCommand = 0, + kStartOrResume = 1, + kClose = 2, + kTick = 3, + kActivateObject = 4, + kMoveObject = 5, + kConsume = 6, + kExamine = 7, + kGo = 8, + kHit = 9, + kOpen = 10, + kOperate = 11, + kSpeak = 12, + kBabble = 13, + kTargetName = 14, + kDebugObject = 15 +}; + +typedef uint32 ObjID; + +class ScriptEngine { +public: + ScriptEngine() {} + ~ScriptEngine() {} + + bool runControl(ControlAction action, ObjID source, ObjID destination, Common::Point delta) { + debug(7, "SCRIPT: Running control %d from obj %d into obj %d, at delta (%d, %d)", + action, source, destination, delta.x, delta.y); + + return false; + } + + bool resume() { + debug(7, "SCRIPT: Resume"); + + return false; + } +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 209b3c1096..d8fd9b4e39 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -17,11 +17,7 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); - _saveGame = new SaveGame(_engine, saveGameRes); - - debug("%x", _saveGame->getGroups()[0][1]); - debug(11, "Parent of player is %d", getObjAttr(1, 0)); - + _saveGame = new SaveGame(_engine, saveGameRes); _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); delete saveGameRes; @@ -39,7 +35,7 @@ World::~World() { } -uint32 World::getObjAttr(uint32 objID, uint32 attrID) { +uint32 World::getObjAttr(ObjID objID, uint32 attrID) { uint32 res; uint32 index = _engine->getGlobalSettings().attrIndices[attrID]; if (!(index & 0x80)) { // It's not a constant @@ -56,6 +52,10 @@ uint32 World::getObjAttr(uint32 objID, uint32 attrID) { return res; } +bool MacVenture::World::isObjActive(ObjID obj) { + return false; +} + bool World::loadStartGameFileName() { Common::SeekableReadStream *res; diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 9a74e5ce3e..e5c728ef58 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -28,8 +28,35 @@ namespace MacVenture { +typedef uint32 ObjID; typedef Common::Array AttributeGroup; +enum ObjectAttributeID { + kAttrParentObject = 0, + kAttrPosX = 1, + kAttrPosY = 2, + kAttrInvisible = 3, + kAttrUnclickable = 4, + kAttrUndraggable = 5, + kAttrContainerOpen = 6, + kAttrPrefixes = 7, + kAttrIsExit = 8, + kAttrExitX = 9, + kAttrExitY = 10, + kAttrHiddenExit = 11, + kAttrOtherDoor = 12, + kAttrIsOpen = 13, + kAttrIsLocked = 14, + kAttrWeight = 16, + kAttrSize = 17, + kAttrHasDescription = 19, + kAttrIsDoor = 20, + kAttrIsContainer = 22, + kAttrIsOperable = 23, + kAttrIsEnterable = 24, + kAttrIsEdible = 25 +}; + class SaveGame { public: SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res); @@ -55,7 +82,8 @@ public: World(MacVentureEngine *engine, Common::MacResManager *resMan); ~World(); - uint32 getObjAttr(uint32 objID, uint32 attrID); + uint32 getObjAttr(ObjID objID, uint32 attrID); + bool isObjActive(ObjID obj); private: bool loadStartGameFileName(); -- cgit v1.2.3