Changeset 10624 for code/trunk/src/modules/objects/triggers
- Timestamp:
- Oct 4, 2015, 9:12:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
code/trunk/src/modules/objects/triggers/CheckPoint.cc
r9667 r10624 93 93 DistanceTrigger::triggered(bIsTriggered); 94 94 95 Asteroids* gametype = orxonox_cast<Asteroids*>(this->getGametype() .get());95 Asteroids* gametype = orxonox_cast<Asteroids*>(this->getGametype()); 96 96 if (gametype) 97 97 { -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc
r9667 r10624 100 100 101 101 // Check for objects that were in range but no longer are. Iterate through all objects, that are in range. 102 for(std:: map<WorldEntity*, WeakPtr<WorldEntity>*>::iterator it = this->range_.begin(); it != this->range_.end(); )102 for(std::set<WeakPtr<WorldEntity> >::iterator it = this->range_.begin(); it != this->range_.end(); ) 103 103 { 104 WorldEntity* entity = it->second->get(); 105 WorldEntity* key = it->first; 106 it++; // Incrementing the iterator in advance, since we don't need the current anymore and we potentially are going to delete the current element thus invalidating the iterator. 104 WorldEntity* entity = *it; 105 107 106 // If the entity no longer exists. 108 107 if(entity == NULL) 109 108 { 110 this->r emoveFromRange(key);109 this->range_.erase(it++); 111 110 continue; 112 111 } … … 116 115 if (distanceVec.length() > this->distance_) 117 116 { 118 // If for some reason the entity could not be removed. 119 if(!this->removeFromRange(key)) 120 continue; 117 this->range_.erase(it++); 121 118 122 119 // If no queue has been created, yet. … … 129 126 state->originator = entity; 130 127 queue->push(state); 128 } 129 else 130 { 131 ++it; 131 132 } 132 133 } … … 260 261 bool DistanceMultiTrigger::addToRange(WorldEntity* entity) 261 262 { 262 WeakPtr<WorldEntity>* weakptr = new WeakPtr<WorldEntity>(entity); 263 std::pair<std::map<WorldEntity*, WeakPtr<WorldEntity>* >::iterator, bool> pair = this->range_.insert(std::pair<WorldEntity*, WeakPtr<WorldEntity>* >(entity, weakptr)); 264 265 if(!pair.second) 266 { 267 delete weakptr; 268 return false; 269 } 270 271 return true; 272 } 273 274 /** 275 @brief 276 Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger. 277 @param entity 278 A pointer ot the entity. 279 @return 280 Returns true if successful. 281 */ 282 bool DistanceMultiTrigger::removeFromRange(WorldEntity* entity) 283 { 284 WeakPtr<WorldEntity>* weakptr = this->range_.find(entity)->second; 285 bool erased = this->range_.erase(entity) > 0; 286 if(erased) 287 delete weakptr; 288 return erased; 289 } 290 263 std::pair<std::set<WeakPtr<WorldEntity> >::iterator, bool> pair = this->range_.insert(entity); 264 return pair.second; 265 } 291 266 } -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h
r9667 r10624 140 140 141 141 bool addToRange(WorldEntity* entity); // Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger. 142 bool removeFromRange(WorldEntity* entity); // Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.143 142 144 143 private: … … 154 153 ClassTreeMask beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons. 155 154 156 std:: map<WorldEntity*, WeakPtr<WorldEntity>*> range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.155 std::set<WeakPtr<WorldEntity> > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger. 157 156 158 157 }; -
code/trunk/src/modules/objects/triggers/DistanceTrigger.cc
r9667 r10624 147 147 { 148 148 // Check whether there is a cached object, it still exists and whether it is still in range, if so nothing further needs to be done. 149 if(this->cache_ .get()!= NULL)150 { 151 if((this->cache_ .get()->getWorldPosition() - this->getWorldPosition()).length() < this->distance_)149 if(this->cache_ != NULL) 150 { 151 if((this->cache_->getWorldPosition() - this->getWorldPosition()).length() < this->distance_) 152 152 return true; 153 153 else … … 213 213 214 214 // Add the entity to the cache. 215 this->cache_ = WeakPtr<WorldEntity>(entity);215 this->cache_ = entity; 216 216 217 217 return true; -
code/trunk/src/modules/objects/triggers/Trigger.cc
r9667 r10624 38 38 #include "core/GameMode.h" 39 39 #include "core/XMLPort.h" 40 #include "core/command/ConsoleCommand .h"40 #include "core/command/ConsoleCommandIncludes.h" 41 41 42 42 #include "Scene.h"
Note: See TracChangeset
for help on using the changeset viewer.