Page 1 of 1
Keeping Mod deterministic
Posted: Tue Oct 04, 2016 9:24 pm
by reaperrar
I've just started creating a mod and I'm wondering how we can keep things deterministic (common things to do/avoid) so they work flawlessly in multiplayer.
Also, I've done some research and have found things as simple as using floating point numbers will result in non-deterministic behaviours across simulations because of rounding logic differences. However, I've looked at the internals of some other mods and floating point number usage is common and seems to not result in a desync :/
Is it safe to do a simple interpolation between two integers, where the scalar value used to multiply is a floating point number?
Re: Keeping Mod deterministic
Posted: Tue Oct 04, 2016 10:08 pm
by aubergine18
Rounding numbers issue should hopefully be resolved since
0.14.10 - if not please report issues in bug reporting forum so the devs know.
Other than that, see
http://lua-api.factorio.com/latest/Data-Lifecycle.html
Re: Keeping Mod deterministic
Posted: Tue Oct 04, 2016 10:24 pm
by reaperrar
I appreciate your response. However, I'm a little confused about the relevancy of the data lifecycle in respect to my opening questions. I can see that the mod load order is deterministic but not much else other than that.
Also, rounding issues are still present in the current version (13.20)? So it is not safe to use floating point numbers currently?
Re: Keeping Mod deterministic
Posted: Tue Oct 04, 2016 10:30 pm
by aubergine18
If you're using old version of Factorio, like 0.13 branch, you will sill have those errors. I suggest upgrading to the 0.14 branch.
If you do need to work around the rounding errors in 0.13, take a look at this code:
https://github.com/narc0tiq/evoGUI/blob ... tor.lua#L8
Another thing that sometimes causes desync is making local references to math functions, for example:
local round = math.round -- this can cause problems
Re: Keeping Mod deterministic
Posted: Tue Oct 04, 2016 10:50 pm
by reaperrar
aubergine18 wrote:If you're using old version of Factorio, like 0.13 branch, you will sill have those errors. I suggest upgrading to the 0.14 branch.
If you do need to work around the rounding errors in 0.13, take a look at this code:
https://github.com/narc0tiq/evoGUI/blob ... tor.lua#L8
Another thing that sometimes causes desync is making local references to math functions, for example:
local round = math.round -- this can cause problems
Cheers, so fixed point math is required in place of float operations then it seems. Your example will help heaps.
On a side note, I'm obviously missing how to upgrade to 0.14 given current steam version is 13.20 (beta opt in needed or such?). Anyway, isn't i most safe when developing for the general public to dev for the current release?
Re: Keeping Mod deterministic
Posted: Tue Oct 04, 2016 10:52 pm
by aubergine18
A lot of mods being uploaded to portal already require 0.14 branch as it fixes so many things with each new release.
To get 0.14 on steam, you'll need to opt in to beta releases via library > right click game in sidebar > properties.
Re: Keeping Mod deterministic
Posted: Wed Oct 05, 2016 12:48 am
by reaperrar
aubergine18 wrote:A lot of mods being uploaded to portal already require 0.14 branch as it fixes so many things with each new release.
To get 0.14 on steam, you'll need to opt in to beta releases via library > right click game in sidebar > properties.
Well, that's fair enough. Unfortunately I'm paying for a service where I don't have access to update the server to opt into beta versions.
That aside, I'm still not understanding how other popular mods (requiring version 0.13) which don't implement any fixed point math are desync free when they are clearly using floating point numbers.