Skip to content

Commit a746473

Browse files
fix: reduce debug string overhead in interpolation (#1262)
* fix: reduce debug string overhead in interpolation * cleanup, exception back
1 parent 5f81331 commit a746473

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

com.unity.netcode.adapter.utp/Tests/Runtime/Helpers/RuntimeTestsHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using NUnit.Framework;
22
using System;
3+
using System.Linq;
34
using System.Collections;
45
using System.Collections.Generic;
5-
using System.Linq;
66
using UnityEngine;
77

88
namespace Unity.Netcode.UTP.RuntimeTests

com.unity.netcode.gameobjects/Components/Interpolator/BufferedLinearInterpolator.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,23 @@ public T Update(float deltaTime)
131131

132132
if (m_LifetimeConsumedCount >= 1) // shouldn't interpolate between default values, let's wait to receive data first, should only interpolate between real measurements
133133
{
134-
double range = m_EndTimeConsumed.Time - m_StartTimeConsumed.Time;
135-
float t;
136-
if (range == 0)
137-
{
138-
t = 1;
139-
}
140-
else
134+
float t = 1.0f;
135+
if (m_EndTimeConsumed.Time != m_StartTimeConsumed.Time)
141136
{
137+
double range = m_EndTimeConsumed.Time - m_StartTimeConsumed.Time;
142138
t = (float)((RenderTime - m_StartTimeConsumed.Time) / range);
143-
}
144139

145-
if (t > 3) // max extrapolation
146-
{
147-
// TODO this causes issues with teleport, investigate
148-
// todo make this configurable
149-
t = 1;
150-
}
140+
if (t < 0.0f)
141+
{
142+
throw new OverflowException($"t = {t} but must be >= 0. range {range}, RenderTime {RenderTime}, Start time {m_StartTimeConsumed.Time}, end time {m_EndTimeConsumed.Time}");
143+
}
151144

152-
if (Debug.isDebugBuild)
153-
{
154-
Debug.Assert(t >= 0, $"t must be bigger than or equal to 0. range {range}, RenderTime {RenderTime}, Start time {m_StartTimeConsumed.Time}, end time {m_EndTimeConsumed.Time}");
145+
if (t > 3.0f) // max extrapolation
146+
{
147+
// TODO this causes issues with teleport, investigate
148+
// todo make this configurable
149+
t = 1.0f;
150+
}
155151
}
156152

157153
var target = InterpolateUnclamped(m_InterpStartValue, m_InterpEndValue, t);

0 commit comments

Comments
 (0)