Lockstep Prediction - MassiveMiniteam/OddModKit GitHub Wiki
Prediction
Due to the lockstep all Commands are delayed for 300ms. Commands can support "prediction" to hide this latency. Normally that means already doing something visually in the presentation before the command is run for real.
Predicted commands run every frame as prediction until they get actually executed.
Inventory
Inventory prediction is a bit more complicated than other predictions. To ensure snappy item dragging and dropping a complete copy of predicted inventory components are created.
In practice that means that the inventory UI that the players see are not showing the data of the actual simulation but a locally predicted copy of it. Every frame (not simulation frame, 60fps for example) the following happens:
- Do a simulation frame if possible and needed.
- Reset all predicted components to the state of the real simulation data (the inventory resets all its items to the same as the simulation data)
- Execute all predicted commands that havent run yet (for example moving an item from slot 1 to slot 2)
This ensures correct visuals when player A picks up an item but player B moves that item 100ms later. For player B it looks like the move worked for the first 200ms. At 200ms the command from player A gets executed and player A picks it up. For the next 100ms until the player B command runs, the prediction also doesnt move the item because its not there anymore.
Predicted components that dont get used for 60s are destroyed.
Spark throwing
Spark throwing is predicted. That means on the local client we throw the spark immediately. To hide the latency of 300ms, the duration of the throw is 300ms longer for the local client than for other clients.
other
We also predict common interactions like placing a building or other interactions that need to feel snappy.