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.
This commit is contained in:
hiker 2018-02-05 16:11:19 +11:00
parent baa0677b1a
commit 884e966ab9
4 changed files with 25 additions and 5 deletions

View File

@ -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

View File

@ -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; i<m_actions.size(); i++)
{
m_actions[i]->resetMaxSpeed();
}
#ifndef BT_NO_PROFILE
CProfileManager::Increment_Frame_Counter();

View File

@ -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);

View File

@ -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; }