aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorrichiesams2013-08-10 17:31:57 -0500
committerrichiesams2013-08-10 17:31:57 -0500
commit2565f96c55b39f5155d10625def873f2c07207e8 (patch)
tree0a755477df10b83a5e6bde0965e1ee06d7a92018 /engines
parentdd11566ffdb46a867550e82b3605e3c76cf194a3 (diff)
downloadscummvm-rg350-2565f96c55b39f5155d10625def873f2c07207e8.tar.gz
scummvm-rg350-2565f96c55b39f5155d10625def873f2c07207e8.tar.bz2
scummvm-rg350-2565f96c55b39f5155d10625def873f2c07207e8.zip
ZVISION: Make ScriptManager::changeLocation delay the actual change until the end of the frame
This prevents memory corruption since changeLocation could be called in the middle of a Puzzle list iteration and changeLocation clears all the Puzzle lists.
Diffstat (limited to 'engines')
-rw-r--r--engines/zvision/script_manager.cpp29
-rw-r--r--engines/zvision/script_manager.h12
2 files changed, 38 insertions, 3 deletions
diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp
index 4ccbbef92d..586cc2af38 100644
--- a/engines/zvision/script_manager.cpp
+++ b/engines/zvision/script_manager.cpp
@@ -33,7 +33,7 @@
namespace ZVision {
-ScriptManager::ScriptManager(ZVision *engine) : _engine(engine) {}
+ScriptManager::ScriptManager(ZVision *engine) : _engine(engine), _changeLocation(false) {}
void ScriptManager::initialize() {
parseScrFile("universe.scr", true);
@@ -42,6 +42,11 @@ void ScriptManager::initialize() {
void ScriptManager::update(uint deltaTimeMillis) {
updateNodes(deltaTimeMillis);
checkPuzzleCriteria();
+
+ if (_changeLocation) {
+ changeLocationIntern();
+ _changeLocation = false;
+ }
}
void ScriptManager::createReferenceTable() {
@@ -178,6 +183,19 @@ void ScriptManager::addActionNode(const Common::SharedPtr<ActionNode> &node) {
}
void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 x) {
+ _nextLocation.world = world;
+ _nextLocation.room = room;
+ _nextLocation.node = node;
+ _nextLocation.view = view;
+ _nextLocation.x = x;
+
+ _changeLocation = true;
+}
+
+void ScriptManager::changeLocationIntern() {
+ assert(_nextLocation.world != 0);
+ debug("Changing location to: %c %c %c %c %u", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view, _nextLocation.x);
+
// Clear all the containers
_referenceTable.clear();
_puzzlesToCheck.clear();
@@ -186,16 +204,21 @@ void ScriptManager::changeLocation(char world, char room, char node, char view,
_activeControls.clear();
// Parse into puzzles and controls
- Common::String fileName = Common::String::format("%c%c%c%c.scr", world, room, node, view);
+ Common::String fileName = Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view);
parseScrFile(fileName);
// Create the puzzle reference table
createReferenceTable();
- // Add all the puzzles to the stack to be checked
+ // Add all the local puzzles to the stack to be checked
for (Common::List<Puzzle>::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) {
_puzzlesToCheck.push(&(*iter));
}
+
+ // Add all the global puzzles to the stack to be checked
+ for (Common::List<Puzzle>::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) {
+ _puzzlesToCheck.push(&(*iter));
+ }
}
} // End of namespace ZVision
diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h
index 29994259c9..8e79548f77 100644
--- a/engines/zvision/script_manager.h
+++ b/engines/zvision/script_manager.h
@@ -39,6 +39,14 @@ namespace ZVision {
class ZVision;
class ActionNode;
+struct Location {
+ char world;
+ char room;
+ char node;
+ char view;
+ uint32 x;
+};
+
class ScriptManager {
public:
ScriptManager(ZVision *engine);
@@ -64,6 +72,9 @@ private:
/** Holds the currently active controls */
Common::List<Common::SharedPtr<Control> > _activeControls;
+ Location _nextLocation;
+ bool _changeLocation;
+
public:
void initialize();
@@ -79,6 +90,7 @@ public:
private:
void createReferenceTable();
+ void changeLocationIntern();
void updateNodes(uint deltaTimeMillis);
void checkPuzzleCriteria();