From f9de8f5bdcbf7bee8a5dc1ec9a09a7ff34429f50 Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Wed, 19 Oct 2022 16:00:19 -0700 Subject: [PATCH] fix rate at which multiplayer images are sent to 20fps (#1379) --- libs/game/sim/multiplayer.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/game/sim/multiplayer.ts b/libs/game/sim/multiplayer.ts index 522b200fc..3f0e26675 100644 --- a/libs/game/sim/multiplayer.ts +++ b/libs/game/sim/multiplayer.ts @@ -51,11 +51,13 @@ namespace pxsim { state: "Pressed" | "Released" | "Held"; } + let postScreenInterval: any; export class MultiplayerState { lastMessageId: number; origin: string; backgroundImage: RefImage; + constructor() { this.lastMessageId = 0; } @@ -74,7 +76,10 @@ namespace pxsim { init(origin: string) { this.origin = origin; runtime.board.addMessageListener(msg => this.messageHandler(msg)); - setInterval(() => { + if (postScreenInterval) { + clearInterval(postScreenInterval) + } + postScreenInterval = setInterval(() => { if (this.origin === "server") { const b = board() as ScreenBoard; const screenState = b && b.screenState;