Page 1 of 1

LuaGameScript.small_tick

Posted: Sun Dec 17, 2023 4:44 am
by DaveMcW
FFF 388 announced engine support for ticks up to 2^64, but only Lua support for ticks up to 2^52.

We can work around the Lua limit by breaking up the tick into two 32-bit numbers. The upper 32 bits are easy to calculate from LuaGameScript.tick. But we need a new property that contains the lower 32 bits. Call it LuaGameScript.small_tick.

Re: LuaGameScript.small_tick

Posted: Sun Dec 17, 2023 9:40 am
by Freddy404
If something like this is done, I think it should be the other way round. If the new property contains the upper, i.e. slower changing bits, everything simply using LuaGameScript.tick will continue to work without issue until tick 2^52-1, instead of breaking immediately.

However, I question the necessity of accessing the upper 12 bits - as stated in the FFF, 52 bits last for 2.37 million years. Even with increased game speed, the limit won't be less than thousands of years of continuously running the same (!) save. It seems unlikely that this is a problem anybody will actually encounter.

Re: LuaGameScript.small_tick

Posted: Sun Dec 17, 2023 10:28 am
by boskid
I do not get what this request is about. In all realistic cases i assume the upper 12 bits will always be 0 so every tick value can be represented accurately by a `double` and as such LuaGameScript::tick exposing full value is the best possible solution.

Re: LuaGameScript.small_tick

Posted: Sun Dec 17, 2023 11:59 am
by curiosity
DaveMcW wrote:
Sun Dec 17, 2023 4:44 am
FFF 388 announced engine support for ticks up to 2^64, but only Lua support for ticks up to 2^52.

We can work around the Lua limit by breaking up the tick into two 32-bit numbers. The upper 32 bits are easy to calculate from LuaGameScript.tick. But we need a new property that contains the lower 32 bits. Call it LuaGameScript.small_tick.
It's more likely that by the time anyone would be capable of reaching 2^52 Factorio will be updated to a newer Lua version and thus be capable of operating on 64-bit integers.

Re: LuaGameScript.small_tick

Posted: Sun Dec 17, 2023 2:57 pm
by FuryoftheStars
Agreed with the other comments here that this is probably not necessary. I mean, just to get the tick count to run out in your lifetime, you'd need to run the game at speed 40 to 50 thousand, maybe faster, depending on your current age and how long you'll live to. Even at 10k speed, it's apt to not run out until several generations down the line. Putting aside whether or not any modern (non-mainframe server) computers can even run the game at those speeds, it would be pointless as we wouldn't be able to process what's going on.

Re: LuaGameScript.small_tick

Posted: Sun Dec 17, 2023 4:20 pm
by quyxkh
It's this simple: 2^52 ticks is over two million years.

Re: LuaGameScript.small_tick

Posted: Sun Dec 17, 2023 5:18 pm
by pleegwat
And even 2^52 microseconds (that is, a million UPS) is well over a hundred years.