Smoother client interactions
Opened this issue · 0 comments
Vap0r1ze commented
The client should be able to predict the result of most actions, so that it can play it's animations when the user interacts, instead of waiting for the server to tell it. There should be some anticipation system, here's my idea of how to do it:
- Make a map of action types to functions that product predicted events
- When sending a client request packet, if the request is a predictable one do the following:
- Backup the client state along with the new predicted events
- Commit the events
- When you recieve your next response, created a filtered version of the new events, by filtering out the predicted events.
- Commit the filtered events
- Now to check that you've anticipated correctly, you need to create two game states to check for equality:
- settle each unfiltered event to the backed up version of the game state, call this the accurate state
- settle each event in the event queue to a copy of the current game state, call this the predicted state. - If the stringified json of the accurate game state matches that of the predicted game state, then clear the backup and do nothing. Otherwise, clear the event queue, change the game state to the accurate one.