fix: replace custom event wake-up with polling, remove craftItem double-capture

Two robustness improvements to the Network capture/processor split:

1. Processor wake-up: replaced os.queueEvent('network_queued') /
   os.pullEvent('network_queued') with sleep(0) polling. Custom events
   can be consumed by other coroutines (e.g. craftItem's unfiltered
   os.pullEvent()) or swallowed by the OS event layer. Polling the
   shared queue every tick is simpler and guaranteed reliable.

2. craftItem: removed ORDER_CHANNEL message buffering and re-queuing.
   With the dedicated Network-capture task, ORDER_CHANNEL messages are
   already safely captured into networkQueue. The old buffering caused
   double-capture: capture task adds to queue, craftItem also buffers,
   then re-queues via os.queueEvent -> capture captures again -> dup.
   The commandId dedup caught these, but removing the source is cleaner.
This commit is contained in:
MayaTheShy
2026-03-28 23:40:09 -04:00
parent 36612ecc9f
commit ec1a681924
2 changed files with 2 additions and 9 deletions

View File

@@ -646,7 +646,6 @@ local function main()
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
if channel == cfg.ORDER_CHANNEL and type(message) == "table" then
table.insert(networkQueue, { replyChannel = replyChannel, message = message })
os.queueEvent("network_queued")
end
end
end),
@@ -658,7 +657,7 @@ local function main()
end
while true do
if #networkQueue == 0 then
os.pullEvent("network_queued")
sleep(0)
end
while #networkQueue > 0 do
local entry = table.remove(networkQueue, 1)

View File

@@ -1338,7 +1338,6 @@ function O.craftItem(recipeIdx, batches)
log.info("CRAFT", "Waiting for turtle reply (timeout: %ds)...", cfg.CRAFT_TIMEOUT)
local deadline = os.clock() + cfg.CRAFT_TIMEOUT
local result = nil
local bufferedMessages = {}
while os.clock() < deadline do
local timerId = os.startTimer(math.max(0.1, deadline - os.clock()))
@@ -1350,18 +1349,13 @@ function O.craftItem(recipeIdx, batches)
if channel == cfg.CRAFT_REPLY_CHANNEL and type(message) == "table" and message.type == "craft_result" then
result = message
break
elseif channel == cfg.ORDER_CHANNEL then
table.insert(bufferedMessages, {event, p1, p2, p3, p4, p5})
end
-- ORDER_CHANNEL messages are captured by the Network-capture task
elseif event == "timer" and p1 == timerId then
-- Timeout tick
end
end
for _, msg in ipairs(bufferedMessages) do
os.queueEvent(table.unpack(msg))
end
activity.crafting = false
state.needsRedraw = true
state.smelterNeedsRedraw = true