mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
asdfasdf
This commit is contained in:
parent
8ecd421744
commit
441a3d256b
@ -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}");
|
||||
|
@ -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
|
||||
|
34
Assets/Mirror/Core/SnapshotInterpolation/SnapshotMode.cs
Normal file
34
Assets/Mirror/Core/SnapshotInterpolation/SnapshotMode.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52699cfa60a34a449565f940a8fec577
|
||||
timeCreated: 1678951970
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user