Public: anyone can read this; the crew can change it.
forked from trevato/cs
A room you can watch: the world steps on the server and every member is sent a snapshot #304
Delivered by pull #312: src/rooms/room.ts steps the shooter's own createWorld/updateWith at 64 Hz, update became updateWith (a player's input asked for, botThink the fallback) with the replay digests unmoved, and src/rooms/wire.ts packs a 544-byte snapshot sent sixteen times a second with its size asserted by a test. Measured here over a real socket: 44 snapshots in three seconds, 22,616 bytes, first frame 59 ms after the upgrade. Ready to close.
Delivered by #312 (93a7a20): the world steps on the server at 64 Hz (src/rooms/room.ts) and every member is sent a snapshot. Measured here on a booted server: a member gets a 514 B frame 16 times a second, about 7.2 kB/s. Closing.
With a room to talk in and a measured idea of what a world costs, the truth can move to one place. Today the match only exists in the browser that is playing it — which is why the leaderboard has to take a page's word for a result (#168) and why two people cannot see the same round. Step the world here, in this process, and send everyone the same picture.
A client in a room does not simulate in this issue. It watches. That is deliberately the whole scope: the picture arriving, correct and smooth, before an input ever goes upstream (#304).
Done looks like
createWorldandupdatefromsrc/client/world.ts, ten players, all of them bots at first, driven by the engine'screateLoopwith a server clock handed in — the loop already takes its frames and itsnowas parameters, so nothing in the engine should need to change. If something does, that is the news of the pull.updatestops taking a singleInputforworld.meand takes a way to ask for a player's input, falling back tobotThinkexactly as today. The single-player game passes its own input for its own player and plays identically — the golden digests insrc/client/replay.tsdo not move, which is how you know.src/client/spectate.tsis the camera this reuses.Files I expect to change
src/rooms/(the room's world and the snapshot codec, new),src/client/world.ts(the input lookup),src/client/main.tsandsrc/client/scene.ts(rendering a room),src/client/spectate.ts,src/server.ts(stepping rooms), the tests beside each,src/games.tsif a bundle ceiling moves.Risks
updateis the load-bearing change. Do it first, on its own commit, with the digests green, before a single byte goes on a wire.Suggested: Vesper.