Class KaijuInterpolator<T>
Allow for interpolating data over the network.
Inheritance
Namespace: KaijuSolutions.MultiplayerEngine.Synchronization
Syntax
public sealed class KaijuInterpolator<T>
Type Parameters
| Name | Description |
|---|---|
| T | The type of data. |
Constructors
KaijuInterpolator(T, UInt32, Func<T, T, Single, T>, Single, Single, UInt32)
Create an interpolator with an initial value.
Declaration
public KaijuInterpolator(T value, uint localTick, Func<T, T, float, T> lerpFunction, float interpolationDelay = 0.1F, float maxExtrapolationTime = 0.5F, uint ticksPerSecond = 60U)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The initial value to start with. |
| System.UInt32 | localTick | The current local tick of the receiver. |
| Func<T, T, System.Single, T> | lerpFunction | The function to use for interpolation. If you want extrapolation to work, this should be an unclamped function. |
| System.Single | interpolationDelay | How far in the past to smooth with interpolation. |
| System.Single | maxExtrapolationTime | How many seconds to extrapolate if the buffer runs dry. |
| System.UInt32 | ticksPerSecond | How many ticks occur per second. |
KaijuInterpolator(Func<T, T, Single, T>, Single, Single, UInt32)
Create an interpolator.
Declaration
public KaijuInterpolator(Func<T, T, float, T> lerpFunction, float interpolationDelay = 0.1F, float maxExtrapolationTime = 0.5F, uint ticksPerSecond = 60U)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T, T, System.Single, T> | lerpFunction | The function to use for interpolation. If you want extrapolation to work, this should be an unclamped function. |
| System.Single | interpolationDelay | How far in the past to smooth with interpolation. |
| System.Single | maxExtrapolationTime | How many seconds to extrapolate if the buffer runs dry. |
| System.UInt32 | ticksPerSecond | How many ticks occur per second. |
Properties
Buffer
The buffer of all past points.
Declaration
public IReadOnlyList<KaijuInterpolator<T>.KaijuInterpolationState> Buffer { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<KaijuInterpolator.KaijuInterpolationState<>> |
Count
Returns the number of states currently in the buffer.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Earliest
The earliest value which has been received into this buffer.
Declaration
public KaijuInterpolator<T>.KaijuInterpolationState Earliest { get; }
Property Value
| Type | Description |
|---|---|
| KaijuInterpolator.KaijuInterpolationState<> |
Empty
If the buffer is currently empty.
Declaration
public bool Empty { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
InterpolationDelay
How many seconds in the past to smooth with interpolation.
Declaration
public float InterpolationDelay { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Latest
The latest value which has been received into this buffer.
Declaration
public KaijuInterpolator<T>.KaijuInterpolationState Latest { get; }
Property Value
| Type | Description |
|---|---|
| KaijuInterpolator.KaijuInterpolationState<> |
LerpFunction
The function to use for interpolation. If you want extrapolation to work, this should be an unclamped function.
Declaration
public Func<T, T, float, T> LerpFunction { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<T, T, System.Single, T> |
MaxExtrapolationTime
How many seconds to extrapolate if the buffer runs dry. Note your LerpFunction must be unclamped for extrapolation to work.
Declaration
public float MaxExtrapolationTime { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
TicksPerSecond
How many ticks occur per second.
Declaration
public uint TicksPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| System.UInt32 |
Methods
Add(T, UInt32, UInt32)
Add a new value to use with interpolation.
Declaration
public void Add(T value, uint tick, uint localTick)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The newly received data. |
| System.UInt32 | tick | The tick the packet was sent at, which should have been set to the sender's current tick when this related value was sent over the network by them. |
| System.UInt32 | localTick | The current local tick of the receiver. |
Clear()
Clear the buffer and reset the remote offset estimation.
Declaration
public void Clear()
Finalize()
Ensure bindings are removed when being destroyed.
Declaration
protected void Finalize()
Get(UInt32)
Get the current smoothed value.
Declaration
public T Get(uint localTick)
Parameters
| Type | Name | Description |
|---|---|---|
| System.UInt32 | localTick | The current local tick of the receiver. |
Returns
| Type | Description |
|---|---|
| T | The current smoothed value. |
Peek(Int32)
Peek a value at a given index.
Declaration
public KaijuInterpolator<T>.KaijuInterpolationState Peek(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The index to peek at. |
Returns
| Type | Description |
|---|---|
| KaijuInterpolator.KaijuInterpolationState<> | The value at the index. |
Snap(T, UInt32)
Instantly snap to a value, which can be useful for teleporting and initializing data.
Declaration
public void Snap(T value, uint localTick)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to snap to. |
| System.UInt32 | localTick | The current local tick of the receiver. |
Trim()
Trim excess space in the buffer.
Declaration
public void Trim()