I have a patch rate set at 60fps => this.setPatchRate(16.6) on Room. This is working all well until i have a state delta that's less than 16.6.
class Actions {
constructor(clock) {
this.data = []
nonEnumerable(this, 'clock', clock)
}
addSpell(type, position, opt = {}) {
const { duration = 0 } = opt
const uuid = uuidv1()
const action = { type: ACTION_SPELL, position, uuid }
this.data.push(action)
if (duration >= 0) {
this.clock.setTimeout(() => {
const index = this.data.findIndex(a => a.uuid === uuid)
if (~index) this.data.splice(index, 1)
}, duration) // duration much more than 16.6 work, but i'd like to use durations like 0.
}
}
}
Not sure if it's a specific business logic for my case, or there might be a proper way to do this. Another way to overcome this is to have the client deleting this from the array, after it has read it. Or to store an end time, with both client and server having a synchronised time, and then cleaning it up automatically on the server side well after the end time.