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.
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
π’ Server Tick
βοΈ Notes
useSnakesOnScreen
hook. It should replace the snake entry for the client with the local version.