mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-28 05:21:05 +01:00
Add warning for long server timesteps, fix comparator-hopper interaction after rebase, disable mesecons dig/place updating redstone state, fix power flow on first couple of switch togglings, add traceback print to mesecon.receptor_{on,off}
This commit is contained in:
parent
b67f2261ed
commit
ef257f0131
6 changed files with 60 additions and 21 deletions
|
@ -104,6 +104,10 @@ if false then
|
||||||
end
|
end
|
||||||
|
|
||||||
local function run_scheduler(dtime)
|
local function run_scheduler(dtime)
|
||||||
|
if dtime > 0.11 then
|
||||||
|
minetest.log("warning", "Timestep greater than 110ms("..tostring(math.floor(dtime*1000)).." ms), server lag detected")
|
||||||
|
end
|
||||||
|
|
||||||
local start_time = minetest_get_us_time()
|
local start_time = minetest_get_us_time()
|
||||||
local end_time = start_time + 50000
|
local end_time = start_time + 50000
|
||||||
time = time + dtime
|
time = time + dtime
|
||||||
|
|
|
@ -87,7 +87,23 @@ local function update_self(pos, node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function mod.trigger_update(pos)
|
local node_readings = {}
|
||||||
|
function mod.trigger_update(pos, node)
|
||||||
|
local node = node or minetest.get_node(pos)
|
||||||
|
local nodedef = minetest.registered_nodes[node.name] or {}
|
||||||
|
|
||||||
|
-- If this position can't provide a comparator reading, we should
|
||||||
|
-- never trigger a comparator update
|
||||||
|
local get_reading = nodedef._mcl_comparators_get_reading
|
||||||
|
if not get_reading then return end
|
||||||
|
|
||||||
|
-- Only update if the reading has changed
|
||||||
|
local pos_hash = minetest.hash_node_position(pos)
|
||||||
|
local old_reading = node_readings[pos_hash]
|
||||||
|
local new_reading = get_reading(pos)
|
||||||
|
if old_reading == new_reading then return end
|
||||||
|
node_readings[pos_hash] = new_reading
|
||||||
|
|
||||||
-- try to find a comparator with the back rule leading to pos
|
-- try to find a comparator with the back rule leading to pos
|
||||||
for i = 1,#POSSIBLE_COMPARATOR_POSITIONS do
|
for i = 1,#POSSIBLE_COMPARATOR_POSITIONS do
|
||||||
local candidate = vector.add(pos, POSSIBLE_COMPARATOR_POSITIONS[i])
|
local candidate = vector.add(pos, POSSIBLE_COMPARATOR_POSITIONS[i])
|
||||||
|
@ -106,7 +122,7 @@ function mod.read_inventory(inv, inv_name)
|
||||||
for i=1,#stacks do
|
for i=1,#stacks do
|
||||||
count = count + ( stacks[i]:get_count() / stacks[i]:get_stack_max() )
|
count = count + ( stacks[i]:get_count() / stacks[i]:get_stack_max() )
|
||||||
end
|
end
|
||||||
return math.floor(count * 16 / 5)
|
return math.floor(count * 16 / #stacks)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- compute tile depending on state and mode
|
-- compute tile depending on state and mode
|
||||||
|
|
|
@ -88,6 +88,7 @@ end)
|
||||||
|
|
||||||
function mesecon.receptor_on(pos, rules)
|
function mesecon.receptor_on(pos, rules)
|
||||||
print("receptor_on(pos="..vector.to_string(pos)..",rules="..dump(rules))
|
print("receptor_on(pos="..vector.to_string(pos)..",rules="..dump(rules))
|
||||||
|
print(debug.traceback())
|
||||||
--mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
|
--mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,6 +117,7 @@ end)
|
||||||
|
|
||||||
function mesecon.receptor_off(pos, rules)
|
function mesecon.receptor_off(pos, rules)
|
||||||
print("receptor_off(pos="..vector.to_string(pos)..",rules="..dump(rules))
|
print("receptor_off(pos="..vector.to_string(pos)..",rules="..dump(rules))
|
||||||
|
print(debug.traceback())
|
||||||
--mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
|
--mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
function mesecon.on_placenode(pos, node)
|
function mesecon.on_placenode(pos, node)
|
||||||
mesecon.execute_autoconnect_hooks_now(pos, node)
|
mesecon.execute_autoconnect_hooks_now(pos, node)
|
||||||
|
--[[
|
||||||
|
|
||||||
-- Receptors: Send on signal when active
|
-- Receptors: Send on signal when active
|
||||||
if mesecon.is_receptor_on(node.name) then
|
if mesecon.is_receptor_on(node.name) then
|
||||||
|
@ -68,6 +69,7 @@ function mesecon.on_placenode(pos, node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
end
|
end
|
||||||
|
|
||||||
function mesecon.on_dignode(pos, node)
|
function mesecon.on_dignode(pos, node)
|
||||||
|
@ -103,7 +105,7 @@ function mesecon.on_blastnode(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_placenode(mesecon.on_placenode)
|
minetest.register_on_placenode(mesecon.on_placenode)
|
||||||
minetest.register_on_dignode(mesecon.on_dignode)
|
--minetest.register_on_dignode(mesecon.on_dignode)
|
||||||
|
|
||||||
-- Overheating service for fast circuits
|
-- Overheating service for fast circuits
|
||||||
local OVERHEAT_MAX = mesecon.setting("overheat_max", 8)
|
local OVERHEAT_MAX = mesecon.setting("overheat_max", 8)
|
||||||
|
|
|
@ -64,10 +64,10 @@ end
|
||||||
local function get_node_multipower_data(pos, no_create)
|
local function get_node_multipower_data(pos, no_create)
|
||||||
local hash = minetest_hash_node_pos(pos)
|
local hash = minetest_hash_node_pos(pos)
|
||||||
local node_multipower = multipower_cache[hash]
|
local node_multipower = multipower_cache[hash]
|
||||||
if not node_multipower and not no_create then
|
if not node_multipower then
|
||||||
local meta = minetest_get_meta(pos)
|
local meta = minetest_get_meta(pos)
|
||||||
node_multipower = minetest_deserialize(meta:get_string("vl_redstone.multipower"))
|
node_multipower = minetest_deserialize(meta:get_string("vl_redstone.multipower"))
|
||||||
if not node_multipower or node_multipower.version ~= 1 then
|
if not no_create and not node_multipower or node_multipower.version ~= 1 then
|
||||||
node_multipower = {
|
node_multipower = {
|
||||||
version = 1,
|
version = 1,
|
||||||
sources={}
|
sources={}
|
||||||
|
@ -78,7 +78,7 @@ local function get_node_multipower_data(pos, no_create)
|
||||||
return node_multipower
|
return node_multipower
|
||||||
end
|
end
|
||||||
|
|
||||||
local function calculate_driven_strength(pos, input_rules_hash)
|
local function calculate_driven_strength(pos, input_rules_hash, dir)
|
||||||
local dir_hash = dir and hash_from_direction(dir)
|
local dir_hash = dir and hash_from_direction(dir)
|
||||||
local node_multipower = get_node_multipower_data(pos)
|
local node_multipower = get_node_multipower_data(pos)
|
||||||
local strength = 0
|
local strength = 0
|
||||||
|
@ -117,8 +117,8 @@ local function calculate_driven_strength(pos, input_rules_hash)
|
||||||
return strength,HASH_REVERSES[strongest_direction_hash]
|
return strength,HASH_REVERSES[strongest_direction_hash]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_node(pos)
|
local function update_node(pos, node)
|
||||||
local node = mcl_util_force_get_node(pos)
|
local node = node or mcl_util_force_get_node(pos)
|
||||||
local nodedef = minetest.registered_nodes[node.name]
|
local nodedef = minetest.registered_nodes[node.name]
|
||||||
|
|
||||||
-- Only do this processing of signal sinks and conductors
|
-- Only do this processing of signal sinks and conductors
|
||||||
|
@ -363,18 +363,24 @@ vl_scheduler.register_function("vl_redstone:flow_power",function(task, source_po
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function vl_redstone.set_power(pos, strength, delay)
|
function vl_redstone.set_power(pos, strength, delay, node)
|
||||||
-- Get existing multipower data, but don't create the data if the strength is zero
|
-- Get existing multipower data, but don't create the data if the strength is zero
|
||||||
local no_create
|
local no_create
|
||||||
if strength == 0 then no_create = true end
|
if strength == 0 then no_create = true end
|
||||||
local node_multipower = get_node_multipower_data(pos, no_create)
|
local node_multipower = get_node_multipower_data(pos, no_create)
|
||||||
if not node_multipower then return end
|
if not node_multipower then
|
||||||
|
print("No node multipower, no_create="..no_create)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Determine how far we need to trace conductors
|
-- Determine how far we need to trace conductors
|
||||||
local distance = node_multipower.drive_strength or 0
|
local distance = node_multipower.drive_strength or 0
|
||||||
|
|
||||||
-- Don't perform an update if the power level is the same as before
|
-- Don't perform an update if the power level is the same as before
|
||||||
if distance == strength then return end
|
if distance == strength then
|
||||||
|
print("Don't perform update distance="..tostring(distance)..",strength="..tostring(strength))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
--print("previous="..tostring(distance)..", new="..tostring(strength))
|
--print("previous="..tostring(distance)..", new="..tostring(strength))
|
||||||
|
|
||||||
|
@ -384,7 +390,7 @@ function vl_redstone.set_power(pos, strength, delay)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Schedule an update
|
-- Schedule an update
|
||||||
vl_scheduler.add_task(delay or 0, "vl_redstone:flow_power", 2, {pos, strength, distance + 1})
|
vl_scheduler.add_task(delay or 0, "vl_redstone:flow_power", 2, {pos, strength, distance + 1, node})
|
||||||
end
|
end
|
||||||
|
|
||||||
function vl_redstone.get_power(pos)
|
function vl_redstone.get_power(pos)
|
||||||
|
@ -411,7 +417,7 @@ function vl_redstone.on_dignode(pos, node)
|
||||||
-- Node was dug, can't power anything
|
-- Node was dug, can't power anything
|
||||||
-- This doesn't work because the node is gone and we don't know what we were powering
|
-- This doesn't work because the node is gone and we don't know what we were powering
|
||||||
-- TODO: get the rules here and use that for the first step
|
-- TODO: get the rules here and use that for the first step
|
||||||
vl_redstone.set_power(pos, 0)
|
vl_redstone.set_power(pos, 0, nil, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Persist multipower data
|
-- Persist multipower data
|
||||||
|
|
|
@ -34,6 +34,12 @@ local mcl_hoppers_formspec = table.concat({
|
||||||
"listring[current_player;main]",
|
"listring[current_player;main]",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local function get_reading(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return mcl_comparators.read_inventory(inv, "main")
|
||||||
|
end
|
||||||
|
|
||||||
local function straight_hopper_act(pos, node, active_object_count, active_count_wider)
|
local function straight_hopper_act(pos, node, active_object_count, active_count_wider)
|
||||||
local timer = minetest.get_node_timer(pos)
|
local timer = minetest.get_node_timer(pos)
|
||||||
if timer:is_started() then
|
if timer:is_started() then
|
||||||
|
@ -52,9 +58,15 @@ local function straight_hopper_act(pos, node, active_object_count, active_count_
|
||||||
dst_def._mcl_hopper_act( dst_pos, dst_node, active_object_count, active_count_wider )
|
dst_def._mcl_hopper_act( dst_pos, dst_node, active_object_count, active_count_wider )
|
||||||
end
|
end
|
||||||
|
|
||||||
mcl_util.hopper_push(pos, dst_pos)
|
local pushed = mcl_util.hopper_push(pos, dst_pos)
|
||||||
|
|
||||||
local src_pos = vector.offset(pos, 0, 1, 0)
|
local src_pos = vector.offset(pos, 0, 1, 0)
|
||||||
mcl_util.hopper_pull(pos, src_pos)
|
local pulled = mcl_util.hopper_pull(pos, src_pos)
|
||||||
|
|
||||||
|
if pushed or pulled then mcl_comparators.trigger_update(pos) end
|
||||||
|
|
||||||
|
-- Update comparators
|
||||||
|
mcl_comparators.trigger_update(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function bent_hopper_act(pos, node, active_object_count, active_object_count_wider)
|
local function bent_hopper_act(pos, node, active_object_count, active_object_count_wider)
|
||||||
|
@ -94,6 +106,9 @@ local function bent_hopper_act(pos, node, active_object_count, active_object_cou
|
||||||
|
|
||||||
local src_pos = vector.offset(pos, 0, 1, 0)
|
local src_pos = vector.offset(pos, 0, 1, 0)
|
||||||
mcl_util.hopper_pull(pos, src_pos)
|
mcl_util.hopper_pull(pos, src_pos)
|
||||||
|
|
||||||
|
-- Update comparators
|
||||||
|
mcl_comparators.trigger_update(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
@ -188,12 +203,6 @@ local function hopper_pull_from_mc(mc_ent, dest_pos, inv_size)
|
||||||
end
|
end
|
||||||
mcl_hoppers.pull_from_minecart = hopper_pull_from_mc
|
mcl_hoppers.pull_from_minecart = hopper_pull_from_mc
|
||||||
|
|
||||||
local function get_reading(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
return mcl_comparators.read_inventory(inv, "main")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Downwards hopper (base definition)
|
-- Downwards hopper (base definition)
|
||||||
|
|
||||||
---@type node_definition
|
---@type node_definition
|
||||||
|
|
Loading…
Reference in a new issue