@zaisma/cli 0.43.0 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ # A short first press
2
+
3
+ Open this when the game is more than a few MB, or when `performance_check` on a version says its first frame is slow. A player who presses Play and waits on a black screen leaves; one who sees something move in a second or two stays.
4
+
5
+ ## The rule
6
+
7
+ Draw a first frame soon, show a loading screen if the rest takes time, and load the rest as it's needed, not all before the first frame.
8
+
9
+ ## By size
10
+
11
+ - **A one-file or small game (under about 5 MB).** Nothing to do: it loads at once. Keep images and audio compressed, and don't load a big font or library the game doesn't use.
12
+ - **A mid-size game (5 to 100 MB).** Load what the first screen needs, show the menu, and load the levels, music and the rest while the player reads it. Show progress on anything that takes more than a second or two.
13
+ - **A big 3D build (100 MB and up, PC-grade).** Split it: a small first download that draws a menu or a loading screen within seconds, then the world in pieces, the first level first, the rest in the background or as the player reaches it. Every engine has a way: Unity's Addressables, Godot's PCK files loaded at runtime, glTF scenes streamed one by one in Three.js or Babylon.js.
14
+
15
+ ## Making it smaller
16
+
17
+ `performance_check` (on `get_version`, `get_game` and in the upload command's output) says how the version started in headless Chrome: `loading_duration_sec` to the first frame, `start_download_size_bytes` before it, and notes with a fix for each. The ones that save the most:
18
+
19
+ - **Textures as KTX2** (Basis Universal): about a quarter of the size and of the graphics memory of PNG or JPEG for WebGL and WebGPU games.
20
+ - **Audio as Ogg Opus** or a compressed format instead of WAV.
21
+ - **Models with mesh compression** (meshopt or Draco).
22
+ - **A release build,** never a development or debug build: they're bigger and slower.
23
+ - **Compressed builds are fine.** Upload Unity's or Godot's `.br` and `.gz` files with `npx @zaisma/cli upload` which unpacks them.
24
+
25
+ ## What not to do
26
+
27
+ - Don't hold the first frame for the whole game to download.
28
+ - Don't hide a long load behind a blank page: show progress, even a simple bar.
29
+ - Don't fetch files from other sites at start: the upload command downloads them into the game, so they come from Zaisma's servers.
@@ -0,0 +1,37 @@
1
+ # Online play that holds up
2
+
3
+ Open this when the game has online play. It covers what Zaisma's rooms already do for a player whose connection is weak, and what the game itself has to add so it doesn't feel broken. The calls and options here are in `sdk.md` and `game-server.md`.
4
+
5
+ ## What the rooms already do
6
+
7
+ - **Reconnecting.** The SDK pings the room and reconnects by itself when the connection goes quiet, with no limit on tries. The game keeps the same room object, and `room.connectionStatus` is `"reconnecting"` meanwhile (`"connecting"`, `"open"`, `"reconnecting"` or `"closed"`).
8
+ - **Sends wait while it's down.** Reliable `room.send` calls made while the connection is down are kept in order and go once it's back, up to 60; past that the oldest is dropped and the room's `error` event says `send_queue_full` once.
9
+ - **A dropped player keeps their seat.** A player whose connection drops is away with reason `lost` for `reconnectTimeoutSec` (30 seconds unless the game server says otherwise, 0 to 300). They stay in `room.players` with `awayReason: "lost"`, nothing is sent to them, and their seat stays theirs. Back in time, the game server's `onBack(state, player, room)` runs; not back in time, `onLeave` with reason `lost`, and the room holds their seat for `seatHoldDurationSec`.
10
+ - **Slow connections are dropped early.** A player whose connection can't keep up (a probe unanswered for 8 seconds, or 2 MB sent since their last answer) is closed with code `4003` and becomes a dropped player, so one bad connection never stalls the match for everyone.
11
+ - **One clock and the ping.** `room.serverTimeMs()` is the room's clock on the game server and in every player's game. `room.pingDurationMs` is the player's round trip in milliseconds, measured by the room, so a player can only make it look worse, never better.
12
+ - **State sync.** With `stateSyncEnabled: true` on the game server, each player gets a full copy of their view as they join or reconnect, then only what changed. `stateView(state, viewer, room)` cuts what each one sees. A backed-up player gets nothing until they've caught up, then one full copy.
13
+ - **Restarts.** Zaisma restarts its rooms when Zaisma is updated: a real-time room saves its state every `stateSaveIntervalSec`, comes back from the save, and runs `onRestored(state, restoreInfo, room)`; every player comes back as a dropped player would.
14
+
15
+ ## What the game must do
16
+
17
+ 1. **Keep the game server in charge.** The game sends input ("move left", "fire at x, y"), never results ("I hit them", "I have 500 coins"). The game server checks every move against its own state and decides what happened. A game that trusts a player's results is a game anyone can cheat in.
18
+ 2. **Show a dropped player as dropped.** Read `awayReason` from `room.players` (and the `players` event). Draw a `lost` player frozen, dimmed or marked "reconnecting", never running on in place. On the game server, skip `lost` players in `onTick` (`room.awayReason(playerId)`), or pause the match or skip their turn.
19
+ 3. **Send the whole state to a player who comes back.** They missed what was sent meanwhile. Send it in `onBack`, and in `onJoin` when `joinInfo.isReturning`, not just what changed. State sync does this by itself.
20
+ 4. **Show the player their own connection.** Listen for the room's `connectionStatus` event and show a small "Reconnecting…" while it's not `"open"`. Don't cover the game or end the match for a blip.
21
+ 5. **Send less while it's down.** Movement and aim replace each other, so send them with `{ delivery: "latest_only", latestKey: "move" }`: only the newest waits, and a stale queue never builds. Keep reliable sends for things that must all arrive, like a purchase or a turn.
22
+ 6. **Handle the end of the room.** Listen for `ended` and `kicked`, and give the player a way back to a menu or a new match.
23
+
24
+ ## Turn-based games
25
+
26
+ A card game, a board game or a word game needs only the first four: the server checks each move, a dropped player's turn waits or is skipped by the game's own rule, a returning player gets the whole board, and the game shows the connection. Turn-based rooms sleep between moves and notice a silent drop within about 75 seconds, which is fine for turns.
27
+
28
+ ## Real-time games
29
+
30
+ A shooter is the measure: if a shooter feels fair on a 150 ms connection with a little loss, every other real-time game will too.
31
+
32
+ - **Tick rate.** `ticksPerSec` on the game server runs `onTick(state, tickDurationSec, room)` that many times a second. 20 to 30 suits most action games; 60 only when the game truly needs it, since every tick is CPU on the game's hosting meter. Players' input reaches `onMessage` just before the next tick, in order.
33
+ - **Interpolation.** Draw other players from `room.smoothedState()` (or `room.smoothedState({ delayMs: 150 })`), the state a moment behind, blended between updates, so they move evenly however packets arrive. Blend angles that wrap around yourself.
34
+ - **Prediction.** Move the player's own character at once on their input, from the game's own copy of the rules, then correct it gently toward what the server says when its update arrives. Without prediction, every move waits a round trip and the game feels heavy. The SDK leaves prediction to the game.
35
+ - **Lag compensation.** For hits, the game server checks a shot against where targets were when the shooter saw them: keep a short history of positions (a few hundred milliseconds), and rewind by the shooter's `room.pingDurationMs(playerId)`. Cap the rewind (about 200 ms), since a slower connection should never be an advantage.
36
+ - **Times on one clock.** Send times as `room.serverTimeMs()` values, like `{ startsAtMs: room.serverTimeMs() + 3000 }` for a countdown, so they mean the same moment for every player.
37
+ - **Test it on a bad connection.** Run `npx @zaisma/cli play-locally`, add a second player, and throttle one tab's network in the browser's developer tools (a slow 4G preset, or offline for a few seconds): the other player should see them freeze, then catch up, and they should see "Reconnecting…", then the whole match back.