diff --git a/Assets/Mirror/Core/NetworkClient.cs b/Assets/Mirror/Core/NetworkClient.cs index 758586f69..8367a87ff 100644 --- a/Assets/Mirror/Core/NetworkClient.cs +++ b/Assets/Mirror/Core/NetworkClient.cs @@ -1697,15 +1697,7 @@ public static void OnGUI() GUILayout.BeginHorizontal("Box"); GUILayout.Label("Snapshot Interp.:"); // color code the current snapshot interpolation mode. - // colors comparable to temperature. red=hot/fast, blue=cold/slow. - switch (snapshotMode) - { - case SnapshotMode.Normal: GUI.color = Color.white; break; - case SnapshotMode.Catchup: GUI.color = Color.yellow; break; - case SnapshotMode.ClampBehind: GUI.color = Color.red; break; - case SnapshotMode.Slowdown: GUI.color = Color.cyan; break; - case SnapshotMode.ClampAhead: GUI.color = Color.blue; break; - } + GUI.color = SnapshotModeUtils.ColorCode(snapshotMode); GUILayout.Box($"timeline: {localTimeline:F2}"); GUILayout.Box($"buffer: {snapshots.Count}"); GUILayout.Box($"mode: {snapshotMode}"); diff --git a/Assets/Mirror/Core/SnapshotInterpolation/SnapshotInterpolation.cs b/Assets/Mirror/Core/SnapshotInterpolation/SnapshotInterpolation.cs index 389be4085..1fc891fd9 100644 --- a/Assets/Mirror/Core/SnapshotInterpolation/SnapshotInterpolation.cs +++ b/Assets/Mirror/Core/SnapshotInterpolation/SnapshotInterpolation.cs @@ -13,16 +13,6 @@ namespace Mirror { - // current interpolation mode is returned for debugging. - public enum SnapshotMode - { - Normal, // regular speed - Catchup, // little behind, catching up - Slowdown, // little ahead, slowing down - ClampBehind, // so far behind that we clamp - ClampAhead, // so far ahead that we clamp - } - public static class SortedListExtensions { // removes the first 'amount' elements from the sorted list diff --git a/Assets/Mirror/Core/SnapshotInterpolation/SnapshotMode.cs b/Assets/Mirror/Core/SnapshotInterpolation/SnapshotMode.cs new file mode 100644 index 000000000..91355dcf0 --- /dev/null +++ b/Assets/Mirror/Core/SnapshotInterpolation/SnapshotMode.cs @@ -0,0 +1,34 @@ +// snapshot mode & color coding for debugging purposes only. +// this is not required for snapshot interpolation to work correctly. +using UnityEngine; + +namespace Mirror +{ + // current interpolation mode is returned for debugging. + public enum SnapshotMode + { + Normal, // regular speed + Catchup, // little behind, catching up + Slowdown, // little ahead, slowing down + ClampBehind, // so far behind that we clamp + ClampAhead // so far ahead that we clamp + } + + public static class SnapshotModeUtils + { + public static Color ColorCode(SnapshotMode mode) + { + // color code the current snapshot interpolation mode. + // colors comparable to temperature. red=hot/fast, blue=cold/slow. + switch (mode) + { + case SnapshotMode.Normal: return Color.white; + case SnapshotMode.Catchup: return Color.yellow; + case SnapshotMode.ClampBehind: return Color.red; + case SnapshotMode.Slowdown: return Color.cyan; + case SnapshotMode.ClampAhead: return Color.blue; + default: return Color.white; + } + } + } +} diff --git a/Assets/Mirror/Core/SnapshotInterpolation/SnapshotMode.cs.meta b/Assets/Mirror/Core/SnapshotInterpolation/SnapshotMode.cs.meta new file mode 100644 index 000000000..b47ffe617 --- /dev/null +++ b/Assets/Mirror/Core/SnapshotInterpolation/SnapshotMode.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 52699cfa60a34a449565f940a8fec577 +timeCreated: 1678951970 \ No newline at end of file diff --git a/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs b/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs index 94cddea1e..bef87bdac 100644 --- a/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs +++ b/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs @@ -40,20 +40,15 @@ public class ClientCube : MonoBehaviour ExponentialMovingAverage driftEma; ExponentialMovingAverage deliveryTimeEma; // average delivery time (standard deviation gives average jitter) - // debugging /////////////////////////////////////////////////////////// - [Header("Debug")] - public Color catchupColor = Color.green; // green traffic light = go fast - public Color slowdownColor = Color.red; // red traffic light = go slow - Color defaultColor; - [Header("Simulation")] bool lowFpsMode; double accumulatedDeltaTime; + // debugging + SnapshotMode mode = SnapshotMode.Normal; + void Awake() { - defaultColor = render.sharedMaterial.color; - // initialize EMA with 'emaDuration' seconds worth of history. // 1 second holds 'sendRate' worth of values. // multiplied by emaDuration gives n-seconds. @@ -87,16 +82,11 @@ public void OnMessage(Snapshot3D snap) SnapshotInterpolation.InsertAndAdjust( snapshots, snap, - ref localTimeline, - ref localTimescale, - server.sendInterval, + localTimeline, bufferTime, - snapshotSettings.catchupSpeed, - snapshotSettings.slowdownSpeed, ref driftEma, - snapshotSettings.catchupNegativeThreshold, - snapshotSettings.catchupPositiveThreshold, - ref deliveryTimeEma); + ref deliveryTimeEma + ); } void Update() @@ -118,16 +108,20 @@ void Update() if (interpolate) { // step - SnapshotInterpolation.Step( + mode = SnapshotInterpolation.Step( snapshots, + ref localTimeline, // accumulate delta is Time.unscaledDeltaTime normally. // and sum of past 10 delta's in low fps mode. accumulatedDeltaTime, - ref localTimeline, - localTimescale, + bufferTime, + driftEma.Value, + snapshotSettings.catchupSpeed, + snapshotSettings.slowdownSpeed, out Snapshot3D fromSnapshot, out Snapshot3D toSnapshot, - out double t); + out double t + ); // interpolate & apply Snapshot3D computed = Snapshot3D.Interpolate(fromSnapshot, toSnapshot, t); @@ -146,12 +140,7 @@ void Update() accumulatedDeltaTime = 0; // color material while catching up / slowing down - if (localTimescale < 1) - render.material.color = slowdownColor; - else if (localTimescale > 1) - render.material.color = catchupColor; - else - render.material.color = defaultColor; + render.material.color = SnapshotModeUtils.ColorCode(mode); } void OnGUI()