SnapshotInterpolation.Compute now returns <T> instead of Snapshot for ease of use

This commit is contained in:
vis2k 2021-08-03 11:11:38 +08:00
parent 23a663bdae
commit 2c70e71555
2 changed files with 7 additions and 6 deletions

View File

@ -294,11 +294,11 @@ void UpdateServer()
ref serverInterpolationTime, ref serverInterpolationTime,
bufferTime, serverBuffer, bufferTime, serverBuffer,
catchupThreshold, catchupMultiplier, catchupThreshold, catchupMultiplier,
out Snapshot computed)) out NTSnapshot computed))
{ {
NTSnapshot start = serverBuffer.Values[0]; NTSnapshot start = serverBuffer.Values[0];
NTSnapshot goal = serverBuffer.Values[1]; NTSnapshot goal = serverBuffer.Values[1];
ApplySnapshot(start, goal, (NTSnapshot)computed); ApplySnapshot(start, goal, computed);
} }
} }
} }
@ -354,11 +354,11 @@ void UpdateClient()
ref clientInterpolationTime, ref clientInterpolationTime,
bufferTime, clientBuffer, bufferTime, clientBuffer,
catchupThreshold, catchupMultiplier, catchupThreshold, catchupMultiplier,
out Snapshot computed)) out NTSnapshot computed))
{ {
NTSnapshot start = clientBuffer.Values[0]; NTSnapshot start = clientBuffer.Values[0];
NTSnapshot goal = clientBuffer.Values[1]; NTSnapshot goal = clientBuffer.Values[1];
ApplySnapshot(start, goal, (NTSnapshot)computed); ApplySnapshot(start, goal, computed);
} }
} }
} }

View File

@ -133,7 +133,7 @@ public static bool Compute<T>(
SortedList<double, T> buffer, SortedList<double, T> buffer,
int catchupThreshold, int catchupThreshold,
float catchupMultiplier, float catchupMultiplier,
out Snapshot computed) out T computed)
where T : Snapshot where T : Snapshot
{ {
// we buffer snapshots for 'bufferTime' // we buffer snapshots for 'bufferTime'
@ -261,7 +261,8 @@ public static bool Compute<T>(
//Debug.Log($"InverseLerp({first.remoteTimestamp:F2}, {second.remoteTimestamp:F2}, {first.remoteTimestamp} + {interpolationTime:F2}) = {t:F2} snapshotbuffer={buffer.Count}"); //Debug.Log($"InverseLerp({first.remoteTimestamp:F2}, {second.remoteTimestamp:F2}, {first.remoteTimestamp} + {interpolationTime:F2}) = {t:F2} snapshotbuffer={buffer.Count}");
// interpolate snapshot, return true to indicate we computed one // interpolate snapshot, return true to indicate we computed one
computed = first.Interpolate(second, t); // TODO casting 'second' to 'Snapshot' still boxes
computed = (T)first.Interpolate(second, t);
// interpolationTime: // interpolationTime:
// overshooting is ONLY allowed for smooth transitions when // overshooting is ONLY allowed for smooth transitions when