summaryrefslogtreecommitdiff
path: root/engine/components
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-09-02 14:40:46 -0600
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-09-02 14:40:46 -0600
commit29ba1c29d7ada13a9e6d475ca880d121a85894ea (patch)
tree35a2b36191d197cd44b255cb0dcbc32077a212b4 /engine/components
parentc551f519cadb8628d58114512770c69b01d80a0c (diff)
downloadjumpstorm-29ba1c29d7ada13a9e6d475ca880d121a85894ea.tar.gz
jumpstorm-29ba1c29d7ada13a9e6d475ca880d121a85894ea.zip
make next update interval a property on network update component instead of inheritable attribute on entities
Diffstat (limited to 'engine/components')
-rw-r--r--engine/components/BoundingBox.ts1
-rw-r--r--engine/components/NetworkUpdateable.ts18
2 files changed, 18 insertions, 1 deletions
diff --git a/engine/components/BoundingBox.ts b/engine/components/BoundingBox.ts
index 921feb9..f01ae9b 100644
--- a/engine/components/BoundingBox.ts
+++ b/engine/components/BoundingBox.ts
@@ -16,6 +16,7 @@ export class BoundingBox extends Component {
}
public isCollidingWith(box: BoundingBox): boolean {
+ // optimization; when neither rotates just check if they overlap
if (this.rotation == 0 && box.rotation == 0) {
const thisTopLeft = this.getTopLeft();
const thisBottomRight = this.getBottomRight();
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;
}
}