[Orxonox-commit 5316] r9979 - code/trunk/src/orxonox/controllers

landauf at orxonox.net landauf at orxonox.net
Sat Jan 4 21:53:50 CET 2014


Author: landauf
Date: 2014-01-04 21:53:50 +0100 (Sat, 04 Jan 2014)
New Revision: 9979

Modified:
   code/trunk/src/orxonox/controllers/HumanController.cc
   code/trunk/src/orxonox/controllers/HumanController.h
Log:
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

Modified: code/trunk/src/orxonox/controllers/HumanController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/HumanController.cc	2014-01-04 20:48:04 UTC (rev 9978)
+++ code/trunk/src/orxonox/controllers/HumanController.cc	2014-01-04 20:53:50 UTC (rev 9979)
@@ -41,7 +41,6 @@
 {
     extern const std::string __CC_fire_name = "fire";
     extern const std::string __CC_suicide_name = "suicide";
-    const std::string __CC_boost_name = "boost";
 
     SetConsoleCommand("HumanController", "moveFrontBack",          &HumanController::moveFrontBack ).addShortcut().setAsInputCommand();
     SetConsoleCommand("HumanController", "moveRightLeft",          &HumanController::moveRightLeft ).addShortcut().setAsInputCommand();
@@ -50,10 +49,10 @@
     SetConsoleCommand("HumanController", "rotatePitch",            &HumanController::rotatePitch   ).addShortcut().setAsInputCommand();
     SetConsoleCommand("HumanController", "rotateRoll",             &HumanController::rotateRoll    ).addShortcut().setAsInputCommand();
     SetConsoleCommand("HumanController", "toggleFormationFlight",  &HumanController::toggleFormationFlight).addShortcut().keybindMode(KeybindMode::OnPress);
-    SetConsoleCommand("HumanController", "FFChangeMode",  &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress);
+    SetConsoleCommand("HumanController", "FFChangeMode",           &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress);
     SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
     SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
-    SetConsoleCommand("HumanController", __CC_boost_name,          &HumanController::keepBoost     ).addShortcut().keybindMode(KeybindMode::OnHold);
+    SetConsoleCommand("HumanController", "boost",                  &HumanController::boost         ).addShortcut().setAsInputCommand().keybindMode(KeybindMode::OnPressAndRelease);
     SetConsoleCommand("HumanController", "greet",                  &HumanController::greet         ).addShortcut();
     SetConsoleCommand("HumanController", "switchCamera",           &HumanController::switchCamera  ).addShortcut();
     SetConsoleCommand("HumanController", "mouseLook",              &HumanController::mouseLook     ).addShortcut();
@@ -68,18 +67,13 @@
     RegisterUnloadableClass(HumanController);
 
     HumanController* HumanController::localController_s = 0;
-    /*static*/ const float HumanController::BOOSTING_TIME = 0.1f;
 
     HumanController::HumanController(Context* context) : FormationController(context)
     {
         RegisterObject(HumanController);
 
         this->controlPaused_ = false;
-        this->boosting_ = false;
-        this->boosting_ = false;
         HumanController::localController_s = this;
-        this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this)));
-        this->boostingTimeout_.stopTimer();
     }
 
     HumanController::~HumanController()
@@ -189,47 +183,39 @@
 
     /**
     @brief
-        Static method,keeps boosting.
+        Static method, controls boosting.
     */
-    /*static*/ void HumanController::keepBoost()
+    /*static*/ void HumanController::boost(const Vector2& value)
     {
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
-            HumanController::localController_s->keepBoosting();
+        {
+            float abs = value.x;
+            if (abs > 0)
+                HumanController::localController_s->startBoosting();
+            else
+                HumanController::localController_s->stopBoosting();
+        }
     }
 
     /**
     @brief
-        Starts, or keeps the boosting mode.
+        Starts the boosting mode.
         Resets the boosting timeout and ells the ControllableEntity to boost (or not boost anymore).
     */
-    void HumanController::keepBoosting(void)
+    void HumanController::startBoosting(void)
     {
-        if(this->boostingTimeout_.isActive())
-        {
-            this->boostingTimeout_.stopTimer();
-            this->boostingTimeout_.startTimer();
-        }
-        else
-        {
-            this->boosting_ = true;
-            this->boostingTimeout_.startTimer();
-            if(this->controllableEntity_)
-                this->controllableEntity_->boost(this->boosting_);
-//            orxout() << "Start boosting" << endl;
-        }
+        if(this->controllableEntity_)
+            this->controllableEntity_->boost(true);
     }
 
     /**
     @brief
-        Terminates the boosting mode.
+        Stops the boosting mode.
     */
-    void HumanController::terminateBoosting(void)
+    void HumanController::stopBoosting(void)
     {
-        this->boosting_ = false;
-        this->boostingTimeout_.stopTimer();
         if(this->controllableEntity_)
-            this->controllableEntity_->boost(this->boosting_);
-//        orxout() << "Stop boosting" << endl;
+            this->controllableEntity_->boost(false);
     }
 
     void HumanController::greet()

Modified: code/trunk/src/orxonox/controllers/HumanController.h
===================================================================
--- code/trunk/src/orxonox/controllers/HumanController.h	2014-01-04 20:48:04 UTC (rev 9978)
+++ code/trunk/src/orxonox/controllers/HumanController.h	2014-01-04 20:53:50 UTC (rev 9979)
@@ -64,15 +64,9 @@
             virtual void doFire(unsigned int firemode);
             static void reload();
 
-            static void keepBoost(); // Static method, keeps boosting.
-            /**
-            @brief Check whether the HumanController is in boosting mode.
-            @return Returns true if it is, false if not.
-            */
-            inline bool isBoosting(void)
-                { return this->boosting_; }
-            void keepBoosting(void);
-            void terminateBoosting(void);
+            static void boost(const Vector2& value); // Static method, controls boosting.
+            void startBoosting(void);
+            void stopBoosting(void);
 
 
             static void greet();
@@ -106,11 +100,6 @@
             static HumanController* localController_s;
             bool controlPaused_;
 
-        private:
-            bool boosting_; // Whether the HumanController is in boosting mode or not.
-            Timer boostingTimeout_; // A timer to check whether the player is no longer boosting.
-            static const float BOOSTING_TIME; // The time after it is checked, whether the player is no longer boosting.
-
     }; // tolua_export
 } // tolua_export
 




More information about the Orxonox-commit mailing list