Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1954


Ignore:
Timestamp:
Oct 19, 2008, 10:03:40 PM (16 years ago)
Author:
bknecht
Message:

Triggers now implemented. Trigger may now have children, two or four states, limited amount of activations and a delay.

Location:
code/branches/script_trigger
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/script_trigger/bin/levels/sample.oxw

    r1851 r1954  
    3838<Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" /-->
    3939
    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>
    4244
    4345<?lua
  • code/branches/script_trigger/src/orxonox/objects/DistanceTrigger.cc

    r1906 r1954  
    9494        Vector3 distanceVec = it->getNode()->getWorldPosition() - this->getNode()->getWorldPosition();
    9595        if (distanceVec.length() < this->distance_)
     96        {
    9697          return true;
     98        }
    9799      }
    98100    }
  • code/branches/script_trigger/src/orxonox/objects/Trigger.cc

    r1906 r1954  
    5454    bUpdating_ = false;
    5555    remainingActivations_ = -1;
    56     bStayTriggered_ = false;
     56    bStayOn_ = false;
    5757    latestState_ = 0x0;
    5858
     
    7979  }
    8080
     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
    8196  void Trigger::tick(float dt)
    8297  {
    8398
    8499    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)
    93107      {
    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
    98117          this->switchState();
    99         }
    100         else
    101         {
    102           latestState_ &= 0xFE; // set trigger bit
    103           this->storeState();
    104         }
    105118      }
     119    }
    106120
    107121    if(remainingTime_ > 0.0)
     
    117131      // time ran out, change state to new one
    118132      char newState = stateChanges_.front().second;
    119       bTriggered_ = newState % 2;
     133      bTriggered_ = (newState & 0x1);
    120134      bActive_ = newState & 2;
    121135      this->stateChanges_.pop();
     
    192206  }
    193207
     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
    194218  void Trigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    195219  {
     
    197221
    198222    XMLPortParamLoadOnly(Trigger, "delay", setDelay, xmlelement, mode);
    199     XMLPortParamLoadOnly(Trigger, "stayTriggered", setStayTriggered, xmlelement, mode);
     223    XMLPortParamLoadOnly(Trigger, "stayOn", setStayOn, xmlelement, mode);
    200224    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);
    201228
    202229    this->init();
     
    211238  bool Trigger::switchState()
    212239  {
    213     if ( remainingActivations_ == -1 || this->latestState_ & 2 || remainingActivations_ > 0)
     240    if ( remainingActivations_ <= -1 || this->latestState_ & 2 || remainingActivations_ > 0)
    214241    {
    215242      this->latestState_ ^= 2; // toggle state bit
  • code/branches/script_trigger/src/orxonox/objects/Trigger.h

    r1851 r1954  
    5656      inline bool isActive() { return bActive_; }
    5757      void addTrigger(Trigger* trig);
     58      const Trigger* getTrigger(unsigned int index) const;
    5859      void setVisibility(bool bVisible);
    5960      void setDelay(float delay);
     
    6263      inline TriggerMode getMode() { return mode_; }
    6364      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; }
    6567      inline void setActivations(int activations) { this->remainingActivations_ = activations; }
    6668      void tick(float dt);
     
    9193      float delay_;
    9294      int remainingActivations_;
    93       bool bStayTriggered_;
     95      bool bStayOn_;
    9496      char latestState_;
    9597  };
Note: See TracChangeset for help on using the changeset viewer.