This commit is contained in:
vis2k 2023-03-16 15:20:46 +08:00
parent 4f553314d2
commit f0cd62c60d
3 changed files with 14 additions and 27 deletions

View File

@ -41,13 +41,7 @@ public static partial class NetworkClient
// double for long running servers, see NetworkTime comments.
internal static double localTimeline;
// catchup / slowdown adjustments are applied to timescale,
// to be adjusted in every update instead of when receiving messages.
internal static double localTimescale = 1;
// catchup /////////////////////////////////////////////////////////////
// we use EMA to average the last second worth of snapshot time diffs.
// manually averaging the last second worth of values with a for loop
// would be the same, but a moving average is faster because we only
@ -92,7 +86,6 @@ static void InitTimeInterpolation()
// Don't reset bufferTimeMultiplier here - whatever their network condition
// was when they disconnected, it won't have changed on immediate reconnect.
localTimeline = 0;
localTimescale = 1;
snapshots.Clear();
// initialize EMA with 'emaDuration' seconds worth of history.
@ -141,15 +134,9 @@ public static void OnTimeSnapshot(TimeSnapshot snap)
SnapshotInterpolation.InsertAndAdjust(
snapshots,
snap,
ref localTimeline,
ref localTimescale,
NetworkServer.sendInterval,
localTimeline,
bufferTime,
snapshotSettings.catchupSpeed,
snapshotSettings.slowdownSpeed,
ref driftEma,
snapshotSettings.catchupNegativeThreshold,
snapshotSettings.catchupPositiveThreshold,
ref deliveryTimeEma);
// Debug.Log($"inserted TimeSnapshot remote={snap.remoteTime:F2} local={snap.localTime:F2} total={snapshots.Count}");
@ -163,7 +150,7 @@ static void UpdateTimeInterpolation()
if (snapshots.Count > 0)
{
// progress local timeline.
SnapshotInterpolation.StepTime(Time.unscaledDeltaTime, ref localTimeline, localTimescale);
SnapshotInterpolation.StepTime(snapshots, ref localTimeline, Time.unscaledDeltaTime, bufferTime, driftEma.Value, snapshotSettings.catchupSpeed, snapshotSettings.slowdownSpeed);
// progress local interpolation.
// TimeSnapshot doesn't interpolate anything.

View File

@ -36,7 +36,6 @@ public class NetworkConnectionToClient : NetworkConnection
ExponentialMovingAverage driftEma;
ExponentialMovingAverage deliveryTimeEma; // average delivery time (standard deviation gives average jitter)
public double remoteTimeline;
public double remoteTimescale;
double bufferTimeMultiplier = 2;
double bufferTime => NetworkServer.sendInterval * bufferTimeMultiplier;
@ -81,15 +80,9 @@ public void OnTimeSnapshot(TimeSnapshot snapshot)
SnapshotInterpolation.InsertAndAdjust(
snapshots,
snapshot,
ref remoteTimeline,
ref remoteTimescale,
NetworkServer.sendInterval,
remoteTimeline,
bufferTime,
NetworkClient.snapshotSettings.catchupSpeed,
NetworkClient.snapshotSettings.slowdownSpeed,
ref driftEma,
NetworkClient.snapshotSettings.catchupNegativeThreshold,
NetworkClient.snapshotSettings.catchupPositiveThreshold,
ref deliveryTimeEma
);
}
@ -100,7 +93,15 @@ public void UpdateTimeInterpolation()
if (snapshots.Count > 0)
{
// progress local timeline.
SnapshotInterpolation.StepTime(Time.unscaledDeltaTime, ref remoteTimeline, remoteTimescale);
SnapshotInterpolation.StepTime(
snapshots,
ref remoteTimeline,
Time.unscaledDeltaTime,
bufferTime,
driftEma.Value,
NetworkClient.snapshotSettings.catchupSpeed,
NetworkClient.snapshotSettings.slowdownSpeed
);
// progress local interpolation.
// TimeSnapshot doesn't interpolate anything.

View File

@ -19,11 +19,10 @@ public class SnapshotInterpolationSettings
// catchup /////////////////////////////////////////////////////////////
// catchup thresholds in 'frames'.
// half a frame might be too aggressive.
[Header("Catchup / Slowdown")]
[Tooltip("Slowdown begins when the local timeline is moving too fast towards remote time. Threshold is in frames worth of snapshots.\n\nThis needs to be negative.\n\nDon't modify unless you know what you are doing.")]
[Obsolete("catchup thresholds are now automated")]
public float catchupNegativeThreshold = -1; // careful, don't want to run out of snapshots
[Tooltip("Catchup begins when the local timeline is moving too slow and getting too far away from remote time. Threshold is in frames worth of snapshots.\n\nThis needs to be positive.\n\nDon't modify unless you know what you are doing.")]
[Obsolete("catchup thresholds are now automated")]
public float catchupPositiveThreshold = 1;
[Tooltip("Local timeline acceleration in % while catching up.")]