summaryrefslogtreecommitdiff
path: root/engine/components/NetworkUpdateable.ts
blob: 78d73241306a4edad0a521f0bd52b792dc48cc77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Component, ComponentNames } from '.';

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
  ) {
    super(ComponentNames.NetworkUpdateable);

    this.updateThreshold = updateThreshold;
    this.jitter = jitter;
  }

  public getNextUpdateTime() {
    return Math.random() * this.jitter + this.updateThreshold;
  }
}