diff options
author | Paul Gilbert | 2014-03-02 23:09:17 -0500 |
---|---|---|
committer | Paul Gilbert | 2014-03-02 23:09:17 -0500 |
commit | 3a842a079c668e9dfc52a6056119d4932e8ef56d (patch) | |
tree | 5f74efaaf79b8c20c1494b1494493d6c39b0511c | |
parent | a0996b7384e5c3321af97347613120d2f90ab64e (diff) | |
download | scummvm-rg350-3a842a079c668e9dfc52a6056119d4932e8ef56d.tar.gz scummvm-rg350-3a842a079c668e9dfc52a6056119d4932e8ef56d.tar.bz2 scummvm-rg350-3a842a079c668e9dfc52a6056119d4932e8ef56d.zip |
MADS: Bulk of implementation of ScreenObjects::check
-rw-r--r-- | engines/mads/action.cpp | 4 | ||||
-rw-r--r-- | engines/mads/action.h | 2 | ||||
-rw-r--r-- | engines/mads/animation.cpp | 2 | ||||
-rw-r--r-- | engines/mads/events.cpp | 7 | ||||
-rw-r--r-- | engines/mads/events.h | 17 | ||||
-rw-r--r-- | engines/mads/game.cpp | 3 | ||||
-rw-r--r-- | engines/mads/game.h | 4 | ||||
-rw-r--r-- | engines/mads/player.cpp | 1 | ||||
-rw-r--r-- | engines/mads/player.h | 1 | ||||
-rw-r--r-- | engines/mads/scene.cpp | 37 | ||||
-rw-r--r-- | engines/mads/scene.h | 20 | ||||
-rw-r--r-- | engines/mads/scene_data.cpp | 154 | ||||
-rw-r--r-- | engines/mads/scene_data.h | 97 |
13 files changed, 314 insertions, 35 deletions
diff --git a/engines/mads/action.cpp b/engines/mads/action.cpp index ce2cf6aba8..9a8080761b 100644 --- a/engines/mads/action.cpp +++ b/engines/mads/action.cpp @@ -337,4 +337,8 @@ bool MADSAction::isAction(int verbId, int objectNameId, int indirectObjectId) { return true; } +void MADSAction::checkActionAtMousePos() { + warning("TODO: checkActionAtMousePos"); +} + } // End of namespace MADS diff --git a/engines/mads/action.h b/engines/mads/action.h index c38b842992..780168a62a 100644 --- a/engines/mads/action.h +++ b/engines/mads/action.h @@ -107,6 +107,8 @@ public: void startAction(); void checkAction(); bool isAction(int verbId, int objectNameId = 0, int indirectObjectId = 0); + + void checkActionAtMousePos(); }; } // End of namespace MADS diff --git a/engines/mads/animation.cpp b/engines/mads/animation.cpp index ebb2289443..8ea95ee168 100644 --- a/engines/mads/animation.cpp +++ b/engines/mads/animation.cpp @@ -287,7 +287,7 @@ void Animation::loadInterface(InterfaceSurface &interfaceSurface, MSurface &dept else if (header._animMode == 4) { // Load a scene interface Common::String resourceName = "*" + header._interfaceFile; - interfaceSurface.load(_vm, resourceName); + interfaceSurface.load(resourceName); if (palAnimData) palAnimData->clear(); diff --git a/engines/mads/events.cpp b/engines/mads/events.cpp index 56bd87cbc6..0c2e2f2aea 100644 --- a/engines/mads/events.cpp +++ b/engines/mads/events.cpp @@ -39,7 +39,13 @@ EventsManager::EventsManager(MADSEngine *vm) { _priorFrameTime = 0; _keyPressed = false; _mouseClicked = false; + _mouseReleased = false; _currentTimer = 0; + _mouseButtons = 0; + _vD2 = 0; + _vD4 = 0; + _vD6 = 0; + _vD8 = 0; } EventsManager::~EventsManager() { @@ -115,6 +121,7 @@ void EventsManager::pollEvents() { case Common::EVENT_LBUTTONDOWN: case Common::EVENT_RBUTTONDOWN: _mouseClicked = true; + _mouseButtons = 1; return; case Common::EVENT_LBUTTONUP: case Common::EVENT_RBUTTONUP: diff --git a/engines/mads/events.h b/engines/mads/events.h index c4fb8786cb..0a6913b38e 100644 --- a/engines/mads/events.h +++ b/engines/mads/events.h @@ -42,10 +42,7 @@ private: uint32 _gameCounter; uint32 _priorFrameTime; Common::Point _mousePos; - int _vCC; - int _vD4; - int _vD8; - int _vD2; + Common::Point _currentPos; /** * Updates the cursor image when the current cursor changes @@ -59,8 +56,15 @@ private: public: SpriteAsset *_cursorSprites; bool _mouseClicked; + bool _mouseReleased; + byte _mouseButtons; bool _keyPressed; uint32 _currentTimer; + int _vCC; + int _vD2; + int _vD4; + int _vD6; + int _vD8; public: /** * Constructor @@ -118,6 +122,11 @@ public: Common::Point mousePos() const { return _mousePos; } /** + * Return the current mouse position + */ + Common::Point currentPos() const { return _currentPos; } + + /** * Delay for a given number of frames */ void delay(int amount); diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index 64b41d23c3..c90cf62210 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -140,6 +140,7 @@ void Game::sectionLoop() { _quotes = nullptr; _scene.clearVocab(); + _scene._dynamicHotspots.clear(); _scene.loadSceneLogic(); _v4 = 0; @@ -148,7 +149,7 @@ void Game::sectionLoop() { _vm->_dialogs->_defaultPosition = Common::Point(-1, -1); _visitedScenes.add(_scene._nextSceneId); - _scene._screenObjects._v8333C = -1; + _scene._screenObjects._v8333C = true; _scene._screenObjects._v832EC = 0; _scene._screenObjects._yp = 0; _v3 = -1; diff --git a/engines/mads/game.h b/engines/mads/game.h index cd727af902..2bfa53db18 100644 --- a/engines/mads/game.h +++ b/engines/mads/game.h @@ -55,7 +55,6 @@ protected: MADSEngine *_vm; MSurface *_surface; Difficulty _difficultyLevel; - Player _player; int _saveSlot; int _statusFlag; SectionHandler *_sectionHandler; @@ -104,6 +103,7 @@ protected: public: static Game *init(MADSEngine *vm); public: + Player _player; int _sectionNumber; int _priorSectionNumber; int _currentSectionNumber; @@ -123,8 +123,6 @@ public: * Run the game */ void run(); - - Player &player() { return _player; } }; } // End of namespace MADS diff --git a/engines/mads/player.cpp b/engines/mads/player.cpp index e09549c6d9..4130ad295f 100644 --- a/engines/mads/player.cpp +++ b/engines/mads/player.cpp @@ -39,6 +39,7 @@ Player::Player(MADSEngine *vm): _vm(vm) { _special = 0; _ticksAmount = 0; _priorTimer = 0; + _unk3 = 0; } void Player::reset() { diff --git a/engines/mads/player.h b/engines/mads/player.h index 67766d8572..f82492f243 100644 --- a/engines/mads/player.h +++ b/engines/mads/player.h @@ -59,6 +59,7 @@ public: int _special; int _ticksAmount; uint32 _priorTimer; + int _unk3; public: Player(MADSEngine *vm); diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index 2c6cb8a112..86b59ccc8b 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -28,7 +28,8 @@ namespace MADS { -Scene::Scene(MADSEngine *vm): _vm(vm), _spriteSlots(vm), _action(_vm) { +Scene::Scene(MADSEngine *vm): _vm(vm), _spriteSlots(vm), _action(_vm), + _dynamicHotspots(vm), _screenObjects(vm), _interface(vm) { _priorSceneId = 0; _nextSceneId = 0; _currentSceneId = 0; @@ -60,11 +61,6 @@ Scene::~Scene() { delete _sceneInfo; } -void Scene::clearDynamicHotspots() { - _dynamicHotspots.clear(); - _dynamicHotspotsChanged = false; -} - void Scene::clearVocab() { freeVocab(); _activeVocabs.clear(); @@ -155,7 +151,7 @@ void Scene::loadScene(int sceneId, const Common::String &prefix, bool palFlag) { _animation = Animation::init(_vm, this); MSurface surface; - _animation->load(surface, _interfaceSurface, prefix, flags, nullptr, nullptr); + _animation->load(surface, _interface, prefix, flags, nullptr, nullptr); _vm->_palette->_paletteUsage.load(0); @@ -266,7 +262,34 @@ bool Scene::getDepthHighBits(const Common::Point &pt) { } void Scene::loop() { + _nextSceneId = _currentSceneId; + + while (!_vm->shouldQuit() && !_reloadSceneFlag && _nextSceneId == _currentSceneId) { + // Handle drawing a game frame + doFrame(); + + if (_vm->_dialogs->_pendingDialog != DIALOG_NONE && !_vm->_game->_abortTimers + && _vm->_game->_player._stepEnabled) + _reloadSceneFlag = true; + } +} + +void Scene::doFrame() { + Player &player = _vm->_game->_player; + + if (_action._selectedAction || !player._stepEnabled) { + _action.clear(); + _action._selectedAction = 0; + } + + if (!_vm->_game->_abortTimers && !player._unk3) { + if (_dynamicHotspots._changed) + _dynamicHotspots.refresh(); + } +} +void Scene::leftClick() { + warning("TODO: Scene::leftClick"); } void Scene::free() { diff --git a/engines/mads/scene.h b/engines/mads/scene.h index 4da6fb297e..a02c4a5d79 100644 --- a/engines/mads/scene.h +++ b/engines/mads/scene.h @@ -54,6 +54,11 @@ private: * Initialises the data for palette animation within the scene */ void initPaletteAnimation(Common::Array<RGB4> &animData, bool animFlag); + + /** + * Handles a single frame within the game scene + */ + void doFrame(); protected: MADSEngine *_vm; public: @@ -66,8 +71,7 @@ public: SpriteSlots _spriteSlots; SpriteSets _sprites; int _spritesIndex; - Common::Array<DynamicHotspot> _dynamicHotspots; - bool _dynamicHotspotsChanged; + DynamicHotspots _dynamicHotspots; byte *_vocabBuffer; Common::Array<int> _activeVocabs; Common::Array<SequenceEntry> _sequences; @@ -80,7 +84,7 @@ public: SceneInfo *_sceneInfo; MSurface _backgroundSurface; MSurface _depthSurface; - InterfaceSurface _interfaceSurface; + InterfaceSurface _interface; bool _animFlag; int _animVal1; int _animCount; @@ -112,11 +116,6 @@ public: ~Scene(); /** - * Clear the dynamic hotspot list - */ - void clearDynamicHotspots(); - - /** * Clear the vocabulary list */ void clearVocab(); @@ -167,6 +166,11 @@ public: void loop(); /** + * Execute a click within the scene + */ + void leftClick(); + + /** * Clear the data for the scene */ void free(); diff --git a/engines/mads/scene_data.cpp b/engines/mads/scene_data.cpp index d7aaa6216d..601d719b8d 100644 --- a/engines/mads/scene_data.cpp +++ b/engines/mads/scene_data.cpp @@ -30,6 +30,114 @@ namespace MADS { +ScreenObject::ScreenObject() { + _category = CAT_NONE; + _descId = 0; + _layer = 0; +} + +/*------------------------------------------------------------------------*/ + +ScreenObjects::ScreenObjects(MADSEngine *vm): _vm(vm) { + _v8333C = false; + _v832EC = 0; + _yp = 0; + _v7FECA = 0; + _v7FED6 = 0; + _v8332A = 0; + _selectedObject = 0; + _category = CAT_NONE; + _objectIndex = 0; + _released = false; +} + +void ScreenObjects::add(const Common::Rect &bounds, ScrCategory category, int descId) { + assert(size() < 100); + + ScreenObject so; + so._bounds = bounds; + so._category = category; + so._descId = descId; + so._layer = 0x1413; + + push_back(so); +} + +void ScreenObjects::check(bool scanFlag) { + Scene &scene = _vm->_game->_scene; + + if (!_vm->_events->_mouseButtons || _v832EC) + _v7FECA = false; + + if ((_vm->_events->_vD6 || _v8332A || _yp || _v8333C) && scanFlag) { + _selectedObject = scanBackwards(_vm->_events->currentPos(), LAYER_GUI); + if (_selectedObject > 0) { + _category = (ScrCategory)((*this)[_selectedObject - 1]._category & 7); + _objectIndex = (*this)[_selectedObject - 1]._descId; + } + + // Handling for easy mouse + ScrCategory category = scene._interface._category; + if (_vm->_easyMouse && !_vm->_events->_vD4 && category != _category + && scene._interface._category != CAT_NONE) { + _released = true; + if (category >= CAT_ACTION && category <= CAT_6) { + scene._interface.elementHighlighted(); + } + } + + _released = _vm->_events->_mouseReleased; + if (_vm->_events->_vD2 || (_vm->_easyMouse && !_vm->_events->_vD4)) + scene._interface._category = _category; + + if (!_vm->_events->_mouseButtons || _vm->_easyMouse) { + if (category >= CAT_ACTION && category <= CAT_6) { + scene._interface.elementHighlighted(); + } + } + + if (_vm->_events->_mouseButtons || (_vm->_easyMouse && scene._action._v83338 > 1 + && scene._interface._category == CAT_INV_LIST) || + (_vm->_easyMouse && scene._interface._category == CAT_HOTSPOT)) { + scene._action.checkActionAtMousePos(); + } + + if (_vm->_events->_mouseReleased) { + scene.leftClick(); + scene._interface._category = CAT_NONE; + } + + if (_vm->_events->_mouseButtons || _vm->_easyMouse || _yp) + proc1(); + + if (_vm->_events->_mouseButtons || _vm->_easyMouse) + scene._action.set(); + + _v8333C = 0; + } + + scene._action.refresh(); + + // Loop through image inter list + warning("TODO: iimageInterList loop"); +} + +int ScreenObjects::scanBackwards(const Common::Point &pt, int layer) { + for (int i = (int)size() - 1; i >= 0; --i) { + if ((*this)[i]._bounds.contains(pt) && ((*this)[i]._layer == layer)) + return i + 1; + } + + // Entry not found + return 0; +} + +void ScreenObjects::proc1() { + warning("TODO: ScreenObjects::proc1"); +} + +/*------------------------------------------------------------------------*/ + SpriteSlot::SpriteSlot() { _spriteType = ST_NONE; _seqIndex = 0; @@ -64,7 +172,7 @@ void SpriteSlots::clear(bool flag) { * Releases any sprites used by the player */ void SpriteSlots::releasePlayerSprites() { - Player &player = _vm->_game->player(); + Player &player = _vm->_game->_player; if (player._spritesLoaded && player._numSprites > 0) { int spriteEnd = player._spritesStart + player._numSprites - 1; @@ -114,6 +222,34 @@ DynamicHotspot::DynamicHotspot() { /*------------------------------------------------------------------------*/ +DynamicHotspots::DynamicHotspots(MADSEngine *vm): _vm(vm) { + _changed = false; +} + +void DynamicHotspots::clear() { + Common::Array<DynamicHotspot>::clear(); + _changed = false; +} + +void DynamicHotspots::refresh() { + Scene &scene = _vm->_game->_scene; + + for (uint idx = 0; idx < size(); ++idx) { + DynamicHotspot &dh = (*this)[idx]; + + switch (scene._screenObjects._v832EC) { + case 0: + case 2: + scene._screenObjects.add(dh._bounds, CAT_12, dh._descId); + scene._screenObjects._v8333C = true; + default: + break; + } + } +} + +/*------------------------------------------------------------------------*/ + SequenceEntry::SequenceEntry() { _spritesIndex = 0; _flipped =0; @@ -216,6 +352,16 @@ void SceneNode::load(Common::SeekableReadStream *f) { /*------------------------------------------------------------------------*/ +InterfaceSurface::InterfaceSurface(MADSEngine *vm): _vm(vm) { + _category = CAT_NONE; +} + +void InterfaceSurface::elementHighlighted() { + warning("TODO: InterfaceSurface::elementHighlighted"); +} + +/*------------------------------------------------------------------------*/ + void SceneInfo::SpriteInfo::load(Common::SeekableReadStream *f) { f->skip(3); _spriteSetIndex = f->readByte(); @@ -228,15 +374,15 @@ void SceneInfo::SpriteInfo::load(Common::SeekableReadStream *f) { /*------------------------------------------------------------------------*/ -void InterfaceSurface::load(MADSEngine *vm, const Common::String &resName) { +void InterfaceSurface::load(const Common::String &resName) { File f(resName); MadsPack madsPack(&f); // Load in the palette Common::SeekableReadStream *palStream = madsPack.getItemStream(0); - RGB4 *gamePalP = &vm->_palette->_gamePalette[0]; - byte *palP = &vm->_palette->_mainPalette[0]; + RGB4 *gamePalP = &_vm->_palette->_gamePalette[0]; + byte *palP = &_vm->_palette->_mainPalette[0]; for (int i = 0; i < 16; ++i, gamePalP++, palP += 3) { palP[0] = palStream->readByte(); diff --git a/engines/mads/scene_data.h b/engines/mads/scene_data.h index 6be54cf3e1..8b874a144f 100644 --- a/engines/mads/scene_data.h +++ b/engines/mads/scene_data.h @@ -43,6 +43,21 @@ class Scene; #define DEPTH_BANDS_SIZE 15 #define MAX_ROUTE_NODES 22 +enum ScrCategory { + CAT_NONE = 0, CAT_ACTION = 1, CAT_INV_LIST = 2, CAT_INV_VOCAB = 3, + CAT_HOTSPOT = 4, CAT_INV_ANIM = 5, CAT_6 = 6, CAT_INV_SCROLLER = 7, + CAT_12 = 12 +}; + +enum Layer { + LAYER_GUI = 19 +}; + +enum SpriteType { + ST_NONE = 0, ST_FOREGROUND = 1, ST_BACKGROUND = -4, + ST_FULL_SCREEN_REFRESH = -2, ST_EXPIRED = -1 +}; + class VerbInit { public: int _id; @@ -53,16 +68,48 @@ public: VerbInit(int id, int action1, int action2): _id(id), _action1(action1), _action2(action2) {} }; -class ScreenObjects { +class ScreenObject { +public: + Common::Rect _bounds; + ScrCategory _category; + int _descId; + int _layer; + + ScreenObject(); +}; + +class ScreenObjects: public Common::Array<ScreenObject> { +private: + MADSEngine *_vm; + + int scanBackwards(const Common::Point &pt, int layer); + + void proc1(); public: - int _v8333C; int _v832EC; + int _v7FECA; + int _v7FED6; + int _v8332A; int _yp; -}; + int _v8333C; + int _selectedObject; + ScrCategory _category; + int _objectIndex; + bool _released; -enum SpriteType { - ST_NONE = 0, ST_FOREGROUND = 1, ST_BACKGROUND = -4, - ST_FULL_SCREEN_REFRESH = -2, ST_EXPIRED = -1 + /* + * Constructor + */ + ScreenObjects(MADSEngine *vm); + + /** + * Add a new item to the list + */ + void add(const Common::Rect &bounds, ScrCategory category, int descId); + + /** + */ + void check(bool scanFlag); }; class SpriteSlotSubset { @@ -143,6 +190,28 @@ public: DynamicHotspot(); }; +class DynamicHotspots : public Common::Array<DynamicHotspot> { +private: + MADSEngine *_vm; +public: + bool _changed; + + /** + * Constructor + */ + DynamicHotspots(MADSEngine *vm); + + /** + * Clear the list + */ + void clear(); + + /** + * Refresh the list + */ + void refresh(); +}; + class SequenceEntry { public: int _spritesIndex; @@ -283,8 +352,22 @@ public: typedef Common::Array<SceneNode> SceneNodeList; class InterfaceSurface : public MSurface { +private: + MADSEngine *_vm; +public: + ScrCategory _category; public: - void load(MADSEngine *vm, const Common::String &resName); + /** + * Constructor + */ + InterfaceSurface(MADSEngine *vm); + + /** + * Loads an interface from a specified resource + */ + void load(const Common::String &resName); + + void elementHighlighted(); }; /** |