Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimistic client movement #118

Open
littensy opened this issue Sep 29, 2023 · 0 comments
Open

Optimistic client movement #118

littensy opened this issue Sep 29, 2023 · 0 comments
Labels
game:core Core mechanics on the client and server needs investigation This issue needs further investigation type:perf Regarding performance and optimization

Comments

@littensy
Copy link
Owner

littensy commented Sep 29, 2023

Consider an accurate way to render the client ahead of the server to mask input delay.

This is a major change, and it requires reworking a lot of internal systems.

🔵 Client Tick

  • The client updates its positions in state
  • The client sends a snapshot of the positions, current angle, desired angle, and boost state to the server
  • The server validates this snapshot
    • Check if the player can boost
      • Give the client a higher minimum score for boosting to prevent rare desyncs here
    • Check if positions are within margin of error of the current snapshot / latest queued snapshot
    • If anything fails, clear the queue and rubber-band
  • The server adds the client's snapshot to a queue

🟢 Server Tick

  • The server iterates through every player queue
  • Pop the earliest snapshot in the queue and update their snake to match
    • If the queue is empty, calculate the next snapshot from the current one
  • AFTER updating, check if a queue isn't empty for too long; if so, clear it and rubber-band

✏️ Notes

  • The client needs its own snake state separate from the server's. This is the best way to prevent interference from the server trying to update it.
  • The app needs to render the client version of the snake. This can be handled in the useSnakesOnScreen hook. It should replace the snake entry for the client with the local version.
  • Both the client and server need to use the same snake solver. Avoid duplicating logic when trying to implement the snake solver on the client, as this makes it harder to maintain.
  • A remote needs to be made to allow the server to force an update on a client.
@littensy littensy added type:perf Regarding performance and optimization game:core Core mechanics on the client and server needs investigation This issue needs further investigation labels Sep 29, 2023
@littensy littensy pinned this issue Sep 29, 2023
@littensy littensy unpinned this issue Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
game:core Core mechanics on the client and server needs investigation This issue needs further investigation type:perf Regarding performance and optimization
Projects
None yet
Development

No branches or pull requests

1 participant