mirror of
https://github.com/t-affeldt/climate_api.git
synced 2024-12-22 17:00:36 +01:00
Merge pull request #8 from mazes-80/mazes-tweaks
Performance optimizations
This commit is contained in:
commit
4d0b080dd5
@ -1,9 +1,12 @@
|
|||||||
local GSCYCLE = 0.03 * climate_mod.settings.tick_speed -- only process event loop after this amount of time
|
local GSCYCLE = 0.3 * climate_mod.settings.tick_speed -- only process event loop after this amount of time
|
||||||
local WORLD_CYCLE = 30.00 * climate_mod.settings.tick_speed -- only update global environment influences after this amount of time
|
local WORLD_CYCLE = 30.00 * climate_mod.settings.tick_speed -- only update global environment influences after this amount of time
|
||||||
|
|
||||||
local gs_timer = 0
|
local gs_timer = 0
|
||||||
local world_timer = 0
|
local world_timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
local player_list = minetest.get_connected_players()
|
||||||
|
if #player_list == 0 then return end
|
||||||
|
|
||||||
gs_timer = gs_timer + dtime
|
gs_timer = gs_timer + dtime
|
||||||
world_timer = world_timer + dtime
|
world_timer = world_timer + dtime
|
||||||
|
|
||||||
@ -26,7 +29,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local current_effects = climate_mod.trigger.get_active_effects()
|
local current_effects = climate_mod.trigger.get_active_effects(player_list)
|
||||||
|
|
||||||
for name, effect in pairs(climate_mod.effects) do
|
for name, effect in pairs(climate_mod.effects) do
|
||||||
local cycle = climate_mod.cycles[name].timespan * climate_mod.settings.tick_speed
|
local cycle = climate_mod.cycles[name].timespan * climate_mod.settings.tick_speed
|
||||||
|
@ -83,20 +83,18 @@ local function get_weather_effects(player, weather_config, env)
|
|||||||
return effects
|
return effects
|
||||||
end
|
end
|
||||||
|
|
||||||
function trigger.get_active_effects()
|
function trigger.get_active_effects(players)
|
||||||
local environments = {}
|
local environments = {}
|
||||||
local effects = {}
|
local effects = {}
|
||||||
climate_mod.current_weather = {}
|
climate_mod.current_weather = {}
|
||||||
|
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(players) do
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
-- skip weather presets for dead players
|
-- skip weather presets for dead players
|
||||||
if hp ~= nil and hp > 0 then
|
if hp ~= nil and hp > 0 then
|
||||||
environments[pname] = trigger.get_player_environment(player)
|
local env = trigger.get_player_environment(player)
|
||||||
end
|
environments[pname] = env
|
||||||
local env = environments[pname]
|
|
||||||
if env ~= nil then
|
|
||||||
for wname, wconfig in pairs(climate_mod.weathers) do
|
for wname, wconfig in pairs(climate_mod.weathers) do
|
||||||
if is_weather_active(player, wname, env) then
|
if is_weather_active(player, wname, env) then
|
||||||
if climate_mod.current_weather[pname] == nil then
|
if climate_mod.current_weather[pname] == nil then
|
||||||
|
Loading…
Reference in New Issue
Block a user