Optimise hudbars: cache settings

This commit is contained in:
rubenwardy 2015-12-06 00:20:25 +00:00
parent fb0285f27c
commit 16aaecfae3

View file

@ -422,25 +422,17 @@ end
local function custom_hud(player) local function custom_hud(player)
if minetest.setting_getbool("enable_damage") or hb.settings.forceload_default_hudbars then local hide = false
local hide
if minetest.setting_getbool("enable_damage") then
hide = false
else
hide = true
end
hb.init_hudbar(player, "health", player:get_hp(), nil, hide) hb.init_hudbar(player, "health", player:get_hp(), nil, hide)
local breath = player:get_breath() local breath = player:get_breath()
local hide_breath local hide_breath
if breath == 11 and hb.settings.autohide_breath == true then hide_breath = true else hide_breath = false end if breath == 11 and hb.settings.autohide_breath == true then hide_breath = true else hide_breath = false end
hb.init_hudbar(player, "breath", math.min(breath, 10), nil, hide_breath or hide) hb.init_hudbar(player, "breath", math.min(breath, 10), nil, hide_breath or hide)
end end
end
-- update built-in HUD bars -- update built-in HUD bars
local function update_hud(player) local function update_hud(player)
if minetest.setting_getbool("enable_damage") then
if hb.settings.forceload_default_hudbars then if hb.settings.forceload_default_hudbars then
hb.unhide_hudbar(player, "health") hb.unhide_hudbar(player, "health")
end end
@ -456,10 +448,6 @@ local function update_hud(player)
--health --health
hb.change_hudbar(player, "health", player:get_hp()) hb.change_hudbar(player, "health", player:get_hp())
elseif hb.settings.forceload_default_hudbars then
hb.hide_hudbar(player, "health")
hb.hide_hudbar(player, "breath")
end
end end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
@ -480,12 +468,10 @@ minetest.register_globalstep(function(dtime)
if main_timer > hb.settings.tick or timer > 4 then if main_timer > hb.settings.tick or timer > 4 then
if main_timer > hb.settings.tick then main_timer = 0 end if main_timer > hb.settings.tick then main_timer = 0 end
-- only proceed if damage is enabled -- only proceed if damage is enabled
if minetest.setting_getbool("enable_damage") or hb.settings.forceload_default_hudbars then
for playername, player in pairs(hb.players) do for playername, player in pairs(hb.players) do
-- update all hud elements -- update all hud elements
update_hud(player) update_hud(player)
end end
end end
end
if timer > 4 then timer = 0 end if timer > 4 then timer = 0 end
end) end)