Co-op voice/session work, config retune, net budget tool, overhaul plan

Snapshot of in-progress work before the alien overhaul so worker
worktrees branch from current code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-05 13:35:53 -04:00
parent 2e6638b744
commit 39f9d15cfe
15 changed files with 1394 additions and 339 deletions

View file

@ -37,8 +37,10 @@ the keys leak somewhere they shouldn't, make new ones at gd-sync.com.
### Voice chat
On by default when both are in: your microphone is sent whenever it's above room noise (GD-Sync's
`VoiceChat`), and your friend's voice plays on the Voice bus.
On by default when both are in: your microphone is sent while you talk, and your friend's voice
plays on the Voice bus. It opens on about a tenth of a second of sound over room noise (a click or
a knock alone doesn't open it) and stays open for 0.4 s after you stop. Talking costs about
10 KB/s online.
- **[M]** mutes and unmutes your microphone; Settings → Co-op does the same.
- Settings → Audio → "Voice chat (your friend)" sets their volume.
- While your friend is talking, a speaker mark shows on their panel.
@ -81,21 +83,46 @@ it acts.
| Piece | File | Does |
|---|---|---|
| `CoopSession` | `game/scripts/coop_session.gd` | The protocol, on both sides: the welcome, snapshots (the clock, both scarecrows with the weapon in hand and the bomb's recharge, animals, enemies in 16-byte records, shots) 20 times a second, the farm state and the loot when they change, news in order (phase changes, the end, sounds, toasts, loot news, breaches, fear bursts, attacks, pumpkin bombs thrown, gather popups), and the partner's input (with its pick of weapon) and requests. The partner's own weapons only aim and show their motion: the host attacks for it, so nothing is hit twice |
| `CoopLink`, `GDSyncLink` | `coop_link.gd`, `gdsync_link.gd` | The wire: GD-Sync remote calls, reliable or not; a loopback pair for tests |
| `CoopSession` | `game/scripts/coop_session.gd` | The protocol, on both sides: the welcome, snapshots in packed bytes 15 times a second (the clock, both scarecrows with the weapon in hand and the bomb's recharge, animals, shots, and the enemies that are due, in 16-byte records), the farm state and the loot when they change, news in order (phase changes, the end, sounds, toasts, loot news, breaches, fear bursts, attacks, pumpkin bombs thrown, gather popups), and the partner's input (with its pick of weapon) and requests. The partner's own weapons only aim and show their motion: the host attacks for it, so nothing is hit twice |
| `CoopLink`, `GDSyncLink` | `coop_link.gd`, `gdsync_link.gd` | The wire: GD-Sync remote calls, reliable or not, large messages compressed; the packing helpers; a loopback pair for tests |
| `CoopLobby` | `coop_lobby.gd` | GD-Sync's LAN and online modes, lobbies, join by address |
| `RemoteControls` | `remote_controls.gd` | The partner's buttons as the host sees them: held state, press counts (a lost packet never loses a press), aim, build mode, menus |
| `RemoteControls` | `remote_controls.gd` | The partner's buttons as the host sees them: held state, press counts (a lost packet never loses a press), aim, build mode, menus; its input record, 39 bytes |
| `Avatar` | `avatar.gd` | One scarecrow and its kit, weapons, and hands; `FarmSim.avatars` holds both |
| `CoopVoice` | `coop_voice.gd` | GD-Sync's `VoiceChat`, one per player, owned by that player |
| `CoopVoice` | `coop_voice.gd` | GD-Sync's `VoiceChat` (the microphone and the playback), one per player, owned by that player; sends speech as 4-bit ADPCM in 60 ms pieces, through its own gate |
| `CoopHud`, `CoopMenu` | `coop_hud.gd`, `coop_menu.gd` | The partner panel and arrow; the menu |
Messages that may be lost (snapshots, input) stay under 1,100 bytes. GD-Sync splits datagrams at
1,200. Nothing depends on any one of them arriving: an enemy missed by a snapshot appears in the
next, and removals are reliable.
1,200. Nothing depends on any one of them arriving, and removals are reliable.
Measured on the loopback test with 90 enemies and a third of the snapshots dropped: about 31 KB/s
from the host and 10 KB/s from the partner, with the largest message under the limit. That's
nothing on a LAN. Online, check it against your GD-Sync plan's data allowance.
### Data use (GD-Sync's allowance)
Online, every byte goes through GD-Sync's servers, and plans are sold by data transfer (the free
one has 200 MB a day). GD-Sync doesn't say whether the relay out to the other player counts too.
What keeps co-op small:
- **Packed snapshots.** Snapshots and the partner's input are packed bytes, not Dictionaries,
where every key's name went out with every value.
- **Few messages.** GD-Sync adds about 220 bytes to each unreliable message (its request, a
signature, the packet's envelope), so a snapshot is one message: shots and the enemies ride
in it.
- **Only what changed.** The farm state goes out when it changes (the phase clock alone doesn't
count: every snapshot has it), the loot likewise, and the partner's input when it changes or
every 0.25 s.
- **Dead reckoning for enemies.** The partner moves each enemy on at the velocity of its last
record, and the host sends a new one only when that guess is 25 cm off, or the velocity,
heading, altitude, or state changed, or it was hit, and at least every second. New and changed
records go out twice more, in case one is lost. In the test's crowd of 64, that's a tenth of
the records.
- **Compression.** Messages over 256 bytes (the welcome, the farm state, the loot, big news
batches) are compressed with zstd before GD-Sync gets them. GD-Sync compresses packets only
after encrypting them, which saves nothing.
- **Voice** goes out as 4-bit ADPCM at 12 kHz, only while you talk: about 10 KB/s, against about
60 KB/s for GD-Sync's own `VoiceChat`, which sends raw samples whenever the microphone peaks.
`game/tools/net_budget.gd` measured a whole vacation (5 nights, 32 minutes, the partner always
moving, no voice): 22 MB sent to the server, against 113 MB before (2026-10-04). That's about 12
KB/s: 6 from the host, 5.5 from the partner. Both machines must run the same version of the game:
the hello and the welcome carry `CoopSession.PROTOCOL`, and a mismatch ends the session with a
message on both sides.
## Testing
@ -109,6 +136,10 @@ nothing on a LAN. Online, check it against your GD-Sync plan's data allowance.
`--discover` uses the network announcements instead. `--online` plays through GD-Sync's
servers (needs the keys): the partner finds the host's lobby in the online list. Give both
sides the same `--host-name`, so an old lobby from an earlier run isn't picked by mistake.
- **`game/tools/net_budget.gd`** measures the traffic for the GD-Sync data allowance: it plays
whole days and nights over a loopback link that packs every message the way GD-Sync does
online, and reports what each side sends to the server, by message kind and by phase, plus
voice chat's rate while talking. `--nights=5` is a whole vacation.
```sh
godot --headless --path . --script res://game/tools/coop_smoke.gd -- --role=host &