summaryrefslogtreecommitdiff
path: root/helpers.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-12-19 22:29:07 +0100
committerorwell96 <orwell@bleipb.de>2018-12-19 22:29:07 +0100
commit97c4e91d3a3c1c378f678f28cca5c063d118e47b (patch)
tree483c6433f1791b893b45a53eb7be7cbd120d10c8 /helpers.lua
parent56d03692df3076a109b73ce78a869bc799d802c9 (diff)
downloadadvtrains_netmapper-97c4e91d3a3c1c378f678f28cca5c063d118e47b.tar.gz
advtrains_netmapper-97c4e91d3a3c1c378f678f28cca5c063d118e47b.tar.bz2
advtrains_netmapper-97c4e91d3a3c1c378f678f28cca5c063d118e47b.zip
Color lines according to depth, add bounds
Diffstat (limited to 'helpers.lua')
-rw-r--r--helpers.lua77
1 files changed, 8 insertions, 69 deletions
diff --git a/helpers.lua b/helpers.lua
index 511d32e..e9ea256 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -353,79 +353,18 @@ end
local hext = { [0]="0",[1]="1",[2]="2",[3]="3",[4]="4",[5]="5",[6]="6",[7]="7",[8]="8",[9]="9",[10]="A",[11]="B",[12]="C",[13]="D",[14]="E",[15]="F"}
local dect = { ["0"]=0,["1"]=1,["2"]=2,["3"]=3,["4"]=4,["5"]=5,["6"]=6,["7"]=7,["8"]=8,["9"]=9,["A"]=10,["B"]=11,["C"]=12,["D"]=13,["E"]=14,["F"]=15}
-local f = atfloor
-
-local function hex(i)
- local x=i+32768
- local c4 = x % 16
- x = f(x / 16)
- local c3 = x % 16
- x = f(x / 16)
+
+-- Hex functions changed for 8bit
+function advtrains.hex(i)
+ local x=math.floor(i)
local c2 = x % 16
- x = f(x / 16)
+ x = math.floor(x / 16)
local c1 = x % 16
- return (hext[c1]) .. (hext[c2]) .. (hext[c3]) .. (hext[c4])
+ return (hext[c1]) .. (hext[c2])
end
local function c(s,i) return dect[string.sub(s,i,i)] end
-local function dec(s)
- return (c(s,1)*4096 + c(s,2)*256 + c(s,3)*16 + c(s,4))-32768
-end
--- Takes a position vector and outputs a encoded value suitable as table index
--- This is essentially a hexadecimal representation of the position (+32768)
--- Order (YYY)YXXXXZZZZ
-function advtrains.encode_pos(pos)
- return hex(pos.y) .. hex(pos.x) .. hex(pos.z)
-end
-
--- decodes a position encoded with encode_pos
-function advtrains.decode_pos(pts)
- local stry = string.sub(pts, 1,4)
- local strx = string.sub(pts, 5,8)
- local strz = string.sub(pts, 9,12)
- return vector.new(dec(strx), dec(stry), dec(strz))
-end
-
---[[ Benchmarking code
-local tdt = {}
-local tlt = {}
-local tet = {}
-
-for i=1,1000000 do
- tdt[i] = vector.new(math.random(-65536, 65535), math.random(-65536, 65535), math.random(-65536, 65535))
- if i%1000 == 0 then
- tlt[#tlt+1] = tdt[i]
- end
-end
-
-local t1=os.clock()
-for i=1,1000000 do
- local pe = advtrains.encode_pos(tdt[i])
- local pb = advtrains.decode_pos(pe)
- tet[pe] = i
-end
-for i,v in ipairs(tlt) do
- local lk = tet[advtrains.encode_pos(v)]
-end
-atdebug("endec",os.clock()-t1,"s")
-
-tet = {}
-
-t1=os.clock()
-for i=1,1000000 do
- local pe = minetest.pos_to_string(tdt[i])
- local pb = minetest.string_to_pos(pe)
- tet[pe] = i
+function advtrains.dec(s)
+ return (c(s,1)*16 + c(s,2))
end
-for i,v in ipairs(tlt) do
- local lk = tet[minetest.pos_to_string(v)]
-end
-atdebug("pts",os.clock()-t1,"s")
-
---Results:
---2018-11-29 16:57:08: ACTION[Main]: [advtrains]endec 1.786451 s
---2018-11-29 16:57:10: ACTION[Main]: [advtrains]pts 2.566377 s
-]]
-
-