thomaswp / BeaverBuddies

GNU General Public License v3.0
16 stars 2 forks source link

Desync when water changes levels due to parallel nondeterminism #34

Open thomaswp opened 1 month ago

thomaswp commented 1 month ago

To reproduce: wait for or cause a large change in water levels and run the game at a high speed as the simulation ticks. Example: desync.zip

What happens: The game desyncs due to (at a minimum) soil moisture levels getting out of sync.

Why: Timberborn currently runs a bunch of simulations in parallel each tick. The result of one simulation seems to depend on another, specifically:

In theory (at least as I understand it), these simulations are designed to have threadsafe data, and they read from the prior tick's results, not the currently processing tick. However, I get non-deterministic results.

One fix may be to investigate when the results flip from the prior to the current tick's simulation results. It's possible this is what's nondeterministic.

Can currently be fixed by setting #NO_PARALLEL, but this would also deteriorate performance, so I'd like to find a workaround if possible.

If not it may have to be a configurable setting.