Uriopass / Egregoria

3D City Builder without a grid
http://douady.paris/blog/
GNU General Public License v3.0
1.53k stars 52 forks source link

Determinism #90

Open Uriopass opened 1 year ago

Uriopass commented 1 year ago

Determinism is a requirement for multiplayer as the state is too big to be synchronized live. We use lockstep networking which means only sending the initial state and subsequent inputs. It is also very useful to be able to save replays to help with bug reports as it is easier to see what the player did to get there.

However this comes with a lot of hurdles as the game needs to be deterministic even through ser/deserialization cycles as the game is sent over the network and serialized mid-replay.

Usually, this means that iteration order must be stable wherever used, ids must be stable if they are stored and used elsewhere, and in general any hidden state should be saved if it affects the game state in any way.

Note that determinism must only be there for the game state (the egregoria crate), the UI can be as random as it wants.

With that said, here's a list of recommendations and tracking issues about this:

Uriopass commented 1 year ago

After a big rewrite I have removed hecs in favor of a simple "entity lists" that has been working well for me for the map.

This allows me to get a better grip on determinism and serialization. However it makes iterations a bit more expensive (less cache friendly).

Uriopass commented 1 year ago

A fork of slotmap with serialized freelist has been made although it is unsound if the serialized data cannot be trusted. (fixed since then)