From 9eaab29afedf9eceee50f882b64cb39a14e616a2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 25 Feb 2014 19:52:35 -0500 Subject: MADS: Starting to refactor some Scene array fields as separate classes --- engines/mads/game.cpp | 102 +++-------------------- engines/mads/game.h | 83 +----------------- engines/mads/game_data.cpp | 116 ++++++++++++++++++++++++++ engines/mads/game_data.h | 126 ++++++++++++++++++++++++++++ engines/mads/module.mk | 1 + engines/mads/nebular/game_nebular.cpp | 12 +-- engines/mads/scene.cpp | 153 ++++------------------------------ engines/mads/scene.h | 34 ++++---- engines/mads/scene_data.cpp | 39 ++++++++- engines/mads/scene_data.h | 38 +++++++-- engines/mads/sound.cpp | 2 +- engines/mads/sound.h | 2 +- 12 files changed, 359 insertions(+), 349 deletions(-) create mode 100644 engines/mads/game_data.cpp create mode 100644 engines/mads/game_data.h diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index 9b60302c7c..2a45c3ee90 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -23,6 +23,7 @@ #include "common/scummsys.h" #include "mads/mads.h" #include "mads/game.h" +#include "mads/game_data.h" #include "mads/nebular/game_nebular.h" #include "mads/graphics.h" #include "mads/msurface.h" @@ -37,7 +38,8 @@ Game *Game::init(MADSEngine *vm) { return nullptr; } -Game::Game(MADSEngine *vm): _vm(vm), _surface(nullptr), _scene(vm) { +Game::Game(MADSEngine *vm): _vm(vm), _surface(nullptr), + _objects(vm), _scene(vm) { _sectionNumber = _priorSectionNumber = 0; _difficultyLevel = DIFFICULTY_HARD; _saveSlot = -1; @@ -110,7 +112,7 @@ void Game::gameLoop() { initSection(_sectionNumber); _sectionHandler->postLoadSection(); - _scene.clearSprites(true); + _scene._spriteSlots.clear(true); if (_sectionNumber == _currentSectionNumber) { sectionLoop(); @@ -141,7 +143,7 @@ void Game::sectionLoop() { _player._stepEnabled = true; _player._visible = true; _vm->_dialogs->_defaultPosition = Common::Point(-1, -1); - addVisitedScene(_scene._nextSceneId); + _visitedScenes.add(_scene._nextSceneId); _scene._screenObjects._v8333C = -1; _scene._screenObjects._v832EC = 0; @@ -151,17 +153,18 @@ void Game::sectionLoop() { _scene._sceneLogic->setup(); if (_player._spritesChanged || _v3) { if (_player._spritesLoaded) - _scene.releasePlayerSprites(); + _scene._spriteSlots.releasePlayerSprites(); _vm->_palette->resetGamePalette(18, 10); - _scene.clearSprites(true); + _scene._spriteSlots.clear(true); } else { _vm->_palette->initGamePalette(); } // TODO: Further palette init - //_scene.loadScene(_aaName, _scene._nextSceneId, 0); - _vm->_sound->queueNewCommands(); + _scene.loadScene(_scene._nextSceneId, _aaName, 0); + _vm->_sound->pauseNewCommands(); + if (!_player._spritesLoaded) { _player.loadSprites(""); _playerSpritesFlag = false; @@ -178,7 +181,7 @@ void Game::sectionLoop() { // Check whether to show a dialog if (_vm->_dialogs->_pendingDialog && _player._stepEnabled && !_globalFlags[5]) { - _scene.releasePlayerSprites(); + _scene._spriteSlots.releasePlayerSprites(); _vm->_dialogs->showDialog(); _vm->_dialogs->_pendingDialog = DIALOG_NONE; } @@ -198,91 +201,8 @@ void Game::initSection(int sectionNumber) { CURSOR_ARROW : CURSOR_WAIT); } -void Game::loadObjects() { - File f("*OBJECTS.DAT"); - - // Get the total numer of inventory objects - int count = f.readUint16LE(); - _objects.reserve(count); - - // Read in each object - for (int i = 0; i < count; ++i) { - InventoryObject obj; - obj.load(f); - _objects.push_back(obj); - - // If it's for the player's inventory, add the index to the inventory list - if (obj._roomNumber == PLAYER_INVENTORY) { - _inventoryList.push_back(i); - assert(_inventoryList.size() <= 32); - } - } -} - -void Game::setObjectData(int objIndex, int id, const byte *p) { - // TODO: This whole method seems weird. Check it out more thoroughly once - // more of the engine is implemented - for (int i = 0; i < (int)_objects.size(); ++i) { - InventoryObject &obj = _objects[i]; - if (obj._vocabList[0]._actionFlags1 <= i) - break; - - if (obj._mutilateString[6 + i] == id) { - _objects[objIndex]._objFolder = p; - } - } -} - -void Game::setObjectRoom(int objectId, int roomNumber) { - warning("TODO: setObjectRoom"); -} - void Game::loadResourceSequence(const Common::String prefix, int v) { warning("TODO: loadResourceSequence"); } -void Game::addVisitedScene(int sceneId) { - if (!visitedScenesExists(sceneId)) - _visitedScenes.push_back(sceneId); -} - -bool Game::visitedScenesExists(int sceneId) { - for (uint i = 0; i < _visitedScenes.size(); ++i) { - if (_visitedScenes[i] == sceneId) - return true; - } - - return false; -} - -/*------------------------------------------------------------------------*/ - -void InventoryObject::load(Common::SeekableReadStream &f) { - _descId = f.readUint16LE(); - _roomNumber = f.readUint16LE(); - _article = f.readByte(); - _vocabCount = f.readByte(); - - for (int i = 0; i < 3; ++i) { - _vocabList[i]._actionFlags1 = f.readByte(); - _vocabList[i]._actionFlags2 = f.readByte(); - _vocabList[i]._vocabId = f.readByte(); - } - - f.skip(4); // field12 - f.read(&_mutilateString[0], 10); - f.skip(16); -} - -/*------------------------------------------------------------------------*/ - -Player::Player() { - _direction = 8; - _newDirection = 8; - _spritesLoaded = false; - _spriteListStart = _numSprites = 0; - _stepEnabled = false; - _visible = false; -} - } // End of namespace MADS diff --git a/engines/mads/game.h b/engines/mads/game.h index fbac20ce1f..4797908b1a 100644 --- a/engines/mads/game.h +++ b/engines/mads/game.h @@ -25,6 +25,7 @@ #include "common/scummsys.h" #include "mads/scene.h" +#include "mads/game_data.h" namespace MADS { @@ -38,56 +39,6 @@ enum Difficulty { DIFFICULTY_HARD = 1, DIFFICULTY_MEDIUM = 2, DIFFICULTY_EASY = 3 }; -class InventoryObject { -public: - int _descId; - int _roomNumber; - int _article; - int _vocabCount; - struct { - int _actionFlags1; - int _actionFlags2; - int _vocabId; - } _vocabList[3]; - char _mutilateString[10]; // ??? - const byte *_objFolder; // ??? - - /** - * Loads the data for a given object - */ - void load(Common::SeekableReadStream &f); -}; - -class Player { -public: - int _direction; - int _newDirection; - bool _spritesLoaded; - int _spriteListStart; - int _numSprites; - bool _stepEnabled; - bool _spritesChanged; - bool _visible; -public: - Player(); - - void loadSprites(const Common::String &prefix) { - warning("TODO: Player::loadSprites"); - } -}; - -class SectionHandler { -protected: - MADSEngine *_vm; -public: - SectionHandler(MADSEngine *vm): _vm(vm) {} - virtual ~SectionHandler() {} - - virtual void preLoadSection() = 0; - virtual void sectionPtr2() = 0; - virtual void postLoadSection() = 0; -}; - class Game { private: /** @@ -99,26 +50,15 @@ private: * Inner game loop for executing gameplay within a game section */ void sectionLoop(); - - /** - * Returns true if a given Scene Id exists in the listed of previously visited scenes. - */ - bool visitedScenesExists(int sceneId); - - /** - * Adds a scene Id to the list of previously visited scenes, if it doesn't already exist - */ - void addVisitedScene(int sceneId); protected: MADSEngine *_vm; MSurface *_surface; Difficulty _difficultyLevel; Player _player; - Scene _scene; int _saveSlot; int _statusFlag; SectionHandler *_sectionHandler; - Common::Array _visitedScenes; + VisitedScenes _visitedScenes; byte *_quotes; int _v1; int _v2; @@ -134,21 +74,6 @@ protected: */ Game(MADSEngine *vm); - /** - * Loads the game's object list - */ - void loadObjects(); - - /** - * Set the associated data? pointer with an inventory object - */ - void setObjectData(int objIndex, int id, const byte *p); - - /** - * Sets the room number - */ - void setObjectRoom(int objectId, int roomNumber); - /** * Initialises the current section number of the game */ @@ -182,8 +107,8 @@ public: int _priorSectionNumber; int _currentSectionNumber; Common::Array _globalFlags; - Common::Array _objects; - Common::Array _inventoryList; + InventoryObjects _objects; + Scene _scene; public: virtual ~Game(); diff --git a/engines/mads/game_data.cpp b/engines/mads/game_data.cpp new file mode 100644 index 0000000000..df4a902c25 --- /dev/null +++ b/engines/mads/game_data.cpp @@ -0,0 +1,116 @@ +/* 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. + * + */ + +#include "common/scummsys.h" +#include "mads/mads.h" +#include "mads/game.h" +#include "mads/nebular/game_nebular.h" +#include "mads/graphics.h" +#include "mads/msurface.h" +#include "mads/resources.h" + +namespace MADS { + +void VisitedScenes::add(int sceneId) { + if (!exists(sceneId)) + push_back(sceneId); +} + +bool VisitedScenes::exists(int sceneId) { + for (uint i = 0; i < size(); ++i) { + if ((*this)[i] == sceneId) + return true; + } + + return false; +} + +void InventoryObject::load(Common::SeekableReadStream &f) { + _descId = f.readUint16LE(); + _roomNumber = f.readUint16LE(); + _article = f.readByte(); + _vocabCount = f.readByte(); + + for (int i = 0; i < 3; ++i) { + _vocabList[i]._actionFlags1 = f.readByte(); + _vocabList[i]._actionFlags2 = f.readByte(); + _vocabList[i]._vocabId = f.readByte(); + } + + f.skip(4); // field12 + f.read(&_mutilateString[0], 10); + f.skip(16); +} + +/*------------------------------------------------------------------------*/ + +void InventoryObjects::load() { + File f("*OBJECTS.DAT"); + + // Get the total numer of inventory objects + int count = f.readUint16LE(); + reserve(count); + + // Read in each object + for (int i = 0; i < count; ++i) { + InventoryObject obj; + obj.load(f); + push_back(obj); + + // If it's for the player's inventory, add the index to the inventory list + if (obj._roomNumber == PLAYER_INVENTORY) { + _inventoryList.push_back(i); + assert(_inventoryList.size() <= 32); + } + } +} + +void InventoryObjects::setData(int objIndex, int id, const byte *p) { + // TODO: This whole method seems weird. Check it out more thoroughly once + // more of the engine is implemented + for (int i = 0; i < (int)size(); ++i) { + InventoryObject &obj = (*this)[i]; + if (obj._vocabList[0]._actionFlags1 <= i) + break; + + if (obj._mutilateString[6 + i] == id) { + (*this)[objIndex]._objFolder = p; + } + } +} + +void InventoryObjects::setRoom(int objectId, int roomNumber) { + warning("TODO: setObjectRoom"); +} + +/*------------------------------------------------------------------------*/ + +Player::Player() { + _direction = 8; + _newDirection = 8; + _spritesLoaded = false; + _spritesStart = _numSprites = 0; + _stepEnabled = false; + _visible = false; +} + +} // End of namespace MADS diff --git a/engines/mads/game_data.h b/engines/mads/game_data.h new file mode 100644 index 0000000000..2d2badd38b --- /dev/null +++ b/engines/mads/game_data.h @@ -0,0 +1,126 @@ +/* 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 MADS_GAME_DATA_H +#define MADS_GAME_DATA_H + +#include "common/scummsys.h" +#include "common/array.h" + +namespace MADS { + +class MADSEngine; +class Game; + +class VisitedScenes: public Common::Array { +public: + /** + * Returns true if a given Scene Id exists in the listed of previously visited scenes. + */ + bool exists(int sceneId); + + /** + * Adds a scene Id to the list of previously visited scenes, if it doesn't already exist + */ + void add(int sceneId); +}; + +class InventoryObject { +public: + int _descId; + int _roomNumber; + int _article; + int _vocabCount; + struct { + int _actionFlags1; + int _actionFlags2; + int _vocabId; + } _vocabList[3]; + char _mutilateString[10]; // ??? + const byte *_objFolder; // ??? + + /** + * Loads the data for a given object + */ + void load(Common::SeekableReadStream &f); +}; + +class InventoryObjects: public Common::Array { +private: + MADSEngine *_vm; +public: + Common::Array _inventoryList; + + /** + * Constructor + */ + InventoryObjects(MADSEngine *vm): _vm(vm) {} + + /** + * Loads the game's object list + */ + void load(); + + /** + * Set the associated data? pointer with an inventory object + */ + void setData(int objIndex, int id, const byte *p); + + /** + * Sets the room number + */ + void setRoom(int objectId, int roomNumber); +}; + +class Player { +public: + int _direction; + int _newDirection; + bool _spritesLoaded; + int _spritesStart; + int _numSprites; + bool _stepEnabled; + bool _spritesChanged; + bool _visible; +public: + Player(); + + void loadSprites(const Common::String &prefix) { + warning("TODO: Player::loadSprites"); + } +}; + +class SectionHandler { +protected: + MADSEngine *_vm; +public: + SectionHandler(MADSEngine *vm): _vm(vm) {} + virtual ~SectionHandler() {} + + virtual void preLoadSection() = 0; + virtual void sectionPtr2() = 0; + virtual void postLoadSection() = 0; +}; + +} // End of namespace MADS + +#endif /* MADS_GAME_DATA_H */ diff --git a/engines/mads/module.mk b/engines/mads/module.mk index 09adc9c5bc..62441ab3c9 100644 --- a/engines/mads/module.mk +++ b/engines/mads/module.mk @@ -14,6 +14,7 @@ MODULE_OBJS := \ events.o \ font.o \ game.o \ + game_data.o \ graphics.o \ mads.o \ msprite.o \ diff --git a/engines/mads/nebular/game_nebular.cpp b/engines/mads/nebular/game_nebular.cpp index 34fe0c7d19..e777ff8def 100644 --- a/engines/mads/nebular/game_nebular.cpp +++ b/engines/mads/nebular/game_nebular.cpp @@ -68,7 +68,7 @@ void GameNebular::initialiseGlobals() { _globalFlags[21] = 0xFFFF; _globalFlags[95] = 0xFFFF; - setObjectData(3, 17, nullptr); + _objects.setData(3, 17, nullptr); // Put the values 0 through 3 in a random order in global slots 83 to 86 for (int i = 0; i < 4;) { @@ -125,21 +125,21 @@ void GameNebular::initialiseGlobals() { switch (_difficultyLevel) { case DIFFICULTY_HARD: _globalFlags[35] = 0; - setObjectRoom(9, 1); - setObjectRoom(50, 1); + _objects.setRoom(9, 1); + _objects.setRoom(50, 1); _globalFlags[137] = 5; _globalFlags[136] = 0; break; case DIFFICULTY_MEDIUM: _globalFlags[35] = 0; - setObjectRoom(8, 1); + _objects.setRoom(8, 1); _globalFlags[137] = 0xFFFF; _globalFlags[136] = 6; break; case DIFFICULTY_EASY: _globalFlags[35] = 2; - setObjectRoom(8, 1); - setObjectRoom(27, 1); + _objects.setRoom(8, 1); + _objects.setRoom(27, 1); break; default: break; diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index 09e965bac3..7bbb4e98ae 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -27,7 +27,7 @@ namespace MADS { -Scene::Scene(MADSEngine *vm): _vm(vm) { +Scene::Scene(MADSEngine *vm): _vm(vm), _spriteSlots(vm) { _priorSceneId = 0; _nextSceneId = 0; _currentSceneId = 0; @@ -52,36 +52,6 @@ Scene::~Scene() { delete _sceneLogic; } -void Scene::clearSprites(bool flag) { - for (int i = 0; i < TEXT_DISPLAY_COUNT; ++i) - _textDisplay[i]._active = false; - - if (flag) - _spriteList.clear(); - - _spriteSlots.clear(); - _spriteSlots.push_back(SpriteSlot(ST_FULL_SCREEN_REFRESH, -1)); -} - -/** - * Releases any sprites used by the player - */ -void Scene::releasePlayerSprites() { - Player &player = _vm->_game->player(); - - if (player._spritesLoaded && player._numSprites > 0) { - int spriteEnd = player._spriteListStart + player._numSprites - 1; - do { - deleteSpriteEntry(spriteEnd); - } while (--spriteEnd >= player._spriteListStart); - } -} - -void Scene::deleteSpriteEntry(int listIndex) { - delete _spriteList[listIndex]; - _spriteList.remove_at(listIndex); -} - void Scene::clearDynamicHotspots() { _dynamicHotspots.clear(); _dynamicHotspotsChanged = false; @@ -135,6 +105,18 @@ void Scene::loadSceneLogic() { } } +void Scene::loadScene(int sceneId, const Common::String &prefix, bool palFlag) { + // Store the previously active scene number and set the new one + _priorSceneId = _currentSceneId; + _currentSceneId = sceneId; + + _v1 = 0; + if (palFlag) + _vm->_palette->resetGamePalette(18, 10); + + +} + void Scene::loadHotspots() { File f(Resources::formatName(RESPREFIX_RM, _currentSceneId, ".HH")); int count = f.readUint16LE(); @@ -177,9 +159,9 @@ void Scene::loadVocabStrings() { f.read(d, f.size()); - int vocabId = 1; +// int vocabId = 1; for (uint strIndex = 0; strIndex < _activeVocabs.size(); ++strIndex) { - + // TODO: Rest of this method } } @@ -191,109 +173,4 @@ void Scene::setPalette(RGB4 *p) { _scenePalette = p; } -/*------------------------------------------------------------------------*/ - -SpriteSlot::SpriteSlot() { - _spriteType = ST_NONE; - _seqIndex = 0; - _spriteListIndex = 0; - _frameNumber = 0; - _depth = 0; - _scale = 0; -} - -SpriteSlot::SpriteSlot(SpriteType type, int seqIndex) { - _spriteType = type; - _seqIndex = seqIndex; - _spriteListIndex = 0; - _frameNumber = 0; - _depth = 0; - _scale = 0; -} - -/*------------------------------------------------------------------------*/ - -TextDisplay::TextDisplay() { - _active = false; - _spacing = 0; - _expire = 0; - _col1 = _col2 = 0; -} - -/*------------------------------------------------------------------------*/ - -DynamicHotspot::DynamicHotspot() { - _seqIndex = 0; - _facing = 0; - _descId = 0; - _field14 = 0; - _articleNumber = 0; - _cursor = 0; -} - -/*------------------------------------------------------------------------*/ - -SequenceEntry::SequenceEntry() { - _spriteListIndex = 0; - _flipped =0; - _frameIndex = 0; - _frameStart = 0; - _numSprites = 0; - _animType = 0; - _frameInc = 0; - _depth = 0; - _scale = 0; - _dynamicHotspotIndex = -1; - _triggerCountdown = 0; - _doneFlag = 0; - _entries._count = 0; - _abortMode = 0; - _actionNouns[0] = _actionNouns[1] = _actionNouns[2] = 0; - _numTicks = 0; - _extraTicks = 0; - _timeout = 0; -} - -KernelMessage::KernelMessage() { - _flags = 0; - _seqInex = 0; - _asciiChar = '\0'; - _asciiChar2 = '\0'; - _colors = 0; - Common::Point _posiition; - _msgOffset = 0; - _numTicks = 0; - _frameTimer2 = 0; - _frameTimer = 0; - _timeout = 0; - _field1C = 0; - _abortMode = 0; - _nounList[0] = _nounList[1] = _nounList[2] = 0; -} - -/*------------------------------------------------------------------------*/ - -Hotspot::Hotspot() { - _facing = 0; - _articleNumber = 0; - _cursor = 0; - _vocabId = 0; - _verbId = 0; -} - -Hotspot::Hotspot(Common::SeekableReadStream &f) { - _bounds.left = f.readSint16LE(); - _bounds.top = f.readSint16LE(); - _bounds.right = f.readSint16LE(); - _bounds.bottom = f.readSint16LE(); - _feetPos.x = f.readSint16LE(); - _feetPos.y = f.readSint16LE(); - _facing = f.readByte(); - _articleNumber = f.readByte(); - f.skip(1); - _cursor = f.readByte(); - _vocabId = f.readUint16LE(); - _verbId = f.readUint16LE(); -} - } // End of namespace MADS diff --git a/engines/mads/scene.h b/engines/mads/scene.h index 0e788c9ebd..7db10771ed 100644 --- a/engines/mads/scene.h +++ b/engines/mads/scene.h @@ -55,10 +55,10 @@ public: int _nextSceneId; int _currentSceneId; Common::Array _verbList; - TextDisplay _textDisplay[TEXT_DISPLAY_COUNT]; - Common::Array _spriteSlots; - Common::Array _spriteList; - int _spriteListIndex; + Common::Array _textDisplay; + SpriteSlots _spriteSlots; + Common::Array _sprites; + int _spritesIndex; Common::Array _dynamicHotspots; bool _dynamicHotspotsChanged; byte *_vocabBuffer; @@ -71,6 +71,7 @@ public: ScreenObjects _screenObjects; RGB4 *_scenePalette; RGB4 _nullPalette[2]; + int _v1; /** * Constructor @@ -82,22 +83,6 @@ public: */ ~Scene(); - /** - * Initialise the sprite data - * @param flag Also reset sprite list - */ - void clearSprites(bool flag); - - /** - * Delete any sprites used by the player - */ - void releasePlayerSprites(); - - /** - * Delete a sprite entry - */ - void deleteSpriteEntry(int listIndex); - /** * Clear the dynamic hotspot list */ @@ -128,6 +113,14 @@ public: */ void loadSceneLogic(); + /** + * Loads the resources associated with the given scene + * @param sceneId Scene to load + * @param prefix Prefix to use for retrieving animation data + * @param palFlag Flag for whether to reset the high/lo palette areas + */ + void loadScene(int sceneId, const Common::String &prefix, bool palFlag); + /** * Loads the hotstpots for the scene */ @@ -143,6 +136,7 @@ public: */ void setPalette(RGB4 *p); + /** * Clear the data for the scene */ diff --git a/engines/mads/scene_data.cpp b/engines/mads/scene_data.cpp index 6821395004..d0e40d4097 100644 --- a/engines/mads/scene_data.cpp +++ b/engines/mads/scene_data.cpp @@ -21,7 +21,7 @@ */ #include "common/scummsys.h" -#include "mads/scene.h" +#include "mads/scene_data.h" #include "mads/mads.h" #include "mads/nebular/nebular_scenes.h" @@ -30,7 +30,7 @@ namespace MADS { SpriteSlot::SpriteSlot() { _spriteType = ST_NONE; _seqIndex = 0; - _spriteListIndex = 0; + _spritesIndex = 0; _frameNumber = 0; _depth = 0; _scale = 0; @@ -39,12 +39,43 @@ SpriteSlot::SpriteSlot() { SpriteSlot::SpriteSlot(SpriteType type, int seqIndex) { _spriteType = type; _seqIndex = seqIndex; - _spriteListIndex = 0; + _spritesIndex = 0; _frameNumber = 0; _depth = 0; _scale = 0; } +/*------------------------------------------------------------------------*/ + +void SpriteSlots::clear(bool flag) { + _vm->_game->_scene._textDisplay.clear(); + + if (flag) + _vm->_game->_scene._sprites.clear(); + + Common::Array::clear(); + push_back(SpriteSlot(ST_FULL_SCREEN_REFRESH, -1)); +} + +/** + * Releases any sprites used by the player + */ +void SpriteSlots::releasePlayerSprites() { + Player &player = _vm->_game->player(); + + if (player._spritesLoaded && player._numSprites > 0) { + int spriteEnd = player._spritesStart + player._numSprites - 1; + do { + deleteEntry(spriteEnd); + } while (--spriteEnd >= player._spritesStart); + } +} + +void SpriteSlots::deleteEntry(int index) { + remove_at(index); +} + + /*------------------------------------------------------------------------*/ TextDisplay::TextDisplay() { @@ -68,7 +99,7 @@ DynamicHotspot::DynamicHotspot() { /*------------------------------------------------------------------------*/ SequenceEntry::SequenceEntry() { - _spriteListIndex = 0; + _spritesIndex = 0; _flipped =0; _frameIndex = 0; _frameStart = 0; diff --git a/engines/mads/scene_data.h b/engines/mads/scene_data.h index a4950dbc0a..b464cbaee3 100644 --- a/engines/mads/scene_data.h +++ b/engines/mads/scene_data.h @@ -30,6 +30,9 @@ namespace MADS { +class MADSEngine; +class Scene; + enum { VERB_LOOK = 3, VERB_TAKE = 4, @@ -70,7 +73,7 @@ class SpriteSlot { public: SpriteType _spriteType; int _seqIndex; - int _spriteListIndex; + int _spritesIndex; int _frameNumber; Common::Point _position; int _depth; @@ -80,6 +83,30 @@ public: SpriteSlot(SpriteType type, int seqIndex); }; +class SpriteSlots: public Common::Array { +private: + MADSEngine *_vm; +public: + SpriteSlots(MADSEngine *vm): _vm(vm) {} + + /** + * Clears any pending slot data and schedules a full screen refresh. + * @param flag Also reset sprite list + */ + void clear(bool flag); + + /** + * Delete any sprites used by the player + */ + void releasePlayerSprites(); + + /** + * Delete a sprite entry + * @param index Specifies the index in the array + */ + void deleteEntry(int index); +}; + class TextDisplay { public: bool _active; @@ -110,7 +137,7 @@ public: class SequenceEntry { public: - int _spriteListIndex; + int _spritesIndex; int _flipped; int _frameIndex; int _frameStart; @@ -175,13 +202,6 @@ public: Hotspot(Common::SeekableReadStream &f); }; -#define SPRITE_COUNT 50 -#define TEXT_DISPLAY_COUNT 40 -#define DYNAMIC_HOTSPOT_COUNT 8 - -class MADSEngine; -class Scene; - class SceneLogic { protected: Scene *_scene; diff --git a/engines/mads/sound.cpp b/engines/mads/sound.cpp index 8608abf4e7..ea0239076b 100644 --- a/engines/mads/sound.cpp +++ b/engines/mads/sound.cpp @@ -77,7 +77,7 @@ void SoundManager::setEnabled(bool flag) { _soundPollFlag = false; } -void SoundManager::queueNewCommands() { +void SoundManager::pauseNewCommands() { _newSoundsPaused = true; } diff --git a/engines/mads/sound.h b/engines/mads/sound.h index 51213f0e4e..0fd9ac1095 100644 --- a/engines/mads/sound.h +++ b/engines/mads/sound.h @@ -70,7 +70,7 @@ public: /** * Temporarily pause the playback of any new sound commands */ - void queueNewCommands(); + void pauseNewCommands(); /** * Stop queueing sound commands, and execute any previously queued ones -- cgit v1.2.3