From 884e966ab9a7ee1bb6a0f895a5e76285d24d4517 Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 5 Feb 2018 16:11:19 +1100 Subject: [PATCH] Added capability to handle setting the maximum speed first to 0, and then later to a higher value (which happens in overworld, which sets max speed to 0, but the value got later overwritten with the normal supertuxkart max_speed handling. --- .../Dynamics/btActionInterface.h | 2 +- .../Dynamics/btDiscreteDynamicsWorld.cpp | 6 ++++++ src/physics/btKart.cpp | 4 ++-- src/physics/btKart.hpp | 18 ++++++++++++++++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/bullet/src/BulletDynamics/Dynamics/btActionInterface.h b/lib/bullet/src/BulletDynamics/Dynamics/btActionInterface.h index e1fea3a49..910752402 100644 --- a/lib/bullet/src/BulletDynamics/Dynamics/btActionInterface.h +++ b/lib/bullet/src/BulletDynamics/Dynamics/btActionInterface.h @@ -39,7 +39,7 @@ public: virtual void updateAction( btCollisionWorld* collisionWorld, btScalar deltaTimeStep)=0; virtual void debugDraw(btIDebugDraw* debugDrawer) = 0; - + virtual void resetMaxSpeed() = 0; }; #endif //_BT_ACTION_INTERFACE_H diff --git a/lib/bullet/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp b/lib/bullet/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp index b006c67b1..a54e6d336 100644 --- a/lib/bullet/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp +++ b/lib/bullet/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp @@ -297,6 +297,12 @@ int btDiscreteDynamicsWorld::stepSimulation( btScalar timeStep,int maxSubSteps, } clearForces(); + // Reset the max speeds of all karts, so that supertuxkart can + // set any new max_speed. + for (int i = 0; iresetMaxSpeed(); + } #ifndef BT_NO_PROFILE CProfileManager::Increment_Frame_Counter(); diff --git a/src/physics/btKart.cpp b/src/physics/btKart.cpp index eefb8656c..34742a3a7 100644 --- a/src/physics/btKart.cpp +++ b/src/physics/btKart.cpp @@ -128,7 +128,7 @@ void btKart::reset() m_additional_rotation = btVector3(0,0,0); m_time_additional_rotation = 0; m_visual_rotation = 0; - m_max_speed = 9999.9f; + m_max_speed = -1.0f; m_min_speed = 0.0f; // Set the brakes so that karts don't slide downhill @@ -1056,7 +1056,7 @@ void btKart::adjustSpeed(btScalar min_speed, btScalar max_speed) m_chassisBody->setLinearVelocity(velocity * velocity_ratio); } } - else if (speed >0 && speed>max_speed) + else if (speed >0 && max_speed >= 0 && speed > max_speed) { const float velocity_ratio = max_speed / speed; m_chassisBody->setLinearVelocity(velocity * velocity_ratio); diff --git a/src/physics/btKart.hpp b/src/physics/btKart.hpp index b8c32d77b..4cb0e917e 100644 --- a/src/physics/btKart.hpp +++ b/src/physics/btKart.hpp @@ -129,7 +129,8 @@ private: * speed requested (in the next physics step). */ btScalar m_min_speed; - /** Maximum speed for the kart. */ + /** Maximum speed for the kart. It is reset to -1 at the end of each + * physics steps, so need to be set again by the application. */ btScalar m_max_speed; /** True if the visual wheels touch the ground. */ @@ -285,7 +286,20 @@ public: float getInstantSpeedIncrease() const { return m_zipper_speed; } // ------------------------------------------------------------------------ /** Sets the maximum speed for this kart. */ - void setMaxSpeed(float s) { m_max_speed = s; } + void setMaxSpeed(float new_max_speed) + { + // Only change m_max_speed if it has not been set (<0), or + // the new value is smaller than the current maximum. For example, + // overworld will set the max_speed to 0 in case of teleporting to + // a bubble, but set it again later (based on zipper etc activated). + // We need to make sure that the 0 is maintained. + if(m_max_speed <0 || m_max_speed > new_max_speed) + m_max_speed = new_max_speed; + } // setMaxSpeed + // ------------------------------------------------------------------------ + /** Resets the maximum so any new maximum value from the application will + * be accepted. */ + virtual void resetMaxSpeed() { m_max_speed = -1.0f; } // ------------------------------------------------------------------------ /** Sets the minimum speed for this kart. */ void setMinSpeed(float s) { m_min_speed = s; }