Skip to content

Mirror upstream PR #9: deterministic prediction + ack replay#7

Open
web3dev1337 wants to merge 5 commits intomasterfrom
review/mirror-upstream-pr-9
Open

Mirror upstream PR #9: deterministic prediction + ack replay#7
web3dev1337 wants to merge 5 commits intomasterfrom
review/mirror-upstream-pr-9

Conversation

@web3dev1337
Copy link
Copy Markdown
Owner

This PR mirrors upstream PR hytopiagg#9 onto this fork’s master so we can review/test it here.

No additional changes beyond cherry-picking the upstream commits.

RicardoDeZoete added 5 commits March 4, 2026 12:09
- Introduced new collision detection logic in the Camera class to improve camera behavior during gameplay.
- Added methods for sampling game camera collision distance and determining when to sample based on movement and direction.
- Updated EntityManager to include vertical velocity estimation and refined movement direction tracking for better local prediction accuracy.
- Adjusted local prediction parameters for horizontal and vertical movement to enhance responsiveness and stability.
- Added new properties to LocalPredictionState for pre-acknowledgment reconciliation and acknowledgment support detection.
- Updated initialization and reset logic to incorporate new state properties.
- Improved command buffering behavior based on acknowledgment support and pre-acknowledgment grace period.
- Refined reconciliation logic to handle pending commands and ensure smoother movement transitions.
- Introduced a new property in LocalPredictionState to track pending speed calibration acknowledgment.
- Updated logic to manage speed calibration input sequence numbers during movement command acknowledgment.
- Refined speed estimation methods to utilize the new calibration acknowledgment for improved accuracy in movement predictions.
…ion logic

- Introduced a new system for handling sequenced movement inputs in the Player class, allowing for better input management and simulation.
- Added methods to enqueue and apply queued movement commands, enhancing responsiveness during gameplay.
- Updated the Camera class to differentiate collision raycast intervals for mobile and desktop platforms, improving camera behavior based on device type.
- Refined movement direction calculations in the DefaultPlayerEntityController to utilize a new deterministic movement resolution method, ensuring smoother character control.
@web3dev1337
Copy link
Copy Markdown
Owner Author

Review notes (mirrored from upstream PR #9)

Overall: direction looks solid — deterministic movement parity + ack-aware replay + tick-aligned server input application should noticeably reduce “tug” and jitter.

🚨 Potential correctness issue (camera yaw/pitch can get dropped)

On the server, sequenced movement packets are queued, but applyQueuedInputForSimulation() collapses the queue to the last command and only applies cp/cy if they exist on that last command:

  • server/src/players/Player.ts (applyQueuedInputForSimulation())

Because the client only includes cp/cy when they change (client/src/input/InputManager.ts), it’s possible for:

  1. cp/cy to be present in an earlier queued command,
  2. not present in the last command,
  3. and then never applied after the batch collapses.

That can leave the server’s camera orientation stale (movement direction resolution becomes wrong) under jitter / packet bunching.

Suggested fix: when consuming a batch, scan the queued commands (from the end) for the most recent defined cp and cy, and apply those even if the last command omits them (similar to how jump intent is preserved via sawJumpPressed).

Compatibility / “old games” risk areas

  • Movement inputs now go unreliable + sequenced. WASD/shift/jump/crouch/joystick are now sent as snapshots with sq and usually unreliable; correctness depends on the resend/continuous-snapshot logic in client/src/input/InputManager.ts. This should be fine, but it’s a behavior change vs reliable edge-triggered packets.
  • Protocol field aq + strict schema. If a newer server sends aq to an older client whose schema doesn’t include it (and additionalProperties: false), validation could reject entity packets. This PR gates on server-side protocol support, not per-client feature negotiation. Safe if client/server/protocol deploy together; risky under mixed versions.
  • Cutscene-style input disabling: server/src/worlds/entities/PlayerEntity.ts calls player.applyQueuedInputForSimulation() even when tickWithPlayerInput is disabled. That may still update player.input + player.camera orientation during “controls disabled” flows.

Performance notes

  • Client prediction cost: per-frame substepping is capped (6 substeps). The heavier path is replay: up to 96 buffered commands × up to 12 substeps each (worst-case spike after stalls). Might be worth capping total replay work per frame or amortizing across frames if spikes show up.
  • Camera collision: switching raycasts from every-frame to interval/threshold-based sampling is a win for CPU, especially on mobile.
  • Network bandwidth: movement snapshots at 60 Hz (desktop) / 30 Hz (mobile) are still small, but higher steady-state than only sending changes.

Suggested manual test matrix

  • High jitter + packet loss: confirm no “stale yaw” movement, no stuck movement on key-up.
  • Mobile third-person: confirm camera collision doesn’t clip through walls during fast turns/teleports.
  • Example games (sdk-examples/): confirm any custom controllers / cutscene input disabling behaves the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant