diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-08-23 19:44:59 -0600 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-08-23 19:44:59 -0600 |
commit | dec7b614d895a1b507137e4a96a8999ff63aa179 (patch) | |
tree | 827437755bf9674db51818ee59d919c74a4ea2fc /engine/systems | |
parent | d64ffb5016119e54f0e20d05ae8ac9c96955d9d5 (diff) | |
download | jumpstorm-dec7b614d895a1b507137e4a96a8999ff63aa179.tar.gz jumpstorm-dec7b614d895a1b507137e4a96a8999ff63aa179.zip |
holy fuck we actually got somewhere
Diffstat (limited to 'engine/systems')
-rw-r--r-- | engine/systems/Input.ts | 5 | ||||
-rw-r--r-- | engine/systems/NetworkUpdate.ts | 31 |
2 files changed, 20 insertions, 16 deletions
diff --git a/engine/systems/Input.ts b/engine/systems/Input.ts index d9b7133..a32ba9a 100644 --- a/engine/systems/Input.ts +++ b/engine/systems/Input.ts @@ -12,12 +12,14 @@ import { Action } from "../interfaces"; import { System, SystemNames } from "."; export class Input extends System { + public clientId: string; private keys: Set<string>; private actionTimeStamps: Map<Action, number>; - constructor() { + constructor(clientId: string) { super(SystemNames.Input); + this.clientId = clientId; this.keys = new Set<string>(); this.actionTimeStamps = new Map<Action, number>(); } @@ -42,6 +44,7 @@ export class Input extends System { const controlComponent = entity.getComponent<Control>( ComponentNames.Control, ); + if (controlComponent.controllableBy != this.clientId) return; if (this.hasSomeKey(KeyConstants.ActionKeys.get(Action.MOVE_RIGHT))) { controlComponent.controlVelocityComponent.velocity.dCartesian.dx += diff --git a/engine/systems/NetworkUpdate.ts b/engine/systems/NetworkUpdate.ts index cdd6de7..6c1d3e4 100644 --- a/engine/systems/NetworkUpdate.ts +++ b/engine/systems/NetworkUpdate.ts @@ -1,43 +1,44 @@ import { System, SystemNames } from "."; import { Game } from "../Game"; import { ComponentNames, NetworkUpdateable } from "../components"; - -export interface MessageQueueProvider { - getNewMessages(): any[]; - clearMessages(): void; -} - -export interface MessagePublisher { - addMessage(message: any): void; - publish(): void; -} +import { + type MessageQueueProvider, + type MessagePublisher, + type MessageProcessor, +} from "../network"; export class NetworkUpdate extends System { private queueProvider: MessageQueueProvider; private publisher: MessagePublisher; + private messageProcessor: MessageProcessor; constructor( queueProvider: MessageQueueProvider, - publisher: MessagePublisher + publisher: MessagePublisher, + messageProcessor: MessageProcessor, ) { super(SystemNames.NetworkUpdate); this.queueProvider = queueProvider; this.publisher = publisher; + this.messageProcessor = messageProcessor; } public update(_dt: number, game: Game) { - const messages = this.queueProvider.getNewMessages(); - if (messages.length) console.log(messages); + this.queueProvider + .getNewMessages() + .forEach((message) => this.messageProcessor.process(message)); this.queueProvider.clearMessages(); game.forEachEntityWithComponent( ComponentNames.NetworkUpdateable, (entity) => { const networkUpdateComponent = entity.getComponent<NetworkUpdateable>( - ComponentNames.NetworkUpdateable + ComponentNames.NetworkUpdateable, ); - } + }, ); + + this.publisher.publish(); } } |