Update entrypointlib.lua

This commit is contained in:
Rivulet
2026-04-05 00:58:12 +00:00
parent 07548ac236
commit e1471df6a8

View File

@@ -1,7 +1,5 @@
local pullEvent = os.pullEventRaw local pullEvent = os.pullEventRaw
local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end) local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
term.clear()
term.setCursorPos(1,1)
local network = {} local network = {}
local message_queue = {} local message_queue = {}
modem.open(15125) modem.open(15125)
@@ -24,7 +22,7 @@ end)
local last_heartbeat = os.epoch("utc") local last_heartbeat = os.epoch("utc")
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id}) modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id})
local function receive() function network.receive()
while true do while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message") local _, _, channel, _, msg, distance = pullEvent("modem_message")
if channel == 15125 then if channel == 15125 then
@@ -73,7 +71,7 @@ function network.send(msg,destination)
message_queue[#message_queue+1] = {protocol="packet",content=msg,destination=destination,sender=os.getComputerID(),hops=0} message_queue[#message_queue+1] = {protocol="packet",content=msg,destination=destination,sender=os.getComputerID(),hops=0}
end end
local function connect() function network.connect()
while true do while true do
if os.epoch("utc") - last_heartbeat > math.max((300*canidate.distance)/100,300) then if os.epoch("utc") - last_heartbeat > math.max((300*canidate.distance)/100,300) then
canidate = {id = -1, distance = 764, max_distance=0} canidate = {id = -1, distance = 764, max_distance=0}
@@ -116,9 +114,7 @@ end
function network.getCandidate() function network.getCandidate()
return canidate return canidate
end end
function network.loop() function network.loop()
parallel.waitForAny(connect,receive) parallel.waitForAll(network.connect,network.receive)
end end
return network return network