Changeset 6860 for code/trunk
- Timestamp:
- May 6, 2010, 4:01:25 PM (15 years ago)
- Location:
- code/trunk/src/modules/objects/triggers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc
r6857 r6860 86 86 87 87 // Check for objects that were in range but no longer are. Iterate through all objects, that are in range. 88 for(std:: set<WorldEntity*>::iterator it = this->range_.begin(); it != this->range_.end(); )88 for(std::map<WorldEntity*, WeakPtr<WorldEntity>* >::iterator it = this->range_.begin(); it != this->range_.end(); ) 89 89 { 90 Vector3 distanceVec = (*it)->getWorldPosition() - this->getWorldPosition(); 90 WorldEntity* entity = it->second->get(); 91 WorldEntity* key = it->first; 92 if(entity == NULL) 93 { 94 it++; 95 this->removeFromRange(key); 96 continue; 97 } 98 99 Vector3 distanceVec = entity->getWorldPosition() - this->getWorldPosition(); 91 100 // If the object is no longer in range. 92 101 if (distanceVec.length() > this->distance_) 93 102 { 94 WorldEntity* temp = *(it++); 95 if(!this->removeFromRange(temp)) 103 if(!this->removeFromRange(entity)) 96 104 continue; 97 105 … … 103 111 MultiTriggerState* state = new MultiTriggerState; 104 112 state->bTriggered = false; 105 state->originator = temp;113 state->originator = entity; 106 114 queue->push(state); 107 115 } … … 113 121 for(ClassTreeMaskObjectIterator it = targetMask.begin(); it != targetMask.end(); ++it) 114 122 { 115 WorldEntity* entity = orxonox_cast<WorldEntity*>(*it);116 if (entity == NULL || this->inRange(entity)) //If the object is no WorldEntity or is already in range.123 WorldEntity* entity = static_cast<WorldEntity*>(*it); 124 if (entity == NULL) //If the object is no WorldEntity or is already in range. 117 125 continue; 118 126 -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h
r6857 r6860 38 38 39 39 #include "worldentities/WorldEntity.h" 40 #include <set> 40 #include "core/WeakPtr.h" 41 #include <map> 41 42 42 43 #include "MultiTrigger.h" … … 79 80 80 81 /** 81 @brief Check whether a given entity is currently (since the last update) in range of the DistanceMultiTrigger.82 @param entity A pointer to the entity.83 @return Returns true if the entity is in the range.84 */85 inline bool inRange(WorldEntity* entity)86 { return this->range_.find(entity) != this->range_.end(); }87 /**88 82 @brief Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger. 89 83 @param entity A pointer to the entity. … … 91 85 */ 92 86 inline bool addToRange(WorldEntity* entity) 93 { std::pair<std:: set<WorldEntity*>::iterator, bool> pair = this->range_.insert(entity); return pair.second; }87 { std::pair<std::map<WorldEntity*, WeakPtr<WorldEntity>* >::iterator, bool> pair = this->range_.insert(std::pair<WorldEntity*, WeakPtr<WorldEntity>* >(entity, new WeakPtr<WorldEntity>(entity))); return pair.second; } 94 88 /** 95 89 @brief Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger. … … 98 92 */ 99 93 inline bool removeFromRange(WorldEntity* entity) 100 { return this->range_.erase(entity) > 0; }94 { (*this->range_.find(entity)->second)->destroy(); bool erased = this->range_.erase(entity) > 0; return erased; } 101 95 102 96 private: 103 97 float distance_; //!< The distance at which the DistanceMultiTrigger triggers. 104 std:: set<WorldEntity*> range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.98 std::map<WorldEntity*, WeakPtr<WorldEntity>* > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger. 105 99 106 100 };
Note: See TracChangeset
for help on using the changeset viewer.