littensy / slither

🐍 A casual game with a soothing Catppuccin color palette

Home Page:https://www.roblox.com/games/14162747150

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimistic client movement

littensy opened this issue · comments

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.