Improve kart kart collision in network
This commit is contained in:
parent
4ec8a33f8c
commit
d203239aa2
@ -2440,7 +2440,7 @@ void Kart::updatePhysics(int ticks)
|
||||
/*fade_out_time*/stk_config->time2Ticks(5.0f));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_bounce_back_ticks > std::numeric_limits<int16_t>::min())
|
||||
m_bounce_back_ticks -= ticks;
|
||||
|
||||
updateEnginePowerAndBrakes(ticks);
|
||||
|
@ -157,7 +157,7 @@ protected:
|
||||
|
||||
/** A short time after a collision acceleration is disabled to allow
|
||||
* the karts to bounce back*/
|
||||
int m_bounce_back_ticks;
|
||||
int16_t m_bounce_back_ticks;
|
||||
|
||||
/** Time a kart is invulnerable. */
|
||||
int16_t m_invulnerable_ticks;
|
||||
|
@ -125,6 +125,11 @@ BareNetworkString* KartRewinder::saveState(std::vector<std::string>* ru)
|
||||
buffer->add(m_vehicle->getTimedRotation());
|
||||
buffer->addUInt8(m_vehicle->getCushioningDisableTime());
|
||||
|
||||
// For collision rewind
|
||||
buffer->addUInt16(m_bounce_back_ticks);
|
||||
buffer->addFloat(m_vehicle->getCentralImpulseTime());
|
||||
buffer->add(m_vehicle->getAdditionalImpulse());
|
||||
|
||||
// 2) Steering and other player controls
|
||||
// -------------------------------------
|
||||
getControls().saveState(buffer);
|
||||
@ -194,6 +199,13 @@ void KartRewinder::restoreState(BareNetworkString *buffer, int count)
|
||||
m_vehicle->setTimedRotation(time_rot, time_rot*buffer->getVec3());
|
||||
m_vehicle->setCushioningDisableTime(buffer->getUInt8());
|
||||
|
||||
// Collision rewind
|
||||
m_bounce_back_ticks = buffer->getUInt16();
|
||||
float central_impulse_time = buffer->getFloat();
|
||||
Vec3 additional_impulse = buffer->getVec3();
|
||||
m_vehicle->setTimedCentralImpulse(central_impulse_time,
|
||||
additional_impulse, true/*rewind*/);
|
||||
|
||||
// For the raycast to determine the current material under the kart
|
||||
// the m_hardPointWS of the wheels is used. So after a rewind we
|
||||
// must restore the m_hardPointWS to the new values, otherwise they
|
||||
@ -251,7 +263,6 @@ std::function<void()> KartRewinder::getLocalStateRestoreFunction()
|
||||
// Variable can be saved locally if its adjustment only depends on the kart
|
||||
// itself
|
||||
bool has_started = m_has_started;
|
||||
int bounce_back_ticks = m_bounce_back_ticks;
|
||||
int brake_ticks = m_brake_ticks;
|
||||
int8_t min_nitro_ticks = m_min_nitro_ticks;
|
||||
|
||||
@ -277,12 +288,11 @@ std::function<void()> KartRewinder::getLocalStateRestoreFunction()
|
||||
// Skidding local state
|
||||
float remaining_jump_time = m_skidding->m_remaining_jump_time;
|
||||
|
||||
return [has_started, bounce_back_ticks, brake_ticks, min_nitro_ticks,
|
||||
return [has_started, brake_ticks, min_nitro_ticks,
|
||||
initial_speed, steer_val_l, steer_val_r, current_fraction,
|
||||
max_speed_fraction, remaining_jump_time, this]()
|
||||
{
|
||||
m_has_started = has_started;
|
||||
m_bounce_back_ticks = bounce_back_ticks;
|
||||
m_brake_ticks = brake_ticks;
|
||||
m_min_nitro_ticks = min_nitro_ticks;
|
||||
getAttachment()->setInitialSpeed(initial_speed);
|
||||
|
@ -223,10 +223,11 @@ public:
|
||||
/** Sets an impulse that is applied for a certain amount of time.
|
||||
* \param t Time for the impulse to be active.
|
||||
* \param imp The impulse to apply. */
|
||||
void setTimedCentralImpulse(float t, const btVector3 &imp)
|
||||
void setTimedCentralImpulse(float t, const btVector3 &imp,
|
||||
bool rewind = false)
|
||||
{
|
||||
// Only add impulse if no other impulse is active.
|
||||
if(m_time_additional_impulse>0) return;
|
||||
if (m_time_additional_impulse > 0 && !rewind) return;
|
||||
m_additional_impulse = imp;
|
||||
m_time_additional_impulse = t;
|
||||
} // setTimedImpulse
|
||||
@ -234,6 +235,9 @@ public:
|
||||
/** Returns the time an additional impulse is activated. */
|
||||
float getCentralImpulseTime() const { return m_time_additional_impulse; }
|
||||
// ------------------------------------------------------------------------
|
||||
const btVector3& getAdditionalImpulse() const
|
||||
{ return m_additional_impulse; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets a rotation that is applied over a certain amount of time (to avoid
|
||||
* a too rapid changes in the kart).
|
||||
* \param t Time for the rotation to be applied.
|
||||
|
Loading…
Reference in New Issue
Block a user