Changeset 7163 for code/trunk/src/modules/objects/triggers
- Timestamp:
- Aug 11, 2010, 8:55:13 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/objects/triggers/CheckPoint.cc
r5929 r7163 38 38 CreateFactory(CheckPoint); 39 39 40 CheckPoint::CheckPoint(BaseObject* creator) : DistanceTrigger(creator) 40 CheckPoint::CheckPoint(BaseObject* creator) 41 : DistanceTrigger(creator) 42 , RadarViewable(creator, static_cast<WorldEntity*>(this)) 41 43 { 42 44 RegisterObject(CheckPoint); -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc
- Property svn:eol-style set to native
r6906 r7163 40 40 namespace orxonox 41 41 { 42 42 43 43 CreateFactory(DistanceMultiTrigger); 44 44 45 45 /** 46 46 @brief 47 Default Constructor. Registers the object and initializes default values. 47 Default Constructor. Registers the object and initializes default values. 48 48 */ 49 49 DistanceMultiTrigger::DistanceMultiTrigger(BaseObject* creator) : MultiTrigger(creator) 50 50 { 51 51 RegisterObject(DistanceMultiTrigger); 52 52 53 53 this->distance_ = 100.0f; 54 54 this->targetName_ = BLANKSTRING; … … 98 98 continue; 99 99 } 100 100 101 101 Vector3 distanceVec = entity->getWorldPosition() - this->getWorldPosition(); 102 102 // If the object is no longer in range. … … 154 154 if(this->singleTargetMode_) 155 155 entity = entity->getParent(); 156 156 157 157 // If no queue has been created, yet. 158 158 if(queue == NULL) … … 166 166 } 167 167 } 168 168 169 169 return queue; 170 170 } 171 171 172 172 } -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h
- Property svn:eol-style set to native
r6906 r7163 56 56 class _ObjectsExport DistanceMultiTrigger : public MultiTrigger 57 57 { 58 58 59 59 public: 60 60 DistanceMultiTrigger(BaseObject* creator); //!< Default Constructor. Registers the object and initializes default values. 61 61 ~DistanceMultiTrigger(); //!< Destructor. 62 62 63 63 void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a DistanceMultiTrigger object through XML. 64 64 … … 75 75 inline const std::string& getTargetName(void) 76 76 { return this->targetName_; } 77 77 78 78 /** 79 79 @brief Set the distance at which the DistanceMultiTrigger triggers. … … 88 88 inline float getDistance() const 89 89 { return this->distance_; } 90 90 91 91 protected: 92 92 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. … … 106 106 inline bool removeFromRange(WorldEntity* entity) 107 107 { WeakPtr<WorldEntity>* weakptr = this->range_.find(entity)->second; bool erased = this->range_.erase(entity) > 0; if(erased) delete weakptr; return erased; } 108 108 109 109 private: 110 110 float distance_; //!< The distance at which the DistanceMultiTrigger triggers. 111 111 std::string targetName_; //!< The target name, used in singleTargetMode. 112 112 bool singleTargetMode_; //!< To indicate whe the MultiDistanceTrigger is in single-target-mode. 113 113 114 114 std::map<WorldEntity*, WeakPtr<WorldEntity>* > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger. 115 115 116 116 }; 117 117 118 118 } 119 119 -
code/trunk/src/modules/objects/triggers/DistanceTrigger.cc
r6906 r7163 136 136 continue; 137 137 } 138 138 139 139 Vector3 distanceVec = entity->getWorldPosition() - this->getWorldPosition(); 140 140 if (distanceVec.length() < this->distance_) … … 155 155 } 156 156 } 157 157 158 return false; 158 159 } -
code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.cc
- Property svn:eol-style set to native
r6906 r7163 35 35 36 36 CreateFactory(DistanceTriggerBeacon); 37 37 38 38 DistanceTriggerBeacon::DistanceTriggerBeacon(BaseObject* creator) : StaticEntity(creator) 39 39 { 40 40 RegisterObject(DistanceTriggerBeacon); 41 41 } 42 42 43 43 } -
code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.h
- Property svn:eol-style set to native
r6906 r7163 39 39 class _ObjectsExport DistanceTriggerBeacon : public StaticEntity 40 40 { 41 41 42 42 public: 43 43 -
code/trunk/src/modules/objects/triggers/EventMultiTrigger.cc
- Property svn:eol-style set to native
r6864 r7163 52 52 EventMultiTrigger::~EventMultiTrigger() 53 53 { 54 54 55 55 } 56 56 … … 61 61 this->setBroadcast(true); 62 62 } 63 63 64 64 void EventMultiTrigger::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 65 65 { -
code/trunk/src/modules/objects/triggers/EventMultiTrigger.h
- Property svn:eol-style set to native
r6864 r7163 44 44 class _ObjectsExport EventMultiTrigger : public MultiTrigger 45 45 { 46 46 47 47 public: 48 48 EventMultiTrigger(BaseObject* creator); -
code/trunk/src/modules/objects/triggers/MultiTrigger.cc
- Property svn:eol-style set to native
r6864 r7163 47 47 /*static*/ const std::string MultiTrigger::or_s = "or"; 48 48 /*static*/ const std::string MultiTrigger::xor_s = "xor"; 49 49 50 50 CreateFactory(MultiTrigger); 51 51 … … 65 65 this->bSwitch_ = false; 66 66 this->bStayActive_ = false; 67 67 68 68 this->remainingActivations_ = INF_s; 69 69 this->maxNumSimultaniousTriggerers_ = INF_s; … … 75 75 76 76 this->parentTrigger_ = NULL; 77 77 78 78 this->targetMask_.exclude(Class(BaseObject)); 79 79 80 80 this->setSyncMode(0x0); 81 81 } 82 82 83 83 /** 84 84 @brief … … 95 95 } 96 96 } 97 97 98 98 /** 99 99 @brief … … 117 117 //TODO: Maybe nicer with explicit subgroup, e.g. triggers 118 118 XMLPortObject(MultiTrigger, MultiTrigger, "", addTrigger, getTrigger, xmlelement, mode); 119 119 120 120 COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") created." << std::endl; 121 121 } 122 122 123 123 124 124 /** … … 131 131 { 132 132 // If this is the first tick. 133 //TODO: Determine need for this, else kick it out. 133 //TODO: Determine need for this, else kick it out. 134 134 if(this->bFirstTick_) 135 135 { … … 174 174 delete state; 175 175 } 176 176 177 177 queue->pop(); 178 178 } … … 185 185 MultiTriggerState* state; 186 186 float timeRemaining; 187 187 188 188 // Go through all pending states. 189 189 for(int size = this->stateQueue_.size(); size >= 1; size--) … … 212 212 this->triggered_.erase(state->originator); 213 213 } 214 214 215 215 bStateChanged = true; 216 216 } … … 229 229 230 230 bool bFire = true; 231 231 232 232 // Add the originator to the objects activating this MultiTrigger. 233 233 if(bActive == true) … … 266 266 else 267 267 this->fire(bActive, state->originator); 268 268 269 269 bStateChanged = true; 270 270 } … … 289 289 } 290 290 } 291 291 292 292 // Remove the state from the state queue. 293 293 this->stateQueue_.pop_front(); … … 509 509 return returnVal; 510 510 } 511 511 512 512 return true; 513 513 } 514 514 515 515 /** 516 516 @brief … … 547 547 return; 548 548 } 549 549 550 550 MultiTriggerContainer* container = new MultiTriggerContainer(this, this, originator); 551 551 this->fireEvent(status, container); … … 563 563 { 564 564 ClassTreeMask& targetMask = this->getTargetMask(); 565 565 566 566 for(ClassTreeMaskObjectIterator it = targetMask.begin(); it != targetMask.end(); ++it) 567 567 { … … 580 580 { 581 581 assert(state); 582 582 583 583 // If the originator is no target of this MultiTrigger. 584 584 if(!this->isTarget(state->originator)) 585 585 return false; 586 586 587 587 // Add it ot the state queue. 588 588 this->stateQueue_.push_back(std::pair<float, MultiTriggerState*>(this->delay_, state)); -
code/trunk/src/modules/objects/triggers/MultiTrigger.h
- Property svn:eol-style set to native
r6864 r7163 94 94 MultiTrigger(BaseObject* creator); //!< Constructor. Registers the objects and initializes default values. 95 95 ~MultiTrigger(); //!< Destructor. 96 96 97 97 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a MultiTrigger object through XML. 98 98 virtual void tick(float dt); //!< A method that is executed each tick. 99 99 100 100 bool isActive(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is active for a given object. 101 101 … … 215 215 void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger. 216 216 void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger. 217 217 218 218 void addTrigger(MultiTrigger* trigger); //!< Adds a MultiTrigger as a sub-trigger to the trigger. 219 219 const MultiTrigger* getTrigger(unsigned int index) const; //!< Get the sub-trigger of this MultiTrigger at the given index. 220 220 221 221 protected: 222 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. 223 223 224 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. 225 225 226 226 bool isModeTriggered(BaseObject* triggerer = NULL); //!< Checks whetherx the MultiTrigger is triggered concerning it's sub-triggers. 227 227 bool isTriggered(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is triggered for a given object. … … 236 236 inline void addParentTrigger(MultiTrigger* parent) 237 237 { this->parentTrigger_ = parent; } 238 238 239 239 /** 240 240 @brief Get the target mask used to identify the targets of this MultiTrigger. … … 248 248 //TODO: Check if something mus be done here. 249 249 virtual void notifyMaskUpdate(void) {} 250 250 251 251 private: 252 252 static const int INF_s; //!< Magic number for infinity. … … 257 257 258 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. 259 259 260 260 bool addState(MultiTriggerState* state); //!< Helper method. Adds a state to the state queue, where the state will wait to become active. 261 261 262 262 bool checkAnd(BaseObject* triggerer); //!< Checks whether the sub-triggers amount to true for the 'and' mode for a given object. 263 263 bool checkOr(BaseObject* triggerer); //!< Checks whether the sub-triggers amount to true for the 'or' mode for a given object. … … 276 276 bool bSwitch_; //!< Bool for the switch-mode, if true the MultiTrigger behaves like a switch. 277 277 bool bStayActive_; //!< Bool for the stay-active-mode, if true the MultiTrigger stays active after its last activation.; 278 278 279 279 int remainingActivations_; //!< The remaining activations of this MultiTrigger. 280 280 int maxNumSimultaniousTriggerers_; //!< The maximum number of objects simultaniously trigggering this MultiTrigger. … … 287 287 MultiTrigger* parentTrigger_; 288 288 std::set<MultiTrigger*> subTriggers_; //!< The sub-triggers of this MultiTrigger. 289 289 290 290 std::set<BaseObject*> active_; //!< The set of all objects the MultiTrigger is active for. 291 291 std::set<BaseObject*> triggered_; //!< The set of all objects the MultiTrigger is triggered for. 292 292 293 293 std::deque< std::pair<float, MultiTriggerState*> > stateQueue_; //!< The queue of states waiting to become active. 294 294 295 295 ClassTreeMask targetMask_; //!< The target mask, masking all objects that can trigger this MultiTrigger. 296 296 297 297 }; 298 298 -
code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc
- Property svn:eol-style set to native
r6859 r7163 40 40 41 41 CreateUnloadableFactory(MultiTriggerContainer); 42 42 43 43 /** 44 44 @brief … … 73 73 MultiTriggerContainer::~MultiTriggerContainer() 74 74 { 75 75 76 76 } 77 77 -
code/trunk/src/modules/objects/triggers/MultiTriggerContainer.h
- Property svn:eol-style set to native
r6856 r7163 50 50 class _ObjectsExport MultiTriggerContainer : public BaseObject 51 51 { 52 52 53 53 public: 54 54 MultiTriggerContainer(BaseObject* creator); //!< Default constructor. Registers the object and creates an empty container. … … 68 68 inline BaseObject* getData(void) 69 69 { return this->data_; } 70 70 71 71 private: 72 72 MultiTrigger* originator_; //!< The originator. 73 73 BaseObject* data_; //!< The data. 74 74 }; 75 75 76 76 } 77 77
Note: See TracChangeset
for help on using the changeset viewer.