From 29ba1c29d7ada13a9e6d475ca880d121a85894ea Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sat, 2 Sep 2023 14:40:46 -0600 Subject: make next update interval a property on network update component instead of inheritable attribute on entities --- engine/components/NetworkUpdateable.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'engine/components/NetworkUpdateable.ts') diff --git a/engine/components/NetworkUpdateable.ts b/engine/components/NetworkUpdateable.ts index 014270c..78d7324 100644 --- a/engine/components/NetworkUpdateable.ts +++ b/engine/components/NetworkUpdateable.ts @@ -1,7 +1,23 @@ import { Component, ComponentNames } from '.'; export class NetworkUpdateable extends Component { - constructor() { + 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; } } -- cgit v1.2.3-70-g09d2