Lag Compensation (Server-side rewind)

Implemented LagCompensationSystem

  • properties are registered the same way as other systems
  • when rewind is called, rewind all properties to the given timestamp
  • restore restores the state of objects before rewind
  • snapshots are recorded in net driver at fixed intervals

Exposed function to get RTT for connection in socket interface, called by developers using the net driver

Example object implementing lag compensation:

// Called after object creation
net::interpolation()->register_property(
    target,
    "set_position",
    net::config()->update_interval() * Target::interpolation_delay_ticks
);
// Function inside the object, called after receiving RPC from client on the server
bool rewound = false;
if (m_lag_comp_enabled)
{
const double rtt_seconds = net::driver()->get_rtt_seconds(from_id);
const double interpolation_delay_seconds = static_cast<double>(net::config()->update_interval()) * static_cast<double>(Target::interpolation_delay_ticks);

const double rewind_time = osi::timer()->passed_seconds() - rtt_seconds - interpolation_delay_seconds;
rewound = net::lag_compensation()->rewind(rewind_time);
}

// ...
// Hit detection logic
// ...

if (rewound)
{
    net::lag_compensation()->restore();
}

Merge request reports

Loading