Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8576 for code


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

Boost is now truly toggled.

Location:
code/branches/gameimmersion/src/orxonox/controllers
Files:
2 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
  • code/branches/gameimmersion/src/orxonox/controllers/HumanController.h

    r8574 r8576  
    3232#include "OrxonoxPrereqs.h"
    3333
     34#include "tools/Timer.h"
    3435#include "tools/interfaces/Tickable.h"
    3536#include "Controller.h"
     
    6465            static void reload();
    6566
    66             static void toggleBoost(); // Static method, toggles boosting.
     67            static void keepBoost(); // Static method, keeps boosting.
    6768            /**
    6869            @brief Check whether the HumanController is in boosting mode.
     
    7172            inline bool isBoosting(void)
    7273                { return this->boosting_; }
    73             void toggleBoosting(void); // Toggles the boosting mode.
     74            void keepBoosting(void);
     75            void terminateBoosting(void);
    7476           
    7577            static void greet();
     
    103105        private:
    104106            bool boosting_; // Whether the HumanController is in boosting mode or not.
     107            Timer boostingTimeout_; // A timer to check whether the player is no longer boosting.
     108            static const float BOOSTING_TIME; // The time after it is checked, whether the player is no longer boosting.
    105109
    106110    }; // tolua_export
Note: See TracChangeset for help on using the changeset viewer.