diff options
author | Ľubomír Remák | 2018-08-04 18:41:33 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-25 23:12:01 +0200 |
commit | 4633b8398642f3005827780313c25479689a72dc (patch) | |
tree | 5299a70ec917c73f5b477e5e4add3d6773e9d177 /engines/mutationofjb/tasks | |
parent | a25715a29b0587ae6795eef63a575172e2cb971d (diff) | |
download | scummvm-rg350-4633b8398642f3005827780313c25479689a72dc.tar.gz scummvm-rg350-4633b8398642f3005827780313c25479689a72dc.tar.bz2 scummvm-rg350-4633b8398642f3005827780313c25479689a72dc.zip |
MUTATIONOFJB: Improve documentation and naming.
Diffstat (limited to 'engines/mutationofjb/tasks')
-rw-r--r-- | engines/mutationofjb/tasks/conversationtask.cpp | 81 | ||||
-rw-r--r-- | engines/mutationofjb/tasks/conversationtask.h | 12 | ||||
-rw-r--r-- | engines/mutationofjb/tasks/objectanimationtask.cpp | 2 | ||||
-rw-r--r-- | engines/mutationofjb/tasks/sequentialtask.h | 3 | ||||
-rw-r--r-- | engines/mutationofjb/tasks/task.h | 3 | ||||
-rw-r--r-- | engines/mutationofjb/tasks/taskmanager.h | 5 |
6 files changed, 59 insertions, 47 deletions
diff --git a/engines/mutationofjb/tasks/conversationtask.cpp b/engines/mutationofjb/tasks/conversationtask.cpp index 8c07b32a69..3b1dcc5246 100644 --- a/engines/mutationofjb/tasks/conversationtask.cpp +++ b/engines/mutationofjb/tasks/conversationtask.cpp @@ -46,7 +46,7 @@ void ConversationTask::start() { widget.setCallback(this); widget.setVisible(true); - _currentLineIndex = 0; + _currentGroupIndex = 0; showChoicesOrPick(); } @@ -57,10 +57,10 @@ void ConversationTask::update() { _sayTask.reset(); switch (_substate) { - case SAYING_NO_CHOICES: + case SAYING_NO_QUESTIONS: finish(); break; - case SAYING_CHOICE: { + case SAYING_QUESTION: { const ConversationLineList &responseList = getTaskManager()->getGame().getAssets().getResponseList(); const ConversationLineList::Line *const line = responseList.getLine(_currentItem->_response); @@ -73,7 +73,7 @@ void ConversationTask::update() { startExtra(); if (_substate != RUNNING_EXTRA) { - gotoNextLine(); + gotoNextGroup(); } break; } @@ -89,25 +89,25 @@ void ConversationTask::update() { delete _innerExecCtx; _innerExecCtx = nullptr; - gotoNextLine(); + gotoNextGroup(); } } } void ConversationTask::onChoiceClicked(ConversationWidget *convWidget, int, uint32 data) { - const ConversationInfo::Item &item = getCurrentLine()->_items[data]; + const ConversationInfo::Item &item = getCurrentGroup()[data]; convWidget->clearChoices(); const ConversationLineList &toSayList = getTaskManager()->getGame().getAssets().getToSayList(); - const ConversationLineList::Line *line = toSayList.getLine(item._choice); + const ConversationLineList::Line *line = toSayList.getLine(item._question); - _substate = SAYING_CHOICE; + _substate = SAYING_QUESTION; createSayTasks(line); getTaskManager()->startTask(_sayTask); _currentItem = &item; if (!line->_speeches[0].isRepeating()) { - getTaskManager()->getGame().getGameData().getCurrentScene()->addExhaustedChoice(_convInfo._context, data + 1, _currentLineIndex + 1); + getTaskManager()->getGame().getGameData().getCurrentScene()->addExhaustedConvItem(_convInfo._context, data + 1, _currentGroupIndex + 1); } } @@ -116,33 +116,33 @@ void ConversationTask::showChoicesOrPick() { GameData &gameData = game.getGameData(); Scene *const scene = gameData.getScene(_sceneId); - Common::Array<uint32> itemsWithValidChoices; + Common::Array<uint32> itemsWithValidQuestions; Common::Array<uint32> itemsWithValidResponses; Common::Array<uint32> itemsWithValidNext; /* - Collect valid "to say" choices (not exhausted and not empty). + Collect valid questions (not exhausted and not empty). Collect valid responses (not exhausted and not empty). - If there are at least two visible choices, we show them. - If there is just one visible choice, pick it automatically ONLY if this is not the first choice in this conversation. + If there are at least two visible questions, we show them. + If there is just one visible question, pick it automatically ONLY if this is not the first question in this conversation. Otherwise we don't start the conversation. - If there are no visible choices, automatically pick first valid response. + If there are no visible questions, automatically pick the first valid response. If nothing above applies, don't start the conversation. */ - const ConversationInfo::Line *const currentLine = getCurrentLine(); - for (ConversationInfo::Items::size_type i = 0; i < currentLine->_items.size(); ++i) { - const ConversationInfo::Item &item = currentLine->_items[i]; + const ConversationInfo::ItemGroup ¤tGroup = getCurrentGroup(); + for (ConversationInfo::ItemGroup::size_type i = 0; i < currentGroup.size(); ++i) { + const ConversationInfo::Item &item = currentGroup[i]; - if (scene->isChoiceExhausted(_convInfo._context, (uint8) i + 1, (uint8) _currentLineIndex + 1)) { + if (scene->isConvItemExhausted(_convInfo._context, (uint8) i + 1, (uint8) _currentGroupIndex + 1)) { continue; } - const uint8 choice = item._choice; + const uint8 toSay = item._question; const uint8 response = item._response; - const uint8 next = item._nextLineIndex; + const uint8 next = item._nextGroupIndex; - if (choice != 0) { - itemsWithValidChoices.push_back(i); + if (toSay != 0) { + itemsWithValidQuestions.push_back(i); } if (response != 0) { @@ -154,38 +154,38 @@ void ConversationTask::showChoicesOrPick() { } } - if (itemsWithValidChoices.size() > 1) { + if (itemsWithValidQuestions.size() > 1) { ConversationWidget &widget = game.getGui().getConversationWidget(); const ConversationLineList &toSayList = game.getAssets().getToSayList(); - for (Common::Array<uint32>::size_type i = 0; i < itemsWithValidChoices.size() && i < ConversationWidget::CONVERSATION_MAX_CHOICES; ++i) { - const ConversationInfo::Item &item = currentLine->_items[itemsWithValidChoices[i]]; - const ConversationLineList::Line *const line = toSayList.getLine(item._choice); + for (Common::Array<uint32>::size_type i = 0; i < itemsWithValidQuestions.size() && i < ConversationWidget::CONVERSATION_MAX_CHOICES; ++i) { + const ConversationInfo::Item &item = currentGroup[itemsWithValidQuestions[i]]; + const ConversationLineList::Line *const line = toSayList.getLine(item._question); const Common::String widgetText = toUpperCP895(line->_speeches[0]._text); - widget.setChoice((int) i, widgetText, itemsWithValidChoices[i]); + widget.setChoice((int) i, widgetText, itemsWithValidQuestions[i]); } _substate = IDLE; _currentItem = nullptr; _haveChoices = true; - } else if (itemsWithValidChoices.size() == 1 && _haveChoices) { + } else if (itemsWithValidQuestions.size() == 1 && _haveChoices) { const ConversationLineList &toSayList = game.getAssets().getToSayList(); - const ConversationInfo::Item &item = currentLine->_items[itemsWithValidChoices.front()]; - const ConversationLineList::Line *const line = toSayList.getLine(item._choice); + const ConversationInfo::Item &item = currentGroup[itemsWithValidQuestions.front()]; + const ConversationLineList::Line *const line = toSayList.getLine(item._question); - _substate = SAYING_CHOICE; + _substate = SAYING_QUESTION; createSayTasks(line); getTaskManager()->startTask(_sayTask); _currentItem = &item; if (!line->_speeches[0].isRepeating()) { - game.getGameData().getCurrentScene()->addExhaustedChoice(_convInfo._context, itemsWithValidChoices.front() + 1, _currentLineIndex + 1); + game.getGameData().getCurrentScene()->addExhaustedConvItem(_convInfo._context, itemsWithValidQuestions.front() + 1, _currentGroupIndex + 1); } _haveChoices = true; } else if (!itemsWithValidResponses.empty() && _haveChoices) { const ConversationLineList &responseList = game.getAssets().getResponseList(); - const ConversationInfo::Item &item = currentLine->_items[itemsWithValidResponses.front()]; + const ConversationInfo::Item &item = currentGroup[itemsWithValidResponses.front()]; const ConversationLineList::Line *const line = responseList.getLine(item._response); _substate = SAYING_RESPONSE; @@ -195,7 +195,7 @@ void ConversationTask::showChoicesOrPick() { _haveChoices = true; } else if (!itemsWithValidNext.empty() && _haveChoices) { - _currentLineIndex = currentLine->_items[itemsWithValidNext.front()]._nextLineIndex - 1; + _currentGroupIndex = currentGroup[itemsWithValidNext.front()]._nextGroupIndex - 1; showChoicesOrPick(); } else { if (_haveChoices) { @@ -203,14 +203,15 @@ void ConversationTask::showChoicesOrPick() { } else { _sayTask = TaskPtr(new SayTask("Nothing to talk about.", _convInfo._color)); // TODO: This is hardcoded in executable. Load it. getTaskManager()->startTask(_sayTask); - _substate = SAYING_NO_CHOICES; + _substate = SAYING_NO_QUESTIONS; _currentItem = nullptr; } } } -const ConversationInfo::Line *ConversationTask::getCurrentLine() const { - return &_convInfo._lines[_currentLineIndex]; +const ConversationInfo::ItemGroup &ConversationTask::getCurrentGroup() const { + assert(_currentGroupIndex < _convInfo._itemGroups.size()); + return _convInfo._itemGroups[_currentGroupIndex]; } void ConversationTask::finish() { @@ -244,11 +245,11 @@ void ConversationTask::startExtra() { } } -void ConversationTask::gotoNextLine() { - if (_currentItem->_nextLineIndex == 0) { +void ConversationTask::gotoNextGroup() { + if (_currentItem->_nextGroupIndex == 0) { finish(); } else { - _currentLineIndex = _currentItem->_nextLineIndex - 1; + _currentGroupIndex = _currentItem->_nextGroupIndex - 1; showChoicesOrPick(); } } diff --git a/engines/mutationofjb/tasks/conversationtask.h b/engines/mutationofjb/tasks/conversationtask.h index bdfa87533f..9522876a27 100644 --- a/engines/mutationofjb/tasks/conversationtask.h +++ b/engines/mutationofjb/tasks/conversationtask.h @@ -33,7 +33,7 @@ class ScriptExecutionContext; class ConversationTask : public Task, public ConversationWidgetCallback { public: - ConversationTask(uint8 sceneId, const ConversationInfo &convInfo, TalkCommand::Mode mode) : _sceneId(sceneId), _convInfo(convInfo), _mode(mode), _currentLineIndex(0), _currentItem(nullptr), _substate(IDLE), _haveChoices(false), _innerExecCtx(nullptr) {} + ConversationTask(uint8 sceneId, const ConversationInfo &convInfo, TalkCommand::Mode mode) : _sceneId(sceneId), _convInfo(convInfo), _mode(mode), _currentGroupIndex(0), _currentItem(nullptr), _substate(IDLE), _haveChoices(false), _innerExecCtx(nullptr) {} virtual ~ConversationTask() {} virtual void start() override; @@ -42,25 +42,25 @@ public: virtual void onChoiceClicked(ConversationWidget *, int response, uint32 data) override; private: void showChoicesOrPick(); - const ConversationInfo::Line *getCurrentLine() const; + const ConversationInfo::ItemGroup &getCurrentGroup() const; void finish(); void startExtra(); - void gotoNextLine(); + void gotoNextGroup(); void createSayTasks(const ConversationLineList::Line *line); uint8 getSpeechColor(const ConversationLineList::Speech &speech); uint8 _sceneId; const ConversationInfo &_convInfo; TalkCommand::Mode _mode; - uint _currentLineIndex; + uint _currentGroupIndex; const ConversationInfo::Item *_currentItem; TaskPtr _sayTask; enum Substate { IDLE, - SAYING_CHOICE, + SAYING_QUESTION, SAYING_RESPONSE, - SAYING_NO_CHOICES, + SAYING_NO_QUESTIONS, RUNNING_EXTRA }; diff --git a/engines/mutationofjb/tasks/objectanimationtask.cpp b/engines/mutationofjb/tasks/objectanimationtask.cpp index e93602c367..2b4bf80cd2 100644 --- a/engines/mutationofjb/tasks/objectanimationtask.cpp +++ b/engines/mutationofjb/tasks/objectanimationtask.cpp @@ -56,7 +56,7 @@ void ObjectAnimationTask::update() { * 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 + * Randomness is used to introduce variety - e.g. in the starting scene a perched bird occasionally * spreads its wings. */ void ObjectAnimationTask::updateObjects() { diff --git a/engines/mutationofjb/tasks/sequentialtask.h b/engines/mutationofjb/tasks/sequentialtask.h index 078fd8aa41..1c00751a61 100644 --- a/engines/mutationofjb/tasks/sequentialtask.h +++ b/engines/mutationofjb/tasks/sequentialtask.h @@ -27,6 +27,9 @@ namespace MutationOfJB { +/** + * Queues multiple tasks. + */ class SequentialTask : public Task { public: SequentialTask(const TaskPtrs &tasks); diff --git a/engines/mutationofjb/tasks/task.h b/engines/mutationofjb/tasks/task.h index b14fc971aa..115668a2cc 100644 --- a/engines/mutationofjb/tasks/task.h +++ b/engines/mutationofjb/tasks/task.h @@ -31,6 +31,9 @@ namespace MutationOfJB { class TaskManager; +/** + * Base class for tasks. + */ class Task { public: enum State { diff --git a/engines/mutationofjb/tasks/taskmanager.h b/engines/mutationofjb/tasks/taskmanager.h index 2f351c0bbf..c88da59a69 100644 --- a/engines/mutationofjb/tasks/taskmanager.h +++ b/engines/mutationofjb/tasks/taskmanager.h @@ -31,6 +31,11 @@ namespace MutationOfJB { class Game; class Task; +/** + * Handles task management. + * + * Tasks are a way run game logic asynchronously. + */ class TaskManager { public: TaskManager(Game &game) : _game(game) {} |