mirror of
https://github.com/minetest-mods/digilines.git
synced 2025-03-27 23:00:24 +01:00
Rename signal -> message
This commit is contained in:
parent
eb891e156b
commit
97f66f4181
@ -2,31 +2,31 @@ local S = digilines.S
|
|||||||
|
|
||||||
local pipeworks_enabled = minetest.get_modpath("pipeworks") ~= nil
|
local pipeworks_enabled = minetest.get_modpath("pipeworks") ~= nil
|
||||||
|
|
||||||
-- Signals which will be sent in a single batch
|
-- Messages which will be sent in a single batch
|
||||||
local batched_signals = {}
|
local batched_messages = {}
|
||||||
-- Maximum interval from the previous signal to include the current one into batch (in seconds)
|
-- Maximum interval from the previous message to include the current one into batch (in seconds)
|
||||||
local interval_to_batch = 0.1
|
local interval_to_batch = 0.1
|
||||||
-- Maximum number of signals in batch
|
-- Maximum number of messages in batch
|
||||||
local max_signals_in_batch = 100
|
local max_messages_in_batch = 100
|
||||||
-- Time of last signal for each chest
|
-- Time of the last message for each chest
|
||||||
local last_signal_time_for_chest = {}
|
local last_message_time_for_chest = {}
|
||||||
|
|
||||||
-- Sends the current batch message of a Digiline chest
|
-- Sends the current batch message of a Digiline chest
|
||||||
-- pos: the position of the Digilines chest node
|
-- pos: the position of the Digilines chest node
|
||||||
-- channel: the channel to which the message will be sent
|
-- channel: the channel to which the message will be sent
|
||||||
local function send_and_clear_batch(pos, channel)
|
local function send_and_clear_batch(pos, channel)
|
||||||
local pos_hash = minetest.hash_node_position(pos)
|
local pos_hash = minetest.hash_node_position(pos)
|
||||||
if #batched_signals[pos_hash] == 1 then
|
if #batched_messages[pos_hash] == 1 then
|
||||||
-- If there is only one signal is the batch, don't send it in a batch
|
-- If there is only one message is the batch, don't send it in a batch
|
||||||
digilines.receptor_send(pos, digilines.rules.default, next(batched_signals[pos_hash]))
|
digilines.receptor_send(pos, digilines.rules.default, next(batched_messages[pos_hash]))
|
||||||
else
|
else
|
||||||
digilines.receptor_send(pos, digilines.rules.default, channel, {
|
digilines.receptor_send(pos, digilines.rules.default, channel, {
|
||||||
action = "batch",
|
action = "batch",
|
||||||
signals = batched_signals[pos_hash]
|
messages = batched_messages[pos_hash]
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
batched_signals[pos_hash] = nil
|
batched_messages[pos_hash] = nil
|
||||||
last_signal_time_for_chest[pos_hash] = nil
|
last_message_time_for_chest[pos_hash] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Sends a message onto the Digilines network.
|
-- Sends a message onto the Digilines network.
|
||||||
@ -49,16 +49,16 @@ local function send_message(pos, action, stack, from_slot, to_slot, side)
|
|||||||
side = side and vector.new(side)
|
side = side and vector.new(side)
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Check if we need to include the current signal into batch
|
-- Check if we need to include the current message into batch
|
||||||
local pos_hash = minetest.hash_node_position(pos)
|
local pos_hash = minetest.hash_node_position(pos)
|
||||||
local prev_time = last_signal_time_for_chest[pos_hash] or 0
|
local prev_time = last_message_time_for_chest[pos_hash] or 0
|
||||||
local cur_time = minetest.get_us_time()
|
local cur_time = minetest.get_us_time()
|
||||||
last_signal_time_for_chest[pos_hash] = cur_time
|
last_message_time_for_chest[pos_hash] = cur_time
|
||||||
if cur_time - prev_time < 1000000 * interval_to_batch then
|
if cur_time - prev_time < 1000000 * interval_to_batch then
|
||||||
batched_signals[pos_hash] = batched_signals[pos_hash] or {}
|
batched_messages[pos_hash] = batched_messages[pos_hash] or {}
|
||||||
table.insert(batched_signals[pos_hash], msg)
|
table.insert(batched_messages[pos_hash], msg)
|
||||||
local node_timer = minetest.get_node_timer(pos)
|
local node_timer = minetest.get_node_timer(pos)
|
||||||
if #batched_signals[pos_hash] >= max_signals_in_batch then
|
if #batched_messages[pos_hash] >= max_messages_in_batch then
|
||||||
-- Send the batch immediately if it's full
|
-- Send the batch immediately if it's full
|
||||||
node_timer:stop()
|
node_timer:stop()
|
||||||
send_and_clear_batch(pos, channel)
|
send_and_clear_batch(pos, channel)
|
||||||
@ -236,7 +236,7 @@ minetest.register_node("digilines:chest", {
|
|||||||
inv:set_size("main", 8*4)
|
inv:set_size("main", 8*4)
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
batched_signals[minetest.hash_node_position(pos)] = nil
|
batched_messages[minetest.hash_node_position(pos)] = nil
|
||||||
end,
|
end,
|
||||||
after_place_node = tubescan,
|
after_place_node = tubescan,
|
||||||
after_dig_node = tubescan,
|
after_dig_node = tubescan,
|
||||||
@ -375,8 +375,8 @@ minetest.register_node("digilines:chest", {
|
|||||||
minetest.log("action", player:get_player_name().." takes stuff from chest at "..minetest.pos_to_string(pos))
|
minetest.log("action", player:get_player_name().." takes stuff from chest at "..minetest.pos_to_string(pos))
|
||||||
end,
|
end,
|
||||||
on_timer = function(pos, _)
|
on_timer = function(pos, _)
|
||||||
-- Send all the batched signals when enough time since the last signal passed
|
-- Send all the batched messages when enough time since the last message passed
|
||||||
if not batched_signals[minetest.hash_node_position(pos)] then
|
if not batched_messages[minetest.hash_node_position(pos)] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local channel = minetest.get_meta(pos):get_string("channel")
|
local channel = minetest.get_meta(pos):get_string("channel")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user