PC3 Phase 2.3: networked play path in the game

- Session autoload: carries {world_id, host, port} from the world browser
  to the game scene.
- world_list.gd "Enter World": POST /api/worlds/{id}/join -> Session.begin
  -> load game.tscn. On 503 (backend has no orchestration) falls back to
  local single-player; other errors surface on the card.
- api_client.gd: join_world().
- game.gd (new, on game.tscn root): local single-player by default; when
  Session.active, connects a NetworkClient to the world's dedicated server
  and runs networked -- forwards the local Player's input each physics
  frame, snaps to the server position past a generous drift threshold
  (the Player keeps predicting locally with real collision), renders other
  players from snapshots (labelled capsules, lerped -- avatar appearance
  sync is a follow-up, the server doesn't replicate loadouts yet), and
  returns to the world list on disconnect.
- player.gd: exposes net_input (the input frame it applied) and
  apply_server_correction().
- network_client.gd: send_input() + get_own_server_state() for callers that
  do their own collision-aware prediction.
- scripts/mp_game_flow_client.gd + run_game_multiplayer_test.sh: two real
  clients each register -> join via the API -> game.tscn -> networked;
  A sees B and moves. PASS.

Verified end to end against an orchestration-enabled backend. Non-networked
smokes green (enter_world 9/9, world_list 5/5, player 15/15,
avatar_in_world 10/10, main_menu_full_flow 12/12).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015jtxAiu5dAW4WxCNdGkrkJ
This commit is contained in:
2026-09-05 22:07:06 +00:00
parent 260b7a38da
commit dba865ae4b
10 changed files with 369 additions and 9 deletions
+77
View File
@@ -0,0 +1,77 @@
extends SceneTree
## One client process for the full networked game-flow test
## (scripts/run_game_multiplayer_test.sh): register -> POST /api/worlds/{id}/join
## -> Session.begin -> load scenes/game.tscn -> run networked.
##
## godot --headless --path . --script res://scripts/mp_game_flow_client.gd -- \
## --role a|b --world 1
##
## role b: joins, holds still, prints RESULT b in_world and stays ~40 s.
## role a: joins, moves forward, prints RESULT a remotes=<n> moved=<bool>;
## exits 0 iff it saw a remote player node AND moved.
var role := "b"
var world_id := 1
func _initialize() -> void:
var args := OS.get_cmdline_user_args()
for i in args.size():
if args[i] == "--role" and i + 1 < args.size():
role = args[i + 1]
elif args[i] == "--world" and i + 1 < args.size():
world_id = int(args[i + 1])
_run()
func _run() -> void:
await process_frame
var api := root.get_node("ApiClient")
var session := root.get_node("Session")
var uname := "mpflow_%s_%d" % [role, int(Time.get_unix_time_from_system() * 1000) % 1000000]
var reg: Dictionary = await api.register(uname, uname + "@e.com", "secret123", true)
if not reg.ok:
print("RESULT %s register_failed %s" % [role, reg.detail])
quit(1); return
var join: Dictionary = await api.join_world(world_id)
if not (join.ok and join.data is Dictionary):
print("RESULT %s join_failed status=%d %s" % [role, join.status, join.detail])
quit(1); return
var d: Dictionary = join.data
session.begin(world_id, str(d["host"]), int(d["port"]))
change_scene_to_file("res://scenes/game.tscn")
# Wait for the scene + NetworkClient connect (game.gd awaits internally).
for i in 180:
await process_frame
var game := current_scene
var netc = game.get_node_or_null("NetworkClient") if game else null
if netc == null or not netc.is_connected_to_server():
print("RESULT %s not_connected" % role)
quit(1); return
if role == "b":
print("RESULT b in_world")
for i in 1200:
await process_frame
quit(0); return
# role a: move and look for a remote node.
var player = game.get_node("Player")
var start: Vector3 = player.global_position
var max_remotes := 0
for i in 120:
# Drive the player forward by faking held input.
player._input_direction = Vector2(0, 1)
await process_frame
var n := 0
for c in game.get_children():
if c.name.begins_with("Remote_"):
n += 1
max_remotes = maxi(max_remotes, n)
var moved: bool = player.global_position.distance_to(start) > 1.0
print("RESULT a remotes=%d moved=%s" % [max_remotes, str(moved)])
quit(0 if (moved and max_remotes >= 1) else 1)