NetworkTransformUnreliable: UpdateClientInterpolation helper function

This commit is contained in:
vis2k 2023-03-14 17:17:33 +08:00
parent 6e142d8cc0
commit 5f1ec83cca

View File

@ -227,6 +227,26 @@ void UpdateClientBroadcast()
} }
} }
void UpdateClientInterpolation()
{
// only while we have snapshots
if (clientSnapshots.Count > 0)
{
// step the interpolation without touching time.
// NetworkClient is responsible for time globally.
SnapshotInterpolation.StepInterpolation(
clientSnapshots,
NetworkTime.time, // == NetworkClient.localTimeline from snapshot interpolation
out TransformSnapshot from,
out TransformSnapshot to,
out double t);
// interpolate & apply
TransformSnapshot computed = TransformSnapshot.Interpolate(from, to, t);
Apply(computed, to);
}
}
void UpdateClient() void UpdateClient()
{ {
// client authority, and local player (= allowed to move myself)? // client authority, and local player (= allowed to move myself)?
@ -238,22 +258,7 @@ void UpdateClient()
// we need to apply snapshots from the buffer // we need to apply snapshots from the buffer
else else
{ {
// only while we have snapshots UpdateClientInterpolation();
if (clientSnapshots.Count > 0)
{
// step the interpolation without touching time.
// NetworkClient is responsible for time globally.
SnapshotInterpolation.StepInterpolation(
clientSnapshots,
NetworkTime.time, // == NetworkClient.localTimeline from snapshot interpolation
out TransformSnapshot from,
out TransformSnapshot to,
out double t);
// interpolate & apply
TransformSnapshot computed = TransformSnapshot.Interpolate(from, to, t);
Apply(computed, to);
}
} }
} }