Changeset 1954
- Timestamp:
- Oct 19, 2008, 10:03:40 PM (16 years ago)
- Location:
- code/branches/script_trigger
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/script_trigger/bin/levels/sample.oxw
r1851 r1954 38 38 <Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" /--> 39 39 40 <DistanceTrigger position="100,0,0" scale="2" distance="80" activations="2" target="SpaceShip"/> 41 40 <Trigger position="0,200,0" scale="2" delay="2" stayOn="1"> 41 <DistanceTrigger position="100,0,0" scale="2" distance="80" stayOn="1.0" target="SpaceShip"/> 42 <DistanceTrigger position="150,0,0" scale="2" distance="80" stayOn="1.0" target="SpaceShip"/> 43 </Trigger> 42 44 43 45 <?lua -
code/branches/script_trigger/src/orxonox/objects/DistanceTrigger.cc
r1906 r1954 94 94 Vector3 distanceVec = it->getNode()->getWorldPosition() - this->getNode()->getWorldPosition(); 95 95 if (distanceVec.length() < this->distance_) 96 { 96 97 return true; 98 } 97 99 } 98 100 } -
code/branches/script_trigger/src/orxonox/objects/Trigger.cc
r1906 r1954 54 54 bUpdating_ = false; 55 55 remainingActivations_ = -1; 56 bStay Triggered_ = false;56 bStayOn_ = false; 57 57 latestState_ = 0x0; 58 58 … … 79 79 } 80 80 81 const Trigger* Trigger::getTrigger(unsigned int index) const 82 { 83 if (children_.size() <= index) 84 return NULL; 85 86 std::set<Trigger*>::iterator it; 87 it = children_.begin(); 88 89 for ( unsigned int i = 0; i != index; i++ ) 90 { 91 it++; 92 } 93 return *it; 94 } 95 81 96 void Trigger::tick(float dt) 82 97 { 83 98 84 99 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) 100 newTriggered = this->isTriggered(); 101 102 // check if new triggering event is really new 103 if((this->latestState_ & 0x1) != newTriggered) 104 { 105 // create new state 106 if(newTriggered) 93 107 { 94 // create new state 95 if(newTriggered) 96 { 97 latestState_ |= 1; // set trigger bit 108 latestState_ |= 1; // set trigger bit 109 this->switchState(); 110 } 111 else 112 { 113 latestState_ &= 0xFE; // set trigger bit 114 if (this->bStayOn_) 115 this->storeState(); 116 else 98 117 this->switchState(); 99 }100 else101 {102 latestState_ &= 0xFE; // set trigger bit103 this->storeState();104 }105 118 } 119 } 106 120 107 121 if(remainingTime_ > 0.0) … … 117 131 // time ran out, change state to new one 118 132 char newState = stateChanges_.front().second; 119 bTriggered_ = newState % 2;133 bTriggered_ = (newState & 0x1); 120 134 bActive_ = newState & 2; 121 135 this->stateChanges_.pop(); … … 192 206 } 193 207 208 void Trigger::setMode(std::string modeName) 209 { 210 if (modeName == "and") 211 setMode(TM_EventTriggerAND); 212 else if (modeName == "or") 213 setMode(TM_EventTriggerOR); 214 else if (modeName == "xor") 215 setMode(TM_EventTriggerXOR); 216 } 217 194 218 void Trigger::XMLPort(Element& xmlelement, XMLPort::Mode mode) 195 219 { … … 197 221 198 222 XMLPortParamLoadOnly(Trigger, "delay", setDelay, xmlelement, mode); 199 XMLPortParamLoadOnly(Trigger, "stay Triggered", setStayTriggered, xmlelement, mode);223 XMLPortParamLoadOnly(Trigger, "stayOn", setStayOn, xmlelement, mode); 200 224 XMLPortParamLoadOnly(Trigger, "activations", setActivations, xmlelement, mode); 225 //XMLPortParamLoadOnlyTemplate(Trigger, "mode", setMode, xmlelement, mode, std::string); 226 227 XMLPortObject(Trigger, Trigger, "", addTrigger, getTrigger, xmlelement, mode, false, true); 201 228 202 229 this->init(); … … 211 238 bool Trigger::switchState() 212 239 { 213 if ( remainingActivations_ == -1 || this->latestState_ & 2 || remainingActivations_ > 0)240 if ( remainingActivations_ <= -1 || this->latestState_ & 2 || remainingActivations_ > 0) 214 241 { 215 242 this->latestState_ ^= 2; // toggle state bit -
code/branches/script_trigger/src/orxonox/objects/Trigger.h
r1851 r1954 56 56 inline bool isActive() { return bActive_; } 57 57 void addTrigger(Trigger* trig); 58 const Trigger* getTrigger(unsigned int index) const; 58 59 void setVisibility(bool bVisible); 59 60 void setDelay(float delay); … … 62 63 inline TriggerMode getMode() { return mode_; } 63 64 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 void setMode(std::string modeName); 66 inline void setStayOn(int stayOn) { if (stayOn == 1) this->bStayOn_ = true; else this->bStayOn_ = false; } 65 67 inline void setActivations(int activations) { this->remainingActivations_ = activations; } 66 68 void tick(float dt); … … 91 93 float delay_; 92 94 int remainingActivations_; 93 bool bStay Triggered_;95 bool bStayOn_; 94 96 char latestState_; 95 97 };
Note: See TracChangeset
for help on using the changeset viewer.