mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-11 16:45:48 -04:00
Use arrays instead of lists for storing netplayer interpolation data.
This commit is contained in:
parent
ab6c4d3546
commit
1b2013f689
@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using ClassicalSharp.Renderers;
|
||||||
using System.Drawing;
|
using OpenTK;
|
||||||
using ClassicalSharp.Renderers;
|
|
||||||
using OpenTK;
|
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
@ -32,15 +30,15 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( !interpolate ) {
|
if( !interpolate ) {
|
||||||
states.Clear();
|
stateCount = 0;
|
||||||
newState = oldState = new State( tickCount, serverPos, serverYaw, serverPitch );
|
newState = oldState = new State( tickCount, serverPos, serverYaw, serverPitch );
|
||||||
} else {
|
} else {
|
||||||
// Smoother interpolation by also adding midpoint.
|
// Smoother interpolation by also adding midpoint.
|
||||||
Vector3 midPos = Vector3.Lerp( lastPos, serverPos, 0.5f );
|
Vector3 midPos = Vector3.Lerp( lastPos, serverPos, 0.5f );
|
||||||
float midYaw = Utils.InterpAngle( lastYaw, serverYaw, 0.5f );
|
float midYaw = Utils.InterpAngle( lastYaw, serverYaw, 0.5f );
|
||||||
float midPitch = Utils.InterpAngle( lastPitch, serverPitch, 0.5f );
|
float midPitch = Utils.InterpAngle( lastPitch, serverPitch, 0.5f );
|
||||||
states.Add( new State( tickCount, midPos, midYaw, midPitch ) );
|
AddState( new State( tickCount, midPos, midYaw, midPitch ) );
|
||||||
states.Add( new State( tickCount, serverPos, serverYaw, serverPitch ) );
|
AddState( new State( tickCount, serverPos, serverYaw, serverPitch ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,8 +59,9 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<State> states = new List<State>();
|
State[] states = new State[10];
|
||||||
State newState, oldState;
|
State newState, oldState;
|
||||||
|
int stateCount;
|
||||||
public override void Tick( double delta ) {
|
public override void Tick( double delta ) {
|
||||||
CheckSkin();
|
CheckSkin();
|
||||||
tickCount++;
|
tickCount++;
|
||||||
@ -70,17 +69,26 @@ namespace ClassicalSharp {
|
|||||||
UpdateAnimState( oldState.pos, newState.pos, delta );
|
UpdateAnimState( oldState.pos, newState.pos, delta );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddState( State state ) {
|
||||||
|
if( stateCount == states.Length )
|
||||||
|
RemoveOldestState();
|
||||||
|
states[stateCount++] = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveOldestState() {
|
||||||
|
for( int i = 0; i < states.Length - 1; i++ ) {
|
||||||
|
states[i] = states[i + 1];
|
||||||
|
}
|
||||||
|
stateCount--;
|
||||||
|
}
|
||||||
|
|
||||||
void UpdateCurrentState() {
|
void UpdateCurrentState() {
|
||||||
oldState = newState;
|
oldState = newState;
|
||||||
if( states.Count < 1 ) return;
|
if( stateCount == 0 ) return;
|
||||||
|
|
||||||
do {
|
//if( states[0].tick > tickCount - 2 ) return; // 100 ms delay
|
||||||
oldState = newState;
|
newState = states[0];
|
||||||
State state = states[0];
|
RemoveOldestState();
|
||||||
//if( state.tick > tickCount - 2 ) break; // 100 ms delay
|
|
||||||
newState = state;
|
|
||||||
states.RemoveAt( 0 );
|
|
||||||
} while( states.Count >= 10 ); // Drop old states, otherwise we will never be able to catch up.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Render( double deltaTime, float t ) {
|
public override void Render( double deltaTime, float t ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user