Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2011, 7:03:45 PM (13 years ago)
Author:
dafrick
Message:

Boost is now truly toggled.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gameimmersion/src/orxonox/controllers/HumanController.cc

    r8574 r8576  
    5252    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
    5353    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
    54     SetConsoleCommand("HumanController", __CC_boost_name,          &HumanController::toggleBoost   ).addShortcut().keybindMode(KeybindMode::OnPress);
     54    SetConsoleCommand("HumanController", __CC_boost_name,          &HumanController::keepBoost     ).addShortcut().keybindMode(KeybindMode::OnHold);
    5555    SetConsoleCommand("HumanController", "greet",                  &HumanController::greet         ).addShortcut();
    5656    SetConsoleCommand("HumanController", "switchCamera",           &HumanController::switchCamera  ).addShortcut();
     
    6767
    6868    HumanController* HumanController::localController_s = 0;
     69    /*static*/ const float HumanController::BOOSTING_TIME = 0.1f;
    6970
    7071    HumanController::HumanController(BaseObject* creator) : Controller(creator)
     
    7273        RegisterObject(HumanController);
    7374
    74         controlPaused_ = false;
     75        this->controlPaused_ = false;
    7576        this->boosting_ = false;
    7677
    7778        HumanController::localController_s = this;
     79        this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this)));
     80        this->boostingTimeout_.stopTimer();
    7881    }
    7982
     
    167170    /**
    168171    @brief
    169         Static method,toggles boosting.
     172        Static method,keeps boosting.
    170173    */
    171     /*static*/ void HumanController::toggleBoost()
    172     {
    173         COUT(3) << "Toggling boost!" << endl; // TODO: Remove!
    174         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    175             HumanController::localController_s->toggleBoosting();
     174    /*static*/ void HumanController::keepBoost()
     175    {
     176        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     177            HumanController::localController_s->keepBoosting();
    176178    }
    177179   
    178180    /**
    179181    @brief
    180         Toggles the boosting mode.
    181         Changes the keybind mode of the boost console command and tells the ControllableEntity to boost (or not boost anymore).
     182        Starts, or keeps the boosting mode.
     183        Resets the boosting timeout and ells the ControllableEntity to boost (or not boost anymore).
    182184    */
    183     void HumanController::toggleBoosting(void)
    184     {
    185         this->boosting_ = !this->boosting_;
    186        
    187         // The keybind mode of the boosting console command is onRelease if in boosting mode and onPress of not in boosting mode.
    188         if(this->boosting_)
    189             ModifyConsoleCommand(__CC_boost_name).keybindMode(KeybindMode::OnRelease);
     185    void HumanController::keepBoosting(void)
     186    {
     187        if(this->boostingTimeout_.isActive())
     188        {
     189            this->boostingTimeout_.stopTimer();
     190            this->boostingTimeout_.startTimer();
     191        }
    190192        else
    191             ModifyConsoleCommand(__CC_boost_name).keybindMode(KeybindMode::OnPress);
     193        {
     194            this->boosting_ = true;
     195            this->boostingTimeout_.startTimer();
     196           
     197            this->controllableEntity_->boost(this->boosting_);
     198            COUT(4) << "Start boosting" << endl;
     199        }
     200    }
     201
     202    /**
     203    @brief
     204        Terminates the boosting mode.
     205    */
     206    void HumanController::terminateBoosting(void)
     207    {
     208        this->boosting_ = false;
     209        this->boostingTimeout_.stopTimer();
    192210
    193211        this->controllableEntity_->boost(this->boosting_);
     212        COUT(4) << "Stop boosting" << endl;
    194213    }
    195214
Note: See TracChangeset for help on using the changeset viewer.