Time-Event driven app
Posted: Thu Sep 02, 2004 3:25 am
I intend to write a small multimedia-type app where events are triggered by various things, including elapsed time.
Before I start I wonder if the below is safe. As timers trigger they call a callback, which determines which timer and takes appropriate action. Obviously in the app that would not be a debug statement.
The timers would make certain "objects" do certain things.
This little test appears to work ok but I am wondering what is happening behind the scenes when, for example, two timers trigger at the same time and the proc is called twice.
Am I doing anything nasty like leaking mem or heading for stack problems, etc.
So, any gurus who care to help?
Thanks. 
EDIT:
Also, I can't find anything in the SDK help that gives limits on number of timers, valid ID range, etc. Any info on this appreciated.
Before I start I wonder if the below is safe. As timers trigger they call a callback, which determines which timer and takes appropriate action. Obviously in the app that would not be a debug statement.
This little test appears to work ok but I am wondering what is happening behind the scenes when, for example, two timers trigger at the same time and the proc is called twice.
Am I doing anything nasty like leaking mem or heading for stack problems, etc.
So, any gurus who care to help?
Code: Select all
Dim timers.l(20)
Global startTime.l,winID.l
Procedure timedEvents(winHandle.l,uMsg.l,idEvent.l,dwTime.l)
If idEvent>0 And idEvent<4
diff=dwTime-startTime
timers(idEvent) * -1
killTimer_(winHandle,idEvent)
If idEvent=1
Debug "1 @ "+Str(diff)
ElseIf idEvent=2
Debug "2 @ "+Str(diff)
ElseIf idEvent=3
Debug "3 @ "+Str(diff)
EndIf
timers(idEvent) * -1
Debug Str(timers(idEvent))
If SetTimer_(winHandle,idEvent,timers(idEvent),@timedEvents())=0
Debug "NOT SET"
EndIf
Else
Debug "HUH "+Str(idEvent)
EndIf
EndProcedure
; This is here just so your forum page doesn't scroll too far to the right.
flgs=#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar
winID=OpenWindow(0,200,300,120,20,flgs,"ToyTimer")
If winID
startTime=getTickCount_()
timers(1)=950
timers(2)=1900
timers(3)=11130
For i=1 To 3
If SetTimer_(winID,i,timers(i),@timedEvents())=0
Debug "NOT INITIALISED"
timers(i)=0
EndIf
Next
Repeat
Event = WaitWindowEvent()
Until Event=#PB_EventCloseWindow
For i=1 To 3
If timers(i)>0
killTimer_(winID,i)
EndIf
Next
EndIfEDIT:
Also, I can't find anything in the SDK help that gives limits on number of timers, valid ID range, etc. Any info on this appreciated.