From f6888eef1069ac5df07c3f4dcc3a30755bc4ebb0 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 4 Mar 2014 09:33:57 -0500 Subject: MADS: Implementation of timer functionality for Scene::doFrame --- engines/mads/animation.cpp | 4 ++-- engines/mads/animation.h | 2 +- engines/mads/game.cpp | 4 ++-- engines/mads/game.h | 2 +- engines/mads/messages.cpp | 14 ++++++++++---- engines/mads/messages.h | 1 + engines/mads/scene.cpp | 39 +++++++++++++++++++++++++++++++++++---- engines/mads/scene.h | 7 ++++++- engines/mads/scene_data.cpp | 4 ++++ engines/mads/scene_data.h | 2 ++ engines/mads/sequence.cpp | 4 ++-- engines/mads/sequence.h | 2 +- 12 files changed, 67 insertions(+), 18 deletions(-) diff --git a/engines/mads/animation.cpp b/engines/mads/animation.cpp index 0546fc3d34..941533fa63 100644 --- a/engines/mads/animation.cpp +++ b/engines/mads/animation.cpp @@ -179,7 +179,7 @@ void Animation::load(MSurface &depthSurface, InterfaceSurface &interfaceSurface, for (int i = 0; i < aaHeader._spriteSetsCount; ++i) _spriteListIndexes.push_back(-1); - _messages.clear(); + _kernelMessages.clear(); if (aaHeader._messagesCount > 0) { // Chunk 2: Following is a list of any messages for the animation Common::SeekableReadStream *msgStream = madsPack.getItemStream(1); @@ -187,7 +187,7 @@ void Animation::load(MSurface &depthSurface, InterfaceSurface &interfaceSurface, for (int i = 0; i < aaHeader._messagesCount; ++i) { AnimMessage rec; rec.load(msgStream); - _messages.push_back(rec); + _kernelMessages.push_back(rec); } delete msgStream; diff --git a/engines/mads/animation.h b/engines/mads/animation.h index 1f0e1fda65..484856f769 100644 --- a/engines/mads/animation.h +++ b/engines/mads/animation.h @@ -119,7 +119,7 @@ public: static Animation *init(MADSEngine *vm, Scene *scene); public: Common::Array _spriteListIndexes; - Common::Array _messages; + Common::Array _kernelMessages; Common::Array _frameEntries; Common::Array _miscEntries; Common::Array _spriteSets; diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index 479c48cc2f..025cf8d530 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -54,7 +54,7 @@ Game::Game(MADSEngine *vm): _vm(vm), _surface(nullptr), _objects(vm), _v5 = _v6 = 0; _aaName = "*I0.AA"; _playerSpritesFlag = false; - _currentTimer = 0; + _priorFrameTimer = 0; _updateSceneFlag = false; _abortTimersMode = ABORTMODE_0; _abortTimersMode2 = ABORTMODE_0; @@ -199,7 +199,7 @@ void Game::sectionLoop() { } _abortTimers = 0; _abortTimersMode2 = ABORTMODE_1; - _currentTimer = _vm->_events->_currentTimer; + _priorFrameTimer = _vm->_events->_currentTimer; // Call the scene logic for entering the given scene _scene._sceneLogic->enter(); diff --git a/engines/mads/game.h b/engines/mads/game.h index 47eed34393..5330cd3138 100644 --- a/engines/mads/game.h +++ b/engines/mads/game.h @@ -116,7 +116,7 @@ public: int _abortTimers2; AbortTimerMode _abortTimersMode; AbortTimerMode _abortTimersMode2; - uint32 _currentTimer; + uint32 _priorFrameTimer; public: virtual ~Game(); diff --git a/engines/mads/messages.cpp b/engines/mads/messages.cpp index c08f29fd91..cc618c4b76 100644 --- a/engines/mads/messages.cpp +++ b/engines/mads/messages.cpp @@ -75,7 +75,7 @@ int KernelMessages::add(const Common::Point &pt, uint fontColor, uint8 flags, rec._position = pt; rec._textDisplayIndex = -1; rec._timeout = timeout; - rec._frameTimer = _vm->_game->_currentTimer; + rec._frameTimer = _vm->_game->_priorFrameTimer; rec._abortTimers = abortTimers; rec._abortMode = _vm->_game->_abortTimersMode2; @@ -100,7 +100,7 @@ void KernelMessages::scrollMessage(int msgIndex, int numTicks, bool quoted) { _entries[msgIndex]._flags |= quoted ? (KMSG_SCROLL | KMSG_QUOTED) : KMSG_SCROLL; _entries[msgIndex]._msgOffset = 0; _entries[msgIndex]._numTicks = numTicks; - _entries[msgIndex]._frameTimer2 = _vm->_game->_currentTimer; + _entries[msgIndex]._frameTimer2 = _vm->_game->_priorFrameTimer; Common::String msg = _entries[msgIndex]._msg; _entries[msgIndex]._asciiChar = msg[0]; @@ -145,7 +145,7 @@ void KernelMessages::reset() { } void KernelMessages::update() { - uint32 currentTimer = _vm->_game->_currentTimer; + uint32 currentTimer = _vm->_game->_priorFrameTimer; for (uint i = 0; i < _entries.size(); ++i) { if (((_entries[i]._flags & KMSG_ACTIVE) != 0) && @@ -157,7 +157,7 @@ void KernelMessages::update() { void KernelMessages::processText(int msgIndex) { Scene &scene = _vm->_game->_scene; KernelMessage &msg = _entries[msgIndex]; - uint32 currentTimer = _vm->_game->_currentTimer; + uint32 currentTimer = _vm->_game->_priorFrameTimer; bool flag = false; if ((msg._flags & KMSG_EXPIRE) != 0) { @@ -277,6 +277,12 @@ void KernelMessages::processText(int msgIndex) { } } +void KernelMessages::delay(uint32 priorFrameTime, uint32 currentTime) { + for (uint i = 0; i < _entries.size(); ++i) { + _entries[i]._timeout += currentTime - priorFrameTime; + } +} + /*------------------------------------------------------------------------*/ TextDisplay::TextDisplay() { diff --git a/engines/mads/messages.h b/engines/mads/messages.h index b60ca8cedc..6967755cdd 100644 --- a/engines/mads/messages.h +++ b/engines/mads/messages.h @@ -86,6 +86,7 @@ public: void reset(); void update(); void processText(int msgIndex); + void delay(uint32 priorFrameTime, uint32 currentTime); }; class TextDisplay { diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index a0888f7d68..4d62e64f31 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -29,7 +29,7 @@ namespace MADS { Scene::Scene(MADSEngine *vm): _vm(vm), _spriteSlots(vm), _action(_vm), - _dirtyAreas(_vm), _dynamicHotspots(vm), _interface(vm), _messages(vm), + _dirtyAreas(_vm), _dynamicHotspots(vm), _interface(vm), _kernelMessages(vm), _screenObjects(vm), _sequences(vm), _textDisplay(vm) { _priorSceneId = 0; _nextSceneId = 0; @@ -97,7 +97,7 @@ void Scene::clearSequenceList() { } void Scene::clearMessageList() { - _messages.clear(); + _kernelMessages.clear(); _talkFont = "*FONTCONV.FF"; _textSpacing = -1; } @@ -125,7 +125,7 @@ void Scene::loadScene(int sceneId, const Common::String &prefix, bool palFlag) { _spriteSlots.clear(false); _sequences.clear(); - _messages.clear(); + _kernelMessages.clear(); // TODO: palletteUsage reset? setPalette(_nullPalette); _sceneInfo = SceneInfo::init(_vm); @@ -371,14 +371,45 @@ void Scene::doFrame() { if (_vm->_debugger->_showMousePos) { Common::Point pt = _vm->_events->mousePos(); Common::String msg = Common::String::format("(%d,%d)", pt.x, pt.y); - _messages.add(Common::Point(5, 5), 0x203, 0, 0, 1, msg); + _kernelMessages.add(Common::Point(5, 5), 0x203, 0, 0, 1, msg); } + if (!_vm->_game->_abortTimers) { + if (_reloadSceneFlag || _currentSceneId != _nextSceneId) + _kernelMessages.reset(); + _kernelMessages.update(); + } + + _vm->_game->_abortTimers2 = !_vm->_game->_abortTimers2; + + warning("TODO: image_inter_list_call"); + + // Write any text needed by the interface + if (_vm->_game->_abortTimers2) + _interface.writeText(); + + // Draw any elements + drawElements(_vm->_game->_abortTimers2, _vm->_game->_abortTimers2); + + // Handle message updates + if (_vm->_game->_abortTimers2) { + uint32 priorTime = _vm->_game->_priorFrameTimer; + uint32 newTime = _vm->_events->getFrameCounter(); + _sequences.delay(newTime, priorTime); + _kernelMessages.delay(newTime, priorTime); + } + + warning("TODO: sub_1DA5A"); + // TODO: Rest of Scene::doFrame } } } +void Scene::drawElements(bool transitionFlag, bool surfaceFlag) { + +} + void Scene::leftClick() { warning("TODO: Scene::leftClick"); } diff --git a/engines/mads/scene.h b/engines/mads/scene.h index f6eecbf093..483ecae23c 100644 --- a/engines/mads/scene.h +++ b/engines/mads/scene.h @@ -87,7 +87,7 @@ public: byte *_vocabBuffer; Common::Array _activeVocabs; SequenceList _sequences; - KernelMessages _messages; + KernelMessages _kernelMessages; Common::String _talkFont; int _textSpacing; Common::Array _hotspots; @@ -183,6 +183,11 @@ public: */ void loop(); + /** + * Draw all the elements onto the scene + */ + void drawElements(bool transitionFlag, bool surfaceFlag); + /** * Execute a click within the scene */ diff --git a/engines/mads/scene_data.cpp b/engines/mads/scene_data.cpp index 985b961e00..5f60a1e56f 100644 --- a/engines/mads/scene_data.cpp +++ b/engines/mads/scene_data.cpp @@ -547,6 +547,10 @@ void InterfaceSurface::elementHighlighted() { warning("TODO: InterfaceSurface::elementHighlighted"); } +void InterfaceSurface::writeText() { + warning("TODO: InterfaceSurface::writeText"); +} + /*------------------------------------------------------------------------*/ void SceneInfo::SpriteInfo::load(Common::SeekableReadStream *f) { diff --git a/engines/mads/scene_data.h b/engines/mads/scene_data.h index f26069ca7e..b18eaffcbd 100644 --- a/engines/mads/scene_data.h +++ b/engines/mads/scene_data.h @@ -360,6 +360,8 @@ public: void load(const Common::String &resName); void elementHighlighted(); + + void writeText(); }; /** diff --git a/engines/mads/sequence.cpp b/engines/mads/sequence.cpp index 7c7b25d32a..8f25007b48 100644 --- a/engines/mads/sequence.cpp +++ b/engines/mads/sequence.cpp @@ -307,10 +307,10 @@ void SequenceList::tick() { } } -void SequenceList::delay(uint32 v1, uint32 v2) { +void SequenceList::delay(uint32 priorFrameTime, uint32 currentTime) { for (uint idx = 0; idx < _entries.size(); ++idx) { if (_entries[idx]._active) { - _entries[idx]._timeout += v1 - v2; + _entries[idx]._timeout += currentTime - priorFrameTime; } } } diff --git a/engines/mads/sequence.h b/engines/mads/sequence.h index 1b9aefe294..f73d48bb8f 100644 --- a/engines/mads/sequence.h +++ b/engines/mads/sequence.h @@ -98,7 +98,7 @@ public: void setSpriteSlot(int seqIndex, SpriteSlot &spriteSlot); bool loadSprites(int seqIndex); void tick(); - void delay(uint32 v1, uint32 v2); + void delay(uint32 priorFrameTime, uint32 currentTime); void setAnimRange(int seqIndex, int startVal, int endVal); void scan(); void setDepth(int seqIndex, int depth); -- cgit v1.2.3