[bb] timers by mindstorms [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : timers
Author : mindstorms
Posted : 1+ years ago

Description : Has all the funcitons of blitzplus's timers, except with an underscore so as not to interfere with blitz3d's timers.  Use as you wish...

Code :
Code (blitzbasic) Select
Type timer
Field milliFrequency#
Field current
Field fCurrent#
Field millis
Field paused
End Type

Function create_timer.timer(frequency%)
t.timer = New timer
tmillifrequency = 1.0/Float(frequency)*1000.0
tcurrent = 0
tfCurrent = 0.0
tmillis = MilliSecs()
tpaused = False
Return t
End Function

Function update_timers()
cmillis = MilliSecs()
For t.timer = Each timer
If Not tpaused Then
temp# = (cmillis-tmillis)/tmillifrequency
tfcurrent = tfcurrent + temp
tcurrent = Floor(tfcurrent)
tmillis = cmillis
EndIf
Next
End Function

Function timer_ticks(t.timer)
Return tcurrent
End Function

Function pause_timer(t.timer)
tpaused = True
End Function

Function resume_timer(t.timer)
tpaused = False
tmillis = millisecs()
End Function

Function reset_timer(t.timer)
tcurrent = 0
tfCurrent = 0.0
tmillis = MilliSecs()
End Function

Function free_timer(t.timer)
Delete t
End Function

Function wait_timer(t.timer)
Repeat
cmillis = MilliSecs()
temp# = (cmillis-tmillis)/tmillifrequency
tfcurrent = tfcurrent + temp
ocurrent = tcurrent
tcurrent = Floor(tfcurrent)
tmillis = cmillis
until tcurrent > ocurrent
End Function


Comments : none...