Mercurial > fife-parpg
changeset 339:0fd74235b34d
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.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 24 Aug 2009 18:52:49 +0000 |
parents | d266506ff4f9 |
children | 7e5717105212 |
files | engine/core/model/structures/instance.cpp engine/core/model/structures/instancetree.cpp engine/core/model/structures/instancetree.h engine/core/pathfinder/routepather/routepathersearch.cpp |
diffstat | 4 files changed, 16 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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<InstanceActionListener*>::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<InstanceActionListener*>::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 {
--- 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 {
--- 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. *
--- 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