2020-04-18 08:01:36 +02:00
|
|
|
local GSCYCLE = 0.03 * climate_mod.settings.tick_speed
|
|
|
|
local WORLD_CYCLE = 2 * climate_mod.settings.tick_speed
|
2020-04-09 09:03:02 +02:00
|
|
|
|
2020-04-13 01:55:39 +02:00
|
|
|
local gs_timer = 0
|
|
|
|
local world_timer = 0
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
gs_timer = gs_timer + dtime
|
|
|
|
world_timer = world_timer + dtime
|
2020-04-09 09:03:02 +02:00
|
|
|
|
2020-04-13 01:55:39 +02:00
|
|
|
if gs_timer + dtime < GSCYCLE then return else gs_timer = 0 end
|
2020-04-09 09:03:02 +02:00
|
|
|
|
2020-04-13 01:55:39 +02:00
|
|
|
if world_timer >= WORLD_CYCLE then
|
|
|
|
local noise_timer = climate_mod.state:get_float("noise_timer") + world_timer
|
|
|
|
world_timer = 0
|
|
|
|
climate_mod.state:set_float("noise_timer", noise_timer)
|
|
|
|
climate_mod.world.update_status(noise_timer)
|
2020-04-25 15:49:53 +02:00
|
|
|
climate_mod.global_environment = climate_mod.trigger.get_global_environment()
|
2020-04-09 18:31:52 +02:00
|
|
|
end
|
2020-04-09 09:03:02 +02:00
|
|
|
|
2020-04-16 08:05:16 +02:00
|
|
|
local previous_effects = table.copy(climate_mod.current_effects)
|
|
|
|
local current_effects = climate_mod.trigger.get_active_effects()
|
2020-04-09 09:03:02 +02:00
|
|
|
|
2020-04-13 01:55:39 +02:00
|
|
|
for name, effect in pairs(climate_mod.effects) do
|
2020-04-18 08:01:36 +02:00
|
|
|
local cycle = climate_mod.cycles[name].timespan * climate_mod.settings.tick_speed
|
|
|
|
if cycle < climate_mod.cycles[name].timer + dtime then
|
2020-04-13 01:55:39 +02:00
|
|
|
climate_mod.cycles[name].timer = 0
|
2020-04-16 08:05:16 +02:00
|
|
|
climate_mod.current_effects[name] = current_effects[name]
|
|
|
|
climate_mod.trigger.call_handlers(name, current_effects[name], previous_effects[name])
|
2020-04-14 05:44:46 +02:00
|
|
|
else
|
|
|
|
climate_mod.cycles[name].timer = climate_mod.cycles[name].timer + dtime
|
2020-04-09 18:31:52 +02:00
|
|
|
end
|
|
|
|
end
|
2020-04-09 09:03:02 +02:00
|
|
|
end)
|