Skip to content
vr-thi edited this page Jul 17, 2017 · 2 revisions

As every image (one per wall and one per eye) is rendered by an own pc, we had to find a way how to synchronize them over a LAN. To achieve a precise but also fast synchronization, we used two basic concepts.

Framelocking / Lockstep

The lockstep algorithm is a wide known method for synchronizing without having to exchange the translation/rotation/scale of every object in every frame. The basic idea is to just synchronize all input values like mouse position, current time, delta time etc. and as every machine runs the same code, the rendered output will also be the same (if the calculations are fully deterministic).

Process

Application Start

When starting your Unity appplication the Synchronizer script will try to establish the connection in the Update() method in the very first frame.

Master

The master waits until all configured slaves have been connected. The whole application will be blocked until this happens, there is no timeout!

Slave

The slaves try to connect to the master. If they fail, they will try again until the 5 seconds timeout is reached. If no connection could be established, the slave will exit.

Frame by frame

Here you can see what happens in every frame after the application start:

At the very beginning of every frame the server sends all input values which are necessary for rendering the next frame to the clients. The clients wait until they have received the input values and then start to render.

At the end of every frame the client sends a package back to the server that he has successfully rendered the scene. After the server has received this message from every client, it starts with the next frame.

In this way we make sure clients render the same state in every frame by just synchronizing a small bundle of input values. Also this method automatically ensures that the rendering speed is nearly the same on all machines.

Application Close

If either a slave or the master is closed after the application started, the application will be closed on every machine simultaneously.

Determinism

The only problem is that this whole process only works, if the rendering process is fully deterministic. This is not true for Unity games. The whole physics calculation is totally random and there is no way to synchronize its random seeds.

So everything which results of the rendering process like rigid body transformations or collision events needs to be synchronized in every frame. Obviously that might not be the fastest solution, but only in this way we can make sure, that computations which rely on those values calculate the same result on slaves and master.

Class diagram

In the next image you can see the class structure which manages the described synchronization:

Clone this wiki locally