use minetest.hash_node_position instead of a custom function to increase performance thanks to @t4im(Tim)

This commit is contained in:
kaadmy 2015-09-22 10:29:46 -07:00
parent fc33cfd001
commit 320c2a9eb9
3 changed files with 19 additions and 13 deletions

View File

@ -9,7 +9,7 @@ music.players = {} -- music players
if minetest.setting_getbool("music_enable") then
function music.stop(pos)
local dp = default.dumpvec(pos)
local dp = minetest.hash_node_position(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Music player(Off)")
@ -22,7 +22,7 @@ if minetest.setting_getbool("music_enable") then
end
function music.start(pos)
local dp = default.dumpvec(pos)
local dp = minetest.hash_node_position(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Music player(On)")
@ -52,7 +52,7 @@ if minetest.setting_getbool("music_enable") then
end
function music.update(pos)
local dp = default.dumpvec(pos)
local dp = minetest.hash_node_position(pos)
if music.players[dp] ~= nil then
local node = minetest.get_node(pos)
@ -70,7 +70,7 @@ if minetest.setting_getbool("music_enable") then
end
function music.toggle(pos)
local dp = default.dumpvec(pos)
local dp = minetest.hash_node_position(pos)
if music.players[dp] == nil then
music.start(pos)
@ -128,7 +128,7 @@ if minetest.setting_getbool("music_enable") then
chance = 1,
interval = 1,
action = function(pos, node)
if music.players[default.dumpvec(pos)] == nil then
if music.players[minetest.hash_node_position(pos)] == nil then
local meta = minetest.get_meta(pos)
if meta:get_int("music_player_enabled") == 1 then
music.start(pos)

View File

@ -27,4 +27,10 @@ if minetest.setting_getbool("testing_enable") then
default.dumpvec({x=0,y=50,z=100})
end
print(string.format("10000 iterations with(custom function) default.dumpvec({x=0,y=50,z=100}) took %.2fms", (os.clock() - t4) * 1000))
local t5 = os.clock()
for i = 1, 10000 do
minetest.hash_node_position({x=0,y=50,z=100})
end
print(string.format("10000 iterations with minetest.hash_node_position({x=0,y=50,z=100}) took %.2fms", (os.clock() - t5) * 1000))
end

View File

@ -207,15 +207,15 @@ function village.spawn_road(pos, houses, built, roads, depth, pr)
nextpos.x = nextpos.x + 12
end
if built[default.dumpvec(nextpos)] == nil then
built[default.dumpvec(nextpos)] = true
if built[minetest.hash_node_position(nextpos)] == nil then
built[minetest.hash_node_position(nextpos)] = true
if depth <= 0 or pr:next(1, 8) < 6 then
houses[default.dumpvec(nextpos)] = {pos = nextpos, front = pos}
houses[minetest.hash_node_position(nextpos)] = {pos = nextpos, front = pos}
local structure = util.choice_element(village.chunktypes, pr)
village.spawn_chunk(nextpos, orient, {}, pr, structure)
else
roads[default.dumpvec(nextpos)] = {pos = nextpos}
roads[minetest.hash_node_position(nextpos)] = {pos = nextpos}
village.spawn_road(nextpos, houses, built, roads, depth - 1, pr)
end
end
@ -237,18 +237,18 @@ function village.spawn_village(pos, pr)
local built = {}
local roads = {}
built[default.dumpvec(pos)] = true
built[minetest.hash_node_position(pos)] = true
village.spawn_road(pos, houses, built, roads, depth, pr)
local function connects(pos, nextpos)
if houses[default.dumpvec(nextpos)] ~= nil then
if vector.equals(houses[default.dumpvec(nextpos)].front, pos) then
if houses[minetest.hash_node_position(nextpos)] ~= nil then
if vector.equals(houses[minetest.hash_node_position(nextpos)].front, pos) then
return true
end
end
if roads[default.dumpvec(nextpos)] ~= nil then
if roads[minetest.hash_node_position(nextpos)] ~= nil then
return true
end