Here is some background info:
I have shared PhysicsEngine which is fully deterministic (if you have the same exact state feeding the same exact inputs and tick the same exact number of times, the end result will be the same). The simulation “ticks” at a constant frequency 20Hz. RenderEngine is working separately at its own refresh rate, so I will no describe it here.
Client-side step:
Creates Input package based on the current keyboard/mouse state.
Assigns unique id (basically frame number) to the Input and send it to the server.
Saves Input in the array for future reconciliation.
Passes the Input to the PhysicsEngine and calculates predicted WorldState.
Receives WorldState from the server, search for the relevant Input in the array and make server reconciliation (re-applies inputs that are not confirmed yet and clears all confirmed inputs based on the id)
Makes a smooth transition from predicted to the authoritative position (if needed).
So, on every step of the simulation, we receive two snapshots:
Input - a packaged information about the current input device state (mouse position, keys pressed and attached unique id)
WorldState - calculated with PhysiscsEngine information about all entities (position, velocity, etc.). Also includes unique id.
Server-side step:
Generates a WorldState based on received Input packages.
Sends a current WorldState to the clients.
QUESTION:
Basically, client-side prediction and server reconciliation works well except one thing. As I said before, both client and server sides running with the same PhysicsEngine code (thanks to js) at the refresh rate 20 times per second. BUT on the client side it runs a little bit faster (here is why).
So WorldState and Input snapshots are generating faster on the client side that server side, e.g. while server generates 484 tick, a client is at 502 or even more. After some time, a difference so big that the client starts to be littered with non-accepted inputs because they are produced more frequency than on the server side.
In ideal will be cool if client and server simulation rates will be independent.
How to deal with that? Any ideas?
↧