Changeset 1851 for code/branches/script_trigger/src/orxonox/objects
- Timestamp:
- Sep 28, 2008, 5:15:45 PM (16 years ago)
- Location:
- code/branches/script_trigger/src/orxonox/objects
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/script_trigger/src/orxonox/objects/DistanceTrigger.h
r1693 r1851 52 52 void setDistance(float dist); 53 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 bool checkDistance(); 55 56 protected: 54 57 bool isTriggered(TriggerMode mode); 55 bool checkDistance();56 58 57 59 private: -
code/branches/script_trigger/src/orxonox/objects/Trigger.cc
r1693 r1851 53 53 bTriggered_ = false; 54 54 bUpdating_ = false; 55 remainingActivations_ = -1; 56 bStayTriggered_ = false; 57 latestState_ = 0x0; 55 58 56 59 debugBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); … … 79 82 { 80 83 81 bool newTriggered = this->isTriggered(); 82 83 84 // check if new triggering event is really new 85 if(this->latestState_ % 2 != newTriggered) 86 { 87 // create new state 88 if(newTriggered) 84 bool newTriggered; 85 if (latestState_ % 2 == 1 && this->bStayTriggered_) 86 newTriggered = true; 87 else 88 newTriggered = this->isTriggered(); 89 90 91 // check if new triggering event is really new 92 if(this->latestState_ % 2 != newTriggered) 89 93 { 90 latestState_ |= 0x1; // set trigger bit 91 latestState_ ^= 0x10; // toggle state bit 94 // create new state 95 if(newTriggered) 96 { 97 latestState_ |= 1; // set trigger bit 98 this->switchState(); 99 } 100 else 101 { 102 latestState_ &= 0xFE; // set trigger bit 103 this->storeState(); 104 } 92 105 } 93 else94 {95 latestState_ &= 0x11111110; // set trigger bit96 }97 98 // put state change into queue99 this->stateChanges_.push(std::pair<float,char>(timeSinceLastEvent_, latestState_));100 // reset time since last event101 timeSinceLastEvent_ = 0.0;102 103 if(this->stateChanges_.size() == 1)104 remainingTime_ = stateChanges_.front().first;105 }106 106 107 107 if(remainingTime_ > 0.0) … … 118 118 char newState = stateChanges_.front().second; 119 119 bTriggered_ = newState % 2; 120 bActive_ = newState >>1 %2;120 bActive_ = newState & 2; 121 121 this->stateChanges_.pop(); 122 122 if(stateChanges_.size() != 0) … … 144 144 } 145 145 146 void Trigger::storeState() 147 { 148 // put state change into queue 149 this->stateChanges_.push(std::pair<float,char>(timeSinceLastEvent_, latestState_)); 150 // reset time since last event 151 timeSinceLastEvent_ = 0.0; 152 153 if(this->stateChanges_.size() == 1) 154 remainingTime_ = stateChanges_.front().first; 155 } 156 146 157 bool Trigger::isTriggered(TriggerMode mode) 147 158 { … … 186 197 187 198 XMLPortParamLoadOnly(Trigger, "delay", setDelay, xmlelement, mode); 199 XMLPortParamLoadOnly(Trigger, "stayTriggered", setStayTriggered, xmlelement, mode); 200 XMLPortParamLoadOnly(Trigger, "activations", setActivations, xmlelement, mode); 188 201 189 202 this->init(); … … 198 211 bool Trigger::switchState() 199 212 { 200 latestState_ ^= 0x10; // toggle state bit 201 // put state change into queue 202 this->stateChanges_.push(std::pair<float,char>(timeSinceLastEvent_, latestState_)); 203 // reset time since last event 204 timeSinceLastEvent_ = 0.0; 205 206 if(this->stateChanges_.size() == 1) 207 remainingTime_ = stateChanges_.front().first; 213 if ( remainingActivations_ == -1 || this->latestState_ & 2 || remainingActivations_ > 0) 214 { 215 this->latestState_ ^= 2; // toggle state bit 216 // increase activation count 217 if (this->latestState_ & 2) remainingActivations_--; 218 this->storeState(); 219 220 return true; 221 } 222 return false; 208 223 } 209 224 … … 214 229 for(it = this->children_.begin(); it != this->children_.end(); it++) 215 230 { 216 if(!((*it)->is Triggered()))231 if(!((*it)->isActive())) 217 232 return false; 218 233 } … … 225 240 for(it = this->children_.begin(); it != this->children_.end(); it++) 226 241 { 227 if((*it)->is Triggered())242 if((*it)->isActive()) 228 243 return true; 229 244 } … … 237 252 for(it = this->children_.begin(); it != this->children_.end(); it++) 238 253 { 239 if(test && (*it)->is Triggered())254 if(test && (*it)->isActive()) 240 255 return false; 241 if((*it)->is Triggered())256 if((*it)->isActive()) 242 257 test = true; 243 258 } -
code/branches/script_trigger/src/orxonox/objects/Trigger.h
r1693 r1851 54 54 ~Trigger(); 55 55 56 inline bool isTriggered() { return this->isTriggered(this->mode_); } 57 virtual bool isTriggered(TriggerMode mode); 56 inline bool isActive() { return bActive_; } 58 57 void addTrigger(Trigger* trig); 59 58 void setVisibility(bool bVisible); … … 63 62 inline TriggerMode getMode() { return mode_; } 64 63 inline void setMode(TriggerMode mode) { this->mode_ = mode; } 64 inline void setStayTriggered(float stayTriggered) { if (stayTriggered == 1.0) this->bStayTriggered_ = true; else this->bStayTriggered_ = false; } 65 inline void setActivations(int activations) { this->remainingActivations_ = activations; } 65 66 void tick(float dt); 66 67 … … 71 72 bool checkXor(); 72 73 void setBillboardColour(ColourValue colour); 74 void storeState(); 75 76 protected: 77 inline bool isTriggered() { return this->isTriggered(this->mode_); } 78 virtual bool isTriggered(TriggerMode mode); 73 79 74 80 private: … … 84 90 BillboardSet debugBillboard_; 85 91 float delay_; 92 int remainingActivations_; 93 bool bStayTriggered_; 86 94 char latestState_; 87 95 };
Note: See TracChangeset
for help on using the changeset viewer.