Skip to content

Commit

Permalink
ZVISION: Convert _activeNodes and _activeControls to Lists of SharedPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
RichieSams committed Aug 4, 2013
1 parent 47f10fe commit 9e996c4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
16 changes: 8 additions & 8 deletions engines/zvision/scr_file_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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];

Expand All @@ -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
13 changes: 4 additions & 9 deletions engines/zvision/script_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions engines/zvision/script_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ class ScriptManager {
*/
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 */
Common::Stack<Puzzle *> _puzzlesToCheck;
/** 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:

Expand All @@ -72,7 +72,7 @@ class ScriptManager {
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);

Expand Down Expand Up @@ -129,7 +129,7 @@ class ScriptManager {
* @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);
};


Expand Down

0 comments on commit 9e996c4

Please sign in to comment.