diff --git a/src/karts/kart_rewinder.cpp b/src/karts/kart_rewinder.cpp index 135059b92..69d98ab28 100644 --- a/src/karts/kart_rewinder.cpp +++ b/src/karts/kart_rewinder.cpp @@ -268,8 +268,11 @@ std::function KartRewinder::getLocalStateRestoreFunction() steer_val_r = pc->m_steer_val_r; } + // Skidding local state + float remaining_jump_time = m_skidding->m_remaining_jump_time; + return [has_started, bounce_back_ticks, brake_ticks, min_nitro_ticks, - initial_speed, steer_val_l, steer_val_r, this]() + initial_speed, steer_val_l, steer_val_r, remaining_jump_time, this]() { m_has_started = has_started; m_bounce_back_ticks = bounce_back_ticks; @@ -282,5 +285,6 @@ std::function KartRewinder::getLocalStateRestoreFunction() pc->m_steer_val_l = steer_val_l; pc->m_steer_val_r = steer_val_r; } + m_skidding->m_remaining_jump_time = remaining_jump_time; }; } // getLocalStateRestoreFunction diff --git a/src/karts/skidding.cpp b/src/karts/skidding.cpp index 63279198e..7e516c3ea 100644 --- a/src/karts/skidding.cpp +++ b/src/karts/skidding.cpp @@ -67,7 +67,7 @@ Skidding::~Skidding() */ void Skidding::reset() { - m_skid_time = 0.0f; + m_skid_time = 0; m_skid_state = SKID_NONE; m_skid_factor = 1.0f; m_real_steering = 0.0f; @@ -101,8 +101,7 @@ void Skidding::reset() void Skidding::saveState(BareNetworkString *buffer) { buffer->addUInt8(m_skid_state); - buffer->addFloat(m_remaining_jump_time); - buffer->addFloat(m_skid_time); + buffer->addUInt16(m_skid_time); buffer->addFloat(m_skid_factor); buffer->addFloat(m_visual_rotation); } // saveState @@ -114,8 +113,7 @@ void Skidding::saveState(BareNetworkString *buffer) void Skidding::rewindTo(BareNetworkString *buffer) { m_skid_state = (SkidState)buffer->getUInt8(); - m_remaining_jump_time = buffer->getFloat(); - m_skid_time = buffer->getFloat(); + m_skid_time = buffer->getUInt16(); m_skid_factor = buffer->getFloat(); m_visual_rotation = buffer->getFloat(); } // rewindTo @@ -146,9 +144,11 @@ void Skidding::checkSmoothing() * kart skids either left or right, the steering fraction is bound by * reduce-turn-min and reduce-turn-max. */ -float Skidding::updateSteering(float steer, float dt) +float Skidding::updateSteering(float steer, int ticks) { - float steer_result; + float dt = stk_config->ticks2Time(ticks); + float skid_time_float = stk_config->ticks2Time(m_skid_time); + float steer_result = 0.0f; const KartProperties *kp = m_kart->getKartProperties(); @@ -158,9 +158,10 @@ float Skidding::updateSteering(float steer, float dt) case SKID_SHOW_GFX_RIGHT: case SKID_NONE: steer_result = steer; - if (m_skid_time < kp->getSkidVisualTime() && m_skid_time > 0) + if (skid_time_float < kp->getSkidVisualTime() && + skid_time_float > 0) { - float f = m_visual_rotation - m_visual_rotation*dt/m_skid_time; + float f = m_visual_rotation - m_visual_rotation*dt/skid_time_float; // Floating point errors when m_skid_time is very close to 0 // can result in visual rotation set to a large number if( (f<0 && m_visual_rotation>0 ) || @@ -184,9 +185,9 @@ float Skidding::updateSteering(float steer, float dt) float f = (1.0f+steer)*0.5f; // map [-1,1] --> [0, 1] steer_result = kp->getSkidReduceTurnMin() + m_skid_reduce_turn_delta * f; - if(m_skid_time < kp->getSkidVisualTime()) + if(skid_time_float < kp->getSkidVisualTime()) m_visual_rotation = kp->getSkidVisual() - * steer_result * m_skid_time + * steer_result * skid_time_float / kp->getSkidVisualTime(); else m_visual_rotation = kp->getSkidVisual() * steer_result; @@ -197,9 +198,9 @@ float Skidding::updateSteering(float steer, float dt) float f = (-1.0f+steer)*0.5f; // map [-1,1] --> [-1, 0] steer_result = -kp->getSkidReduceTurnMin() + m_skid_reduce_turn_delta * f; - if(m_skid_time < kp->getSkidVisualTime()) + if(skid_time_float < kp->getSkidVisualTime()) m_visual_rotation = kp->getSkidVisual() - * steer_result * m_skid_time + * steer_result * skid_time_float / kp->getSkidVisualTime(); else m_visual_rotation = kp->getSkidVisual() * steer_result; @@ -466,7 +467,7 @@ void Skidding::update(int ticks, bool is_on_ground, m_real_steering, m_kart->getSpeed(), m_kart->getMaxSteerAngle(m_kart->getSpeed())); #endif - m_skid_time += dt; + m_skid_time += ticks; float bonus_time, bonus_speed, bonus_force; unsigned int level = getSkidBonus(&bonus_time, &bonus_speed, &bonus_force); @@ -488,13 +489,14 @@ void Skidding::update(int ticks, bool is_on_ground, m_skid_state = m_skid_state == SKID_ACCUMULATE_LEFT ? SKID_SHOW_GFX_LEFT : SKID_SHOW_GFX_RIGHT; - float t = std::min(m_skid_time, kp->getSkidVisualTime()); + float skid_time_float = stk_config->ticks2Time(m_skid_time); + float t = std::min(skid_time_float, kp->getSkidVisualTime()); t = std::min(t, kp->getSkidRevertVisualTime()); btVector3 rot(0, m_visual_rotation * kp->getSkidPostSkidRotateFactor(), 0); m_kart->getVehicle()->setTimedRotation(t, rot); // skid_time is used to count backwards for the GFX - m_skid_time = t; + m_skid_time = stk_config->time2Ticks(t); if(bonus_time>0) { m_kart->getKartGFX() @@ -525,10 +527,10 @@ void Skidding::update(int ticks, bool is_on_ground, } // case case SKID_SHOW_GFX_LEFT: case SKID_SHOW_GFX_RIGHT: - m_skid_time -= dt; - if(m_skid_time<=0) + if (m_skid_time > 0) + m_skid_time -= ticks; + if (m_skid_time == 0) { - m_skid_time = 0; m_kart->getKartGFX() ->setCreationRateAbsolute(KartGFX::KGFX_SKIDL, 0); m_kart->getKartGFX() @@ -538,7 +540,7 @@ void Skidding::update(int ticks, bool is_on_ground, } } // switch - m_real_steering = updateSteering(steering, dt); + m_real_steering = updateSteering(steering, ticks); } // update // ---------------------------------------------------------------------------- @@ -560,7 +562,8 @@ unsigned int Skidding::getSkidBonus(float *bonus_time, *bonus_force = 0; for (unsigned int i = 0; i < kp->getSkidBonusSpeed().size(); i++) { - if (m_skid_time <= kp->getSkidTimeTillBonus()[i]) + if (stk_config->ticks2Time(m_skid_time) <= + kp->getSkidTimeTillBonus()[i]) return i; *bonus_speed = kp->getSkidBonusSpeed()[i]; *bonus_time = kp->getSkidBonusTime()[i]; diff --git a/src/karts/skidding.hpp b/src/karts/skidding.hpp index 80024bb61..b7aaced0d 100644 --- a/src/karts/skidding.hpp +++ b/src/karts/skidding.hpp @@ -37,6 +37,7 @@ class ShowCurve; class Skidding { +friend class KartRewinder; public: LEAK_CHECK(); private: @@ -56,7 +57,7 @@ private: /** Keeps track on how long a kart has been skidding, in order to * trigger the skidding bonus. */ - float m_skid_time; + uint16_t m_skid_time; /** True if the kart has skidded long enough to get a skid bonus if it * stopped skidding now. */ @@ -99,7 +100,7 @@ private: unsigned int getSkidBonus(float *bonus_time, float *bonus_speed, float *bonus_force) const; - float updateSteering(float steer, float dt); + float updateSteering(float steer, int ticks); public: Skidding(Kart *kart); ~Skidding();