Add in dynamic redstone queue sleep

This commit is contained in:
oilboi 2020-07-02 02:49:50 -04:00
parent 1cd7d5d4bc
commit 1e95c7a19e
3 changed files with 46 additions and 22 deletions

View File

@ -706,22 +706,30 @@ function redstone.update(pos,is_capacitor)
--calculate(pos,is_capacitor)
end
local dtime_goal = 0.02
local sleep = 0
minetest.register_globalstep(function(dtime)
minetest.register_globalstep(function()
player_detector_calculation()
if table.getn(queue) > 0 then
--print(dump(queue))
local element = queue[1]
calculate(element.pos,element.is_capacitor)
queue[1] = nil
for index,data in pairs(queue) do
queue[index-1] = data
end
queue[table.getn(queue)] = nil
if dtime > dtime_goal then
sleep = dtime - dtime_goal
end
--recursion_check = {}
if sleep == 0 then
player_detector_calculation()
for index,element in pairs(queue) do
calculate(element.pos,element.is_capacitor)
end
queue = {}
--recursion_check = {}
else
sleep = sleep - dtime
if sleep <= 0 then
sleep = 0
end
end
end)

View File

@ -42,12 +42,13 @@ minetest.register_node("redstone:inverter_on", {
dir = dir
})
redstone.update(pos)
redstone.update(vector.add(pos,dir))
end,
after_destruct = function(pos, oldnode)
local param2 = oldnode.param2
local dir = minetest.facedir_to_dir(param2)
redstone.inject(pos,nil)
redstone.update(pos)
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end
})
@ -68,7 +69,7 @@ redstone.register_activator({
output = vector.add(pos,dir),
dir = dir
})
redstone.update(pos)
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end
})
@ -87,6 +88,8 @@ minetest.register_lbm({
output = vector.add(pos,dir),
dir = dir
})
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end,
})
@ -132,12 +135,13 @@ minetest.register_node("redstone:inverter_off", {
dir = dir
})
redstone.update(pos)
redstone.update(vector.add(pos,dir))
end,
after_destruct = function(pos, oldnode)
local param2 = oldnode.param2
local dir = minetest.facedir_to_dir(param2)
redstone.inject(pos,nil)
redstone.update(pos)
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end
})
@ -156,7 +160,7 @@ redstone.register_activator({
output = vector.add(pos,dir),
dir = dir
})
redstone.update(pos)
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end
})
@ -177,5 +181,7 @@ minetest.register_lbm({
output = vector.add(pos,dir),
dir = dir
})
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end,
})

View File

@ -68,13 +68,16 @@ minetest.register_node("redstone:repeater_on_"..level, {
output = vector.add(pos,dir),
dir = dir
})
redstone.update(pos)
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end,
after_destruct = function(pos, oldnode)
local param2 = oldnode.param2
local dir = minetest.facedir_to_dir(param2)
redstone.inject(pos,nil)
redstone.update(pos)
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end,
after_place_node = function(pos)
@ -89,6 +92,7 @@ minetest.register_node("redstone:repeater_on_"..level, {
dir = dir
})
redstone.update(pos)
redstone.update(vector.add(pos,dir))
end
})
@ -118,7 +122,8 @@ minetest.register_lbm({
output = vector.add(pos,dir),
dir = dir
})
redstone.update(pos)
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end,
})
@ -177,7 +182,7 @@ minetest.register_node("redstone:repeater_off_"..level, {
output = vector.add(pos,dir),
dir = dir
})
redstone.update(pos)
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end,
@ -200,8 +205,11 @@ minetest.register_node("redstone:repeater_off_"..level, {
end,
after_destruct = function(pos, oldnode)
local param2 = oldnode.param2
local dir = minetest.facedir_to_dir(param2)
redstone.inject(pos,nil)
redstone.update(pos)
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end,
after_place_node = function(pos)
@ -214,6 +222,7 @@ minetest.register_node("redstone:repeater_off_"..level, {
dir = dir
})
redstone.update(pos)
redstone.update(vector.add(pos,dir))
end
})
@ -241,7 +250,8 @@ minetest.register_lbm({
input = vector.subtract(pos,dir),
dir = dir
})
redstone.update(pos)
--redstone.update(pos)
redstone.update(vector.add(pos,dir))
end,
})