Make cloud parameters deterministic across sessions

This commit is contained in:
sfan5 2023-12-30 11:30:46 +01:00 committed by GitHub
parent c0200b0a01
commit e9676fa632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,13 +76,21 @@ local function rangelim(value, lower, upper)
return math.min(math.max(value, lower), upper) return math.min(math.max(value, lower), upper)
end end
local os_time_0 = os.time() local t_offset
local t_offset = math.random(0, 300000) do
local meta = minetest.get_mod_storage()
if meta:contains("time_offset") then
t_offset = meta:get_int("time_offset")
else
-- Use random offset so not each new world behaves the same.
t_offset = math.random(0, 300000)
meta:set_int("time_offset", t_offset)
end
end
local function update_clouds() local function update_clouds()
-- Time in seconds. -- Adjusted time in seconds
-- Add random time offset to avoid identical behaviour each server session. local time = math.floor(minetest.get_gametime() - t_offset)
local time = os.difftime(os.time(), os_time_0) - t_offset
nobj_density = nobj_density or minetest.get_perlin(np_density) nobj_density = nobj_density or minetest.get_perlin(np_density)
nobj_thickness = nobj_thickness or minetest.get_perlin(np_thickness) nobj_thickness = nobj_thickness or minetest.get_perlin(np_thickness)
@ -103,10 +111,10 @@ local function update_clouds()
-- density_max = 0.8 at humid = 50. -- density_max = 0.8 at humid = 50.
-- density_max = 1.35 at humid = 100. -- density_max = 1.35 at humid = 100.
local density_max = 0.8 + ((humid - 50) / 50) * 0.55 local density_max = 0.8 + ((humid - 50) / 50) * 0.55
-- Range limit density_max to always have occasional
-- small scattered clouds at extreme low humidity.
local density = rangelim(density_max, 0.2, 1.0) * n_density local density = rangelim(density_max, 0.2, 1.0) * n_density
player:set_clouds({ player:set_clouds({
-- Range limit density_max to always have occasional
-- small scattered clouds at extreme low humidity.
density = density, density = density,
thickness = math.max(math.floor( thickness = math.max(math.floor(
rangelim(32 * humid / 100, 8, 32) * n_thickness rangelim(32 * humid / 100, 8, 32) * n_thickness