From a367a9b8185d1c01c137a942f11bb58f8959199d Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Fri, 3 Jul 2020 16:15:14 -0400 Subject: [PATCH] Push all debug info --- mods/redstone/comparator.lua | 87 ++------------------------------ mods/redstone/dispenser.lua | 0 mods/redstone/init.lua | 55 +++++++++++++------- mods/redstone/pressure_plate.lua | 2 +- 4 files changed, 43 insertions(+), 101 deletions(-) create mode 100644 mods/redstone/dispenser.lua diff --git a/mods/redstone/comparator.lua b/mods/redstone/comparator.lua index 9d81556..77f4403 100644 --- a/mods/redstone/comparator.lua +++ b/mods/redstone/comparator.lua @@ -1,71 +1,7 @@ local minetest,vector,math = minetest,vector,math -local function comparator_logic(pos) - - local old_power = get_powered_state_directional(pos) - - local param2 = minetest.get_node(pos).param2 - local dir = minetest.facedir_to_dir(param2) - local get_group = minetest.get_item_group - - --get inputs and outputs - local input_pos_straight = vector.subtract(pos,dir) - - --if you're reading this, this is an easy way to get 90 degrees from a direction (math.pi would be 180 degrees which you can simply -1 multiply the direction instead) - local input_pos_right = vector.add(minetest.yaw_to_dir(minetest.dir_to_yaw(dir)-(math.pi/2)),pos) - local input_pos_left = vector.add(minetest.yaw_to_dir(minetest.dir_to_yaw(dir)+(math.pi/2)),pos) - - local output_pos = vector.add(pos,dir) - local output = false - - local comparator_level = get_group(minetest.get_node(pos).name, "comparator") - - local input_level = get_group(minetest.get_node(input_pos_straight).name, "redstone_power") - local output_level = get_group(minetest.get_node(output_pos).name, "redstone_power") - - --this prefers right to left-- - - local output_node = minetest.get_node(output_pos).name - local input_node_straight = minetest.get_node(input_pos_straight).name - - local left_level = get_group(minetest.get_node(input_pos_left).name, "redstone_power") - local right_level = get_group(minetest.get_node(input_pos_right).name, "redstone_power") - - local compare_level = 0 - if right_level > compare_level then - compare_level = right_level - end - if left_level > compare_level then - compare_level = left_level - end - local new_output_level = 0 - - if input_level > compare_level then - new_output_level = 9 - elseif input_level <= compare_level then - new_output_level = 0 - end - - --charge - if input_level > 0 then--and output_level ~= new_output_level-1 then - if comparator_level ~= new_output_level then - --print("comparator on") - minetest.swap_node(pos, {name="redstone:comparator_"..new_output_level,param2=param2}) - redstone.collect_info(output_pos) - end - elseif output_level ~= new_output_level-1 then - if comparator_level ~= new_output_level then - --print("comparator off") - minetest.swap_node(pos, {name="redstone:comparator_"..new_output_level,param2=param2}) - redstone.collect_info(output_pos) - end - end - - set_old_power(pos,old_power) -end - -for i = 0,9 do +for i = 0,16 do minetest.register_node("redstone:comparator_"..i, { description = "Redstone Comparator", tiles = {"repeater_on.png"}, @@ -87,29 +23,14 @@ for i = 0,9 do {0.4, -0.5, -0.35, 0.2, 0.1, -0.15}, --input post }, }, - redstone_activation = function(pos) - comparator_logic(pos) - end, - redstone_deactivation = function(pos) - comparator_logic(pos) - end, - redstone_update = function(pos) - comparator_logic(pos) - end, - on_construct = function(pos) - end, + after_place_node = function(pos, placer, itemstack, pointed_thing) redstone.collect_info(pos) end, - on_dig = function(pos, node, digger) - local param2 = minetest.get_node(pos).param2 - minetest.node_dig(pos, node, digger) - local dir = minetest.facedir_to_dir(param2) - redstone.collect_info(vector.add(pos,dir)) - end, - after_destruct = function(pos) + on_destruct = function(pos) end, }) + end diff --git a/mods/redstone/dispenser.lua b/mods/redstone/dispenser.lua new file mode 100644 index 0000000..e69de29 diff --git a/mods/redstone/init.lua b/mods/redstone/init.lua index 79ffbe2..9fe5d08 100644 --- a/mods/redstone/init.lua +++ b/mods/redstone/init.lua @@ -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, diff --git a/mods/redstone/pressure_plate.lua b/mods/redstone/pressure_plate.lua index 5def16f..078fa0e 100644 --- a/mods/redstone/pressure_plate.lua +++ b/mods/redstone/pressure_plate.lua @@ -1,6 +1,6 @@ local minetest,ipairs,vector = minetest,ipairs,vector -r_max + for level = 0,9 do local subtracter = 0 -- 2.44.0