This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
Remove floating point string formatting for multiplayer multiplatform compatibility, fixes issue #34 #47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The only sensor using floating points was the evolution factor and pollution around player sensors. Day time, kill count, player locations, and play time all used integers already.
I believe the main problem with floats is that the string.format (which essentially just calls the system library printf or similar) is platform-dependent. This is supported by FFF 108: https://www.factorio.com/blog/post/fff-108 . The gist of the problem, as I understand it, is that the system library may return differing values for Linux, Mac, and Windows. However, there is no differing return values for integers, so doing mathematical trickery to break a floating point number into two integers (the whole number component and fractional decimal component), and printing a floating number as a string made up of two integers should side-step the platform-dependency issues. This fixes #34 [reformatted for auto-close -Narc].
Possibly in the future when Factorio moves to LuaJIT, this will go away (as LuaJIT has it's own platform-independent string formatter), but for now, this code is needed.