This commit is contained in:
Chris Wanstrath 2025-09-27 19:55:33 -07:00
parent 1f311679f7
commit 7ebabb5cc3

View File

@ -6,17 +6,20 @@ import { randomId } from "../shared/utils.js"
import { setStatus, addOutput } from "./scrollback.js"
import { browserCommands } from "./commands.js"
const FPS = 30
let oldMode = "cinema"
let stopGame = false
let canvas: HTMLCanvasElement
type Game = { init?: () => void, update?: (delta: number, input: InputState) => void, draw?: (ctx: GameContext) => void }
const pressedStack = new Set()
const pressedStack = new Set<string>()
let pressed: InputState = {
key: "",
shift: false,
ctrl: false,
meta: false,
pressed: pressedStack
}
export async function handleGameStart(msg: Message) {
@ -86,7 +89,7 @@ function gameLoop(ctx: GameContext, game: Game) {
if (stopGame) return
const delta = ts - last
if (delta >= 1000 / 30) {
if (delta >= 1000 / FPS) {
if (game.update) game.update(delta, pressed)
if (game.draw) game.draw(ctx)
last = ts