thomaswp/BeaverBuddies

Replace random

Closed this issue · 1 comments

I haven't had a chance to test out the mod yet, but after reading some of the documentation I have noticed room for two improvements that could be made with a single change.

The documentation states that you had to reroute everything away from the random function to keep it consistent across all users. What I suggest is to simply outright replace the call to the RNG entirely with a simpler method.

Let be honest, why risk desync errors throughout the game from weird bugs when you could have the mod simply double check its work for any given tick against a static list? Let say pi as an example. At the start of the game have the host make a single random call for where to start reading in the massive string of numbers and simply progress from there?

By making the call once at the start you still get a pseudo random series of events while completely cutting out the chance that a dysnc occurs because someone didn't update on the tick correctly and tried to play catchup with incorrect info. This isn't a Vegas casino, we don't need true random and I highly doubt most players will ever notice any kind of pattern in the tree growth or beaver injuries.

The second part of this is that by doing it this way you could allow for players to join mid game simply by having the host send the position in the number string for the connecting players to sync up to.

Doing it this way not only makes it much easier to fix some existing problems but would allow for so many other features and other mod developers to add content without utterly breaking the entire thing.

As a non-programmer I'm obviously simplifying things, but if I'm understanding everything I've read then this seems like the best solution to properly synchronize everything.

@Krell356 thanks for the suggestion. What you're suggesting is already how the game (and the mod) work. There's not such thing as random in a computer game. We use pseudorandom number generators, and if you give them a seed, they're completely deterministic. So your suggestion of "a massive string of numbers" that both client and server share is exactly what happens. The problem is that if one computer asks for a number one more time than the other, now they're completely desynced, since starting that sequence at position X will yield completely different results than starting it at position X-1.

You might think we could just sync the start position at every frame, and that would reduce the diversion between the client and server if something like this happened. But unfortunately if the game state differs in any way, even if they generate the same set of random numbers each frame, the two computers will still desync. E.g. if one game has a beaver get sick and another doesn't, the game would play out differently even if there was no randomness at all.

You could sync the whole state of the game every frame, but that's a massive endeavor, which wouldn't be maintainable at all as the game releases new updates. So unfortunately, this is our only option.