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:
2026-11-12 08:26:02 -05:00
co-authored by Claude Opus 5.5
parent 881f449d10
commit e535c1f39c
26 changed files with 1695 additions and 24 deletions
+15 -3
View File
@@ -1,9 +1,13 @@
## Command-line configuration for a headless server.
##
## tools/godot.sh -- --server [--seed=N] [--port=N] [--players=N] [--bots=N]
## tools/godot.sh -- --server [--listen] [--port=N] [--seed=N] [--players=N] [--bots=N]
## [--bot-difficulty=mixed|easy|normal|hard] [--ticks=N]
## [--unthrottled] [--log-every=N]
##
## With `--listen` the server takes network players on UDP `--port`, waits in the lobby
## for the first of them, and with any `--bots` above 0 fills each match's empty places
## with bots. Without it the match starts at once with `--players` idle slots.
##
## Unknown or malformed arguments are errors, so a typo can't silently run the wrong
## match. See `parse()`.
class_name ServerConfig
@@ -19,9 +23,11 @@ var server: bool = false
## The match seed. `has_seed` is false when none was given and the server must pick one.
var match_seed: int = 0
var has_seed: bool = false
## UDP port the server will listen on once networking lands (v0.5).
## True when `--listen` was given: take network players on `port`.
var listen: bool = false
## UDP port a listening server uses.
var port: int = DEFAULT_PORT
## Player slots for human clients. Until v0.5 they join as idle players.
## Idle player slots, for a server that isn't listening.
var players: int = 0
var bots: int = 0
## Every bot's difficulty, as an index into Tuning.BOT_DIFFICULTIES, or -1 to mix them.
@@ -59,6 +65,7 @@ func is_valid() -> bool:
func to_dictionary() -> Dictionary:
return {
"seed": match_seed,
"listen": listen,
"port": port,
"players": players,
"bots": bots,
@@ -72,6 +79,9 @@ func _parse_one(arg: String) -> void:
if arg == "--unthrottled":
unthrottled = true
return
if arg == "--listen":
listen = true
return
var parts: PackedStringArray = arg.split("=", true, 1)
if parts.size() != 2 or not arg.begins_with("--"):
errors.append("unknown argument '%s'" % arg)
@@ -129,6 +139,8 @@ func _validate() -> void:
"--players plus --bots is %d, more than the match size of %d"
% [players + bots, Tuning.SOLO_PLAYERS]
)
if listen and players > 0:
errors.append("--players is for a server that isn't listening; with --listen, people join over the network")
if ticks < 0:
errors.append("--ticks can't be negative")
if log_every < 0: