use custom dump function

This commit is contained in:
kaadmy 2015-09-09 08:59:11 -07:00
parent 4eca91857b
commit d42ef6e74c
7 changed files with 60 additions and 15 deletions

View File

@ -38,9 +38,12 @@ weather_enable = true
# if pvp is enabled
enable_pvp = true
# tnt is enabledxx
# tnt is enabled
tnt_enable = true
# if testing stuff is enabled
testing_enable = false
# server
max_users = 16
max_block_generate_distance = 4

View File

@ -10,7 +10,11 @@ default.WATER_VISC = 1
default.LIGHT_MAX = 14
function default.log(text, type)
print("Pixture ["..type.."] "..text)
minetest.log("Pixture ["..type.."] "..text)
end
function default.dumpvec(v)
return v.x..":"..v.y..":"..v.z
end
minetest.nodedef_default.stack_max = 60

View File

@ -9,7 +9,7 @@ music.players = {} -- music players
if minetest.setting_getbool("music_enable") then
function music.stop(pos)
local dp = dump(pos)
local dp = default.dumpvec(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 = dump(pos)
local dp = default.dumpvec(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 = dump(pos)
local dp = default.dumpvec(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 = dump(pos)
local dp = default.dumpvec(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[dump(pos)] == nil then
if music.players[default.dumpvec(pos)] == nil then
local meta = minetest.get_meta(pos)
if meta:get_int("music_player_enabled") == 1 then
music.start(pos)

7
mods/testing/README.txt Normal file
View File

@ -0,0 +1,7 @@
Testing mod
===========
By Kaadmy
Adds some testing stuff
Source license: WTFPL

1
mods/testing/depends.txt Normal file
View File

@ -0,0 +1 @@
default

30
mods/testing/init.lua Normal file
View File

@ -0,0 +1,30 @@
--
-- Testing mod
-- By Kaadmy, for Pixture
--
if minetest.setting_getbool("testing_enable") then
local t1 = os.clock()
for i = 1, 10000 do
dump({x=0,y=50,z=100})
end
print(string.format("10000 iterations with dump({x=0,y=50,z=100}) took %.2fms", (os.clock() - t1) * 1000))
local t2 = os.clock()
for i = 1, 10000 do
tostring({x=0,y=50,z=100})
end
print(string.format("10000 iterations with tostring({x=0,y=50,z=100}) took %.2fms", (os.clock() - t2) * 1000))
local t3 = os.clock()
for i = 1, 10000 do
minetest.serialize({x=0,y=50,z=100})
end
print(string.format("10000 iterations with minetest.serialize({x=0,y=50,z=100}) took %.2fms", (os.clock() - t3) * 1000))
local t4 = os.clock()
for i = 1, 10000 do
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))
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[dump(nextpos)] == nil then
built[dump(nextpos)] = true
if built[default.dumpvec(nextpos)] == nil then
built[default.dumpvec(nextpos)] = true
if depth <= 0 or pr:next(1, 8) < 6 then
houses[dump(nextpos)] = {pos = nextpos, front = pos}
houses[default.dumpvec(nextpos)] = {pos = nextpos, front = pos}
local structure = util.choice_element(village.chunktypes, pr)
village.spawn_chunk(nextpos, orient, {}, pr, structure)
else
roads[dump(nextpos)] = {pos = nextpos}
roads[default.dumpvec(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[dump(pos)] = true
built[default.dumpvec(pos)] = true
village.spawn_road(pos, houses, built, roads, depth, pr)
local function connects(pos, nextpos)
if houses[dump(nextpos)] ~= nil then
if vector.equals(houses[dump(nextpos)].front, pos) then
if houses[default.dumpvec(nextpos)] ~= nil then
if vector.equals(houses[default.dumpvec(nextpos)].front, pos) then
return true
end
end
if roads[dump(nextpos)] ~= nil then
if roads[default.dumpvec(nextpos)] ~= nil then
return true
end