From d8026b9ef72d7ca22721486244309ccd4a003cae Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 3 Mar 2014 00:42:41 -0500 Subject: MADS: Implementing Scene::doFrame --- engines/mads/action.cpp | 7 ++-- engines/mads/action.h | 7 ++-- engines/mads/events.h | 4 +- engines/mads/game.cpp | 2 + engines/mads/game.h | 1 + engines/mads/player.cpp | 31 +++++++++++++++ engines/mads/player.h | 10 +++++ engines/mads/scene.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++ engines/mads/scene.h | 13 +++++++ engines/mads/scene_data.cpp | 7 ++-- engines/mads/scene_data.h | 6 ++- 11 files changed, 170 insertions(+), 13 deletions(-) (limited to 'engines/mads') diff --git a/engines/mads/action.cpp b/engines/mads/action.cpp index 9a8080761b..134321f4c7 100644 --- a/engines/mads/action.cpp +++ b/engines/mads/action.cpp @@ -34,6 +34,7 @@ MADSAction::MADSAction(MADSEngine *vm) : _vm(vm) { _statusTextIndex = -1; _selectedAction = 0; _inProgress = false; + _savedSelectedRow = false; } void MADSAction::clear() { @@ -49,9 +50,9 @@ void MADSAction::clear() { _hotspotId = -1; _v86F3A = -1; _v86F4C = -1; - _action.verbId = -1; - _action.objectNameId = -1; - _action.indirectObjectId = -1; + _action._verbId = -1; + _action._objectNameId = -1; + _action._indirectObjectId = -1; _textChanged = true; _walkFlag = false; } diff --git a/engines/mads/action.h b/engines/mads/action.h index 780168a62a..da738ac34f 100644 --- a/engines/mads/action.h +++ b/engines/mads/action.h @@ -50,9 +50,9 @@ enum { class MADSEngine; struct ActionDetails { - int verbId; - int objectNameId; - int indirectObjectId; + int _verbId; + int _objectNameId; + int _indirectObjectId; }; struct MADSActionSavedFields { @@ -86,6 +86,7 @@ public: int _hotspotId; MADSActionSavedFields _savedFields; bool _walkFlag; + bool _savedSelectedRow; // Unknown fields int16 _v86F3A; diff --git a/engines/mads/events.h b/engines/mads/events.h index 0a6913b38e..2782253bcc 100644 --- a/engines/mads/events.h +++ b/engines/mads/events.h @@ -37,8 +37,6 @@ class MADSEngine; class EventsManager { private: MADSEngine *_vm; - CursorType _cursorId; - CursorType _newCursorId; uint32 _gameCounter; uint32 _priorFrameTime; Common::Point _mousePos; @@ -55,6 +53,8 @@ private: void checkForNextFrameCounter(); public: SpriteAsset *_cursorSprites; + CursorType _cursorId; + CursorType _newCursorId; bool _mouseClicked; bool _mouseReleased; byte _mouseButtons; diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index c90cf62210..37027685dd 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -56,6 +56,8 @@ Game::Game(MADSEngine *vm): _vm(vm), _surface(nullptr), _objects(vm), _playerSpritesFlag = false; _currentTimer = 0; _updateSceneFlag = false; + _abortTimersMode = ABORTMODE_0; + _abortTimersMode2 = ABORTMODE_0; } Game::~Game() { diff --git a/engines/mads/game.h b/engines/mads/game.h index 2bfa53db18..148fc121cd 100644 --- a/engines/mads/game.h +++ b/engines/mads/game.h @@ -114,6 +114,7 @@ public: int _v4; int _abortTimers; int _abortTimers2; + AbortTimerMode _abortTimersMode; AbortTimerMode _abortTimersMode2; uint32 _currentTimer; public: diff --git a/engines/mads/player.cpp b/engines/mads/player.cpp index 4130ad295f..b0f4b72667 100644 --- a/engines/mads/player.cpp +++ b/engines/mads/player.cpp @@ -84,8 +84,39 @@ void Player::resetActionList() { warning("TODO: Player::resetActionList"); } +void Player::setDest(const Common::Point &pt, int facing) { + warning("TODO: Player::setDest"); +} + +void Player::nextFrame() { + _priorTimer += _ticksAmount; + if (_vm->_events->_currentTimer >= _priorTimer) { + _priorTimer = _vm->_events->_currentTimer; + if (_moving) { + move(); + } else { + idle(); + } + + postUpdate(); + update(); + } +} + +void Player::move() { + warning("TODO: Player::move"); +} + void Player::idle() { warning("TODO: Player::idle"); } +void Player::postUpdate() { + warning("TODO: Player::postUpdate"); +} + +void Player::update() { + warning("TODO: Player::update"); +} + } // End of namespace MADS diff --git a/engines/mads/player.h b/engines/mads/player.h index f82492f243..7792fb6bdd 100644 --- a/engines/mads/player.h +++ b/engines/mads/player.h @@ -39,6 +39,12 @@ private: void reset(); void resetActionList(); + + void move(); + + void postUpdate(); + + void update(); public: int _direction; int _newDirection; @@ -74,6 +80,10 @@ public: void updateFrame(); void idle(); + + void setDest(const Common::Point &pt, int facing); + + void nextFrame(); }; } // End of namespace MADS diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index 86b59ccc8b..47b9bfac0d 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -42,6 +42,8 @@ Scene::Scene(MADSEngine *vm): _vm(vm), _spriteSlots(vm), _action(_vm), _v1A = _v1C = 0; _roomChanged = false; _reloadSceneFlag = false; + _destFacing = 0; + _freeAnimationFlag = false; _verbList.push_back(VerbInit(VERB_LOOK, 2, 0)); _verbList.push_back(VerbInit(VERB_TAKE, 2, 0)); @@ -276,6 +278,7 @@ void Scene::loop() { void Scene::doFrame() { Player &player = _vm->_game->_player; + bool flag = false; if (_action._selectedAction || !player._stepEnabled) { _action.clear(); @@ -285,6 +288,75 @@ void Scene::doFrame() { if (!_vm->_game->_abortTimers && !player._unk3) { if (_dynamicHotspots._changed) _dynamicHotspots.refresh(); + + _screenObjects.check(player._stepEnabled && !_action._startWalkFlag && + !_vm->_game->_abortTimers2); + } + + if (_action._selectedAction && player._stepEnabled && !_action._startWalkFlag && + !_vm->_game->_abortTimers && !player._unk3) { + _action.startAction(); + if (_action._activeAction._verbId == Nebular::NOUN_LOOK_AT) { + _action._activeAction._verbId = VERB_LOOK; + _action._savedSelectedRow = false; + } + + flag = true; + } + + if (flag || (_vm->_game->_abortTimers && _vm->_game->_abortTimersMode == ABORTMODE_2)) { + doPreactions(); + } + + checkStartWalk(); + if (!_vm->_game->_abortTimers2) + _vm->_events->_currentTimer = _vm->_events->getFrameCounter(); + + if ((_action._inProgress && !player._moving && !_action._startWalkFlag && + player._newDirection == player._direction) || + (_vm->_game->_abortTimers && _vm->_game->_abortTimersMode == ABORTMODE_0)) { + doAction(); + } + + if (_currentSceneId != _nextSceneId) { + _freeAnimationFlag = true; + } else { + doSceneStep(); + checkKeyboard(); + + if (_currentSceneId != _nextSceneId) { + _freeAnimationFlag = true; + } else { + player.nextFrame(); + + // Cursor update code + CursorType cursorId = CURSOR_ARROW; + if (_action._v83338 == 1 && !_screenObjects._v7FECA && + _screenObjects._category == CAT_HOTSPOT) { + int idx = _screenObjects._selectedObject - _interface._screenObjectsCount; + if (idx >= (int)_hotspots.size()) { + idx -= _hotspots.size(); + _vm->_events->_newCursorId = _dynamicHotspots[idx]._cursor; + } else { + _vm->_events->_newCursorId = _hotspots[idx]._cursor; + } + + cursorId = _vm->_events->_newCursorId == CURSOR_NONE ? + CURSOR_ARROW : _vm->_events->_newCursorId; + } + + if (!player._stepEnabled) + cursorId = CURSOR_WAIT; + if (cursorId >= _vm->_events->_cursorSprites->getCount()) + cursorId = (CursorType)_vm->_events->_cursorSprites->getCount(); + _vm->_events->_newCursorId = cursorId; + + if (cursorId != _vm->_events->_cursorId) { + _vm->_events->setCursor(cursorId); + } + + // TODO: Rest of Scene::doFrame + } } } @@ -292,6 +364,29 @@ void Scene::leftClick() { warning("TODO: Scene::leftClick"); } +void Scene::doPreactions() { + warning("TODO: Scene::doPreactions"); +} + +void Scene::doAction() { + warning("TODO: Scene::doAction"); +} + +void Scene::checkStartWalk() { + if (_action._startWalkFlag && _action._walkFlag) { + _vm->_game->_player.setDest(_destPos, _destFacing); + _action._startWalkFlag = false; + } +} + +void Scene::doSceneStep() { + warning("TODO: Scene::doSceneStep"); +} + +void Scene::checkKeyboard() { + warning("TODO: Scene::checkKeyboard"); +} + void Scene::free() { warning("TODO: Scene::free"); } diff --git a/engines/mads/scene.h b/engines/mads/scene.h index a02c4a5d79..4b822d111b 100644 --- a/engines/mads/scene.h +++ b/engines/mads/scene.h @@ -59,6 +59,16 @@ private: * Handles a single frame within the game scene */ void doFrame(); + + void doPreactions(); + + void doAction(); + + void checkStartWalk(); + + void doSceneStep(); + + void checkKeyboard(); protected: MADSEngine *_vm; public: @@ -93,6 +103,7 @@ public: SceneNodeList _nodes; Common::StringArray _vocabStrings; Animation *_animation; + bool _freeAnimationFlag; int _depthStyle; int _bandsRange; int _scaleRange; @@ -104,6 +115,8 @@ public: MADSAction _action; bool _roomChanged; bool _reloadSceneFlag; + Common::Point _destPos; + int _destFacing; /** * Constructor diff --git a/engines/mads/scene_data.cpp b/engines/mads/scene_data.cpp index 601d719b8d..10d346ed11 100644 --- a/engines/mads/scene_data.cpp +++ b/engines/mads/scene_data.cpp @@ -217,7 +217,7 @@ DynamicHotspot::DynamicHotspot() { _descId = 0; _field14 = 0; _articleNumber = 0; - _cursor = 0; + _cursor = CURSOR_NONE; } /*------------------------------------------------------------------------*/ @@ -292,7 +292,7 @@ KernelMessage::KernelMessage() { Hotspot::Hotspot() { _facing = 0; _articleNumber = 0; - _cursor = 0; + _cursor = CURSOR_NONE; _vocabId = 0; _verbId = 0; } @@ -307,7 +307,7 @@ Hotspot::Hotspot(Common::SeekableReadStream &f) { _facing = f.readByte(); _articleNumber = f.readByte(); f.skip(1); - _cursor = f.readByte(); + _cursor = (CursorType)f.readByte(); _vocabId = f.readUint16LE(); _verbId = f.readUint16LE(); } @@ -354,6 +354,7 @@ void SceneNode::load(Common::SeekableReadStream *f) { InterfaceSurface::InterfaceSurface(MADSEngine *vm): _vm(vm) { _category = CAT_NONE; + _screenObjectsCount = 0; } void InterfaceSurface::elementHighlighted() { diff --git a/engines/mads/scene_data.h b/engines/mads/scene_data.h index 8b874a144f..c11c59aee1 100644 --- a/engines/mads/scene_data.h +++ b/engines/mads/scene_data.h @@ -30,6 +30,7 @@ #include "common/rect.h" #include "mads/action.h" #include "mads/assets.h" +#include "mads/events.h" #include "mads/game_data.h" namespace MADS { @@ -185,7 +186,7 @@ public: int _descId; int _field14; int _articleNumber; - int _cursor; + CursorType _cursor; DynamicHotspot(); }; @@ -271,7 +272,7 @@ public: Common::Point _feetPos; int _facing; int _articleNumber; - int _cursor; + CursorType _cursor; int _vocabId; int _verbId; @@ -356,6 +357,7 @@ private: MADSEngine *_vm; public: ScrCategory _category; + int _screenObjectsCount; public: /** * Constructor -- cgit v1.2.3