Fixed skidding in network mode. Only the jump duration is part of

the state, the current height of the kart in case of a jump is
then computed (without keeping track of speed etc). Jumping is
now only done during updateGraphics().
This commit is contained in:
hiker 2018-04-20 17:31:31 +10:00
parent c2b5e566c0
commit 4a0444987a
5 changed files with 50 additions and 45 deletions

View File

@ -124,7 +124,7 @@ void SkidMarks::update(float dt, bool force_skid_marks,
( force_skid_marks ||
( (skid->getSkidState()==Skidding::SKID_ACCUMULATE_LEFT||
skid->getSkidState()==Skidding::SKID_ACCUMULATE_RIGHT )
&& skid->getGraphicalJumpOffset()<=0
&& !skid->isJumping()
&& delta.length2()>=0.0001f ) );
if(m_skid_marking)

View File

@ -2428,9 +2428,9 @@ void Kart::updatePhysics(int ticks)
m_skidding->update(ticks, isOnGround(), m_controls.getSteer(),
m_controls.getSkidControl());
m_vehicle->setVisualRotation(m_skidding->getVisualSkidRotation());
if(( m_skidding->getSkidState() == Skidding::SKID_ACCUMULATE_LEFT ||
m_skidding->getSkidState() == Skidding::SKID_ACCUMULATE_RIGHT ) &&
m_skidding->getGraphicalJumpOffset()==0)
if( ( m_skidding->getSkidState() == Skidding::SKID_ACCUMULATE_LEFT ||
m_skidding->getSkidState() == Skidding::SKID_ACCUMULATE_RIGHT ) &&
!m_skidding->isJumping() )
{
if(m_skid_sound->getStatus()!=SFXBase::SFX_PLAYING && !isWheeless())
m_skid_sound->play(getXYZ());
@ -3011,9 +3011,9 @@ void Kart::updateGraphics(float dt)
Vec3 center_shift(0, 0, 0);
center_shift.setY(m_skidding->getGraphicalJumpOffset()
+ fabsf(lean_height)
+m_graphical_y_offset);
// Update the skidding jump height:
float jump_height = m_skidding->updateGraphics(dt);
center_shift.setY(jump_height + fabsf(lean_height) + m_graphical_y_offset);
center_shift = getTrans().getBasis() * center_shift;
float heading = m_skidding->getVisualSkidRotation();

View File

@ -370,7 +370,7 @@ void KartGFX::updateTerrain(const ParticleKind *pk)
const float skidding = m_kart->getSkidding()->getSkidFactor();
// Only create particles when the kart is actually on ground
bool on_ground = m_kart->isOnGround() &&
m_kart->getSkidding()->getGraphicalJumpOffset()==0;
!m_kart->getSkidding()->isJumping();
if (skidding > 1.0f && on_ground)
rate = fabsf(m_kart->getControls().getSteer()) > 0.8 ? skidding - 1 : 0;
else if (speed >= 0.5f && on_ground)

View File

@ -72,9 +72,7 @@ void Skidding::reset()
m_real_steering = 0.0f;
m_visual_rotation = 0.0f;
m_skid_bonus_ready = false;
m_gfx_jump_offset = 0.0f;
m_remaining_jump_time = 0.0f;
m_jump_speed = 0.0f;
m_kart->getKartGFX()->setCreationRateAbsolute(KartGFX::KGFX_SKIDL, 0);
m_kart->getKartGFX()->setCreationRateAbsolute(KartGFX::KGFX_SKIDR, 0);
m_kart->getKartGFX()->updateSkidLight(0);
@ -88,10 +86,11 @@ void Skidding::reset()
// ----------------------------------------------------------------------------
/** Save the skidding state of a kart. It only saves the important physics
* values, not visual only values like m_visual_rotation, m_gfx_jump_offset,
* m_remaining_jump_time and m_jump_speed. Similarly m_real_steering is output
* of updateRewind() and will be recomputed every frame when update() is called,
* and similart m_skid_bonus_ready
* values including m_remaining_jump_time (while this is mostly a graphical
* effect, ou ycan't skid while still doing a jump, so it does affect the
* staet), but not visual only values like m_visual_rotation. Similarly
* m_real_steering is output of updateRewind() and will be recomputed every
* frame when update() is called, and similar for m_skid_bonus_ready
* \param buffer Buffer for the state information.
*/
void Skidding::saveState(BareNetworkString *buffer)
@ -224,7 +223,38 @@ float Skidding::getSteeringWhenSkidding(float steering) const
} // getSteeringWhenSkidding
// ----------------------------------------------------------------------------
/** Updates skidding status.
/** Called once per rendered frame to potentially update the graphical jump
* height. The jump at the start of a skid is graphical only.
* \param dt Time step size.
* \return Current height of the jump.
*/
float Skidding::updateGraphics(float dt)
{
if (m_remaining_jump_time <= 0) return 0;
if (m_remaining_jump_time < 0)
{
m_remaining_jump_time = 0.0f;
return 0.0f;
}
const KartProperties *kp = m_kart->getKartProperties();
// At the beginning of the jump the speed is:
// v0 = 0.5 * gravity * full_jump_time
// and it is reduced by gravity. So:
// v(t) = v0 - t*gravity
// Therefore the height 't' seconds after start of the jump is:
// h(t) = v0*t - 0.5 * gravity *t^2
float gravity = Track::getCurrentTrack()->getGravity();
float v0 = 0.5f * gravity * kp->getSkidGraphicalJumpTime();
float jump_time = kp->getSkidGraphicalJumpTime()
- m_remaining_jump_time;
return v0 * jump_time - 0.5f * gravity * jump_time * jump_time;
} // updateGraphics
// ----------------------------------------------------------------------------
/** Updates skidding status.
* \param ticks Number of physics time steps - should be 1.
* \param is_on_ground True if the kart is on ground.
* \param steering Raw steering of the kart [-1,1], i.e. not adjusted by
@ -236,6 +266,8 @@ void Skidding::update(int ticks, bool is_on_ground,
{
float dt = stk_config->ticks2Time(ticks);
m_remaining_jump_time -= dt;
const KartProperties *kp = m_kart->getKartProperties();
// If a kart animation is shown, stop all skidding bonuses.
@ -285,19 +317,6 @@ void Skidding::update(int ticks, bool is_on_ground,
else
if (m_skid_factor < 1.0f) m_skid_factor = 1.0f;
// If skidding was started and a graphical jump should still
// be displayed, update the data
if(m_remaining_jump_time>0)
{
m_jump_speed -= Track::getCurrentTrack()->getGravity()*dt;
m_gfx_jump_offset += m_jump_speed * dt;
m_remaining_jump_time -= dt;
if(m_remaining_jump_time<0)
{
m_remaining_jump_time = 0.0f;
m_gfx_jump_offset = 0.0f;
}
}
// This is only reached if the new skidding is enabled
// ---------------------------------------------------
@ -347,8 +366,6 @@ void Skidding::update(int ticks, bool is_on_ground,
m_kart->getVehicle()->getRigidBody()->applyCentralImpulse(imp);
// Some karts might use a graphical-only jump. Set it up:
m_jump_speed = Track::getCurrentTrack()->getGravity()
* 0.5f * kp->getSkidGraphicalJumpTime();
m_remaining_jump_time = kp->getSkidGraphicalJumpTime();
#ifdef SKID_DEBUG

View File

@ -65,14 +65,6 @@ private:
/** Set to >0 when a graphical jump is to be done. */
float m_remaining_jump_time;
/** A vertical offset used to make the kart do a graphical 'jump' when
* skidding is started. */
float m_gfx_jump_offset;
/** Keeps track of a graphical jump speed (which simulates the physics,
* i.e. gravity is used to reduce the jump speed. */
float m_jump_speed;
public:
/** SKID_NONE: Kart is currently not skidding.
* SKID_ACCUMULATE_LEFT: Kart is skidding to the left and accumulating
@ -104,6 +96,7 @@ public:
Skidding(Kart *kart);
~Skidding();
void reset();
float updateGraphics(float dt);
void update(int dt, bool is_on_ground, float steer,
KartControl::SkidControl skidding);
void saveState(BareNetworkString *buffer);
@ -124,12 +117,6 @@ public:
* a fraction of the maximum steering angle ( so in [-1, 1]). */
float getSteeringFraction() { return m_real_steering; }
// ------------------------------------------------------------------------
/** Returns an additional height offset that is used to show a graphical
* jump when a skid starts. So when this is >0 the wheels appear not to
* touch the ground (though in reality the physical kart does, but also
* see physical jumping implemented in this object). */
float getGraphicalJumpOffset() const { return m_gfx_jump_offset; }
// ------------------------------------------------------------------------
/** Returns the skidding state. */
SkidState getSkidState() const { return m_skid_state; }
// ------------------------------------------------------------------------
@ -139,7 +126,8 @@ public:
* stopped skidding now. This function returns false if the kart is
* actually using the skid bonus. */
bool getSkidBonusReady() const { return m_skid_bonus_ready; }
// ------------------------------------------------------------------------
bool isJumping() const { return m_remaining_jump_time > 0; }
}; // Skidding