Posted 17 May 2015 - 07:41 PM
Atm I try to fix a bug, where a timer seems to miss sometimes an event and is then dead.
As I also want to make the program fit for multi player (even more events) I searched
the forum and wiki for details / examples about how event queues are handled, bur was not successful.
Before I do more tests (and may insert other bugs) I'd like to get some expert advice.
Listening to mutliple event types and process the event:
Question 1 (just to make sure)
While the program executes code e.g. stuff for channel 44, incoming messages are lost, as there is no os.pullEvent listening to them?
Parallel listening and processing (pseudo code):
Question 2:
Does the above pseudo code help to reduce missed event? I think it still may happen?
Question 3:
I probably should not use any os.sleep() commands in the event processing part, as the internally generated events will mess everything up?
Question 4:
I'm thinking about using a dedicated timer computer, which only sends time information on request, nothing more.
Then it's probably tricky to get this information into the modem_message processing.
Maybe s.th. like a ) request time information for processing an event b ) put the not fully solved event back on queuec ) resolve this event after time info has arrived?
This stuff is interesting :)/> but not really easy! :(/>
Edit: queue
As I also want to make the program fit for multi player (even more events) I searched
the forum and wiki for details / examples about how event queues are handled, bur was not successful.
Before I do more tests (and may insert other bugs) I'd like to get some expert advice.
Listening to mutliple event types and process the event:
myTimer = os.startTimer(1)
while true do
-- event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
event, par1, par2, par3, par4, par5 = os.pullEvent()
-- event processing
if event=="timer" and par1==myTimer then
-- handle timer event
myTime=myTime+1
myTimer = os.startTimer(1)
elseif event=="modem_message" then
if par2==44 then
-- do stuff for channel 44
elseif par2==33 then
-- do stuff for channel 33
else
-- not interested in this message
end
else
-- not interested in this event
end
end
Question 1 (just to make sure)
While the program executes code e.g. stuff for channel 44, incoming messages are lost, as there is no os.pullEvent listening to them?
Parallel listening and processing (pseudo code):
local "manually managed queue"
local function pullEvents()
event, par1, par2, par3, par4, par5 = os.pullEvent()
-- filtering of interesting events
-- if interesting then put event, par1, par2, par3, par4, par5 in a manually managed queue
end
while true do
parallel.waitForAny(
pullEvents,
function()
-- event processing
-- get somehow FIFO event, par1, par2, par3, par4, par5 from manually managed queue
if event=="timer" and par1==myTimer then
-- handle timer event
myTime=myTime+1
myTimer = os.startTimer(1)
elseif event=="modem_message" then
if par2==44 then
-- do stuff for channel 44
elseif par2==33 then
-- do stuff for channel 33
else
-- not interested in this message
end
else
-- not interested in this event
end
-- make sure to remove the event from manually managed queue
end
)
end
Question 2:
Does the above pseudo code help to reduce missed event? I think it still may happen?
Question 3:
I probably should not use any os.sleep() commands in the event processing part, as the internally generated events will mess everything up?
Question 4:
I'm thinking about using a dedicated timer computer, which only sends time information on request, nothing more.
Then it's probably tricky to get this information into the modem_message processing.
Maybe s.th. like a ) request time information for processing an event b ) put the not fully solved event back on queuec ) resolve this event after time info has arrived?
This stuff is interesting :)/> but not really easy! :(/>
Edit: queue
Edited on 17 May 2015 - 08:07 PM