PC3 Phase 2.1: server-authoritative sim + prediction/reconciliation with replay
Made the multiplayer core actually work (it had never run a real sim): - project.godot: physics pinned to 30 Hz -- the shared sim/snapshot/prediction rate. - server.gd: loads the world's level (real ground + collision), spawns a server Player per peer at the level's PlayerSpawn, broadcasts a full snapshot every physics frame with each peer's state AND last_seq (the last input seq applied for that peer). Accepts `--port/--world/--status-file` args (status file = player count for a future idle reaper); defaults keep `godot res://scenes/server.tscn` working standalone. - player_spawner.gd (server Player): rewrote -- drains its whole input queue each physics frame in seq order, integrates gravity/walk/jump with the shared constants, move_and_slide(), tracks last_applied_seq. No more no-op process_server_input(). - network_client.gd: rewrote reconciliation -- drops inputs the server has acked (last_seq), re-simulates the still-in-flight ones from the authoritative state, snaps only on real drift. Exposes get_remote_states() (peer_id -> latest snapshot state) for the game to render other players. predict_and_send() now also sends body yaw. - proxies trimmed to the RPC set the rewrite actually uses. - scripts/mp_test_client.gd + run_multiplayer_2p_test.sh: two real client processes vs one real server -- client A sees client B and its own movement round-trips. PASS. - run_checkpoint_tests.py: also run the 2p shell test. smoke_test_network_client 4/4, player 15/15, avatar_in_world 10/10, all green. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015jtxAiu5dAW4WxCNdGkrkJ
This commit is contained in:
@@ -1,38 +1,15 @@
|
||||
extends Node
|
||||
## Client-side proxy node, attached at runtime to a Node named "Server" at
|
||||
## the SceneTree root by NetworkClient.connect_to_server(). Exists purely so
|
||||
## Godot's RPC path-matching finds a receiver for _receive_snapshot -- see
|
||||
## network_client.gd's class docstring for the full explanation of why this
|
||||
## has to exist at this exact path. Not a real server in any sense.
|
||||
##
|
||||
## Godot's multiplayer layer verifies an "RPC node checksum" -- both peers
|
||||
## must declare the *same set* of @rpc methods at a matching path, or every
|
||||
## RPC at that path (not just the mismatched one) starts failing with
|
||||
## "rpc node checksum failed". So every @rpc method scripts/server.gd
|
||||
## declares on its own root "Server" node has to be mirrored here too, even
|
||||
## the ones this proxy never actually needs to receive.
|
||||
## Client-side proxy node, attached at runtime as a Node named "Server" at the
|
||||
## SceneTree root by NetworkClient. Exists purely so Godot's RPC path-matching
|
||||
## finds a receiver for _receive_snapshot (the server calls it on its own root
|
||||
## "Server" node, so the client needs a node at /root/Server declaring the same
|
||||
## @rpc set). Not a real server.
|
||||
|
||||
var owner_client: Node = null
|
||||
|
||||
|
||||
## Must match scripts/server.gd's own @rpc annotation on _receive_snapshot
|
||||
## exactly -- Godot enforces the receiving method's declared mode/transfer
|
||||
## config, a mismatch here would silently drop the call.
|
||||
## Must match scripts/server.gd's @rpc annotation on _receive_snapshot exactly.
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func _receive_snapshot(snapshot_data: Dictionary) -> void:
|
||||
if owner_client and is_instance_valid(owner_client):
|
||||
owner_client._handle_snapshot(snapshot_data)
|
||||
|
||||
|
||||
## Mirrors scripts/server.gd's _kick -- never actually invoked on this side
|
||||
## (the server calls it on a Player_<id> node's own rpc_id target, not this
|
||||
## root proxy), declared only so the RPC checksum for this path matches.
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func _kick(_reason: String) -> void:
|
||||
pass
|
||||
|
||||
|
||||
## Mirrors scripts/server.gd's _disconnect -- same reasoning as _kick above.
|
||||
@rpc("call_remote", "reliable")
|
||||
func _disconnect(_reason: String) -> void:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user