@@ -115,7 +115,6 @@ public BufferedItem(T item, double timeSent, int itemId)
115115 internal struct CurrentState
116116 {
117117 public BufferedItem ? Target ;
118-
119118 public double StartTime ;
120119 public double EndTime ;
121120 public double TimeToTargetValue ;
@@ -129,7 +128,6 @@ internal struct CurrentState
129128 public T CurrentValue ;
130129 public T PreviousValue ;
131130 public T PredictValue ;
132- public T PredictTarget ;
133131 public T Phase1Value ;
134132 public T Phase2Value ;
135133
@@ -151,8 +149,6 @@ public void AddDeltaTime(float deltaTime)
151149 }
152150 DeltaTime = Math . Min ( DeltaTime + deltaTime , TimeToTargetValue ) ;
153151 DeltaTimePredict = Math . Min ( DeltaTime + deltaTime , TimeToTargetValue + MaxDeltaTime ) ;
154- //DeltaTime = Math.Min(DeltaTime + m_AverageDeltaTime, TimeToTargetValue);
155- //DeltaTimePredict = Math.Min(DeltaTimePredict + m_AverageDeltaTime, TimeToTargetValue + MaxDeltaTime);
156152 LerpT = ( float ) ( TimeToTargetValue == 0.0 ? 1.0 : DeltaTime / TimeToTargetValue ) ;
157153 if ( PredictingNext )
158154 {
@@ -174,12 +170,6 @@ public void SetTimeToTarget(double timeToTarget)
174170 TimeToTargetValue = timeToTarget ;
175171 }
176172
177- public void ResetDelta ( )
178- {
179- m_AverageDeltaTime = 0.0f ;
180- DeltaTime = 0.0f ;
181- }
182-
183173 public bool TargetTimeAproximatelyReached ( float adjustForNext = 1.0f )
184174 {
185175 if ( ! Target . HasValue )
@@ -195,7 +185,6 @@ public void Reset(T currentValue)
195185 CurrentValue = currentValue ;
196186 PreviousValue = currentValue ;
197187 PredictValue = currentValue ;
198- PredictTarget = currentValue ;
199188 Phase1Value = currentValue ;
200189 Phase2Value = currentValue ;
201190 TargetReached = false ;
@@ -207,7 +196,7 @@ public void Reset(T currentValue)
207196 TimeToTargetValue = 0.0f ;
208197 DeltaTime = 0.0f ;
209198 DeltaTimePredict = 0.0f ;
210- ResetDelta ( ) ;
199+ m_AverageDeltaTime = 0.0f ;
211200 }
212201 }
213202
@@ -332,7 +321,7 @@ private void TryConsumeFromBuffer(double renderTime, double minDeltaTime, double
332321 if ( ! noStateSet )
333322 {
334323 potentialItemNeedsProcessing = ( potentialItem . TimeSent <= renderTime ) && potentialItem . TimeSent >= InterpolateState . Target . Value . TimeSent ;
335- currentTargetTimeReached = InterpolateState . TargetTimeAproximatelyReached ( potentialItemNeedsProcessing ? 1.15f : 0.85f ) ;
324+ currentTargetTimeReached = InterpolateState . TargetTimeAproximatelyReached ( potentialItemNeedsProcessing ? 1.25f : 0.75f ) ;
336325 if ( ! potentialItemNeedsProcessing && ! InterpolateState . TargetReached )
337326 {
338327 InterpolateState . TargetReached = IsAproximately ( InterpolateState . CurrentValue , InterpolateState . Target . Value . Item ) ;
@@ -371,23 +360,20 @@ private void TryConsumeFromBuffer(double renderTime, double minDeltaTime, double
371360 InterpolateState . TargetReached = false ;
372361 InterpolateState . PredictingNext = false ;
373362 startTime = InterpolateState . Target . Value . TimeSent ;
374- InterpolateState . Phase1Value = InterpolateState . PreviousValue ;
375- InterpolateState . Phase2Value = InterpolateState . PredictValue ;
376- InterpolateState . PredictTarget = target . Item ;
363+ if ( isPredictedLerp )
364+ {
365+ InterpolateState . Phase1Value = InterpolateState . PreviousValue ;
366+ InterpolateState . Phase2Value = Interpolate ( InterpolateState . Phase1Value , target . Item , InterpolateState . AverageDeltaTime ) ;
367+ }
377368 InterpolateState . MaxDeltaTime = maxDeltaTime ;
378369 }
379- if ( m_BufferQueue . TryPeek ( out BufferedItem lookAheadItem ) )
380- {
381- InterpolateState . PredictTarget = Interpolate ( target . Item , lookAheadItem . Item , InterpolateState . AverageDeltaTime ) ;
382- InterpolateState . PredictingNext = true ;
383- }
370+ InterpolateState . PredictingNext = m_BufferQueue . Count > 0 ;
384371 // TODO: We might consider creating yet another queue to add these items to and assure that the time is accelerated
385372 // for each item as opposed to losing the resolution of the values.
386373 var timeToTarget = Math . Clamp ( ( float ) ( target . TimeSent - startTime ) , minDeltaTime , maxDeltaTime ) ;
387374 InterpolateState . SetTimeToTarget ( timeToTarget ) ;
388375 InterpolateState . Target = target ;
389376 }
390- InterpolateState . ResetDelta ( ) ;
391377 }
392378 }
393379 else
@@ -435,37 +421,32 @@ internal T Update(float deltaTime, double tickLatencyAsTime, double minDeltaTime
435421 if ( ! InterpolateState . TargetReached )
436422 {
437423 InterpolateState . AddDeltaTime ( deltaTime ) ;
438-
424+ var targetValue = InterpolateState . CurrentValue ;
439425 // SmoothDampen or LerpExtrapolateBlend
440426 if ( ! isLerpAndExtrapolate )
441427 {
442428 InterpolateState . PreviousValue = SmoothDamp ( InterpolateState . PreviousValue , InterpolateState . Target . Value . Item , ref m_RateOfChange , ( float ) InterpolateState . TimeToTargetValue , ( float ) InterpolateState . DeltaTime ) ;
443- var predictedTime = InterpolateState . PredictingNext ? InterpolateState . DeltaTime : Math . Min ( InterpolateState . TimeToTargetValue , InterpolateState . DeltaTime + InterpolateState . AverageDeltaTime ) ;
444- InterpolateState . PredictValue = SmoothDamp ( InterpolateState . PredictValue , InterpolateState . Target . Value . Item , ref m_PredictedRateOfChange , ( float ) InterpolateState . TimeToTargetValue , ( float ) predictedTime ) ;
445- // Determine if smooth dampening is enabled to get our lerp "t" time
446- var timeDelta = lerpSmoothing ? deltaTime / MaximumInterpolationTime : deltaTime ;
447- // Lerp between the PreviousValue and PredictedValue using the calculated time delta
448- InterpolateState . CurrentValue = Interpolate ( InterpolateState . PreviousValue , InterpolateState . PredictValue , timeDelta ) ;
429+ InterpolateState . PredictValue = SmoothDamp ( InterpolateState . PredictValue , InterpolateState . Target . Value . Item , ref m_PredictedRateOfChange , ( float ) InterpolateState . TimeToTargetValue , ( float ) ( InterpolateState . DeltaTime + deltaTime ) ) ;
449430 }
450431 else
451432 {
452433 InterpolateState . PreviousValue = Interpolate ( InterpolateState . Phase1Value , InterpolateState . Target . Value . Item , InterpolateState . LerpT ) ;
453-
454434 // Note: InterpolateState.LerpTPredict is clamped to LerpT if we have no next target
455435 InterpolateState . PredictValue = InterpolateUnclamped ( InterpolateState . Phase2Value , InterpolateState . Target . Value . Item , InterpolateState . LerpTPredict ) ;
436+ }
456437
457- // Lerp between the PreviousValue and PredictedValue using this frame's delta time
458- var targetValue = Interpolate ( InterpolateState . PreviousValue , InterpolateState . PredictValue , deltaTime ) ;
459- if ( lerpSmoothing )
460- {
461- // If lerp smoothing is enabled, then smooth current value towards the target value
462- InterpolateState . CurrentValue = Interpolate ( InterpolateState . CurrentValue , targetValue , deltaTime / MaximumInterpolationTime ) ;
463- }
464- else
465- {
466- // Otherwise, just assign the target value.
467- InterpolateState . CurrentValue = targetValue ;
468- }
438+ // Lerp between the PreviousValue and PredictedValue using the calculated time delta
439+ targetValue = Interpolate ( InterpolateState . PreviousValue , InterpolateState . PredictValue , deltaTime ) ;
440+
441+ if ( lerpSmoothing )
442+ {
443+ // If lerp smoothing is enabled, then smooth current value towards the target value
444+ InterpolateState . CurrentValue = Interpolate ( InterpolateState . CurrentValue , targetValue , deltaTime / MaximumInterpolationTime ) ;
445+ }
446+ else
447+ {
448+ // Otherwise, just assign the target value.
449+ InterpolateState . CurrentValue = targetValue ;
469450 }
470451 }
471452 }
@@ -522,7 +503,6 @@ private void TryConsumeFromBuffer(double renderTime, double serverTime)
522503 InterpolateState . EndTime = target . TimeSent ;
523504 InterpolateState . Target = target ;
524505 }
525- InterpolateState . ResetDelta ( ) ;
526506 }
527507 }
528508 else
0 commit comments