Changeset 6851
- Timestamp:
- May 3, 2010, 9:52:45 PM (15 years ago)
- Location:
- code/trunk/src/modules/objects/triggers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/triggers/MultiTrigger.cc
r6805 r6851 78 78 } 79 79 80 //TODO: Clean up?80 //TODO: Document. 81 81 void MultiTrigger::XMLPort(Element& xmlelement, XMLPort::Mode mode) 82 82 { … … 94 94 XMLPortObject(MultiTrigger, MultiTrigger, "", addTrigger, getTrigger, xmlelement, mode); 95 95 96 COUT(4) << "MultiTrigger &" << this << "created." << std::endl;96 COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") created." << std::endl; 97 97 } 98 98 … … 113 113 114 114 std::queue<MultiTriggerState*>* queue = this->letTrigger(); 115 if(queue != NULL)116 COUT(4) << "MultiTrigger &" << this << ": " << queue->size() << " new states to state queue." << std::endl;117 115 118 116 if(queue != NULL) … … 124 122 if(state == NULL) 125 123 break; 126 127 this->addState(state->bTriggered & this->isModeTriggered(state->originator), state->originator); 124 125 bool bTriggered = (state->bTriggered & this->isModeTriggered(state->originator)) ^ this->bInvertMode_; 126 if(bTriggered ^ this->isTriggered(state->originator)) 127 this->addState(bTriggered, state->originator); 128 128 queue->pop(); 129 129 delete state; 130 130 } 131 131 delete queue; 132 } 132 } 133 133 134 134 if (this->stateQueue_.size() > 0) … … 172 172 // Remove the state from the state queue. 173 173 this->stateQueue_.pop_front(); 174 COUT(4) << "MultiTrigger &" << this << ": State processed, removing from state queue. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << state->bActive << "|" << this->isActive(state->originator) << ", triggered: " << state->bTriggered << "|" << this->isTriggered(state->originator) << "." << std::endl;174 COUT(4) << "MultiTrigger '" << this->getName() << "' &" << this << ": State processed, removing from state queue. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << state->bActive << "|" << this->isActive(state->originator) << ", triggered: " << state->bTriggered << "|" << this->isTriggered(state->originator) << "." << std::endl; 175 175 delete state; 176 176 size -= 1; … … 180 180 this->stateQueue_.push_back(std::pair<float, MultiTriggerState*>(timeRemaining-dt, state)); 181 181 this->stateQueue_.pop_front(); 182 COUT(4) << "MultiTrigger &" << this << ": State processed, decreasing time remaining. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << state->bActive << ", triggered: " << state->bTriggered << ", time remaining: " << timeRemaining-dt << "." << std::endl;182 COUT(4) << "MultiTrigger '" << this->getName() << "' &" << this << ": State processed, decreasing time remaining. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << state->bActive << ", triggered: " << state->bTriggered << ", time remaining: " << timeRemaining-dt << "." << std::endl; 183 183 } 184 184 } … … 218 218 std::queue<MultiTriggerState*>* MultiTrigger::letTrigger(void) 219 219 { 220 // Goes through all trigger children and gets the objects triggering them. 221 std::set<BaseObject*>* triggerers = new std::set<BaseObject*>(); 222 std::set<BaseObject*>::iterator objIt; 223 for(std::set<MultiTrigger*>::iterator it = this->children_.begin(); it != this->children_.end(); it ++) 224 { 225 std::set<BaseObject*> set = (*it)->getActive(); 226 for(objIt = set.begin(); objIt != set.end(); objIt++) 227 { 228 triggerers->insert(*objIt); 229 } 230 } 231 232 // Goes through all the triggerers of this trigger. 233 for(objIt = this->active_.begin(); objIt != this->active_.end(); objIt++) 234 { 235 triggerers->insert(*objIt); 236 } 237 238 if(triggerers->size() == 0) 239 return NULL; 240 220 241 std::queue<MultiTriggerState*>* queue = new std::queue<MultiTriggerState*>(); 221 MultiTriggerState* state = new MultiTriggerState; 222 state->bTriggered = true; 223 state->originator = NULL; 224 queue->push(state); 242 MultiTriggerState* state = NULL; 243 for(std::set<BaseObject*>::iterator it = triggerers->begin(); it != triggerers->end(); it++) 244 { 245 state = new MultiTriggerState; 246 state->bTriggered = true; 247 state->originator = *it; 248 queue->push(state); 249 } 250 delete triggerers; 251 225 252 return queue; 226 253 } … … 280 307 return false; 281 308 282 bTriggered ^= this->bInvertMode_;283 309 // If the state doesn't change. 284 310 if(this->isTriggered() && bTriggered) … … 289 315 // If the MultiTrigger is in switch mode. 290 316 if(this->bSwitch_ && !bTriggered) 291 return false; 292 317 { 318 bActive = this->isActive(originator); 319 } 293 320 // If the state changes to active. 294 if(this->remainingActivations_ != INF_s && bActive)321 else if(this->remainingActivations_ != INF_s && bActive) 295 322 { 296 323 if(this->remainingActivations_ == 0) … … 300 327 else 301 328 { 302 // If the MultiTrigger should stay active and there are no more remaining activations. 329 // If the MultiTrigger should stay active if there are no more remaining activations. 330 //TODO: Find out how this applies to infinitely many activations. 303 331 if(this->bStayActive_ && this->remainingActivations_ == 0) 304 332 return false; 305 333 } 306 334 307 COUT(4) << "MultiTrigger &" << this << ": State added to state queue. originator: " << originator->getIdentifier()->getName() << " (&" << originator << "), active: " << bActive << "|" << this->isActive(originator) << ", triggered: " << bTriggered << "|" << this->isTriggered(originator) << "." << std::endl;335 COUT(4) << "MultiTrigger &" << this << ": State added to state queue. originator: " << originator->getIdentifier()->getName() << " (&" << originator << "), active: " << bActive << "|" << this->isActive(originator) << ", triggered: " << bTriggered << "|" << this->isTriggered(originator) << ", remaining activations: " << this->remainingActivations_ << "." << std::endl; 308 336 309 337 // Create state. -
code/trunk/src/modules/objects/triggers/MultiTrigger.h
r6800 r6851 60 60 bool bTriggered; 61 61 }; 62 62 63 /** 64 @brief 65 The MultiTrigger class implements a trigger that has a distinct state for each object triggering it. 66 */ 63 67 class _ObjectsExport MultiTrigger : public StaticEntity, public Tickable 64 68 { … … 140 144 bool checkXor(BaseObject* triggerer); 141 145 146 std::set<BaseObject*>& getActive(void) 147 { return this->active_; } 148 142 149 bool bFirstTick_; 143 150
Note: See TracChangeset
for help on using the changeset viewer.