Added the cushioning time to the network state (to be decided later

if local state might be good enough).
This commit is contained in:
hiker 2018-07-26 21:47:05 +10:00
parent b12205332c
commit f8acc1ad49
3 changed files with 19 additions and 3 deletions

View File

@ -123,6 +123,7 @@ BareNetworkString* KartRewinder::saveState(std::vector<std::string>* ru)
buffer->addFloat(m_vehicle->getMinSpeed());
buffer->addFloat(m_vehicle->getTimedRotationTime());
buffer->add(m_vehicle->getTimedRotation());
buffer->addUInt8(m_vehicle->getCushioningDisableTime());
// 2) Steering and other player controls
// -------------------------------------
@ -189,6 +190,8 @@ void KartRewinder::restoreState(BareNetworkString *buffer, int count)
float time_rot = buffer->getFloat();
// Set timed rotation divides by time_rot
m_vehicle->setTimedRotation(time_rot, time_rot*buffer->getVec3());
m_vehicle->setCushioningDisableTime(buffer->getUInt8());
// 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

View File

@ -514,7 +514,7 @@ void btKart::updateVehicle( btScalar step )
// not be strong enough to prevent the chassis from hitting the ground.
// Try to detect this upcoming crash, and apply an upward impulse if
// necessary that will slow down the falling speed.
m_cushioning_disable_time --;
if(m_cushioning_disable_time>0) m_cushioning_disable_time --;
bool needed_cushioning = false;
btVector3 v =
@ -543,7 +543,7 @@ void btKart::updateVehicle( btScalar step )
// predict the upcoming collision correcty - so we add an offset
// to the predicted kart movement, which was found experimentally:
btScalar gravity = m_chassisBody->getGravity().length();
if (v_down.getY()<0 && m_cushioning_disable_time <=0 &&
if (v_down.getY()<0 && m_cushioning_disable_time==0 &&
m_wheelInfo[wheel_index].m_raycastInfo.m_suspensionLength
< step * (-v_down.getY()+gravity*step)+offset)
{

15
src/physics/btKart.hpp Executable file → Normal file
View File

@ -94,7 +94,7 @@ private:
int m_num_wheels_on_ground;
/** Number of time steps during which cushioning is disabled. */
int m_cushioning_disable_time;
unsigned int m_cushioning_disable_time;
/** Index of the right axis. */
int m_indexRightAxis;
@ -248,6 +248,19 @@ public:
// ------------------------------------------------------------------------
float getTimedRotationTime() const { return m_time_additional_rotation; }
// ------------------------------------------------------------------------
/** Returns the time cushioning is disabled. Used for networking state
* saving. */
unsigned int getCushioningDisableTime() const
{
return m_cushioning_disable_time;
} // getCushioningDisableTime
// ------------------------------------------------------------------------
/** Sets the cushioning disable time. Used for networking state saving. */
void setCushioningDisableTime(unsigned int cdt)
{
m_cushioning_disable_time = cdt;
} // setCushioningDisableTime
// ------------------------------------------------------------------------
/** Sets the maximum speed for this kart. */
void setMaxSpeed(float new_max_speed)
{