mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
mode for debugging
This commit is contained in:
parent
f0cd62c60d
commit
d81bec12c2
@ -13,6 +13,16 @@
|
|||||||
|
|
||||||
namespace Mirror
|
namespace Mirror
|
||||||
{
|
{
|
||||||
|
// current interpolation mode is returned for debugging.
|
||||||
|
public enum InterpolationMode
|
||||||
|
{
|
||||||
|
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
|
public static class SortedListExtensions
|
||||||
{
|
{
|
||||||
// removes the first 'amount' elements from the sorted list
|
// removes the first 'amount' elements from the sorted list
|
||||||
@ -247,7 +257,9 @@ public static void Sample<T>(
|
|||||||
// to reproduce, try snapshot interpolation demo and press the button to
|
// to reproduce, try snapshot interpolation demo and press the button to
|
||||||
// simulate the client timeline at multiple seconds behind. it'll take
|
// simulate the client timeline at multiple seconds behind. it'll take
|
||||||
// a long time to catch up if the timeline is a long time behind.
|
// a long time to catch up if the timeline is a long time behind.
|
||||||
public static void StepTime<T>(
|
//
|
||||||
|
// returns InterpolationMode for debugging
|
||||||
|
public static InterpolationMode StepTime<T>(
|
||||||
SortedList<double, T> buffer, // snapshot buffer
|
SortedList<double, T> buffer, // snapshot buffer
|
||||||
ref double localTimeline,// local interpolation time based on server time
|
ref double localTimeline,// local interpolation time based on server time
|
||||||
double deltaTime, // engine delta time (unscaled)
|
double deltaTime, // engine delta time (unscaled)
|
||||||
@ -272,33 +284,34 @@ public static void StepTime<T>(
|
|||||||
if (drift > bufferTime)
|
if (drift > bufferTime)
|
||||||
{
|
{
|
||||||
localTimeline = targetTime - bufferTime;
|
localTimeline = targetTime - bufferTime;
|
||||||
return;
|
return InterpolationMode.ClampBehind;
|
||||||
}
|
}
|
||||||
|
|
||||||
// way too far ahead. clamp hard.
|
// way too far ahead. clamp hard.
|
||||||
if (drift < bufferTime)
|
if (drift < bufferTime)
|
||||||
{
|
{
|
||||||
localTimeline = targetTime + bufferTime;
|
localTimeline = targetTime + bufferTime;
|
||||||
return;
|
return InterpolationMode.ClampAhead;
|
||||||
}
|
}
|
||||||
|
|
||||||
// just a little behind: move by delta time and accelerate n%.
|
// just a little behind: move by delta time and accelerate n%.
|
||||||
if (drift > bufferTime / 2)
|
if (drift > bufferTime / 2)
|
||||||
{
|
{
|
||||||
localTimeline += deltaTime * (1 + catchupSpeed);
|
localTimeline += deltaTime * (1 + catchupSpeed);
|
||||||
return;
|
return InterpolationMode.Catchup;
|
||||||
}
|
}
|
||||||
|
|
||||||
// just a little ahead: move by delta time and slow down n%.
|
// just a little ahead: move by delta time and slow down n%.
|
||||||
if (drift < bufferTime / 2)
|
if (drift < bufferTime / 2)
|
||||||
{
|
{
|
||||||
localTimeline += deltaTime * (1 - slowdownSpeed);
|
localTimeline += deltaTime * (1 - slowdownSpeed);
|
||||||
return;
|
return InterpolationMode.Slowdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise we are within normal range.
|
// otherwise we are within normal range.
|
||||||
// move linearly.
|
// move linearly.
|
||||||
localTimeline += deltaTime;
|
localTimeline += deltaTime;
|
||||||
|
return InterpolationMode.Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sample, clear old.
|
// sample, clear old.
|
||||||
@ -345,12 +358,12 @@ public static void StepInterpolation<T>(
|
|||||||
//
|
//
|
||||||
// ONLY CALL IF SNAPSHOTS.COUNT > 0!
|
// ONLY CALL IF SNAPSHOTS.COUNT > 0!
|
||||||
//
|
//
|
||||||
// returns true if there is anything to apply (requires at least 1 snap)
|
// returns InterpolationMode for debugging.
|
||||||
// from/to/t are out parameters instead of an interpolated 'computed'.
|
// from/to/t are out parameters instead of an interpolated 'computed'.
|
||||||
// this allows us to store from/to/t globally (i.e. in NetworkClient)
|
// this allows us to store from/to/t globally (i.e. in NetworkClient)
|
||||||
// and have each component apply the interpolation manually.
|
// and have each component apply the interpolation manually.
|
||||||
// besides, passing "Func Interpolate" would allocate anyway.
|
// besides, passing "Func Interpolate" would allocate anyway.
|
||||||
public static void Step<T>(
|
public static InterpolationMode Step<T>(
|
||||||
SortedList<double, T> buffer, // snapshot buffer
|
SortedList<double, T> buffer, // snapshot buffer
|
||||||
ref double localTimeline, // local interpolation time based on server time
|
ref double localTimeline, // local interpolation time based on server time
|
||||||
double deltaTime, // engine delta time (unscaled)
|
double deltaTime, // engine delta time (unscaled)
|
||||||
@ -363,8 +376,9 @@ public static void Step<T>(
|
|||||||
out double t) // at ratio 't' [0,1]
|
out double t) // at ratio 't' [0,1]
|
||||||
where T : Snapshot
|
where T : Snapshot
|
||||||
{
|
{
|
||||||
StepTime(buffer, ref localTimeline, deltaTime, bufferTime, driftEma, catchupSpeed, slowdownSpeed);
|
InterpolationMode mode = StepTime(buffer, ref localTimeline, deltaTime, bufferTime, driftEma, catchupSpeed, slowdownSpeed);
|
||||||
StepInterpolation(buffer, localTimeline, out fromSnapshot, out toSnapshot, out t);
|
StepInterpolation(buffer, localTimeline, out fromSnapshot, out toSnapshot, out t);
|
||||||
|
return mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user