Repository navigation
feat: add netcode ticks, input sequencing and reconciliation - #145
Merged
Merged
Conversation
This was referenced Nov 26, 2026
FlightInput quantizes and packs a client's recent per-tick inputs (sequence, movement, boost, requested facing) with fire and targeting intent. InputBuffer orders and deduplicates them per pilot, consumes one per server tick, reuses the last input while starved, idles after a tick timeout and drops surplus depth to bound latency, counting applied, duplicate, late, lost, dropped and starved inputs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The server numbers its 60 Hz simulation ticks and consumes exactly one buffered input per remote pilot per tick through Pilot.simulate_input(), keeping the 720°/s turn limit and every life, docking and map check. Fire intent ages in server ticks instead of wall-clock time. Snapshots carry the server tick; owner entries carry the last processed input, buffer depth, turn budget and input counters (network schema 24). Clients sample one input per physics tick, predict it with the same step, send the last ten unacknowledged inputs 30 times per second and, on each owner snapshot, rewind to the authoritative state and replay the rest. A decaying render offset on the model and camera hides corrections; the view facing is never rewound. The F8 overlay shows unacknowledged and replayed inputs, ack lag, server buffer depth, input counters, simulation error and the visual offset, and the benchmark reports them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ENet's default throttle deceleration discarded 25-35% of unreliable commands and snapshots at 200 ms round trips: with steady added delay its round-trip variance is tiny, so frame-timing noise kept decelerating it. Clients and the server configure every server/client peer with deceleration 0. Reliable traffic keeps ENet's windowing and resends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The input buffer test covers duplicates, reordering, redundancy under 5% loss and three-packet bursts, gaps, starvation, catch-up, the tick timeout, resets and packet round trips. The reconciliation test flies a pilot through the network simulator: replays match the server on a clean link and through station collisions, corrections stay bounded at 150 ± 30 ms with 5% loss with no lost inputs, client teleports never move the server ship, and an instant 180° flip stays within the turn limit. Both run in the Windows and Linux suites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Timerk
force-pushed
the
feat/netcode-ticks
branch
from
November 26, 2026 19:21
8a63bb0 to
28d2af0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2 of 6 of the real-time netcode rework (
GAME_PLAN.md, "Real-time netcode rework").Depends on #144 (phase 1, network simulator) and targets its branch
feat/network-simulator. Merge #144 first, then retarget this PR tomain.Behaviour
command_flightis replaced byflight_inputs(PackedByteArray);NETWORK_SCHEMAis 24.InputBuffer, per pilot). Deduplicates by sequence, accepts reordering and consumes exactly one input per server tick throughPilot.simulate_input(), which keeps the 720°/s turn limit. The server never reads a client position or velocity, and all life, docking, death, map and jump checks stay.TIMEOUT_TICKS(30) the pilot is idle (no thrust, facing held) and brakes. This replaces the wall-clockCOMMAND_TIMEOUT, and fire intent also ages in server ticks.SPARE_DEPTH(2), the oldest surplus inputs are dropped. Depth is capped atMAX_DEPTH(12 ticks, 200 ms).FlightPrediction). On each new owner snapshot, the next client physics tick drops acknowledged inputs, resets position, velocity, energy, simulation facing and turn budget to the authoritative state, and replays the rest through the server's step, includingmove_and_slide()collisions. The body moves with the simulation facing on both sides, so station collisions replay the same contacts. The view facing (rotation) is never rewound, so mouse steering stays immediate; only the turn-limited simulation facing used for thrust follows the server.FlightPrediction.SMOOTHING_TIME= 0.12 s and snaps aboveSNAP_DISTANCE= 10 m. Respawn, jump, dock, launch and connect reset it. Exhaust plumes track the drawn position. Remote ships and aliens keep their current interpolation (phase 3).throttle_configure(5000, 2, 0)(FlightSession.ENET_THROTTLE). Reliable traffic keeps ENet's windowing and resends.Playtesting settings:
FlightPrediction.SMOOTHING_TIME,SNAP_DISTANCE,SEND_INTERVAL_TICKS;FlightInput.REDUNDANCY;InputBuffer.SPARE_DEPTH,CATCH_UP_WINDOW,MAX_DEPTH,TIMEOUT_TICKS.Before / after (
tests/netcode_benchmark.gd, same scripted flight)Three metrics changed meaning (explained in
docs/netcode-baseline.mdand the benchmark header). Error is now the simulation error at reconciliation, not the distance to a round-trip-old position. Correction is now the visible offset, not the 20% lerp jump. Lost now counts per-tick inputs.Error and correction p95 are 0.00 m in every after row. The remaining maxima are single catch-up drops or starved ticks, one tick of motion each, hidden over about 0.3 s. Client upload rose from 1.1 to 3.5 KB/s for the redundant 30 Hz packets. The gap grows by design: the local ship now leads the server by the upstream delay plus 2–5 buffered ticks, instead of being dragged back toward old snapshots.
ENet throttle, same phase 2 build at 200 ms with 5% loss: with ENet's default deceleration the server sent 10.5 KB/s (−27%), snapshot jitter p95 was 127 ms, sim error max 2.16 m and the server starved 11 ticks. With deceleration 0: 14.4 KB/s, 49 ms, 0.62 m and 1 tick. Full tables are in
docs/netcode-baseline.md.Validation
./tools/dev.ps1 check(Windows suite): passed (exit 0, 1011 s, every group including the newnetcode_reconciliation).netcode_reconciliationgroup):tests/input_buffer_test.gd: duplicates, reordering, redundancy with 5% loss plus three-packet bursts (0 lost), gaps and late arrivals, starvation reuse, tick timeout, catch-up to the spare depth, theMAX_DEPTHand flood bounds, life resets, packet round trips and malformed packets.tests/reconciliation_test.gd: a scripted client through the relay. On a clean link sim error p95 is 0.004 m and max 0.035 m, with no lost inputs. Flying into Outpost 01's collision envelope (81 colliding server ticks) gives max 0.0013 m. At 150 ± 30 ms with 5% loss, p95 is 0.005 m and max 0.63 m, with 0 lost and 0 late inputs. Bounds: p95 ≤ 0.02 m clean and ≤ 0.25 m degraded, max ≤ 1.5 m and ≤ 3.0 m. A client-side teleport does not move the server ship and is undone. An instant 180° flip never exceeds the per-tick turn limit and still converges.command_flightto useFlightSession.send_command(), which builds a real input packet. The non-finite command check became malformed-packet and non-finite-value checks. The slow-frame fire-timeout regression inalien_sector_testnow advances server ticks, because intents age in ticks.Known limitations (for phases 3–5)
SPARE_DEPTHandCATCH_UP_WINDOWare the tuning knobs.🤖 Generated with Claude Code