aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrichiesams2013-07-11 00:26:32 -0500
committerrichiesams2013-08-04 13:32:14 -0500
commit24dc3e1793749269daa30350a5923f51d7892efd (patch)
tree6ec0ae37ecd598001507a2bc781127f05a4f4c9e
parent9c7203c4b922845d63b00236a78e48e4f55bd633 (diff)
downloadscummvm-rg350-24dc3e1793749269daa30350a5923f51d7892efd.tar.gz
scummvm-rg350-24dc3e1793749269daa30350a5923f51d7892efd.tar.bz2
scummvm-rg350-24dc3e1793749269daa30350a5923f51d7892efd.zip
ZVISION: Create ScriptManager state handling logic
-rw-r--r--engines/zvision/script_manager.cpp88
-rw-r--r--engines/zvision/script_manager.h12
-rw-r--r--engines/zvision/zvision.cpp6
3 files changed, 103 insertions, 3 deletions
diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp
index 13438d4fa6..b4ad1cc003 100644
--- a/engines/zvision/script_manager.cpp
+++ b/engines/zvision/script_manager.cpp
@@ -22,19 +22,103 @@
#include "common/scummsys.h"
+#include "common/algorithm.h"
+#include "common/hashmap.h"
+
#include "zvision/script_manager.h"
+#include "zvision/actions.h"
+#include "zvision/action_node.h"
+#include "zvision/utility.h"
namespace ZVision {
+ScriptManager::ScriptManager(ZVision *engine) : _engine(engine) {}
+
// TODO: Actually do something in the initialize or remove it
void ScriptManager::initialize() {
}
+void ScriptManager::createReferenceTable() {
+ // Iterate through each Puzzle
+ for (Common::List<Puzzle>::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) {
+ Puzzle *puzzlePtr = &(*activePuzzleIter);
+
+ // Iterate through each Criteria and add a reference from the criteria key to the Puzzle
+ for (Common::List<Criteria>::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).criteriaList.end(); criteriaIter++) {
+ _referenceTable[criteriaIter->key].push_back(puzzlePtr);
+
+ // If the argument is a key, add a reference to it as well
+ if (criteriaIter->argument)
+ _referenceTable[criteriaIter->argument].push_back(puzzlePtr);
+ }
+ }
+
+ // Remove duplicate entries
+ for (Common::HashMap<uint32, Common::Array<Puzzle *>>::iterator referenceTableIter; referenceTableIter != _referenceTable.end(); referenceTableIter++) {
+ removeDuplicateEntries(&(referenceTableIter->_value));
+ }
+}
+
+void ScriptManager::updateNodes(uint32 deltaTimeMillis) {
+ // If process() returns true, it means the node can be deleted
+ for (Common::List<ActionNode *>::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) {
+ if ((*iter)->process(_engine, deltaTimeMillis)) {
+ // Remove the node from _activeNodes, then delete it
+ ActionNode *node = *iter;
+ iter = _activeNodes.erase(iter);
+ delete node;
+ } else {
+ iter++;
+ }
+ }
+}
+
+void ScriptManager::checkPuzzleCriteria() {
+ while (!_puzzlesToCheck.empty()) {
+ Puzzle *puzzle = _puzzlesToCheck.pop();
+ // Check each Criteria
+ for (Common::List<Criteria>::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) {
+ bool criteriaMet = false;
+
+ // Get the value to compare against
+ byte argumentValue;
+ if ((*iter).argument)
+ argumentValue = getStateValue(iter->argument);
+ else
+ argumentValue = iter->argument;
+
+ // Do the comparison
+ switch ((*iter).criteriaOperator) {
+ case EQUAL_TO:
+ criteriaMet = getStateValue(iter->key) == argumentValue;
+ break;
+ case NOT_EQUAL_TO:
+ criteriaMet = getStateValue(iter->key) != argumentValue;
+ break;
+ case GREATER_THAN:
+ criteriaMet = getStateValue(iter->key) > argumentValue;
+ break;
+ case LESS_THAN:
+ criteriaMet = getStateValue(iter->key) < argumentValue;
+ break;
+ }
+
+ // TODO: Add logic for the different Flags (aka, ONCE_PER_INST)
+ if (criteriaMet) {
+ for (Common::List<ResultAction *>::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) {
+ (*resultIter)->execute(_engine);
+ }
+ }
+ }
+ }
+}
+
byte ScriptManager::getStateValue(uint32 key) {
return _globalState[key];
}
+// TODO: Add logic to check _referenceTable and add to _puzzlesToCheck if necessary
void ScriptManager::setStateValue(uint32 key, byte value) {
_globalState[key] = value;
}
@@ -43,4 +127,8 @@ void ScriptManager::addToStateValue(uint32 key, byte valueToAdd) {
_globalState[key] += valueToAdd;
}
+void ScriptManager::addActionNode(ActionNode *node) {
+ _activeNodes.push_back(node);
+}
+
} // End of namespace ZVision
diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h
index 5be4c171e0..42f4bba602 100644
--- a/engines/zvision/script_manager.h
+++ b/engines/zvision/script_manager.h
@@ -33,10 +33,15 @@
namespace ZVision {
+class ZVision;
class ActionNode;
class ScriptManager {
+public:
+ ScriptManager(ZVision *engine);
+
private:
+ ZVision *_engine;
/**
* Holds the global state variable. Do NOT directly modify this. Use the accessors and
* mutators getStateValue() and setStateValue(). This ensures that Puzzles that reference a
@@ -57,11 +62,18 @@ private:
public:
void initialize();
+ void updateNodes(uint32 deltaTimeMillis);
+ void checkPuzzleCriteria();
+
byte getStateValue(uint32 key);
void setStateValue(uint32 key, byte value);
void addToStateValue(uint32 key, byte valueToAdd);
+ void addActionNode(ActionNode *node);
+
private:
+ void createReferenceTable();
+
/**
* Parses a script file into triggers and events
*
diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp
index de1730f354..c126a9ad7c 100644
--- a/engines/zvision/zvision.cpp
+++ b/engines/zvision/zvision.cpp
@@ -70,7 +70,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc)
_rnd = new Common::RandomSource("zvision");
// Create managers
- _scriptManager = new ScriptManager();
+ _scriptManager = new ScriptManager(this);
debug("ZVision::ZVision");
}
@@ -126,8 +126,8 @@ Common::Error ZVision::run() {
if (_currentVideo != 0)
continueVideo();
else {
- updateScripts();
- updateAnimations(deltaTime);
+ _scriptManager->updateNodes(deltaTime);
+ _scriptManager->checkPuzzleCriteria();
}
if (_needsScreenUpdate || _console->isActive()) {