Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 4, 2014, 9:53:50 PM (11 years ago)
Author:
landauf
Message:

simplified the boost command in HumanController by using the new keybind mode 'OnPressAndRelease'. depending on the command's argument the boost is started or stopped.
this also fixes a bug: boost didn't work if the frame-rate was too low or the game speed too high because boostingTimeout_ ended before the next tick

Location:
code/trunk/src/orxonox/controllers
Files:
2 edited

Legend:

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

    r9667 r9979  
    4242    extern const std::string __CC_fire_name = "fire";
    4343    extern const std::string __CC_suicide_name = "suicide";
    44     const std::string __CC_boost_name = "boost";
    4544
    4645    SetConsoleCommand("HumanController", "moveFrontBack",          &HumanController::moveFrontBack ).addShortcut().setAsInputCommand();
     
    5150    SetConsoleCommand("HumanController", "rotateRoll",             &HumanController::rotateRoll    ).addShortcut().setAsInputCommand();
    5251    SetConsoleCommand("HumanController", "toggleFormationFlight",  &HumanController::toggleFormationFlight).addShortcut().keybindMode(KeybindMode::OnPress);
    53     SetConsoleCommand("HumanController", "FFChangeMode",  &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress);
     52    SetConsoleCommand("HumanController", "FFChangeMode",           &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress);
    5453    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
    5554    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
    56     SetConsoleCommand("HumanController", __CC_boost_name,          &HumanController::keepBoost     ).addShortcut().keybindMode(KeybindMode::OnHold);
     55    SetConsoleCommand("HumanController", "boost",                  &HumanController::boost         ).addShortcut().setAsInputCommand().keybindMode(KeybindMode::OnPressAndRelease);
    5756    SetConsoleCommand("HumanController", "greet",                  &HumanController::greet         ).addShortcut();
    5857    SetConsoleCommand("HumanController", "switchCamera",           &HumanController::switchCamera  ).addShortcut();
     
    6968
    7069    HumanController* HumanController::localController_s = 0;
    71     /*static*/ const float HumanController::BOOSTING_TIME = 0.1f;
    7270
    7371    HumanController::HumanController(Context* context) : FormationController(context)
     
    7674
    7775        this->controlPaused_ = false;
    78         this->boosting_ = false;
    79         this->boosting_ = false;
    8076        HumanController::localController_s = this;
    81         this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this)));
    82         this->boostingTimeout_.stopTimer();
    8377    }
    8478
     
    190184    /**
    191185    @brief
    192         Static method,keeps boosting.
    193     */
    194     /*static*/ void HumanController::keepBoost()
    195     {
    196         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    197             HumanController::localController_s->keepBoosting();
    198     }
    199 
    200     /**
    201     @brief
    202         Starts, or keeps the boosting mode.
     186        Static method, controls boosting.
     187    */
     188    /*static*/ void HumanController::boost(const Vector2& value)
     189    {
     190        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     191        {
     192            float abs = value.x;
     193            if (abs > 0)
     194                HumanController::localController_s->startBoosting();
     195            else
     196                HumanController::localController_s->stopBoosting();
     197        }
     198    }
     199
     200    /**
     201    @brief
     202        Starts the boosting mode.
    203203        Resets the boosting timeout and ells the ControllableEntity to boost (or not boost anymore).
    204204    */
    205     void HumanController::keepBoosting(void)
    206     {
    207         if(this->boostingTimeout_.isActive())
    208         {
    209             this->boostingTimeout_.stopTimer();
    210             this->boostingTimeout_.startTimer();
    211         }
    212         else
    213         {
    214             this->boosting_ = true;
    215             this->boostingTimeout_.startTimer();
    216             if(this->controllableEntity_)
    217                 this->controllableEntity_->boost(this->boosting_);
    218 //            orxout() << "Start boosting" << endl;
    219         }
    220     }
    221 
    222     /**
    223     @brief
    224         Terminates the boosting mode.
    225     */
    226     void HumanController::terminateBoosting(void)
    227     {
    228         this->boosting_ = false;
    229         this->boostingTimeout_.stopTimer();
     205    void HumanController::startBoosting(void)
     206    {
    230207        if(this->controllableEntity_)
    231             this->controllableEntity_->boost(this->boosting_);
    232 //        orxout() << "Stop boosting" << endl;
     208            this->controllableEntity_->boost(true);
     209    }
     210
     211    /**
     212    @brief
     213        Stops the boosting mode.
     214    */
     215    void HumanController::stopBoosting(void)
     216    {
     217        if(this->controllableEntity_)
     218            this->controllableEntity_->boost(false);
    233219    }
    234220
  • code/trunk/src/orxonox/controllers/HumanController.h

    r9667 r9979  
    6565            static void reload();
    6666
    67             static void keepBoost(); // Static method, keeps boosting.
    68             /**
    69             @brief Check whether the HumanController is in boosting mode.
    70             @return Returns true if it is, false if not.
    71             */
    72             inline bool isBoosting(void)
    73                 { return this->boosting_; }
    74             void keepBoosting(void);
    75             void terminateBoosting(void);
     67            static void boost(const Vector2& value); // Static method, controls boosting.
     68            void startBoosting(void);
     69            void stopBoosting(void);
    7670
    7771
     
    107101            bool controlPaused_;
    108102
    109         private:
    110             bool boosting_; // Whether the HumanController is in boosting mode or not.
    111             Timer boostingTimeout_; // A timer to check whether the player is no longer boosting.
    112             static const float BOOSTING_TIME; // The time after it is checked, whether the player is no longer boosting.
    113 
    114103    }; // tolua_export
    115104} // tolua_export
Note: See TracChangeset for help on using the changeset viewer.