Changeset 11071 for code/trunk/src/modules/objects/triggers
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/objects/triggers/CheckPoint.cc
r10624 r11071 56 56 57 57 this->setRadarObjectColour(ColourValue::Green); 58 this->setRadarObjectShape(RadarViewable:: Dot);58 this->setRadarObjectShape(RadarViewable::Shape::Dot); 59 59 this->setRadarVisibility(false); 60 60 -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc
r10624 r11071 58 58 59 59 this->distance_ = 100.0f; 60 this->setBeaconModeDirect( distanceMultiTriggerBeaconMode::off);60 this->setBeaconModeDirect(DistanceMultiTriggerBeaconMode::off); 61 61 this->targetName_ = ""; 62 62 this->beaconMask_.exclude(Class(BaseObject)); … … 97 97 { 98 98 99 std::queue<MultiTriggerState*>* queue = NULL;99 std::queue<MultiTriggerState*>* queue = nullptr; 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::set<WeakPtr<WorldEntity> 102 for(std::set<WeakPtr<WorldEntity>>::iterator it = this->range_.begin(); it != this->range_.end(); ) 103 103 { 104 104 WorldEntity* entity = *it; 105 105 106 106 // If the entity no longer exists. 107 if(entity == NULL)107 if(entity == nullptr) 108 108 { 109 109 this->range_.erase(it++); … … 118 118 119 119 // If no queue has been created, yet. 120 if(queue == NULL)120 if(queue == nullptr) 121 121 queue = new std::queue<MultiTriggerState*>(); 122 122 … … 136 136 ClassTreeMask targetMask = this->getTargetMask(); 137 137 // If we are in identify-mode another target mask has to be applies to find the DistanceTriggerBeacons. 138 if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify)138 if(this->beaconMode_ == DistanceMultiTriggerBeaconMode::identify) 139 139 targetMask = this->beaconMask_; 140 140 … … 145 145 146 146 // If the DistanceMultiTrigger is in identify-mode and the DistanceTriggerBeacon attached to the object has the wrong name we ignore it. 147 if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify)147 if(this->beaconMode_ == DistanceMultiTriggerBeaconMode::identify) 148 148 { 149 149 if(entity->getName() != this->targetName_) … … 155 155 156 156 // If the DistanceMultiTrigger is in exclude mode and the DistanceTriggerBeacon attached to the object has the right name, we ignore it. 157 if(this->beaconMode_ == distanceMultiTriggerBeaconMode::exclude)157 if(this->beaconMode_ == DistanceMultiTriggerBeaconMode::exclude) 158 158 { 159 159 160 const std::set<WorldEntity*> attached = entity->getAttachedObjects();160 const std::set<WorldEntity*> attachedObjects = entity->getAttachedObjects(); 161 161 bool found = false; 162 for( std::set<WorldEntity*>::const_iterator it = attached.begin(); it != attached.end(); it++)162 for(WorldEntity* attachedObject : attachedObjects) 163 163 { 164 if( (*it)->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()) && static_cast<DistanceTriggerBeacon*>(*it)->getName() == this->targetName_)164 if(attachedObject->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()) && static_cast<DistanceTriggerBeacon*>(attachedObject)->getName() == this->targetName_) 165 165 { 166 166 found = true; … … 182 182 183 183 // Change the entity to the parent of the DistanceTriggerBeacon (if in identify-mode), which is the entity to which the beacon is attached. 184 if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify)184 if(this->beaconMode_ == DistanceMultiTriggerBeaconMode::identify) 185 185 entity = entity->getParent(); 186 186 187 187 // If no queue has been created, yet. 188 if(queue == NULL)188 if(queue == nullptr) 189 189 queue = new std::queue<MultiTriggerState*>(); 190 190 … … 206 206 The mode as an enum. 207 207 */ 208 void DistanceMultiTrigger::setBeaconModeDirect( distanceMultiTriggerBeaconMode::Value mode)208 void DistanceMultiTrigger::setBeaconModeDirect(DistanceMultiTriggerBeaconMode mode) 209 209 { 210 210 this->beaconMode_ = mode; … … 221 221 switch(this->getBeaconModeDirect()) 222 222 { 223 case distanceMultiTriggerBeaconMode::off :223 case DistanceMultiTriggerBeaconMode::off : 224 224 return DistanceMultiTrigger::beaconModeOff_s; 225 case distanceMultiTriggerBeaconMode::identify:225 case DistanceMultiTriggerBeaconMode::identify: 226 226 return DistanceMultiTrigger::beaconModeIdentify_s; 227 case distanceMultiTriggerBeaconMode::exclude:227 case DistanceMultiTriggerBeaconMode::exclude: 228 228 return DistanceMultiTrigger::beaconModeExlcude_s; 229 229 default : … … 242 242 { 243 243 if(mode == DistanceMultiTrigger::beaconModeOff_s) 244 this->setBeaconModeDirect( distanceMultiTriggerBeaconMode::off);244 this->setBeaconModeDirect(DistanceMultiTriggerBeaconMode::off); 245 245 else if(mode == DistanceMultiTrigger::beaconModeIdentify_s) 246 this->setBeaconModeDirect( distanceMultiTriggerBeaconMode::identify);246 this->setBeaconModeDirect(DistanceMultiTriggerBeaconMode::identify); 247 247 else if(mode == DistanceMultiTrigger::beaconModeExlcude_s) 248 this->setBeaconModeDirect( distanceMultiTriggerBeaconMode::exclude);248 this->setBeaconModeDirect(DistanceMultiTriggerBeaconMode::exclude); 249 249 else 250 250 orxout(internal_error, context::triggers) << "Invalid beacon mode in DistanceMultiTrigger." << endl; … … 261 261 bool DistanceMultiTrigger::addToRange(WorldEntity* entity) 262 262 { 263 std::pair<std::set<WeakPtr<WorldEntity> 263 std::pair<std::set<WeakPtr<WorldEntity>>::iterator, bool> pair = this->range_.insert(entity); 264 264 return pair.second; 265 265 } -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h
r10624 r11071 55 55 @ingroup MultiTrigger 56 56 */ 57 namespace distanceMultiTriggerBeaconMode 58 { 59 enum Value { 60 off, //!< The DistanceMultiTrigger is not in <em>beacon-mode</em>. 61 identify, //!< The DistanceTrigger is in <em>identify-mode</em>. 62 exclude //!< The DistanceTrigger is in <em>exclude-mode</em>. 63 }; 64 } 57 enum class DistanceMultiTriggerBeaconMode { 58 off, //!< The DistanceMultiTrigger is not in <em>beacon-mode</em>. 59 identify, //!< The DistanceTrigger is in <em>identify-mode</em>. 60 exclude //!< The DistanceTrigger is in <em>exclude-mode</em>. 61 }; 65 62 66 63 /** … … 113 110 { return this->distance_; } 114 111 115 void setBeaconModeDirect( distanceMultiTriggerBeaconMode::Value mode); // Set the beacon mode.112 void setBeaconModeDirect(DistanceMultiTriggerBeaconMode mode); // Set the beacon mode. 116 113 /** 117 114 @brief Get the beacon mode. 118 115 @return Returns the mode as an enum. 119 116 */ 120 inline distanceMultiTriggerBeaconMode::Value getBeaconModeDirect(void) const117 inline DistanceMultiTriggerBeaconMode getBeaconModeDirect(void) const 121 118 { return this->beaconMode_; } 122 119 void setBeaconMode(const std::string& mode); // Set the beacon mode. … … 149 146 float distance_; //!< The distance at which the DistanceMultiTrigger triggers. 150 147 151 distanceMultiTriggerBeaconMode::Value beaconMode_; //!< The beacon mode, the DistanceMultiTrigger is in.148 DistanceMultiTriggerBeaconMode beaconMode_; //!< The beacon mode, the DistanceMultiTrigger is in. 152 149 std::string targetName_; //!< The target name, used in <em>single-target</em> mode. 153 150 ClassTreeMask beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons. 154 151 155 std::set<WeakPtr<WorldEntity> 152 std::set<WeakPtr<WorldEntity>> range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger. 156 153 157 154 }; -
code/trunk/src/modules/objects/triggers/DistanceTrigger.cc
r10624 r11071 106 106 this->setForPlayer(true); 107 107 108 if (targetId == NULL)108 if (targetId == nullptr) 109 109 { 110 110 orxout(internal_error, context::triggers) << "\"" << targetStr << "\" is not a valid class name to include in ClassTreeMask (in " << this->getName() << ", class " << this->getIdentifier()->getName() << ')' << endl; … … 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_ != NULL)149 if(this->cache_ != nullptr) 150 150 { 151 151 if((this->cache_->getWorldPosition() - this->getWorldPosition()).length() < this->distance_) … … 158 158 ClassTreeMask targetMask = this->targetMask_; 159 159 // If we are in identify-mode another target mask has to be applies to find the DistanceTriggerBeacons. 160 if(this->beaconMode_ == distanceTriggerBeaconMode::identify)160 if(this->beaconMode_ == DistanceTriggerBeaconMode::identify) 161 161 targetMask = this->beaconMask_; 162 162 … … 167 167 168 168 // If the DistanceTrigger is in identify-mode and the DistanceTriggerBeacon attached to the object has the wrong name we ignore it. 169 if(this->beaconMode_ == distanceTriggerBeaconMode::identify)169 if(this->beaconMode_ == DistanceTriggerBeaconMode::identify) 170 170 { 171 171 if(entity->getName() != this->targetName_) … … 177 177 178 178 // If the DistanceTrigger is in exclude mode and the DistanceTriggerBeacon attached to the object has the right name, we ignore it. 179 if(this->beaconMode_ == distanceTriggerBeaconMode::exclude)179 if(this->beaconMode_ == DistanceTriggerBeaconMode::exclude) 180 180 { 181 181 182 const std::set<WorldEntity*> attached = entity->getAttachedObjects();182 const std::set<WorldEntity*> attachedObjects = entity->getAttachedObjects(); 183 183 bool found = false; 184 for( std::set<WorldEntity*>::const_iterator it = attached.begin(); it != attached.end(); it++)184 for(WorldEntity* attachedObject : attachedObjects) 185 185 { 186 if( (*it)->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()) && static_cast<DistanceTriggerBeacon*>(*it)->getName() == this->targetName_)186 if(attachedObject->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()) && static_cast<DistanceTriggerBeacon*>(attachedObject)->getName() == this->targetName_) 187 187 { 188 188 found = true; … … 202 202 { 203 203 // Change the entity to the parent of the DistanceTriggerBeacon (if in identify-mode), which is the entity to which the beacon is attached. 204 if(this->beaconMode_ == distanceTriggerBeaconMode::identify)204 if(this->beaconMode_ == DistanceTriggerBeaconMode::identify) 205 205 entity = entity->getParent(); 206 206 207 207 Pawn* pawn = orxonox_cast<Pawn*>(entity); 208 if(pawn != NULL)208 if(pawn != nullptr) 209 209 this->setTriggeringPawn(pawn); 210 210 else 211 orxout(internal_warning, context::triggers) << "Pawn was NULL." << endl;211 orxout(internal_warning, context::triggers) << "Pawn was nullptr." << endl; 212 212 } 213 213 … … 228 228 The mode as an enum. 229 229 */ 230 void DistanceTrigger::setBeaconModeDirect( distanceTriggerBeaconMode::Value mode)230 void DistanceTrigger::setBeaconModeDirect(DistanceTriggerBeaconMode mode) 231 231 { 232 232 this->beaconMode_ = mode; … … 243 243 switch(this->getBeaconModeDirect()) 244 244 { 245 case distanceTriggerBeaconMode::off :245 case DistanceTriggerBeaconMode::off : 246 246 return DistanceTrigger::beaconModeOff_s; 247 case distanceTriggerBeaconMode::identify:247 case DistanceTriggerBeaconMode::identify: 248 248 return DistanceTrigger::beaconModeIdentify_s; 249 case distanceTriggerBeaconMode::exclude:249 case DistanceTriggerBeaconMode::exclude: 250 250 return DistanceTrigger::beaconModeExlcude_s; 251 251 default : … … 264 264 { 265 265 if(mode == DistanceTrigger::beaconModeOff_s) 266 this->setBeaconModeDirect( distanceTriggerBeaconMode::off);266 this->setBeaconModeDirect(DistanceTriggerBeaconMode::off); 267 267 else if(mode == DistanceTrigger::beaconModeIdentify_s) 268 this->setBeaconModeDirect( distanceTriggerBeaconMode::identify);268 this->setBeaconModeDirect(DistanceTriggerBeaconMode::identify); 269 269 else if(mode == DistanceTrigger::beaconModeExlcude_s) 270 this->setBeaconModeDirect( distanceTriggerBeaconMode::exclude);270 this->setBeaconModeDirect(DistanceTriggerBeaconMode::exclude); 271 271 else 272 272 orxout(internal_error, context::triggers) << "Invalid beacon mode in DistanceTrigger." << endl; … … 282 282 Returns true if it is triggered ,false if not. 283 283 */ 284 bool DistanceTrigger::isTriggered(TriggerMode ::Valuemode)284 bool DistanceTrigger::isTriggered(TriggerMode mode) 285 285 { 286 286 if (Trigger::isTriggered(mode)) -
code/trunk/src/modules/objects/triggers/DistanceTrigger.h
r9667 r11071 55 55 @ingroup NormalTrigger 56 56 */ 57 namespace distanceTriggerBeaconMode 58 { 59 enum Value { 60 off, 61 identify, 62 exclude 63 }; 64 } 57 enum class DistanceTriggerBeaconMode { 58 off, 59 identify, 60 exclude 61 }; 65 62 66 63 /** … … 118 115 { return this->distance_; } 119 116 120 void setBeaconModeDirect( distanceTriggerBeaconMode::Value mode); // Set the beacon mode.117 void setBeaconModeDirect(DistanceTriggerBeaconMode mode); // Set the beacon mode. 121 118 /** 122 119 @brief Get the beacon mode. 123 120 @return Returns the mode as an enum. 124 121 */ 125 inline distanceTriggerBeaconMode::Value getBeaconModeDirect(void) const122 inline DistanceTriggerBeaconMode getBeaconModeDirect(void) const 126 123 { return this->beaconMode_; } 127 124 void setBeaconMode(const std::string& mode); // Set the beacon mode. … … 144 141 145 142 protected: 146 virtual bool isTriggered(TriggerMode ::Value mode); // Check whether the DistanceTrigger is triggered.143 virtual bool isTriggered(TriggerMode mode) override; // Check whether the DistanceTrigger is triggered. 147 144 /** 148 145 @brief Notifies interested parties about a change of the DistanceTrigger's target mask. … … 160 157 float distance_; //!< The range of the DistanceTrigger. 161 158 162 distanceTriggerBeaconMode::Value beaconMode_; //!< The beacon mode.159 DistanceTriggerBeaconMode beaconMode_; //!< The beacon mode. 163 160 std::string targetName_; //!< The name a DistanceTriggerBeacon needs to have to make the DistanceTrigger react to it if in beacon-mode. 164 161 ClassTreeMask beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons. -
code/trunk/src/modules/objects/triggers/EventMultiTrigger.cc
r9667 r11071 96 96 { 97 97 // If the originator is a MultiTriggerContainer, the event originates from a MultiTrigger and thus the event only triggers the EventMultiTrigger for the originator that caused the MultiTrigger to trigger. 98 if(originator != NULL&& originator->isA(ClassIdentifier<MultiTriggerContainer>::getIdentifier()))98 if(originator != nullptr && originator->isA(ClassIdentifier<MultiTriggerContainer>::getIdentifier())) 99 99 { 100 100 MultiTriggerContainer* container = static_cast<MultiTriggerContainer*>(originator); -
code/trunk/src/modules/objects/triggers/EventTrigger.cc
r9667 r11071 79 79 It should be triggered if it is triggered according just to its sub-triggers and if the last event that came in was an event that changed from not triggered to triggered. 80 80 */ 81 bool EventTrigger::isTriggered(TriggerMode ::Valuemode)81 bool EventTrigger::isTriggered(TriggerMode mode) 82 82 { 83 83 if (Trigger::isTriggered(mode)) -
code/trunk/src/modules/objects/triggers/EventTrigger.h
r9667 r11071 84 84 85 85 protected: 86 virtual bool isTriggered(TriggerMode ::Value mode); // Check whether the EventTrigger should be triggered.86 virtual bool isTriggered(TriggerMode mode) override; // Check whether the EventTrigger should be triggered. 87 87 88 88 private: -
code/trunk/src/modules/objects/triggers/MultiTrigger.cc
r11020 r11071 124 124 // Let the MultiTrigger return the states that trigger and process the new states if there are any. 125 125 std::queue<MultiTriggerState*>* queue = this->letTrigger(); 126 if(queue != NULL)126 if(queue != nullptr) 127 127 { 128 128 while(queue->size() > 0) 129 129 { 130 130 MultiTriggerState* state = queue->front(); 131 // If the state is NULL. (This really shouldn't happen)132 if(state == NULL)131 // If the state is nullptr. (This really shouldn't happen) 132 if(state == nullptr) 133 133 { 134 orxout(internal_error, context::triggers) << "In MultiTrigger '" << this->getName() << "' (&" << this << "), Error: State of new states queue was NULL. State ignored." << endl;134 orxout(internal_error, context::triggers) << "In MultiTrigger '" << this->getName() << "' (&" << this << "), Error: State of new states queue was nullptr. State ignored." << endl; 135 135 queue->pop(); 136 136 continue; … … 227 227 { 228 228 // If the MultiTrigger is set to broadcast and has no originator a boradcast is fired. 229 if(this->getBroadcast() && state->originator == NULL)229 if(this->getBroadcast() && state->originator == nullptr) 230 230 this->broadcast(bActive); 231 231 // Else a normal event is fired. … … 240 240 { 241 241 // Print some debug output if the state has changed. 242 if(state->originator != NULL)242 if(state->originator != nullptr) 243 243 orxout(verbose, context::triggers) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << bActive << ", triggered: " << state->bTriggered << "." << endl; 244 244 else 245 orxout(verbose, context::triggers) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: NULL, active: " << bActive << ", triggered: " << state->bTriggered << "." << endl;245 orxout(verbose, context::triggers) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: nullptr, active: " << bActive << ", triggered: " << state->bTriggered << "." << endl; 246 246 247 247 // If the MultiTrigger has a parent trigger, that is itself a MultiTrigger, it needs to call a method to notify him, that its activity has changed. 248 if(this->parent_ != NULL&& this->parent_->isMultiTrigger())248 if(this->parent_ != nullptr && this->parent_->isMultiTrigger()) 249 249 static_cast<MultiTrigger*>(this->parent_)->childActivityChanged(state->originator); 250 250 } … … 265 265 else 266 266 { 267 this->stateQueue_. push_back(std::pair<float, MultiTriggerState*>(timeRemaining-dt, state));267 this->stateQueue_.emplace_back(timeRemaining-dt, state); 268 268 this->stateQueue_.pop_front(); 269 269 } … … 299 299 300 300 // If the target is not a valid class name display an error. 301 if (target == NULL)301 if (target == nullptr) 302 302 { 303 303 orxout(internal_error, context::triggers) << "'" << targetStr << "' is not a valid class name to include in ClassTreeMask (in " << this->getName() << ", class " << this->getIdentifier()->getName() << ")" << endl; … … 327 327 328 328 // If the target is not a valid class name display an error. 329 if (target == NULL)329 if (target == nullptr) 330 330 { 331 331 orxout(internal_error, context::triggers) << "'" << targetStr << "' is not a valid class name to include in ClassTreeMask (in " << this->getName() << ", class " << this->getIdentifier()->getName() << ")" << endl; … … 346 346 std::queue<MultiTriggerState*>* MultiTrigger::letTrigger(void) 347 347 { 348 return NULL;348 return nullptr; 349 349 } 350 350 … … 443 443 void MultiTrigger::fire(bool status, BaseObject* originator) 444 444 { 445 // If the originator is NULL, a normal event without MultiTriggerContainer is sent.446 if(originator == NULL)445 // If the originator is nullptr, a normal event without MultiTriggerContainer is sent. 446 if(originator == nullptr) 447 447 { 448 448 this->fireEvent(status); … … 479 479 bool MultiTrigger::addState(MultiTriggerState* state) 480 480 { 481 assert(state); // The state really shouldn't be NULL.481 assert(state); // The state really shouldn't be nullptr. 482 482 483 483 // If the originator is no target of this MultiTrigger. … … 489 489 490 490 // Add it ot the state queue with the delay specified for the MultiTrigger. 491 this->stateQueue_. push_back(std::pair<float, MultiTriggerState*>(this->getDelay(), state));491 this->stateQueue_.emplace_back(this->getDelay(), state); 492 492 493 493 return true; … … 504 504 bool MultiTrigger::checkAnd(BaseObject* triggerer) 505 505 { 506 for(std::set<TriggerBase*>::iterator it = this->children_.begin(); it != this->children_.end(); ++it) 507 { 508 TriggerBase* trigger = *it; 506 for(TriggerBase* trigger : this->children_) 507 { 509 508 if(trigger->isMultiTrigger()) 510 509 { … … 531 530 bool MultiTrigger::checkOr(BaseObject* triggerer) 532 531 { 533 for(std::set<TriggerBase*>::iterator it = this->children_.begin(); it != this->children_.end(); ++it) 534 { 535 TriggerBase* trigger = *it; 532 for(TriggerBase* trigger : this->children_) 533 { 536 534 if(trigger->isMultiTrigger()) 537 535 { … … 559 557 { 560 558 bool triggered = false; 561 for(std::set<TriggerBase*>::iterator it = this->children_.begin(); it != this->children_.end(); ++it) 562 { 563 TriggerBase* trigger = *it; 559 for(TriggerBase* trigger : this->children_) 560 { 564 561 if(triggered) 565 562 { -
code/trunk/src/modules/objects/triggers/MultiTrigger.h
r9667 r11071 76 76 - @b simultaneousTriggerers The number of simultaneous triggerers limits the number of objects that are allowed to trigger the MultiTrigger at the same time. Or more precisely, the number of distinct objects the MultiTrigger has <em>triggered</em> states for, at each point in time. The default is <code>-1</code>, which denotes infinity. 77 77 - @b mode The mode describes how the MultiTrigger acts in relation to all the triggers, that are appended to it. There are 3 modes: <em>and</em>, meaning that the MultiTrigger can only be triggered if all the appended triggers are active. <em>or</em>, meaning that the MultiTrigger can only triggered if at least one of the appended triggers is active. And <em>xor</em>, meaning that the MultiTrigger can only be triggered if one and only one appended trigger is active. Note, that I wrote <em>can only be active</em>, that implies, that there is an additional condition to the <em>activity</em> of the MultiTrigger and that is the fulfillment of the triggering condition (the MultiTrigger itself doesn't have one, but all derived classes should). Also bear in mind, that the <em>activity</em> of a MultiTrigger is still coupled to the object that triggered it. The default is <em>and</em>. 78 - @b broadcast Broadcast is a boolean, if true the MutliTrigger is in <em>broadcast-mode</em>, meaning, that all trigger events that are caused by no originator (originator is NULL) are broadcast as having come from every possible originator, or more precisely as having come from all objects that are specified targets of this MultiTrigger. The default is false.78 - @b broadcast Broadcast is a boolean, if true the MutliTrigger is in <em>broadcast-mode</em>, meaning, that all trigger events that are caused by no originator (originator is nullptr) are broadcast as having come from every possible originator, or more precisely as having come from all objects that are specified targets of this MultiTrigger. The default is false. 79 79 - @b target The target describes the kind of objects that are allowed to trigger this MultiTrigger. The default is @ref orxonox::Pawn "Pawn". 80 80 - Also there is the possibility of appending triggers (as long as they inherit from TriggerBase) to the MultiTrigger just by adding them as children in the XML description of your MultiTrigger. … … 110 110 */ 111 111 inline bool isActive(void) const 112 { return this->isActive( NULL); }113 bool isActive(BaseObject* triggerer = NULL) const; //!< Check whether the MultiTrigger is active for a given object.112 { return this->isActive(nullptr); } 113 bool isActive(BaseObject* triggerer = nullptr) const; //!< Check whether the MultiTrigger is active for a given object. 114 114 115 115 /** … … 145 145 */ 146 146 inline bool isTarget(BaseObject* target) 147 { if(target == NULL) return true; else return targetMask_.isIncluded(target->getIdentifier()); }147 { if(target == nullptr) return true; else return targetMask_.isIncluded(target->getIdentifier()); } 148 148 149 149 void addTarget(const std::string& targets); //!< Add some target to the MultiTrigger. … … 152 152 virtual std::queue<MultiTriggerState*>* letTrigger(void); //!< This method is called by the MultiTrigger to get information about new trigger events that need to be looked at. 153 153 154 void changeTriggered(BaseObject* originator = NULL); //!< This method can be called by any class inheriting from MultiTrigger to change it's triggered status for a specified originator.155 156 bool isModeTriggered(BaseObject* triggerer = NULL); //!< Checks whether the MultiTrigger is triggered concerning it's children.157 bool isTriggered(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is triggered for a given object.158 159 virtual void fire(bool status, BaseObject* originator = NULL); //!< Helper method. Creates an Event for the given status and originator and fires it.154 void changeTriggered(BaseObject* originator = nullptr); //!< This method can be called by any class inheriting from MultiTrigger to change it's triggered status for a specified originator. 155 156 bool isModeTriggered(BaseObject* triggerer = nullptr); //!< Checks whether the MultiTrigger is triggered concerning it's children. 157 bool isTriggered(BaseObject* triggerer = nullptr); //!< Get whether the MultiTrigger is triggered for a given object. 158 159 virtual void fire(bool status, BaseObject* originator = nullptr); //!< Helper method. Creates an Event for the given status and originator and fires it. 160 160 void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target. 161 161 … … 192 192 std::set<BaseObject*> triggered_; //!< The set of all objects the MultiTrigger is triggered for. 193 193 194 std::deque< std::pair<float, MultiTriggerState*>> stateQueue_; //!< The queue of states waiting to become active.194 std::deque<std::pair<float, MultiTriggerState*>> stateQueue_; //!< The queue of states waiting to become active. 195 195 196 196 ClassTreeMask targetMask_; //!< The target mask, masking all objects that can trigger this MultiTrigger. -
code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc
r9667 r11071 50 50 The creator. 51 51 */ 52 MultiTriggerContainer::MultiTriggerContainer(Context* context) : BaseObject(context), originator_( NULL), data_(NULL)52 MultiTriggerContainer::MultiTriggerContainer(Context* context) : BaseObject(context), originator_(nullptr), data_(nullptr) 53 53 { 54 54 RegisterObject(MultiTriggerContainer); … … 70 70 71 71 Pawn* pawn = orxonox_cast<Pawn*>(data); 72 if(pawn != NULL)72 if(pawn != nullptr) 73 73 { 74 74 this->setForPlayer(true); -
code/trunk/src/modules/objects/triggers/Trigger.cc
r10624 r11071 37 37 #include "core/CoreIncludes.h" 38 38 #include "core/GameMode.h" 39 #include "core/XMLPort.h"40 39 #include "core/command/ConsoleCommandIncludes.h" 41 40 … … 86 85 { 87 86 88 }89 90 /**91 @brief92 Method for creating a Trigger object through XML.93 */94 void Trigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)95 {96 SUPER(Trigger, XMLPort, xmlelement, mode);97 87 } 98 88 … … 203 193 Returns true if the Trigger should be triggered and false if not. 204 194 */ 205 bool Trigger::isTriggered(TriggerMode ::Valuemode)195 bool Trigger::isTriggered(TriggerMode mode) 206 196 { 207 197 // If the trigger has sub-triggers. … … 234 224 { 235 225 // Iterate over all sub-triggers. 236 for ( std::set<TriggerBase*>::iterator it = this->children_.begin(); it != this->children_.end(); ++it)237 { 238 if (! (*it)->isActive())226 for (TriggerBase* child : this->children_) 227 { 228 if (!child->isActive()) 239 229 return false; 240 230 } … … 252 242 { 253 243 // Iterate over all sub-triggers. 254 for ( std::set<TriggerBase*>::iterator it = this->children_.begin(); it != this->children_.end(); ++it)255 { 256 if ( (*it)->isActive())244 for (TriggerBase* child : this->children_) 245 { 246 if (child->isActive()) 257 247 return true; 258 248 } … … 270 260 { 271 261 bool test = false; 272 for ( std::set<TriggerBase*>::iterator it = this->children_.begin(); it != this->children_.end(); ++it)273 { 274 if (test && (*it)->isActive())262 for (TriggerBase* child : this->children_) 263 { 264 if (test && child->isActive()) 275 265 return false; 276 if ( (*it)->isActive())266 if (child->isActive()) 277 267 test = true; 278 268 } … … 346 336 { 347 337 // Iterate over all Triggers. 348 for ( ObjectList<Trigger>::iterator it = ObjectList<Trigger>::begin(); it != ObjectList<Trigger>::end(); ++it)349 it->setVisible(bVisible);338 for (Trigger* trigger : ObjectList<Trigger>()) 339 trigger->setVisible(bVisible); 350 340 } 351 341 -
code/trunk/src/modules/objects/triggers/Trigger.h
r9667 r11071 83 83 virtual ~Trigger(); 84 84 85 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); // Method for creating a Trigger object through XML.86 85 virtual void tick(float dt); 87 86 … … 105 104 inline bool isTriggered() 106 105 { return this->isTriggered(this->mode_); } 107 virtual bool isTriggered(TriggerMode ::Valuemode); // Check whether the Trigger should be triggered, given only its sub-triggers, given a specific mode.106 virtual bool isTriggered(TriggerMode mode); // Check whether the Trigger should be triggered, given only its sub-triggers, given a specific mode. 108 107 virtual void triggered(bool bIsTriggered); // Fires an event with the input triggered state. 109 108 … … 127 126 BillboardSet debugBillboard_; //!< A set of debug billboards to visualize the state of the trigger. 128 127 129 std::queue<std::pair<float, char> 128 std::queue<std::pair<float, char>> stateChanges_; //!< A queue of state changes (in the same format as latestState_) paired with the time they will take effect since the last state change took effect. 130 129 }; 131 130 -
code/trunk/src/modules/objects/triggers/TriggerBase.cc
r9667 r11071 67 67 this->mode_ = TriggerMode::EventTriggerAND; 68 68 69 this->parent_ = NULL;69 this->parent_ = nullptr; 70 70 71 71 this->bMultiTrigger_ = false; … … 100 100 101 101 XMLPortObject(TriggerBase, TriggerBase, "", addTrigger, getTrigger, xmlelement, mode); 102 }103 104 /**105 @brief106 A method that is executed each tick.107 @param dt108 The duration of the last tick.109 */110 void TriggerBase::tick(float dt)111 {112 SUPER(TriggerBase, tick, dt);113 102 } 114 103 … … 170 159 The index. 171 160 @return 172 Returns a pointer ot the trigger. NULLif no such trigger exists.161 Returns a pointer ot the trigger. nullptr if no such trigger exists. 173 162 */ 174 163 const TriggerBase* TriggerBase::getTrigger(unsigned int index) const … … 176 165 // If the index is greater than the number of children. 177 166 if (this->children_.size() <= index) 178 return NULL;167 return nullptr; 179 168 180 169 std::set<TriggerBase*>::const_iterator it; -
code/trunk/src/modules/objects/triggers/TriggerBase.h
r9667 r11071 52 52 @ingroup Triggers 53 53 */ 54 namespaceTriggerMode54 enum class TriggerMode 55 55 { 56 enum Value 57 { 58 EventTriggerAND, //!< The <em>and</em> mode. The trigger can only trigger if all the children are active. 59 EventTriggerOR, //!< The <em>or</em> mode. The trigger can only trigger if at least one child is active. 60 EventTriggerXOR, //!< The <em>xor</em> mode. The trigger can only trigger if exactly one child is active. 61 }; 62 } 56 EventTriggerAND, //!< The <em>and</em> mode. The trigger can only trigger if all the children are active. 57 EventTriggerOR, //!< The <em>or</em> mode. The trigger can only trigger if at least one child is active. 58 EventTriggerXOR, //!< The <em>xor</em> mode. The trigger can only trigger if exactly one child is active. 59 }; 63 60 64 61 /** … … 78 75 79 76 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a TriggerBase object through XML. 80 virtual void tick(float dt); //!< A method that is executed each tick.81 77 82 78 /** … … 158 154 @param mode The mode of the trigger. 159 155 */ 160 inline void setMode(TriggerMode ::Valuemode) //!< Get the mode of the trigger.156 inline void setMode(TriggerMode mode) //!< Get the mode of the trigger. 161 157 { this->mode_ = mode; } 162 158 const std::string& getModeString(void) const; … … 165 161 @return Returns and Enum for the mode of the trigger. 166 162 */ 167 inline TriggerMode ::ValuegetMode(void) const163 inline TriggerMode getMode(void) const 168 164 { return mode_; } 169 165 … … 211 207 212 208 bool bInvertMode_; //!< Bool for the invert-mode, if true the trigger is inverted. 213 TriggerMode ::Valuemode_; //!< The mode of the trigger.209 TriggerMode mode_; //!< The mode of the trigger. 214 210 215 211 TriggerBase* parent_; //!< The parent of this trigger.
Note: See TracChangeset
for help on using the changeset viewer.