Desync-safe generated coordinates list?
Posted: Fri Feb 21, 2020 10:43 am
The following code produces an array of grid coordinates and then sorts them into order of distance from (0,0):
I want this list to be available for a function in control.lua, for plonking down item spills in a circular pattern from the origin, rather than running the maths every time the function is called. It's basically a look-up table for the nth nearest grid position from the centre.
It's deterministic, right?
... Isn't it?
I could do the following:
1. Believe it's deterministic and will always have the same result on any machine, so it's desync-safe, so I can just keep it in a local variable and treat it as a constant.
2. Keep it in the global table to be safe, but it will be sent around the network a fair bit even though it never changes during a game session.
3. Dump it to a text file, turn that output into a Lua table, and require it as fixed data. And then have to re-do all of that if I ever need it to change.
I want 1 because I'm lazy. But paranoia reigns. What would you do?
Code: Select all
local circle_list = {}
for x = -5,5 do
for y = -5,5 do
table.insert(circle_list, {x=x,y=y})
end
end
table.sort(circle_list, function (k1,k2) return math.sqrt((k1.x^2)+(k1.y^2)) < math.sqrt((k2.x^2)+(k2.y^2)) end )
It's deterministic, right?
... Isn't it?
I could do the following:
1. Believe it's deterministic and will always have the same result on any machine, so it's desync-safe, so I can just keep it in a local variable and treat it as a constant.
2. Keep it in the global table to be safe, but it will be sent around the network a fair bit even though it never changes during a game session.
3. Dump it to a text file, turn that output into a Lua table, and require it as fixed data. And then have to re-do all of that if I ever need it to change.
I want 1 because I'm lazy. But paranoia reigns. What would you do?