# HG changeset patch # User phoku@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1251139969 0 # Node ID 0fd74235b34dcaa5897d2fda4c84f2cd82609655 # Parent d266506ff4f908472c7356526445d0a717ec4766 Fixes. * The signature of InstanceTree.add/remove is adapted to the new behaviour. * Add/Remove ActionListeners from Instances should now be reentrant. * Small compile warning fixed. diff -r d266506ff4f9 -r 0fd74235b34d engine/core/model/structures/instance.cpp --- a/engine/core/model/structures/instance.cpp Mon Aug 24 18:32:03 2009 +0000 +++ b/engine/core/model/structures/instance.cpp Mon Aug 24 18:52:49 2009 +0000 @@ -230,7 +230,7 @@ std::vector::iterator i = m_activity->m_actionlisteners.begin(); while (i != m_activity->m_actionlisteners.end()) { if ((*i) == listener) { - m_activity->m_actionlisteners.erase(i); + *i = NULL; return; } ++i; @@ -422,9 +422,15 @@ std::vector::iterator i = m_activity->m_actionlisteners.begin(); while (i != m_activity->m_actionlisteners.end()) { - (*i)->onInstanceActionFinished(this, action); + if(*i) + (*i)->onInstanceActionFinished(this, action); ++i; } + m_activity->m_actionlisteners.erase( + std::remove(m_activity->m_actionlisteners.begin(), + m_activity->m_actionlisteners.end(), + (InstanceActionListener*)NULL), + m_activity->m_actionlisteners.end()); } Action* Instance::getCurrentAction() const { diff -r d266506ff4f9 -r 0fd74235b34d engine/core/model/structures/instancetree.cpp --- a/engine/core/model/structures/instancetree.cpp Mon Aug 24 18:32:03 2009 +0000 +++ b/engine/core/model/structures/instancetree.cpp Mon Aug 24 18:52:49 2009 +0000 @@ -43,7 +43,7 @@ InstanceTree::~InstanceTree() { } - bool InstanceTree::addInstance(Instance* instance) { + void InstanceTree::addInstance(Instance* instance) { ModelCoordinate coords = instance->getLocationRef().getLayerCoordinates(); InstanceTreeNode * node = m_tree.find_container(coords.x,coords.y,0,0); InstanceList& list = node->data(); @@ -51,10 +51,9 @@ if( m_reverse.find(instance) != m_reverse.end() ) throw new InconsistencyDetected("Duplicate Instance."); m_reverse[instance] = node; - return true; } - bool InstanceTree::removeInstance(Instance* instance) { + void InstanceTree::removeInstance(Instance* instance) { ModelCoordinate coords = instance->getLocationRef().getLayerCoordinates(); InstanceTreeNode * node = m_reverse[instance]; if( !node ) @@ -64,10 +63,10 @@ for(InstanceList::iterator i = list.begin(); i != list.end(); ++i) { if((*i) == instance) { list.erase(i); - return true; + return; } } - return false; + throw new InconsistencyDetected("Removing Ghost Instance (not in list?)."); } class InstanceListCollector { diff -r d266506ff4f9 -r 0fd74235b34d engine/core/model/structures/instancetree.h --- a/engine/core/model/structures/instancetree.h Mon Aug 24 18:32:03 2009 +0000 +++ b/engine/core/model/structures/instancetree.h Mon Aug 24 18:52:49 2009 +0000 @@ -62,16 +62,18 @@ * area. * * @param instance A pointer to the instance to add. + * @note In case you added the instance before this will throw. */ - bool addInstance(Instance* instance); + void addInstance(Instance* instance); /** Removes an instance from the quad tree. * * Locates an instance in the quad tree then removes it. * * @param instance A pointer to the instance to find and remove. + * @note In case you did @b not add the instance before this will throw. */ - bool removeInstance(Instance* instance); + void removeInstance(Instance* instance); /** Find all instances in a given area. * diff -r d266506ff4f9 -r 0fd74235b34d engine/core/pathfinder/routepather/routepathersearch.cpp --- a/engine/core/pathfinder/routepather/routepathersearch.cpp Mon Aug 24 18:32:03 2009 +0000 +++ b/engine/core/pathfinder/routepather/routepathersearch.cpp Mon Aug 24 18:52:49 2009 +0000 @@ -107,7 +107,6 @@ Location to(m_to); to.setExactLayerCoordinates(FIFE::intPt2doublePt(to.getLayerCoordinates())); path.push_back(to); - int count = 0; while(current != end) { if(m_spt[current] < 0 ) { // This is when the size of m_spt can not handle the distance of the location