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
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
delay | number | <optional> | 100 | delay between state received and state delivered/computed |
computeBandWidth | boolean | <optional> | false | compute bandwidth of state |
- Source
Members
_notConsumedStates :Array.<State>
buffer of states deprecated (out of time) but not treated (not deliver/compute)
- Array.<State>
- Source
bandWidthStateValue :object
- object
- Source
computeBandWidth :boolean
- boolean
- Source
delay :number
delay between state received and state delivered
- number
- Source
firstStateTimestamp :number
time of the first state received
- number
- Source
lastTimeState :number
time of the last state received
- number
- Source
ping :object
time between last state received and the previous one
- object
- Source
startTimestamp :number
interpolator start time
- number
- Source
states :Array.<State>
buffer of states received
- Array.<State>
- Source
Methods
_computeCurrentServerTime() → {number}
Compute current server time, server is the entity where states are computed
- Source
- current server time
- Type:
- number
_computeIndexBaseState() → {number}
- Source
- the index of the first state before server time
- Type:
- number
_getLastStateReceived() → {State}
- Source
- the last state received
- Type:
- State
computeCurrentState() → {State}
Deliver/Compute current state
- Source
- current state
- Type:
- State
computeCurrentStates() → {Array.<State>}
Deliver/Compute current state + add the ones not treated/consumed
- Source
- current states
- Type:
- Array.<State>
getPing() → {number}
- Source
- interpolator ping
- Type:
- number
onFirstState(state)
Init interpolator attributes with a first state
Name | Type | Description |
---|---|---|
state | State | first state received |
- Source
onNewDiff(diff)
Compute the next state based on a Diff
Name | Type | Description |
---|---|---|
diff | Diff | diff received |
- Source
onNewState(state)
Add a new state to interpolator
Name | Type | Description |
---|---|---|
state | State | new state receive |
- Source