Interpolator

new Interpolator(delayopt, computeBandWidthopt)

Handle reception of states over time and can on demand compute current states that need to be processed. Current states are delivered/computed with a delay and can be interpolated in order to "smooth" them see State to have a better understanding

Very inspired (quite identical) from there https://victorzhou.com/blog/build-an-io-game-part-1/#7-client-state

Parameters:
NameTypeAttributesDefaultDescription
delaynumber<optional>
100

delay between state received and state delivered/computed

computeBandWidthboolean<optional>
false

compute bandwidth of state

Members

_notConsumedStates :Array.<State>

buffer of states deprecated (out of time) but not treated (not deliver/compute)

Type:

bandWidthStateValue :object

Type:
  • object

computeBandWidth :boolean

Type:
  • boolean

delay :number

delay between state received and state delivered

Type:
  • number

firstStateTimestamp :number

time of the first state received

Type:
  • number

lastTimeState :number

time of the last state received

Type:
  • number

ping :object

time between last state received and the previous one

Type:
  • object

startTimestamp :number

interpolator start time

Type:
  • number

states :Array.<State>

buffer of states received

Type:

Methods

_computeCurrentServerTime() → {number}

Compute current server time, server is the entity where states are computed

Returns:
  • current server time
Type: 
number

_computeIndexBaseState() → {number}

Returns:
  • the index of the first state before server time
Type: 
number

_getLastStateReceived() → {State}

Returns:
  • the last state received
Type: 
State

computeCurrentState() → {State}

Deliver/Compute current state

Returns:
  • current state
Type: 
State

computeCurrentStates() → {Array.<State>}

Deliver/Compute current state + add the ones not treated/consumed

Returns:
  • current states
Type: 
Array.<State>

getPing() → {number}

Returns:
  • interpolator ping
Type: 
number

onFirstState(state)

Init interpolator attributes with a first state

Parameters:
NameTypeDescription
stateState

first state received

onNewDiff(diff)

Compute the next state based on a Diff

Parameters:
NameTypeDescription
diffDiff

diff received

onNewState(state)

Add a new state to interpolator

Parameters:
NameTypeDescription
stateState

new state receive