aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/zvision/scr_file_handling.cpp16
-rw-r--r--engines/zvision/script_manager.cpp13
-rw-r--r--engines/zvision/script_manager.h8
3 files changed, 16 insertions, 21 deletions
diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp
index 860e77147d..8c8c6c488a 100644
--- a/engines/zvision/scr_file_handling.cpp
+++ b/engines/zvision/scr_file_handling.cpp
@@ -56,9 +56,10 @@ void ScriptManager::parseScrFile(Common::String fileName) {
parsePuzzle(puzzle, file);
_activePuzzles.push_back(puzzle);
} else if (line.matchString("control:*", true)) {
- Control *control = parseControl(line, file);
+ Common::SharedPtr<Control> control;
+
// Some controls don't require nodes. They just initialize the scene
- if (control != 0) {
+ if (parseControl(line, file, control)) {
_activeControls.push_back(control);
}
}
@@ -289,8 +290,7 @@ uint ScriptManager::parseFlags(Common::SeekableReadStream &stream) const {
return flags;
}
-Control *ScriptManager::parseControl(Common::String &line, Common::SeekableReadStream &stream) {
- Control *control = 0;
+bool ScriptManager::parseControl(Common::String &line, Common::SeekableReadStream &stream, Common::SharedPtr<Control> &control) {
uint32 key;
char controlTypeBuffer[20];
@@ -302,17 +302,17 @@ Control *ScriptManager::parseControl(Common::String &line, Common::SeekableReadS
} else if (controlType.equalsIgnoreCase("flat")) {
Control::parseFlatControl(_engine);
- return 0;
+ return false;
} else if (controlType.equalsIgnoreCase("pana")) {
Control::parsePanoramaControl(_engine, stream);
- return 0;
+ return false;
}
else if (controlType.equalsIgnoreCase("tilt")) {
Control::parseTiltControl(_engine, stream);
- return 0;
+ return false;
}
- return control;
+ return true;
}
} // End of namespace ZVision
diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp
index cd4e174a7c..55cd570467 100644
--- a/engines/zvision/script_manager.cpp
+++ b/engines/zvision/script_manager.cpp
@@ -62,12 +62,10 @@ void ScriptManager::createReferenceTable() {
void ScriptManager::updateNodes(uint deltaTimeMillis) {
// If process() returns true, it means the node can be deleted
- for (Common::List<ActionNode *>::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) {
+ for (Common::List<Common::SharedPtr<ActionNode> >::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) {
if ((*iter)->process(_engine, deltaTimeMillis)) {
- // Remove the node from _activeNodes, then delete it
- ActionNode *node = *iter;
+ // Remove the node from _activeNodes, the SharedPtr destructor will delete the actual ActionNode
iter = _activeNodes.erase(iter);
- delete node;
} else {
iter++;
}
@@ -132,7 +130,7 @@ void ScriptManager::addToStateValue(uint32 key, uint valueToAdd) {
_globalState[key] += valueToAdd;
}
-void ScriptManager::addActionNode(ActionNode *node) {
+void ScriptManager::addActionNode(const Common::SharedPtr<ActionNode> &node) {
_activeNodes.push_back(node);
}
@@ -141,10 +139,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view,
_referenceTable.clear();
_puzzlesToCheck.clear();
_activePuzzles.clear();
- // _activeControls is a list of pointers to the heap, so we have to delete the Controls before we call clear()
- for (Common::List<Control *>::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) {
- delete (*iter);
- }
+ // We can clear without deleting from the heap because we use SharedPtr
_activeControls.clear();
// Parse into puzzles and controls
diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h
index c43030d62b..88340313cc 100644
--- a/engines/zvision/script_manager.h
+++ b/engines/zvision/script_manager.h
@@ -52,7 +52,7 @@ private:
*/
Common::HashMap<uint32, uint> _globalState;
/** Holds the currently active ActionNodes */
- Common::List<ActionNode *> _activeNodes;
+ Common::List<Common::SharedPtr<ActionNode> > _activeNodes;
/** References _globalState keys to Puzzles */
Common::HashMap<uint32, Common::Array<Puzzle *> > _referenceTable;
/** Holds the Puzzles that should be checked this frame */
@@ -60,7 +60,7 @@ private:
/** Holds the currently active puzzles */
Common::List<Puzzle> _activePuzzles;
/** Holds the currently active controls */
- Common::List<Control *> _activeControls;
+ Common::List<Common::SharedPtr<Control> > _activeControls;
public:
@@ -72,7 +72,7 @@ public:
void setStateValue(uint32 key, uint value);
void addToStateValue(uint32 key, uint valueToAdd);
- void addActionNode(ActionNode *node);
+ void addActionNode(const Common::SharedPtr<ActionNode> &node);
void changeLocation(char world, char room, char node, char view, uint32 x);
@@ -129,7 +129,7 @@ private:
* @param line The line initially read
* @param stream Scr file stream
*/
- Control *parseControl(Common::String &line, Common::SeekableReadStream &stream);
+ bool parseControl(Common::String &line, Common::SeekableReadStream &stream, Common::SharedPtr<Control> &control);
};