N10: Playable network client

The client program now turns a connection into a match someone can play.

- ClientSession: a ClientGame, the keyboard and mouse as commands
  (ClientInput), and a MatchView of the client's own copy of the world.
- ClientMirror writes what the client is showing into that world every
  frame: other players from the recent past, its own player where it was
  predicted, items, the barge, the clock and the sea. The existing views
  draw it unchanged.
- LocalServer: offline play is the same ServerLoop and NetGame in the same
  process, with packets handed across in memory, so there is one path.
- main.gd: --connect=HOST[:PORT] joins a server, otherwise an offline
  match; --autoplay and --client-seconds=N for scripts and checks.
- The camera aboard the barge follows the player's own place on the deck.

Tests drive a scripted client through a whole match on a real server over
loopback UDP, lobby to results, and through an offline match. `make
client-check` does it with two real processes, and `make client-captures`
renders what the client sees.

Closes #77

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 14:50:52 -05:00
co-authored by Claude Opus 5.5
parent 6b21e9d4f1
commit 9a36ae8615
25 changed files with 1089 additions and 13 deletions
+55 -3
View File
@@ -1,18 +1,70 @@
## Application entry point. Picks the mode from the command line:
##
## tools/godot.sh -- --server [options] headless dedicated server (see ServerConfig)
## tidewall [options] the game: an offline match, or
## tidewall --connect=HOST[:PORT] a match on a server (see ClientConfig)
##
## Client startup is added by later milestones.
## Without a window (tools/godot.sh is always headless) the game only starts when
## --offline or --connect asks for it, so a bare run prints a line and stops.
extends Node
var _config: ClientConfig
var _session: ClientSession
var _left: float = 0.0
func _ready() -> void:
var args: PackedStringArray = OS.get_cmdline_user_args()
if not args.has("--server"):
# Also accept --server before the "--" separator.
args = OS.get_cmdline_args()
var all: PackedStringArray = OS.get_cmdline_args()
if all.has("--server"):
args = all
var config: ServerConfig = ServerConfig.parse(args)
if config.server:
add_child(HeadlessServer.new(config))
return
print("Tidewall")
_config = ClientConfig.parse(args)
if not _config.is_valid():
for problem: String in _config.errors:
printerr("tidewall: " + problem)
get_tree().quit(2)
return
if DisplayServer.get_name() == "headless" and not _config.asked:
print("Tidewall")
return
_session = ClientSession.new()
_session.input.autoplay = _config.autoplay
if _config.host.is_empty():
var match_seed: int = _config.match_seed if _config.has_seed else int(Time.get_unix_time_from_system() * 1000.0) & 0x7FFFFFFF
_session.play_offline(match_seed, _config.bots)
else:
var error: Error = _session.connect_to(_config.host, _config.port, _config.player_name)
if error != OK:
printerr("tidewall: couldn't open a connection: %s" % error_string(error))
get_tree().quit(1)
return
add_child(_session)
_left = _config.seconds
func _process(delta: float) -> void:
if _session == null or _config.seconds <= 0.0:
return
_left -= delta
if _left > 0.0:
return
# A timed run says what happened, for scripts: one JSON line.
var phases: Array[String] = []
for phase: int in _session.phases:
phases.append(Match.PHASE_NAMES[phase])
var joined: bool = _session.local != null or _session.link.state == NetClient.JOINED
print(JSON.stringify({
"event": "client", "joined": joined, "status": _session.status_text(), "phases": phases,
"frames": _session.frames, "frames_playing": _session.frames_playing,
"world_messages": _session.game.replica.applied, "bad_packets": _session.game.bad_packets,
"corrections": _session.game.prediction.mispredictions,
}))
_session.leave()
_session = null
get_tree().quit(0 if joined else 1)