December 03, 2020, 07:50:01 PM

Author Topic: [bb] timers by mindstorms [ 1+ years ago ]  (Read 641 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] timers by mindstorms [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
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
  1. Type timer
  2.         Field milliFrequency#
  3.         Field current
  4.         Field fCurrent#
  5.         Field millis
  6.         Field paused
  7. End Type
  8.  
  9. Function create_timer.timer(frequency%)
  10.         t.timer = New timer
  11.         tmillifrequency = 1.0/Float(frequency)*1000.0
  12.         tcurrent = 0
  13.         tfCurrent = 0.0
  14.         tmillis = MilliSecs()
  15.         tpaused = False
  16.         Return t
  17. End Function
  18.  
  19. Function update_timers()
  20. cmillis = MilliSecs()
  21. For t.timer = Each timer
  22.         If Not tpaused Then
  23.                 temp# = (cmillis-tmillis)/tmillifrequency
  24.                 tfcurrent = tfcurrent + temp
  25.                 tcurrent = Floor(tfcurrent)
  26.                 tmillis = cmillis
  27.         EndIf
  28. Next
  29. End Function
  30.  
  31. Function timer_ticks(t.timer)
  32.         Return tcurrent
  33. End Function
  34.  
  35. Function pause_timer(t.timer)
  36.         tpaused = True
  37. End Function
  38.  
  39. Function resume_timer(t.timer)
  40.         tpaused = False
  41.         tmillis = millisecs()
  42. End Function
  43.  
  44. Function reset_timer(t.timer)
  45.         tcurrent = 0
  46.         tfCurrent = 0.0
  47.         tmillis = MilliSecs()
  48. End Function
  49.  
  50. Function free_timer(t.timer)
  51.         Delete t
  52. End Function
  53.  
  54. Function wait_timer(t.timer)
  55.         Repeat
  56.                 cmillis = MilliSecs()
  57.                 temp# = (cmillis-tmillis)/tmillifrequency
  58.                 tfcurrent = tfcurrent + temp
  59.                 ocurrent = tcurrent
  60.                 tcurrent = Floor(tfcurrent)
  61.                 tmillis = cmillis
  62.         until tcurrent > ocurrent
  63. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal