Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4906 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons


Ignore:
Timestamp:
Jul 20, 2005, 1:41:19 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: states are now flow'n through

Location:
orxonox/trunk/src/world_entities/weapons
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/world_entities/weapons/test_gun.cc

    r4895 r4906  
    7070      animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
    7171
    72       animation2->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
    73       animation2->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
    74 
    75       animation3->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
    76       animation3->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
     72      animation2->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     73      animation2->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     74
     75      animation3->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     76      animation3->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
    7777    }
    7878  else if( this->leftRight == W_RIGHT)
     
    100100  //ObjectManager::getInstance()->debug();
    101101
    102   this->setStateDuration(WS_SHOOTING, .2);
    103   this->setStateDuration(WS_RELOADING, .5);
     102  this->setStateDuration(WS_SHOOTING, .4);
     103  this->setStateDuration(WS_RELOADING, 1);
    104104  //this->setStateDuration(WS_ACTIVATING, .4);
    105105  //this->setStateDuration(WS_DEACTIVATING, .4);
  • orxonox/trunk/src/world_entities/weapons/weapon.cc

    r4895 r4906  
    8181  this->emissionPoint.setParent(this);
    8282
    83   this->active = true;
    8483  this->projectile = NULL;
     84
     85  this->hideInactive = true;
    8586
    8687  this->minCharge = 1.0;
     
    171172void Weapon::requestAction(WeaponAction action)
    172173{
    173   if (this->requestedAction != WA_NONE)
    174     return;
    175   else
    176   {
     174  if (likely(this->isActive()))
     175  {
     176    if (this->requestedAction != WA_NONE)
     177      return;
    177178    printf("next action will be %s in %f seconds\n", actionToChar(action), this->stateDuration);
    178179    this->requestedAction = action;
     180  }
     181  //else
     182  else if (unlikely(action == WA_ACTIVATE))
     183  {
     184    this->currentState = WS_ACTIVATING;
     185    this->requestAction(WA_ACTIVATE);
    179186  }
    180187}
     
    215222bool Weapon::execute()
    216223{
    217 
     224#if DEBUG > 4
    218225  PRINTF(4)("trying to execute action %s\n", actionToChar(this->requestedAction));
    219226  this->debug();
     227#endif
    220228
    221229  switch (this->requestedAction)
     
    246254bool Weapon::activateW()
    247255{
    248 //  if (this->currentState == WS_INACTIVE)
     256  if (this->currentState == WS_INACTIVE)
    249257  {
    250258        // play Sound
     
    256264    PRINTF(4)("Activating the Weapon %s\n", this->getName());
    257265    this->activate();
    258     this->active = true;
    259266    // setting up for next action
     267    this->currentState = WS_ACTIVATING;
    260268    this->stateDuration = this->times[WA_ACTIVATE] + this->stateDuration;
    261269  }
     
    280288        // deactivate
    281289    this->deactivate();
    282     this->active = false;
    283290        // setting up for next action
     291    this->currentState = WS_DEACTIVATING;
    284292    this->stateDuration = this->times[WA_DEACTIVATE] + this->stateDuration;
    285293  }
     
    305313        // setting up for the next state
    306314    this->requestedAction = WA_NONE;
     315    this->currentState = WS_CHARGING;
    307316    this->stateDuration = this->times[WA_CHARGE] + this->stateDuration;
    308317  }
     
    334343          // setting up for the next state
    335344    this->stateDuration = this->times[WA_SHOOT] + this->stateDuration;
     345    this->currentState = WS_SHOOTING;
    336346    this->requestedAction = WA_NONE;
    337347  }
     
    379389
    380390  this->requestedAction = WA_NONE;
     391  this->currentState = WS_RELOADING;
    381392  this->stateDuration = this->times[WA_RELOAD] + this->stateDuration;
    382393
     
    387398 * tick signal for time dependent/driven stuff
    388399*/
    389 void Weapon::tick(float dt)
     400void Weapon::tickW(float dt)
    390401{
    391402  // setting up the timing properties
     
    394405  if (this->isActive())
    395406  {
    396     if (this->stateDuration <= 0.0 && this->requestedAction != WA_NONE)
    397     {
    398       this->stateDuration = -dt;
    399       this->execute();
    400     }
    401   }
    402   else
    403     if (this->requestedAction == WA_ACTIVATE)
    404       this->activate();
    405 
     407    if (this->stateDuration <= 0.0)
     408    {
     409      if (unlikely (this->currentState != WS_DEACTIVATING))
     410        this->currentState = WS_IDLE;
     411      else
     412        this->currentState = WS_INACTIVE;
     413
     414      if (this->requestedAction != WA_NONE)
     415      {
     416        this->stateDuration = -dt;
     417        this->execute();
     418      }
     419    }
     420  }
     421  tick(dt);
    406422}
    407423
     
    569585      return "idle";
    570586      break;
     587    case WS_INACTIVE:
     588      return "inactive";
     589      break;
    571590    default:
    572591      return "none";
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4895 r4906  
    8181    float increaseEnergy(float energyToAdd);
    8282
    83     /** @returns true if the Weapon is Active */
    84     inline bool isActive() const { return this->active; };
     83    /** @returns true if the Weapon is Active  (this is used to check if the weapon must be drawn)*/
     84    inline bool isActive() const { return (this->currentState == WS_INACTIVE)?false:true; };
     85    /** @returns true if the weapon must be drawn */
     86    inline bool isVisible() const { return (this->currentState != WS_INACTIVE || !this->hideInactive)?true:false; };
    8587
    8688    // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
     
    113115
    114116    Animation3D* getAnimation(WeaponState state, PNode* node = NULL);
     117    Animation3D* copyAnimation(WeaponState from, WeaponState to);
    115118
    116119    // FLOW
    117     virtual void tick(float dt);
     120    void tickW(float dt); //!< this is a function that must be called by the weaponManager, or any other weaponHandler, all other functions are handled from within
     121    virtual void tick(float dt) {};
    118122    virtual void draw();
    119123
     
    175179    PNode                emissionPoint;                   //!< The point, where the projectiles are emitted. (this is coppled with the Weapon by default)
    176180
    177     bool                 active;                          //!< states wheter the weapon is enabled or not
    178181    bool                 hideInactive;                    //!< Hides the Weapon if it is inactive
    179182    bool                 chargeable;                      //!< if the Weapon is charcheable
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.cc

    r4895 r4906  
    7575      this->configs[i].slots[j] = NULL;
    7676  }
    77   this->currConfID = W_CONFIG0;
     77  this->currConfID = WM_CONFIG0;
    7878
    7979
     
    141141 *
    142142 * if you add explicitly a weapon at config:n, slot:m, the weapon placed at this location will be
    143  * replaced by the weapon specified. if you use the W_FREE_SLOT, the manager will look for a free
     143 * replaced by the weapon specified. if you use the WM_FREE_SLOT, the manager will look for a free
    144144 * slot in this weaponconfiguration. if there is non, the weapon won't be added and there will be
    145145 * a error message.
     
    147147void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)
    148148{
    149   if( slotID == W_FREE_SLOT)
     149  if( slotID == WM_FREE_SLOT)
    150150  {
    151151    int freeSlot = this->getNextFreeSlot( configID);
     
    187187  lastConfID = this->currConfID;
    188188  for(i = this->currConfID + 1; i < W_MAX_CONFIGS && !this->configs[i].bUsed; ++i);
    189   if( i == W_MAX_CONFIGS) this->currConfID = W_CONFIG0;
     189  if( i == W_MAX_CONFIGS) this->currConfID = WM_CONFIG0;
    190190  else this->currConfID = i;
    191191
     
    241241{
    242242  Weapon* w;
    243   for (int j = 0; j < 4; ++j )
    244     for(int i = 0; i < W_MAX_SLOTS; ++i)
    245   {
    246     w = this->configs[j].slots[i];
    247     if( w != NULL) w->tick(dt);
     243  for(int i = 0; i < W_MAX_SLOTS; ++i)
     244  {
     245    w = this->configs[this->currConfID].slots[i];
     246    if( w != NULL && w->isActive())
     247      w->tickW(dt);
    248248  }
    249249
     
    262262  {
    263263    w = this->configs[j].slots[i];
    264     if( w != NULL)
     264    if( w != NULL && w->isVisible())
    265265      w->draw();
    266266  }
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.h

    r4837 r4906  
    3939
    4040//! this is an identifier for the weapon config
    41 #define    W_CONFIG0     0
    42 #define    W_CONFIG1     1
    43 #define    W_CONFIG2     2
    44 #define    W_CONFIG3     3
     41typedef enum
     42{
     43  WM_CONFIG0           = 0,
     44  WM_CONFIG1           = 1,
     45  WM_CONFIG2           = 2,
     46  WM_CONFIG3           = 3,
    4547
     48  WM_CONFIGCOUNT       = 4
     49} WM_CONFIG;
    4650
    4751//! this is an identifier for the slot. there are up to 8 weapon slots -> this means there can't be more than 8 weapons at the same time
    48 #define    W_SLOT0       0
    49 #define    W_SLOT1       1
    50 #define    W_SLOT2       2
    51 #define    W_SLOT3       3
    52 #define    W_SLOT4       4
    53 #define    W_SLOT5       5
    54 #define    W_SLOT6       6
    55 #define    W_SLOT7       7
    56 #define    W_FREE_SLOT   99
     52typedef enum
     53{
     54  WM_SLOT0              = 0,
     55  WM_SLOT1              = 1,
     56  WM_SLOT2              = 2,
     57  WM_SLOT3              = 3,
     58  WM_SLOT4              = 4,
     59  WM_SLOT5              = 5,
     60  WM_SLOT6              = 6,
     61  WM_SLOT7              = 7,
    5762
     63  WM_SLOT_COUNT         = 8,
     64
     65  WM_FREE_SLOT          = -1
     66} WM_SLOT;
    5867
    5968//! this is a weapon Configuration: it has up to 8 slots
     
    7786    void setSlotCount(int nrOfSlots);
    7887
    79     void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT);
    80     void removeWeapon(Weapon* weapon, int configID = W_CONFIG0);
     88    void addWeapon(Weapon* weapon, int configID = WM_CONFIG0, int slotID = WM_FREE_SLOT);
     89    void removeWeapon(Weapon* weapon, int configID = WM_CONFIG0);
    8190    void nextWeaponConf();
    8291
Note: See TracChangeset for help on using the changeset viewer.