From 2faaf8488bb5bdace2c017b37f825bc38f41ef84 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 2 Aug 2013 15:30:02 -0500 Subject: ZVISION: Convert ResultAction pointers to SharePtr This gets rid of the need for specific destruction as well as making the copy swap operations in the ScriptManger _referenceTable more efficient --- engines/zvision/module.mk | 1 - engines/zvision/puzzle.cpp | 46 ----------------------------------- engines/zvision/puzzle.h | 13 +++------- engines/zvision/scr_file_handling.cpp | 11 ++++----- engines/zvision/script_manager.cpp | 2 +- engines/zvision/script_manager.h | 9 ++++--- 6 files changed, 15 insertions(+), 67 deletions(-) delete mode 100644 engines/zvision/puzzle.cpp (limited to 'engines') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index f90bb156e6..26cf4ee696 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -8,7 +8,6 @@ MODULE_OBJS := \ detection.o \ events.o \ lzss_read_stream.o \ - puzzle.o \ render_manager.o \ render_table.o \ scr_file_handling.o \ diff --git a/engines/zvision/puzzle.cpp b/engines/zvision/puzzle.cpp deleted file mode 100644 index 8399919399..0000000000 --- a/engines/zvision/puzzle.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* ScummVM - Graphic Adventure Engine -* -* ScummVM is the legal property of its developers, whose names -* are too numerous to list here. Please refer to the COPYRIGHT -* file distributed with this source distribution. -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. - -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. - -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -*/ - -#include "common/scummsys.h" - -#include "zvision/actions.h" -#include "zvision/puzzle.h" - -namespace ZVision { - -Puzzle::~Puzzle() { - for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { - delete (*iter); - } -} - -Puzzle::Puzzle(const Puzzle &other) - : key(other.key), - criteriaList(other.criteriaList), - flags(flags) { - // We have to clone the ResultActions since they are on the heap - for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { - resultActions.push_back((*iter)->clone()); - } -} - -} // End of namespace ZVision diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index c73a345c3a..5e060c009a 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -23,19 +23,15 @@ #ifndef ZVISION_PUZZLE_H #define ZVISION_PUZZLE_H + #include "common/list.h" +#include "common/ptr.h" namespace ZVision { class ResultAction; -class Puzzle { -public: - Puzzle() {} - ~Puzzle(); - Puzzle(const Puzzle &other); - -public: +struct Puzzle { /** How criteria should be decided */ enum CriteriaOperator { EQUAL_TO, @@ -65,11 +61,10 @@ public: DISABLED = 0x04 }; -public: uint32 key; Common::List criteriaList; // This has to be list of pointers because ResultAction is abstract - Common::List resultActions; + Common::List> resultActions; uint flags; // Used by the ScriptManager to allow unique-ification of _referenceTable diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 0bd28ec4a9..860e77147d 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -134,7 +134,7 @@ bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableRe return true; } -void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::List &actionList) const { +void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::List > &actionList) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -143,14 +143,13 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis while (!line.contains('}')) { // Parse for the action type if (line.matchString("*:add*", true)) { - actionList.push_back(new ActionAdd(line)); + actionList.push_back(Common::SharedPtr(new ActionAdd(line))); } else if (line.matchString("*:animplay*", true)) { - actionList.push_back(new ActionPlayAnimation(line)); + actionList.push_back(Common::SharedPtr(new ActionPlayAnimation(line))); } else if (line.matchString("*:animpreload*", true)) { - actionList.push_back(new ActionPreloadAnimation(line)); + actionList.push_back(Common::SharedPtr(new ActionPreloadAnimation(line))); } else if (line.matchString("*:animunload*", true)) { - - + actionList.push_back(Common::SharedPtr(new ActionUnloadAnimation(line))); } else if (line.matchString("*:attenuate*", true)) { diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index ad986d6568..540971ad8b 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -112,7 +112,7 @@ void ScriptManager::checkPuzzleCriteria() { // TODO: Add logic for the different Flags (aka, ONCE_PER_INST) // criteriaList can be empty. Aka, the puzzle should be executed immediately if (puzzle->criteriaList.empty() || criteriaMet) { - for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { + for (Common::List >::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { (*resultIter)->execute(_engine); } } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 07dd3d8586..c43030d62b 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -106,13 +106,14 @@ private: bool parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const; /** - * Parses the stream into a Results object + * Parses the stream into a ResultAction objects * Helper method for parsePuzzle. * - * @param stream Scr file stream - * @return Created Results object + * @param stream Scr file stream + * @param actionList The list where the results will be added + * @return Created Results object */ - void parseResults(Common::SeekableReadStream &stream, Common::List &actionList) const; + void parseResults(Common::SeekableReadStream &stream, Common::List > &actionList) const; /** * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum -- cgit v1.2.3