Deterministic Lockstep Study

This repository is intended to study real time physics-based gameplay using deterministic lockstep with delay and rollback.

The following examples were performed:

  • In the same computer (theorically it should also work in different ones because I'm using a deterministic cross-platform physics engine)
  • Applying inputs on the left window
  • Simulated latency of 50 and 200ms respectively
same-computer-50ms.mp4
same-computer-200ms.mp4

In the 200ms game on the right, it's really noticiable things teleporting after rollback caused by missprediction. This could be addressed by #37.

One last thing to emphasize is that even if you stop the video at the same frame, especially in the 200ms, you might see a slightly different simulation which is not an issue because eventually it'll rollback and correct the position. An determinism/implementation problem is noticiable at the level you can tell that both simulations are completely different without needing to pause it because a small error becomes big in no time.

Overview

The physics is being simulated by a deterministic cross-platform physics engine called Rapier.

The client/server communication is performed by Colyseus, a library built over WebSockets that creates a TCP connection, which basically means that we have guaranteed in-order delivery

The netcode uses deterministic lockstep with static delay and rollback, the basic idea is that we only send/receive inputs to recreate the exactly same simulation in all clients, that's why we need a deterministic cross-platform physics engine.

For more details about the netcode, take a look at the Deterministic Lockstep implementation doc.

Developing

Install dependencies from client and server:

./install.sh

Start in watch mode, it'll reload server/client after every change:

yarn watch

Note that after changing client code it'll take a while to transpile and you'll need to reload the html page.

Open localhost:2567/client with a single or more browser windows to play

Controls:

  • WASD - move character
  • Space - jump/fly

Credits

License

MIT