ZVISION: Remove ScriptManager::_activeNodes and change all iterators to iterate over _activeControls

We also change _activeControls to a List instead of a HashMap because a List should have
slightly better iteration time.
This commit is contained in:
richiesams 2013-08-26 14:13:27 -05:00
parent b667002124
commit a6b2bb7581
2 changed files with 8 additions and 15 deletions

View file

@ -108,11 +108,10 @@ void ScriptManager::createReferenceTable() {
void ScriptManager::updateNodes(uint deltaTimeMillis) { void ScriptManager::updateNodes(uint deltaTimeMillis) {
// If process() returns true, it means the node can be deleted // 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<Control *>::iterator iter = _activeControls.begin(); iter != _activeControls.end();) {
if ((*iter)->process(deltaTimeMillis)) { if ((*iter)->process(deltaTimeMillis)) {
// Delete the node then remove the pointer // Remove the node
delete (*iter); iter = _activeControls.erase(iter);
iter = _activeNodes.erase(iter);
} else { } else {
iter++; iter++;
} }
@ -257,12 +256,10 @@ void ScriptManager::changeLocationIntern() {
delete (*iter); delete (*iter);
} }
_activePuzzles.clear(); _activePuzzles.clear();
for (Common::HashMap<uint32, Control *>::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { for (Common::List<Control *>::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) {
delete (*iter)._value; delete (*iter);
} }
_activeControls.clear(); _activeControls.clear();
_engine->clearAllMouseEvents();
// TODO: See if we need to clear _activeNodes as well. And if so, remember to delete the nodes before clearing the list
// Revert to the idle cursor // Revert to the idle cursor
_engine->getCursorManager()->revertToIdle(); _engine->getCursorManager()->revertToIdle();
@ -278,8 +275,8 @@ void ScriptManager::changeLocationIntern() {
_engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset); _engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset);
// Enable all the controls // Enable all the controls
for (Common::HashMap<uint32, Control *>::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { for (Common::List<Control *>::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) {
(*iter)._value->enable(); (*iter)->enable();
} }
// Add all the local puzzles to the queue to be checked // Add all the local puzzles to the queue to be checked

View file

@ -37,7 +37,6 @@ class SeekableReadStream;
namespace ZVision { namespace ZVision {
class ZVision; class ZVision;
class ActionNode;
struct Location { struct Location {
char world; char world;
@ -60,8 +59,6 @@ private:
* particular state key are checked after the key is modified. * particular state key are checked after the key is modified.
*/ */
Common::HashMap<uint32, uint> _globalState; Common::HashMap<uint32, uint> _globalState;
/** Holds the currently active ActionNodes */
Common::List<ActionNode *> _activeNodes;
/** References _globalState keys to Puzzles */ /** References _globalState keys to Puzzles */
Common::HashMap<uint32, Common::Array<Puzzle *> > _referenceTable; Common::HashMap<uint32, Common::Array<Puzzle *> > _referenceTable;
/** Holds the Puzzles that should be checked this frame */ /** Holds the Puzzles that should be checked this frame */
@ -71,13 +68,12 @@ private:
/** Holds the global puzzles */ /** Holds the global puzzles */
Common::List<Puzzle *>_globalPuzzles; Common::List<Puzzle *>_globalPuzzles;
/** Holds the currently active controls */ /** Holds the currently active controls */
Common::HashMap<uint32, Control *> _activeControls; Common::List<Control *> _activeControls;
Location _nextLocation; Location _nextLocation;
bool _changeLocation; bool _changeLocation;
public: public:
void initialize(); void initialize();
void update(uint deltaTimeMillis); void update(uint deltaTimeMillis);