Fixed shaking after collecting bubble gum (caused by restoring item state

after restorint kart state - during item state restoration items can
be 'collected', which overwrites kart states values that just had been
restored).
This commit is contained in:
hiker
2018-09-17 18:19:23 +10:00
parent 1291d2c0d3
commit 23acbf5260
2 changed files with 22 additions and 3 deletions

View File

@@ -1488,7 +1488,7 @@ void Kart::update(int ticks)
"v(16-18) %f %f %f steerf(20) %f maxangle(22) %f speed(24) %f "
"steering(26-27) %f %f clock(29) %lf skidstate(31) %d factor(33) %f "
"maxspeed(35) %f engf(37) %f braketick(39) %d brakes(41) %d heading(43) %f "
"noderot(45) %f suslen %f",
"bubticks(45) %d bubtor(47) %f",
getIdent().c_str(),
World::getWorld()->getTime(), World::getWorld()->getTicksSinceStart(),
getXYZ().getX(), getXYZ().getY(), getXYZ().getZ(),
@@ -1509,8 +1509,8 @@ void Kart::update(int ticks)
m_brake_ticks, //39
m_controls.getButtonsCompressed(), //41
getHeading(), //43
m_node->getAbsoluteTransformation().getRotationDegrees().Y, //45
m_vehicle->getWheelInfo(0).m_raycastInfo.m_suspensionLength
m_bubblegum_ticks, // 45
m_bubblegum_torque // 47
);
#endif
// After the physics step was done, the position of the wheels (as stored

View File

@@ -154,8 +154,27 @@ void RewindManager::saveState()
m_overall_state_size = 0;
std::vector<std::string> rewinder_using;
// We must save the item state first (so that it is restored first),
// otherwise state updates for a kart could be overwritten by
// e.g. simulating the item collection later (which resets bubblegum
// counter).
BareNetworkString* buffer = NULL;
if(auto r = m_all_rewinder["N"].lock())
buffer = r->saveState(&rewinder_using);
if (buffer)
{
m_overall_state_size += buffer->size();
gp->addState(buffer);
}
delete buffer; // buffer can be freed
for (auto& p : m_all_rewinder)
{
// The Network ItemManager was saved first before this loop,
// so skip it here.
if(p.first=="N") continue;
// TODO: check if it's worth passing in a sufficiently large buffer from
// GameProtocol - this would save the copy operation.
BareNetworkString* buffer = NULL;