]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/redstone/init.lua
Push all debug info
[Crafter.git] / mods / redstone / init.lua
index 79ffbe2fd7d2554e9cbde8a57a1ea81ab795775b..9fe5d08c8e99f8b9140cdd87771d3d3bca31e089 100644 (file)
@@ -36,11 +36,12 @@ local vec_equals      = vector.equals
 local activator_table = {} -- this holds the translation data of activator tables (activator functions)
 local capacitor_table = {}
 local player_detection_table = {}
+local instructions = 0
 
 -- redstone class
 redstone = {}
 
-redstone.max_state = 9 -- the limit to power transmission
+redstone.max_state = 64 -- the limit to power transmission
 
 redstone.player_detector_add = function(pos)
        player_detection_table[minetest.serialize(pos)] = pos
@@ -90,19 +91,22 @@ dofile(path.."/detector.lua")
 --this is written out manually so that
 --math.abs is not needed
 local order = {
-       {x=0,y=0,z=0},
-
-       {x=1, y=0, z=0}, {x=-1, y=0, z= 0},
-       {x=0, y=0, z=1}, {x= 0, y=0, z=-1},
-
-       {x=0, y=1, z=0}, {x= 0, y=-1, z=0},
-
-       {x=1, y=1, z=0}, {x=-1, y=1, z= 0},
-       {x=0, y=1, z=1}, {x= 0, y=1, z=-1},
-
-       {x=1, y=-1, z=0}, {x=-1, y=-1, z= 0},
-       {x=0, y=-1, z=1}, {x= 0, y=-1, z=-1},
-}
+       {x= 0,y= 0,z= 0},
+       {x= 1,y= 0,z= 0},
+       {x=-1,y= 0,z= 0},
+       {x= 0,y= 0,z= 1},
+       {x= 0,y= 0,z=-1},
+       {x= 0,y= 1,z= 0},
+       {x= 0,y=-1,z= 0},
+       {x= 1,y= 1,z= 0}, 
+       {x=-1,y= 1,z= 0},
+       {x= 0,y= 1,z= 1},
+       {x= 0,y= 1,z=-1},
+       {x= 1,y=-1,z= 0},
+       {x=-1,y=-1,z= 0},
+       {x= 0,y=-1,z= 1},
+       {x= 0,y=-1,z=-1},
+       }
 
 --thanks to RhodiumToad for helping me figure out a good method to do this
 
@@ -110,20 +114,27 @@ local pool = {} -- this holds all redstone data (literal 3d virtual memory map)
 
 
 local function data_injection(pos,data)
+       instructions = instructions + 1
        -- add data into 3d memory
        if data then
                if not pool[pos.x] then pool[pos.x] = {} end
                if not pool[pos.x][pos.y] then pool[pos.x][pos.y] = {} end
                pool[pos.x][pos.y][pos.z] = data
+               instructions = instructions + 1
+               --print("building 3d memory")
        --delete data from 3d memory
        else
                if pool and pool[pos.x] and pool[pos.x][pos.y] then
                        pool[pos.x][pos.y][pos.z] = data
+                       instructions = instructions + 1
+                       --print("deleting 3d memory")
                        if pool[pos.x][pos.y] and not next(pool[pos.x][pos.y]) then
                                pool[pos.x][pos.y] = nil
+                               instructions = instructions + 1
                                -- only run this if y axis is empty
                                if pool[pos.x] and not next(pool[pos.x]) then
                                        pool[pos.x] = nil
+                                       instructions = instructions + 1
                                end
                        end
                end
@@ -158,13 +169,18 @@ local table_3d
 local temp_pool
 local r_max = redstone.max_state
 local function create_boundary_box(pos)
+       instructions = instructions + 1
        table_3d = {}
        for x = pos.x-r_max,pos.x+r_max do
+               instructions = instructions + 1
                if pool[x] then
                        for y = pos.y-r_max,pos.y+r_max do
+                               instructions = instructions + 1
                                if pool[x][y] then
                                        for z = pos.z-r_max,pos.z+r_max do
+                                               instructions = instructions + 1
                                                temp_pool = pool[x][y][z]
+                                               instructions = instructions + 1
                                                if temp_pool then
                                                        if not table_3d[x] then table_3d[x] = {} end
                                                        if not table_3d[x][y] then table_3d[x][y] = {} end
@@ -194,7 +210,7 @@ local i
 local index
 local function capacitor_pathfind(source,mem_map)
        for _,order in pairs(order) do
-
+               
                i = add_vec(source,order)
                if not mem_map[i.x] then mem_map[i.x] = {} end
                if not mem_map[i.x][i.y] then mem_map[i.x][i.y] = {} end
@@ -364,6 +380,7 @@ local function redstone_distribute(pos,power,mem_map,output)
        else
                --redstone and torch
                for _,order in pairs(order) do
+                       instructions = instructions + 1
                        i = add_vec(pos,order)
                        x=i.x
                        y=i.y
@@ -410,6 +427,7 @@ local function dust_sniff(pos,mem_map,boundary,single,origin,ignore)
        if not single then
                --print("all position index--")
                for _,order in pairs(order) do
+                       instructions = instructions + 1
                        i = add_vec(pos,order)
 
                        if not mem_map[i.x] then mem_map[i.x] = {} end
@@ -730,6 +748,10 @@ minetest.register_globalstep(function(dtime)
                end
        end
        ]]--
+       if instructions and instructions > 0 then
+               print(instructions)
+       end
+       instructions = 0
 end)
 
 
@@ -823,8 +845,7 @@ for i = 0,d_max do
                        data_injection(pos,{dust=i})
                        calculate(pos)
                end,
-               after_destruct = function(pos)
-                       print("test")
+               after_destruct = function(pos)                  
                        data_injection(pos,nil)
                        calculate(pos)
                end,