From 578a6794de9ba7679966fee9aec02c6b2bdbce94 Mon Sep 17 00:00:00 2001 From: Miroslav Remák Date: Thu, 19 Jul 2018 16:21:39 +0200 Subject: MUTATIONOFJB: Improve documentation, rename cryptic variables. --- engines/mutationofjb/tasks/objectanimationtask.cpp | 34 +++++++++++++++------- engines/mutationofjb/tasks/saytask.cpp | 10 ++++--- 2 files changed, 29 insertions(+), 15 deletions(-) (limited to 'engines/mutationofjb/tasks') diff --git a/engines/mutationofjb/tasks/objectanimationtask.cpp b/engines/mutationofjb/tasks/objectanimationtask.cpp index 75c15bf624..90438f8bc2 100644 --- a/engines/mutationofjb/tasks/objectanimationtask.cpp +++ b/engines/mutationofjb/tasks/objectanimationtask.cpp @@ -31,6 +31,7 @@ namespace MutationOfJB { static const int TICK_MILLIS = 100; +// TODO: Respect currentScene._delay. ObjectAnimationTask::ObjectAnimationTask() : _timer(TICK_MILLIS) { } @@ -47,6 +48,17 @@ void ObjectAnimationTask::update() { } } +/** + * Advances every object animation in the current scene to the next frame. + * + * Normally the animation restarts after the last object frame. However, some animations have random + * elements to them. If _randomFrame is set, the animation restarts when _randomFrame is reached. + * Additionally, there is a chance with each frame until _randomFrame that the animation may jump + * straight to _randomFrame and continue until the last frame, then wrap around to the first frame. + * + * Randomness is used to introduce variety - e.g. in the starting scene a perched bird occassionally + * spreads its wings. + */ void ObjectAnimationTask::updateObjects() { Scene *const scene = getTaskManager()->getGame().getGameData().getCurrentScene(); if (!scene) { @@ -56,34 +68,34 @@ void ObjectAnimationTask::updateObjects() { for (uint8 i = 1; i <= scene->getNoObjects(); ++i) { Object *const object = scene->getObject(i); // Skip if object animation not active. - if (!object->_AC) + if (!object->_active) continue; - // Number of framers must be higher than 1. - if (object->_NA <= 1) + // Number of frames must be higher than 1. + if (object->_numFrames <= 1) continue; - const uint8 currentAnimOffset = object->_CA - object->_FA; + const uint8 currentAnimOffset = object->_currentFrame - object->_firstFrame; - const bool randomized = object->_FR != 0; - const bool belowRandomFrame = currentAnimOffset < (object->_FR - 1); + const bool randomized = object->_randomFrame != 0; + const bool belowRandomFrame = currentAnimOffset < (object->_randomFrame - 1); - uint8 maxAnimOffset = object->_NA - 1; + uint8 maxAnimOffset = object->_numFrames - 1; if (randomized && belowRandomFrame) { - maxAnimOffset = object->_FR - 2; + maxAnimOffset = object->_randomFrame - 2; } uint8 nextAnimationOffset = currentAnimOffset + 1; if (currentAnimOffset == maxAnimOffset) { - if (randomized && object->_unknown != 0 && getTaskManager()->getGame().getRandomSource().getRandomNumber(object->_unknown) == 0) - nextAnimationOffset = object->_FR - 1; + if (randomized && object->_jumpChance != 0 && getTaskManager()->getGame().getRandomSource().getRandomNumber(object->_jumpChance) == 0) + nextAnimationOffset = object->_randomFrame - 1; else nextAnimationOffset = 0; } // TODO: Hardcoded animations. - object->_CA = nextAnimationOffset + object->_FA; + object->_currentFrame = nextAnimationOffset + object->_firstFrame; getTaskManager()->getGame().getRoom().drawObjectAnimation(i, nextAnimationOffset); } } diff --git a/engines/mutationofjb/tasks/saytask.cpp b/engines/mutationofjb/tasks/saytask.cpp index c9c2a95ad8..bd89805c68 100644 --- a/engines/mutationofjb/tasks/saytask.cpp +++ b/engines/mutationofjb/tasks/saytask.cpp @@ -60,10 +60,12 @@ void SayTask::drawSubtitle(const Common::String &text, int16 talkX, int16 talkY, Common::Array lines; font.wordWrap(text, MAX_LINE_WIDTH, lines); + // Get the x, y coordinates of the top center point of the text's bounding box + // from the (rather strange) talk coordinates coming from scripts. int16 x = talkX; - int16 y = talkY - (lines.size() - 1) * font.getLineHeight() - 15; // Get the top y + int16 y = talkY - (lines.size() - 1) * font.getLineHeight() - 15; - // Clamp to screen edges + // Clamp to screen edges. y = MAX(y, 3); int16 maxWidth = 0; for (uint i = 0; i < lines.size(); i++) { @@ -75,12 +77,12 @@ void SayTask::drawSubtitle(const Common::String &text, int16 talkX, int16 talkY, x = MIN(x, 317 - lineWidth / 2); } - // Draw lines + // Draw lines. for (uint i = 0; i < lines.size(); i++) { font.drawString(lines[i], color, x - font.getWidth(lines[i]) / 2, y + i * font.getLineHeight(), getTaskManager()->getGame().getScreen()); } - // Remember the area occupied by the text + // Remember the area occupied by the text. _boundingBox.top = x - maxWidth / 2; _boundingBox.left = y; _boundingBox.setWidth(maxWidth); -- cgit v1.2.3