summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon <brandon@bremaweb.com>2013-06-20 09:11:19 -0500
committerBrandon <brandon@bremaweb.com>2013-06-20 09:11:19 -0500
commitceb46b8bf61d0b02a6eb3a12d6f5a255dc1fa247 (patch)
tree4603f01114c6cf6e02f3638fb59c9bf670012cc6
parent75c9d33b5ee8404074b0786511794e4fa67f6ed2 (diff)
make global_step more efficient, don't redraw hud if land owner hasn't changed
-rw-r--r--init.lua26
1 files changed, 19 insertions, 7 deletions
diff --git a/init.lua b/init.lua
index 030e355..a0e10fa 100644
--- a/init.lua
+++ b/init.lua
@@ -317,16 +317,28 @@ minetest.register_entity("landrush:showarea",{
minetest.register_globalstep(function(dtime)
gstepCount = gstepCount + dtime
- if ( gstepCount > 1 ) then
+ if ( gstepCount > 2 ) then
+ local sameowner = false
for _,player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
- if ( playerHudItems[name] ) then
- player:hud_remove(playerHudItems[name])
- end
owner = landrush.get_owner(player:getpos())
- if ( owner ~= nil ) then
- playerHudItems[name] = player:hud_add({
+
+ if ( playerHudItems[name] ~= nil ) then
+ if ( playerHudItems[name].lastowner == owner ) then
+ -- same owner as last time don't update the hud
+ sameowner = true
+ end
+ end
+
+ if ( playerHudItems[name] ~= nil and sameowner == false ) then
+ player:hud_remove(playerHudItems[name].hud)
+ playerHudItems[name] = nil
+ end
+
+ if ( owner ~= nil and sameowner == false ) then
+ minetest.log('action','Redraw hud for'..name)
+ playerHudItems[name] = {hud = player:hud_add({
hud_elem_type = "text",
name = "LandOwner",
number = 0xFFFFFF,
@@ -334,7 +346,7 @@ minetest.register_globalstep(function(dtime)
text="Land Owner: "..owner,
scale = {x=200,y=25},
alignment = {x=0, y=0},
- })
+ }), lastowner=owner}
end
end
gstepCount = 0