N2: Snapshot replication and interest management
NetSnapshot defines the game traffic after the handshake: delta snapshots of quantized entity records, the client's input packet and a reliable match notice. SnapshotSender builds each client's snapshot against the newest one it acknowledged, tells it only about entities near the player it is watching, and keeps every snapshot under 1,200 bytes, nearest first, with a staleness bonus so nothing starves. SnapshotReceiver rebuilds the picture, ignores old and repeated snapshots and asks for a fresh start if it is ever sent a delta on something it doesn't hold. NetGame joins the transport to the match: people who connect become participants, their inputs go through ServerLoop.submit() once per tick, and snapshots go out 20 times a second. `--server --listen` makes the headless server take network players and wait in the lobby for the first of them. Measured by test on a 24-player match start with every player a client, a tenth of packets lost and late acknowledgements: 2.4 KB/s mean and 2.5 KB/s for the worst client, packet headers included, against a 40 KB/s limit. Closes #33 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,25 @@ const MAX_COMMAND_LEAD_TICKS: int = 60
|
||||
## Width and depth of the playable world. Positions are clamped inside it.
|
||||
const WORLD_SIZE_METRES: float = 1024.0
|
||||
|
||||
# Network. See docs/ARCHITECTURE.md, "Snapshot format".
|
||||
## Server ticks between snapshots: 20 a second.
|
||||
const NET_SNAPSHOT_INTERVAL_TICKS: int = 3
|
||||
## The most bytes in one snapshot. Keeps a packet inside one UDP datagram on any
|
||||
## ordinary link, and a client under 24 KB/s before packet headers.
|
||||
const NET_SNAPSHOT_MAX_BYTES: int = 1200
|
||||
## A client is sent other players and shots within this many metres on the map of the
|
||||
## player it is watching: a little further than the longest weapon reaches.
|
||||
const NET_INTEREST_PLAYERS_METRES: float = 380.0
|
||||
## And items lying on the ground within this many.
|
||||
const NET_INTEREST_PICKUPS_METRES: float = 90.0
|
||||
## Snapshots the server remembers per client, to send changes against.
|
||||
const NET_SNAPSHOT_HISTORY: int = 40
|
||||
## When a snapshot is full, each snapshot an entity has waited counts as this many
|
||||
## metres closer, so nothing far away waits for ever.
|
||||
const NET_STALE_METRES_PER_SNAPSHOT: float = 6.0
|
||||
## Commands a client repeats in each input packet, so a lost packet costs nothing.
|
||||
const NET_INPUT_REDUNDANCY: int = 3
|
||||
|
||||
# Match sizes
|
||||
const SOLO_PLAYERS: int = 24
|
||||
const DUO_TEAMS: int = 12
|
||||
|
||||
Reference in New Issue
Block a user