Optimize saving of max speed state in network

This commit is contained in:
Benau
2018-07-30 15:36:16 +08:00
parent 782e966fa5
commit a8434624a1
3 changed files with 17 additions and 13 deletions

View File

@@ -268,11 +268,18 @@ std::function<void()> KartRewinder::getLocalStateRestoreFunction()
steer_val_r = pc->m_steer_val_r;
}
// Max speed local state (terrain)
float current_fraction = m_max_speed->m_speed_decrease
[MaxSpeed::MS_DECREASE_TERRAIN].m_current_fraction;
float max_speed_fraction = m_max_speed->m_speed_decrease
[MaxSpeed::MS_DECREASE_TERRAIN].m_max_speed_fraction;
// 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, remaining_jump_time, this]()
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;
@@ -285,6 +292,10 @@ std::function<void()> KartRewinder::getLocalStateRestoreFunction()
pc->m_steer_val_l = steer_val_l;
pc->m_steer_val_r = steer_val_r;
}
m_max_speed->m_speed_decrease[MaxSpeed::MS_DECREASE_TERRAIN]
.m_current_fraction = current_fraction;
m_max_speed->m_speed_decrease[MaxSpeed::MS_DECREASE_TERRAIN]
.m_max_speed_fraction = max_speed_fraction;
m_skidding->m_remaining_jump_time = remaining_jump_time;
};
} // getLocalStateRestoreFunction

View File

@@ -363,14 +363,10 @@ void MaxSpeed::saveState(BareNetworkString *buffer) const
for(unsigned int i=MS_DECREASE_MIN, b=1; i<MS_DECREASE_MAX; i++, b <<= 1)
{
// Terrain slowodn is not fully stored in the state, since it can
// be computed from the raycast. But the current slowdown fraction
// must be stored (otherwise on a rewind the current slowdown would
// be start from 1.0 again).
if (i == MS_DECREASE_TERRAIN)
{
buffer->addFloat(m_speed_decrease[i].m_current_fraction);
buffer->addFloat(m_speed_decrease[i].m_max_speed_fraction);
// Handle in local state
continue;
}
else if (active_slowdown & b)
m_speed_decrease[i].saveState(buffer);
@@ -407,14 +403,10 @@ void MaxSpeed::rewindTo(BareNetworkString *buffer)
for(unsigned int i=MS_DECREASE_MIN, b=1; i<MS_DECREASE_MAX; i++, b <<= 1)
{
// Terrain slowodn is not fully stored in the state, since it can
// be computed from the raycast. But the current slowdown fraction
// must be stored (otherwise on a rewind the current slowdown would
// be start from 1.0 again).
if (i == MS_DECREASE_TERRAIN)
{
m_speed_decrease[i].m_current_fraction = buffer->getFloat();
m_speed_decrease[i].m_max_speed_fraction = buffer->getFloat();
// Handle in local state
continue;
}
else
m_speed_decrease[i].rewindTo(buffer, (active_slowdown & b) == b);

View File

@@ -26,6 +26,7 @@ class BareNetworkString;
class MaxSpeed
{
friend class KartRewinder;
public:
/** The categories to use for increasing the speed of a kart:
* Increase due to zipper, slipstream, nitro, rubber band,