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,43 +1,11 @@
|
||||
extends Node
|
||||
## Client-side proxy for the server's real PlayerNode (scripts/
|
||||
## player_spawner.gd), attached at runtime to a Node named "Player_<peer_id>"
|
||||
## under the /root/Server proxy by NetworkClient._on_connected().
|
||||
## Client-side proxy for the server's PlayerNode (scripts/player_spawner.gd),
|
||||
## attached at runtime as "Player_<own_peer_id>" under the /root/Server proxy.
|
||||
##
|
||||
## rpc_request_input is the only one of these actually CALLED from this
|
||||
## side -- the real implementations all live on the server. But two things
|
||||
## force every @rpc method on the real PlayerNode to be mirrored here too,
|
||||
## not just the one this class uses:
|
||||
## 1. Godot's rpc_id() looks up the RPC transfer config (mode/reliability)
|
||||
## from the LOCAL script before it will even send a call, so the method
|
||||
## being called has to be declared locally with a matching annotation.
|
||||
## 2. Godot's multiplayer layer also 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 starts failing, not just the one
|
||||
## that's actually missing. So even rpc_request_interact/attack/
|
||||
## set_position/set_rotation, which this class never calls, have to be
|
||||
## declared here with matching annotations or rpc_request_input itself
|
||||
## breaks too.
|
||||
## rpc_request_input is the only RPC the client sends. Godot resolves the RPC
|
||||
## transfer config from the LOCAL node's declaration and verifies both peers
|
||||
## declare the same @rpc set at this path, so it must match player_spawner.gd.
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func rpc_request_input(_input_state: Dictionary, _seq: int) -> void:
|
||||
pass # Never invoked locally -- see the note above.
|
||||
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func rpc_request_interact(_target_id: int) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func rpc_request_attack(_target_id: int, _aim_dir: Vector3) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@rpc("authority", "call_remote", "reliable")
|
||||
func rpc_set_position(_pos: Vector3) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@rpc("authority", "call_remote", "reliable")
|
||||
func rpc_set_rotation(_rot: Vector3) -> void:
|
||||
pass
|
||||
func rpc_request_input(_input: Dictionary, _seq: int) -> void:
|
||||
pass # Real implementation is on the server.
|
||||
|
||||
Reference in New Issue
Block a user