diff options
author | richiesams | 2013-08-20 20:50:14 -0500 |
---|---|---|
committer | richiesams | 2013-08-20 20:50:14 -0500 |
commit | 35622827f8e8b507e6c2450773857975f2864a56 (patch) | |
tree | aab08f7675b7c73eb3311cabc1a5f86b7101cca0 /engines | |
parent | ad5756fa31113b88fb486c679adfe2197daeca08 (diff) | |
download | scummvm-rg350-35622827f8e8b507e6c2450773857975f2864a56.tar.gz scummvm-rg350-35622827f8e8b507e6c2450773857975f2864a56.tar.bz2 scummvm-rg350-35622827f8e8b507e6c2450773857975f2864a56.zip |
ZVISION: Store the Puzzles in _activePuzzles and _globalPuzzles on the heap
This allows List::push_back() to not cause a data copy
Diffstat (limited to 'engines')
-rw-r--r-- | engines/zvision/scr_file_handling.cpp | 12 | ||||
-rw-r--r-- | engines/zvision/script_manager.cpp | 37 | ||||
-rw-r--r-- | engines/zvision/script_manager.h | 7 |
3 files changed, 33 insertions, 23 deletions
diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index f4d4563c63..7ccd939e54 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -52,8 +52,8 @@ void ScriptManager::parseScrFile(const Common::String &fileName, bool isGlobal) continue; if (line.matchString("puzzle:*", true)) { - Puzzle puzzle; - sscanf(line.c_str(),"puzzle:%u",&(puzzle.key)); + Puzzle *puzzle = new Puzzle(); + sscanf(line.c_str(),"puzzle:%u",&(puzzle->key)); parsePuzzle(puzzle, file); if (isGlobal) { @@ -67,17 +67,17 @@ void ScriptManager::parseScrFile(const Common::String &fileName, bool isGlobal) } } -void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream) { +void ScriptManager::parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream) { Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); while (!stream.eos() && !line.contains('}')) { if (line.matchString("criteria {", true)) { - parseCriteria(stream, puzzle.criteriaList); + parseCriteria(stream, puzzle->criteriaList); } else if (line.matchString("results {", true)) { - parseResults(stream, puzzle.resultActions); + parseResults(stream, puzzle->resultActions); } else if (line.matchString("flags {", true)) { - puzzle.flags = parseFlags(stream); + puzzle->flags = parseFlags(stream); } line = stream.readLine(); diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 6a1794dabf..390fe0d742 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -41,6 +41,15 @@ ScriptManager::ScriptManager(ZVision *engine) _changeLocation(false) { } +ScriptManager::~ScriptManager() { + for (Common::List<Puzzle *>::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { + delete (*iter); + } + for (Common::List<Puzzle *>::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { + delete (*iter); + } +} + void ScriptManager::initialize() { parseScrFile("universe.scr", true); changeLocation('g', 'a', 'r', 'y', 0); @@ -58,11 +67,11 @@ void ScriptManager::update(uint deltaTimeMillis) { void ScriptManager::createReferenceTable() { // Iterate through each local Puzzle - for (Common::List<Puzzle>::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { - Puzzle *puzzlePtr = &(*activePuzzleIter); + for (Common::List<Puzzle *>::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { + Puzzle *puzzlePtr = (*activePuzzleIter); // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle - for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).criteriaList.end(); criteriaIter++) { + for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = (*activePuzzleIter)->criteriaList.begin(); criteriaIter != (*activePuzzleIter)->criteriaList.end(); criteriaIter++) { for (Common::List<Puzzle::CriteriaEntry>::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { _referenceTable[entryIter->key].push_back(puzzlePtr); @@ -75,11 +84,11 @@ void ScriptManager::createReferenceTable() { } // Iterate through each global Puzzle - for (Common::List<Puzzle>::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); globalPuzzleIter++) { - Puzzle *puzzlePtr = &(*globalPuzzleIter); + for (Common::List<Puzzle *>::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); globalPuzzleIter++) { + Puzzle *puzzlePtr = (*globalPuzzleIter); // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle - for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = globalPuzzleIter->criteriaList.begin(); criteriaIter != (*globalPuzzleIter).criteriaList.end(); criteriaIter++) { + for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = (*globalPuzzleIter)->criteriaList.begin(); criteriaIter != (*globalPuzzleIter)->criteriaList.end(); criteriaIter++) { for (Common::List<Puzzle::CriteriaEntry>::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { _referenceTable[entryIter->key].push_back(puzzlePtr); @@ -263,23 +272,23 @@ void ScriptManager::changeLocationIntern() { } // Add all the local puzzles to the queue to be checked - for (Common::List<Puzzle>::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { + for (Common::List<Puzzle *>::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { // Reset any Puzzles that have the flag ONCE_PER_INST - if (((*iter).flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { - setStateValue((*iter).key, 0); + if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { + setStateValue((*iter)->key, 0); } - _puzzlesToCheck.push(&(*iter)); + _puzzlesToCheck.push((*iter)); } // Add all the global puzzles to the queue to be checked - for (Common::List<Puzzle>::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { + for (Common::List<Puzzle *>::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { // Reset any Puzzles that have the flag ONCE_PER_INST - if (((*iter).flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { - setStateValue((*iter).key, 0); + if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { + setStateValue((*iter)->key, 0); } - _puzzlesToCheck.push(&(*iter)); + _puzzlesToCheck.push((*iter)); } // Create the puzzle reference table diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 884699a6b0..2372703cbe 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -50,6 +50,7 @@ struct Location { class ScriptManager { public: ScriptManager(ZVision *engine); + ~ScriptManager(); private: ZVision *_engine; @@ -66,9 +67,9 @@ private: /** Holds the Puzzles that should be checked this frame */ Common::Queue<Puzzle *> _puzzlesToCheck; /** Holds the currently active puzzles */ - Common::List<Puzzle> _activePuzzles; + Common::List<Puzzle *> _activePuzzles; /** Holds the global puzzles */ - Common::List<Puzzle>_globalPuzzles; + Common::List<Puzzle *>_globalPuzzles; /** Holds the currently active controls */ Common::HashMap<uint32, Control *> _activeControls; @@ -112,7 +113,7 @@ private: * @param puzzle The object to store what is parsed * @param stream Scr file stream */ - void parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream); + void parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream); /** * Parses the stream into a Criteria object |