Improve kart kart collision in network

This commit is contained in:
Benau 2018-07-31 01:14:02 +08:00
parent 4ec8a33f8c
commit d203239aa2
4 changed files with 23 additions and 9 deletions

View File

@ -2440,8 +2440,8 @@ void Kart::updatePhysics(int ticks)
/*fade_out_time*/stk_config->time2Ticks(5.0f)); /*fade_out_time*/stk_config->time2Ticks(5.0f));
} }
} }
if (m_bounce_back_ticks > std::numeric_limits<int16_t>::min())
m_bounce_back_ticks-=ticks; m_bounce_back_ticks -= ticks;
updateEnginePowerAndBrakes(ticks); updateEnginePowerAndBrakes(ticks);

View File

@ -157,7 +157,7 @@ protected:
/** A short time after a collision acceleration is disabled to allow /** A short time after a collision acceleration is disabled to allow
* the karts to bounce back*/ * the karts to bounce back*/
int m_bounce_back_ticks; int16_t m_bounce_back_ticks;
/** Time a kart is invulnerable. */ /** Time a kart is invulnerable. */
int16_t m_invulnerable_ticks; int16_t m_invulnerable_ticks;

View File

@ -125,6 +125,11 @@ BareNetworkString* KartRewinder::saveState(std::vector<std::string>* ru)
buffer->add(m_vehicle->getTimedRotation()); buffer->add(m_vehicle->getTimedRotation());
buffer->addUInt8(m_vehicle->getCushioningDisableTime()); 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 // 2) Steering and other player controls
// ------------------------------------- // -------------------------------------
getControls().saveState(buffer); getControls().saveState(buffer);
@ -193,7 +198,14 @@ void KartRewinder::restoreState(BareNetworkString *buffer, int count)
// Set timed rotation divides by time_rot // Set timed rotation divides by time_rot
m_vehicle->setTimedRotation(time_rot, time_rot*buffer->getVec3()); m_vehicle->setTimedRotation(time_rot, time_rot*buffer->getVec3());
m_vehicle->setCushioningDisableTime(buffer->getUInt8()); 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 // For the raycast to determine the current material under the kart
// the m_hardPointWS of the wheels is used. So after a rewind we // the m_hardPointWS of the wheels is used. So after a rewind we
// must restore the m_hardPointWS to the new values, otherwise they // 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 // Variable can be saved locally if its adjustment only depends on the kart
// itself // itself
bool has_started = m_has_started; bool has_started = m_has_started;
int bounce_back_ticks = m_bounce_back_ticks;
int brake_ticks = m_brake_ticks; int brake_ticks = m_brake_ticks;
int8_t min_nitro_ticks = m_min_nitro_ticks; int8_t min_nitro_ticks = m_min_nitro_ticks;
@ -277,12 +288,11 @@ std::function<void()> KartRewinder::getLocalStateRestoreFunction()
// Skidding local state // Skidding local state
float remaining_jump_time = m_skidding->m_remaining_jump_time; 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, initial_speed, steer_val_l, steer_val_r, current_fraction,
max_speed_fraction, remaining_jump_time, this]() max_speed_fraction, remaining_jump_time, this]()
{ {
m_has_started = has_started; m_has_started = has_started;
m_bounce_back_ticks = bounce_back_ticks;
m_brake_ticks = brake_ticks; m_brake_ticks = brake_ticks;
m_min_nitro_ticks = min_nitro_ticks; m_min_nitro_ticks = min_nitro_ticks;
getAttachment()->setInitialSpeed(initial_speed); getAttachment()->setInitialSpeed(initial_speed);

View File

@ -223,10 +223,11 @@ public:
/** Sets an impulse that is applied for a certain amount of time. /** Sets an impulse that is applied for a certain amount of time.
* \param t Time for the impulse to be active. * \param t Time for the impulse to be active.
* \param imp The impulse to apply. */ * \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. // 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_additional_impulse = imp;
m_time_additional_impulse = t; m_time_additional_impulse = t;
} // setTimedImpulse } // setTimedImpulse
@ -234,6 +235,9 @@ public:
/** Returns the time an additional impulse is activated. */ /** Returns the time an additional impulse is activated. */
float getCentralImpulseTime() const { return m_time_additional_impulse; } 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 /** Sets a rotation that is applied over a certain amount of time (to avoid
* a too rapid changes in the kart). * a too rapid changes in the kart).
* \param t Time for the rotation to be applied. * \param t Time for the rotation to be applied.