jumpstorm/engine/components/NetworkUpdateable.ts

24 lines
606 B
TypeScript
Raw Normal View History

2023-08-25 18:48:17 -04:00
import { Component, ComponentNames } from '.';
2023-08-13 18:47:58 -04:00
export class NetworkUpdateable extends Component {
static DEFAULT_UPDATE_JITTER_MS = 30;
static DEFAULT_THRESHOLD_TIME_MS = 20;
public updateThreshold: number;
public jitter: number;
constructor(
updateThreshold = NetworkUpdateable.DEFAULT_THRESHOLD_TIME_MS,
jitter = NetworkUpdateable.DEFAULT_UPDATE_JITTER_MS
) {
2023-08-13 18:47:58 -04:00
super(ComponentNames.NetworkUpdateable);
this.updateThreshold = updateThreshold;
this.jitter = jitter;
}
public getNextUpdateTime() {
return Math.random() * this.jitter + this.updateThreshold;
2023-08-13 18:47:58 -04:00
}
}