Split slipstream instant speed update for better rewind

This commit is contained in:
Benau 2018-10-24 14:29:44 +08:00
parent 2a4c5ad557
commit d3db5d8808
3 changed files with 25 additions and 27 deletions

View File

@ -44,6 +44,7 @@
*/
SlipStream::SlipStream(AbstractKart* kart)
{
m_speed_increase_ticks = m_speed_increase_duration = -1;
m_kart = kart;
m_moving = NULL;
m_moving_fast = NULL;
@ -215,7 +216,7 @@ void SlipStream::reset()
m_slipstream_mode = SS_NONE;
m_slipstream_time = 0;
m_bonus_time = 0;
m_speed_increase_ticks = m_speed_increase_duration = -1;
// Reset a potential max speed increase
m_kart->increaseMaxSpeed(MaxSpeed::MS_INCREASE_SLIPSTREAM, 0, 0, 0, 0);
} // reset
@ -827,28 +828,8 @@ void SlipStream::update(int ticks)
m_slipstream_time = 0.0f;
m_bonus_active = true;
float speed_increase = kp->getSlipstreamMaxSpeedIncrease();
float add_power = kp->getSlipstreamAddPower();
int duration = stk_config->time2Ticks(m_bonus_time);
int fade_out = kp->getSlipstreamFadeOutTicks();
m_kart->instantSpeedIncrease(
MaxSpeed::MS_INCREASE_SLIPSTREAM, speed_increase,
speed_increase, add_power, duration, fade_out);
if (RewindManager::get()->useLocalEvent())
{
AbstractKart* kart = m_kart;
RewindManager::get()->addRewindInfoEventFunction(new
RewindInfoEventFunction(
World::getWorld()->getTicksSinceStart(),
[](){},
[kart, speed_increase, add_power, duration, fade_out]()
{
kart->instantSpeedIncrease(
MaxSpeed::MS_INCREASE_SLIPSTREAM, speed_increase,
speed_increase, add_power, duration, fade_out);
}));
}
m_speed_increase_duration = stk_config->time2Ticks(m_bonus_time);
m_speed_increase_ticks = World::getWorld()->getTicksSinceStart();
}
if(!is_sstreaming)
@ -913,3 +894,18 @@ void SlipStream::update(int ticks)
#endif
m_slipstream_mode = SS_COLLECT;
} // update
// ----------------------------------------------------------------------------
void SlipStream::updateSpeedIncrease()
{
if (m_speed_increase_ticks == World::getWorld()->getTicksSinceStart())
{
const KartProperties* kp = m_kart->getKartProperties();
float speed_increase = kp->getSlipstreamMaxSpeedIncrease();
float add_power = kp->getSlipstreamAddPower();
int fade_out = kp->getSlipstreamFadeOutTicks();
m_kart->instantSpeedIncrease(
MaxSpeed::MS_INCREASE_SLIPSTREAM, speed_increase,
speed_increase, add_power, m_speed_increase_duration, fade_out);
}
} // updateSpeedIncrease

View File

@ -94,7 +94,8 @@ private:
int m_current_target_id;
int m_previous_target_id;
int m_speed_increase_ticks;
int m_speed_increase_duration;
/** Slipstream mode: either nothing happening, or the kart is collecting
* 'slipstream credits'. Credits can be accumulated while the bonus is used */
@ -121,11 +122,11 @@ private:
void updateBonusTexture();
public:
SlipStream (AbstractKart* kart);
virtual ~SlipStream ();
~SlipStream ();
void reset();
virtual void update(int ticks);
void update(int ticks);
bool isSlipstreamReady() const;
void updateSpeedIncrease();
// ------------------------------------------------------------------------
/** Returns the quad in which slipstreaming is effective for
* this kart. */

View File

@ -1463,6 +1463,7 @@ void Kart::update(int ticks)
if (!RewindManager::get()->isRewinding())
m_slipstream->update(ticks);
m_slipstream->updateSpeedIncrease();
// TODO: hiker said this probably will be moved to btKart or so when updating bullet engine.
// Neutralize any yaw change if the kart leaves the ground, so the kart falls more or less