diff --git a/mods/CORE/vl_scheduler/init.lua b/mods/CORE/vl_scheduler/init.lua index c98404c57..b8f840d2d 100644 --- a/mods/CORE/vl_scheduler/init.lua +++ b/mods/CORE/vl_scheduler/init.lua @@ -104,6 +104,10 @@ if false then end 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 end_time = start_time + 50000 time = time + dtime diff --git a/mods/ITEMS/REDSTONE/mcl_comparators/init.lua b/mods/ITEMS/REDSTONE/mcl_comparators/init.lua index 37bf65a62..961471c81 100644 --- a/mods/ITEMS/REDSTONE/mcl_comparators/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_comparators/init.lua @@ -87,7 +87,23 @@ local function update_self(pos, node) 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 for i = 1,#POSSIBLE_COMPARATOR_POSITIONS do 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 count = count + ( stacks[i]:get_count() / stacks[i]:get_stack_max() ) end - return math.floor(count * 16 / 5) + return math.floor(count * 16 / #stacks) end -- compute tile depending on state and mode diff --git a/mods/ITEMS/REDSTONE/mesecons/init.lua b/mods/ITEMS/REDSTONE/mesecons/init.lua index 8874ff9b2..45b189000 100644 --- a/mods/ITEMS/REDSTONE/mesecons/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons/init.lua @@ -88,6 +88,7 @@ end) function mesecon.receptor_on(pos, 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) end @@ -116,6 +117,7 @@ end) function mesecon.receptor_off(pos, 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) end diff --git a/mods/ITEMS/REDSTONE/mesecons/services.lua b/mods/ITEMS/REDSTONE/mesecons/services.lua index 7d1fce2d8..36b9b8c72 100644 --- a/mods/ITEMS/REDSTONE/mesecons/services.lua +++ b/mods/ITEMS/REDSTONE/mesecons/services.lua @@ -2,6 +2,7 @@ function mesecon.on_placenode(pos, node) mesecon.execute_autoconnect_hooks_now(pos, node) + --[[ -- Receptors: Send on signal when active if mesecon.is_receptor_on(node.name) then @@ -68,6 +69,7 @@ function mesecon.on_placenode(pos, node) end end end + ]] end function mesecon.on_dignode(pos, node) @@ -103,7 +105,7 @@ function mesecon.on_blastnode(pos, node) end 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 local OVERHEAT_MAX = mesecon.setting("overheat_max", 8) diff --git a/mods/ITEMS/REDSTONE/vl_redstone/init.lua b/mods/ITEMS/REDSTONE/vl_redstone/init.lua index 39d895b35..cd604d080 100644 --- a/mods/ITEMS/REDSTONE/vl_redstone/init.lua +++ b/mods/ITEMS/REDSTONE/vl_redstone/init.lua @@ -64,10 +64,10 @@ end local function get_node_multipower_data(pos, no_create) local hash = minetest_hash_node_pos(pos) 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) 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 = { version = 1, sources={} @@ -78,7 +78,7 @@ local function get_node_multipower_data(pos, no_create) return node_multipower 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 node_multipower = get_node_multipower_data(pos) local strength = 0 @@ -117,8 +117,8 @@ local function calculate_driven_strength(pos, input_rules_hash) return strength,HASH_REVERSES[strongest_direction_hash] end -local function update_node(pos) - local node = mcl_util_force_get_node(pos) +local function update_node(pos, node) + local node = node or mcl_util_force_get_node(pos) local nodedef = minetest.registered_nodes[node.name] -- 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) -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 local no_create if strength == 0 then no_create = true end 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 local distance = node_multipower.drive_strength or 0 -- 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)) @@ -384,7 +390,7 @@ function vl_redstone.set_power(pos, strength, delay) end -- 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 function vl_redstone.get_power(pos) @@ -411,7 +417,7 @@ function vl_redstone.on_dignode(pos, node) -- 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 -- 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 -- Persist multipower data diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index 4680d1776..6905bffa7 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -34,6 +34,12 @@ local mcl_hoppers_formspec = table.concat({ "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 timer = minetest.get_node_timer(pos) 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 ) 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) - 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 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) mcl_util.hopper_pull(pos, src_pos) + + -- Update comparators + mcl_comparators.trigger_update(pos, node) end --[[ @@ -188,12 +203,6 @@ local function hopper_pull_from_mc(mc_ent, dest_pos, inv_size) end 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) ---@type node_definition