summaryrefslogtreecommitdiff
path: root/engine/systems/NetworkUpdate.ts
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/systems/NetworkUpdate.ts
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/systems/NetworkUpdate.ts')
-rw-r--r--engine/systems/NetworkUpdate.ts23
1 files changed, 13 insertions, 10 deletions
diff --git a/engine/systems/NetworkUpdate.ts b/engine/systems/NetworkUpdate.ts
index f4c8f9c..524ebf4 100644
--- a/engine/systems/NetworkUpdate.ts
+++ b/engine/systems/NetworkUpdate.ts
@@ -1,6 +1,6 @@
import { System, SystemNames } from '.';
import { Game } from '../Game';
-import { ComponentNames } from '../components';
+import { ComponentNames, NetworkUpdateable } from '../components';
import {
type MessageQueueProvider,
type MessagePublisher,
@@ -55,15 +55,20 @@ export class NetworkUpdate extends System {
// 2. send entity updates
const updateMessages: EntityUpdateBody[] = [];
- // todo: figure out if we can use the controllable component to determine if we should publish an update
game.forEachEntityWithComponent(
ComponentNames.NetworkUpdateable,
(entity) => {
+ const networkUpdateableComponent =
+ entity.getComponent<NetworkUpdateable>(
+ ComponentNames.NetworkUpdateable
+ );
+ const nextUpdateTime = networkUpdateableComponent.getNextUpdateTime();
+
const newHash = stringify(entity.serialize());
let updateInfo: EntityUpdateInfo = this.entityUpdateInfo.get(
entity.id
) ?? {
- timer: this.getNextUpdateTimeMs(),
+ timer: nextUpdateTime,
hash: newHash
};
@@ -71,13 +76,11 @@ export class NetworkUpdate extends System {
updateInfo.timer -= dt;
this.entityUpdateInfo.set(entity.id, updateInfo);
if (updateInfo.timer > 0) return;
- updateInfo.timer = entity.getNextUpdateInterval();
+ updateInfo.timer = nextUpdateTime;
this.entityUpdateInfo.set(entity.id, updateInfo);
- // maybe update if hash is not consitent
- if (updateInfo.hash == newHash) {
- return;
- }
+ // maybe update, if hash is not consistent
+ if (updateInfo.hash == newHash) return;
updateInfo.hash = newHash;
this.entityUpdateInfo.set(entity.id, updateInfo);
@@ -102,7 +105,7 @@ export class NetworkUpdate extends System {
}
}
- private getNextUpdateInterval(): number {
- return Math.random() * 30;
+ private getNextUpdateInterval() {
+ return Math.random() * 30 + 20;
}
}