Changeset 6864 for code/trunk/src/modules
- Timestamp:
- May 9, 2010, 10:56:43 AM (15 years ago)
- Location:
- code/trunk/src/modules/objects
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/ObjectsPrereqs.h
r6800 r6864 87 87 class DistanceMultiTrigger; 88 88 class DistanceTrigger; 89 class EventMultiTrigger; 89 90 class EventTrigger; 90 91 class MultiTrigger; -
code/trunk/src/modules/objects/triggers/CMakeLists.txt
r6800 r6864 3 3 DistanceMultiTrigger.cc 4 4 DistanceTrigger.cc 5 EventMultiTrigger.cc 5 6 EventTrigger.cc 6 7 MultiTrigger.cc -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc
r6860 r6864 59 59 DistanceMultiTrigger::~DistanceMultiTrigger() 60 60 { 61 62 61 } 63 62 … … 81 80 std::queue<MultiTriggerState*>* DistanceMultiTrigger::letTrigger(void) 82 81 { 83 ClassTreeMask& targetMask = this->getTargetMask();84 82 85 83 std::queue<MultiTriggerState*>* queue = NULL; … … 92 90 if(entity == NULL) 93 91 { 94 it++;92 ++it; 95 93 this->removeFromRange(key); 96 94 continue; … … 101 99 if (distanceVec.length() > this->distance_) 102 100 { 103 if(!this->removeFromRange(entity)) 101 if(!this->removeFromRange(key)) 102 { 103 ++it; 104 104 continue; 105 } 105 106 106 107 // If no queue has been created, yet. … … 117 118 ++it; 118 119 } 120 121 ClassTreeMask& targetMask = this->getTargetMask(); 119 122 120 123 // Check for new objects that are in range -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h
r6860 r6864 92 92 */ 93 93 inline bool removeFromRange(WorldEntity* entity) 94 { (*this->range_.find(entity)->second)->destroy(); bool erased = this->range_.erase(entity) > 0; return erased; }94 { WeakPtr<WorldEntity>* weakptr = this->range_.find(entity)->second; bool erased = this->range_.erase(entity) > 0; if(erased) delete weakptr; return erased; } 95 95 96 96 private: -
code/trunk/src/modules/objects/triggers/MultiTrigger.cc
r6859 r6864 72 72 this->mode_ = MultiTriggerMode::EventTriggerAND; 73 73 74 this->bBroadcast_ = false; 75 74 76 this->parentTrigger_ = NULL; 75 77 … … 85 87 MultiTrigger::~MultiTrigger() 86 88 { 87 COUT(4) << "Dest orying MultiTrigger &" << this << ". " << this->stateQueue_.size() << " states still in queue. Deleting." << std::endl;89 COUT(4) << "Destroying MultiTrigger &" << this << ". " << this->stateQueue_.size() << " states still in queue. Deleting." << std::endl; 88 90 while(this->stateQueue_.size() > 0) 89 91 { … … 110 112 XMLPortParam(MultiTrigger, "invert", setInvert, getInvert, xmlelement, mode); 111 113 XMLPortParamTemplate(MultiTrigger, "mode", setMode, getModeString, xmlelement, mode, const std::string&); 114 XMLPortParam(MultiTrigger, "broadcast", setBroadcast, getBroadcast, xmlelement, mode); 112 115 XMLPortParamLoadOnly(MultiTrigger, "target", addTargets, xmlelement, mode).defaultValues("Pawn"); //TODO: Remove load only 113 116 … … 257 260 if(bFire) 258 261 { 259 this->fire(bActive, state->originator); 262 if(this->bBroadcast_ && state->originator == NULL) 263 { 264 this->broadcast(bActive); 265 } 266 else 267 this->fire(bActive, state->originator); 268 260 269 bStateChanged = true; 261 270 } … … 265 274 if(bStateChanged) 266 275 { 267 COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl; 276 if(state->originator != NULL) 277 COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl; 278 else 279 COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: NULL, active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl; 268 280 if(this->parentTrigger_ != NULL) 269 this->parentTrigger_-> activityChanged(state->originator);281 this->parentTrigger_->subTrigggerActivityChanged(state->originator); 270 282 } 271 283 … … 425 437 This method is called by the MultiTrigger to get information about new trigger events that need to be looked at. 426 438 This method is the device for the behaviour (the conditions under which the MultiTrigger triggers) of any derived class from MultiTrigger. 427 428 In this implementation it collects all objects triggering all sub-triggers nd the MultiTrigger itself and creates a state for each of them.429 439 @return 430 440 A pointer to a queue of MultiTriggerState pointers is returned, containing all the neccessary information to decide whether these states should indeed become new states of the MultiTrigger. … … 435 445 return NULL; 436 446 } 437 438 void MultiTrigger::activityChanged(BaseObject* originator) 447 448 /** 449 @brief 450 This method can be called by any class inheriting from MultiTrigger to change it's triggered status for a specified originator. 451 452 Compared to the letTrigger mode, which just polls and lets the pollee send it's state changed back, the changeTriggered method lets the trigger advertise its state changes just as they happen so it's much like the interrupt version of letTrigger. 453 @param originator 454 The originator which triggered the state change. 455 */ 456 void MultiTrigger::changeTriggered(BaseObject* originator) 457 { 458 MultiTriggerState* state = new MultiTriggerState; 459 state->bTriggered = (!this->isTriggered(originator) & this->isModeTriggered(originator)) ^ this->bInvertMode_; 460 state->originator = originator; 461 this->addState(state); 462 } 463 464 /** 465 @brief 466 This method is called by any sub-trigger to advertise changes in it's state to it's parent-trigger. 467 @param originator 468 The object that caused the change in activity. 469 */ 470 void MultiTrigger::subTrigggerActivityChanged(BaseObject* originator) 439 471 { 440 472 MultiTriggerState* state = new MultiTriggerState; … … 499 531 /** 500 532 @brief 501 Helper method. Creates an event for the given status and originator and fires it.533 Helper method. Creates an Event for the given status and originator and fires it. 502 534 Or more precisely creates a MultiTriggerContainer to encompass all neccesary information and creates an Event from that and sends it. 503 535 @param status 504 The status of the event to be fired. This is equivalent to the activity of the MultiTrigger.536 The status of the Event to be fired. This is equivalent to the activity of the MultiTrigger. 505 537 @param originator 506 538 The object that triggered the MultiTrigger to fire this Event. … … 512 544 { 513 545 this->fireEvent(status); 546 COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << "): Fired event. status: " << status << "." << std::endl; 514 547 return; 515 548 } … … 523 556 /** 524 557 @brief 558 Helper method. Broadcasts an Event for every object that is a target. 559 @param status 560 The status of the Events to be fired. This is equivalent to the activity of the MultiTrigger. 561 */ 562 void MultiTrigger::broadcast(bool status) 563 { 564 ClassTreeMask& targetMask = this->getTargetMask(); 565 566 for(ClassTreeMaskObjectIterator it = targetMask.begin(); it != targetMask.end(); ++it) 567 { 568 BaseObject* object = static_cast<BaseObject*>(*it); 569 this->fire(status, object); 570 } 571 } 572 573 /** 574 @brief 525 575 Helper method. Adds a state to the state queue, where the state will wait to become active. 526 576 @param state -
code/trunk/src/modules/objects/triggers/MultiTrigger.h
r6859 r6864 82 82 'simultaniousTriggerers': The number of simultanious triggerers limits the number of object that are allowed to trigger the MultiTrigger at the same time. Or a little more precisely, the number of distinct objects the MultiTrigger has 'triggered' states for, at each point in time. 83 83 'mode': The mode describes how the MultiTrigger acts in relation to all the MultiTriggers, that are appended to it. There are 3 modes: 'and', meaning that the MultiTrigger can only be triggered if all the appended MultiTriggers are active. 'or', meaning that the MultiTrigger can only triggered if at least one of the appendend MultiTriggers is active. And 'xor', meaning that the MultiTrigger can only be triggered if one and only one appended MultiTrigger is active. Notice, that I wrote 'can only be active', that implies, that there is an addtitional condition to the activity 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 activity of a MultiTrigger is still coupled to the object that triggered it. The default is 'and'. 84 'broadcast' Broadcast is a bool, if true the MutliTrigger is in broadcast-mode, meaining, that all trigger events that are caused by no originator (originator is NULL) are broadcasted as having come from every possible originator, or more precisely as having come from all objects that are specified targets of this MultiTrigger. 84 85 'target': The target describes the kind of objects that are allowed to trigger this MultiTrigger. The default is 'Pawn'. 85 86 Also there is the possibility of appending MultiTriggers to the MultiTrigger just by adding them as subobjects in the XML description of your MultiTrigger. … … 109 110 @return The delay. 110 111 */ 111 inline float getDelay( ) const112 inline float getDelay(void) const 112 113 { return this->delay_; } 113 114 … … 122 123 @return Returns true if the MultiTriger is in switch-mode. 123 124 */ 124 inline bool getSwitch( ) const125 inline bool getSwitch(void) const 125 126 { return this->bSwitch_; } 126 127 … … 135 136 @return Returns true if the MultiTrigger stays active. 136 137 */ 137 inline bool getStayActive( ) const138 inline bool getStayActive(void) const 138 139 { return this->bStayActive_; } 139 140 … … 148 149 @return The number of activations. -1 denotes infinity. 149 150 */ 150 inline int getActivations( ) const151 inline int getActivations(void) const 151 152 { return this->remainingActivations_; } 152 153 … … 174 175 @return Returns true if the MultiTrigger is set to invert. 175 176 */ 176 inline bool getInvert( ) const177 inline bool getInvert(void) const 177 178 { return this->bInvertMode_; } 178 179 … … 193 194 194 195 /** 196 @brief Set the broadcast-mode of the MultiTrigger. 197 @param bBroadcast If true the MultiTrigger is set to broadcast; 198 */ 199 inline void setBroadcast(bool bBroadcast) 200 { this->bBroadcast_ = bBroadcast; } 201 /** 202 @brief Get the broadcast-mode of the MultiTrigger. 203 @return Returns true if the MultiTrigger is set to broadcast. 204 */ 205 inline bool getBroadcast(void) 206 { return this->bBroadcast_; } 207 208 /** 195 209 @brief Get whether the input object is a target of the MultiTrigger. 196 210 @param target A pointer to the object. … … 198 212 */ 199 213 inline bool isTarget(BaseObject* target) 200 { return targetMask_.isIncluded(target->getIdentifier()); }214 { if(target == NULL) return true; else return targetMask_.isIncluded(target->getIdentifier()); } 201 215 void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger. 202 216 void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger. … … 208 222 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. 209 223 210 void activityChanged(BaseObject* originator);224 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. 211 225 212 226 bool isModeTriggered(BaseObject* triggerer = NULL); //!< Checks whetherx the MultiTrigger is triggered concerning it's sub-triggers. 213 227 bool isTriggered(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is triggered for a given object. 214 228 215 void fire(bool status, BaseObject* originator = NULL); //!< Helper method. Creates an event for the given status and originator and fires it. 229 void fire(bool status, BaseObject* originator = NULL); //!< Helper method. Creates an Event for the given status and originator and fires it. 230 void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target. 216 231 217 232 /** … … 240 255 static const std::string or_s; 241 256 static const std::string xor_s; 257 258 void subTrigggerActivityChanged(BaseObject* originator); //!< This method is called by any sub-trigger to advertise changes in it's state to it's parent-trigger. 242 259 243 260 bool addState(MultiTriggerState* state); //!< Helper method. Adds a state to the state queue, where the state will wait to become active. … … 266 283 MultiTriggerMode::Value mode_; //!< The mode of the MultiTrigger. 267 284 285 bool bBroadcast_; //!< Bool for the broadcast-mode, if true all triggers go to all possible targets. 286 268 287 MultiTrigger* parentTrigger_; 269 288 std::set<MultiTrigger*> subTriggers_; //!< The sub-triggers of this MultiTrigger.
Note: See TracChangeset
for help on using the changeset viewer.