minitimer.bmx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ' *******************************************************************
  2. ' Source: Mini Timer
  3. ' Version: 1.00
  4. ' Author: Rob Hutchinson 2004
  5. ' Email: [email protected]
  6. ' WWW: http://www.proteanide.co.uk/
  7. ' -------------------------------------------------------------------
  8. ' This include provides a class for a timer object. The class works
  9. ' in milliseconds. First of all the object can be enabled and
  10. ' disabled at will by setting the Enabled field
  11. ' to true or false. The Interval field can be set
  12. ' to mark a milliseconds interval that, when reached, IntervalReached
  13. ' will become true. You can use the Reset() method to reset the timer
  14. ' and MiillisecondsElapsed() will tell you the number of milliseconds
  15. ' that have passed since you called Reset. Enabled field only has
  16. ' any effect on the IntervalReached function of the timer. If false
  17. ' then the method will always return false.
  18. ' Ported directly from my .NET Framework game library: Lita.
  19. ' -------------------------------------------------------------------
  20. ' Required:
  21. ' - Nothing.
  22. ' *******************************************************************
  23. Type MiniTimer
  24. '#Region Declarations
  25. Field TimeStarted:Int
  26. Field Interval:Int
  27. Field Enabled:Int = True
  28. '#End Region
  29. '#Region Method: Reset
  30. '''-----------------------------------------------------------------------------
  31. ''' <summary>
  32. ''' Resets the timer.
  33. ''' </summary>
  34. '''-----------------------------------------------------------------------------
  35. Method Reset()
  36. Self.TimeStarted = MilliSecs()
  37. End Method
  38. '#End Region
  39. '#Region Method: MiillisecondsElapsed
  40. '''-----------------------------------------------------------------------------
  41. ''' <summary>
  42. ''' Gets the number of milliseconds that have passed since a call to Reset.
  43. ''' </summary>
  44. '''-----------------------------------------------------------------------------
  45. Method MiillisecondsElapsed:Int()
  46. If Self.TimeStarted = 0 Then Return 0
  47. Local TimeNow:Int = MilliSecs()
  48. Return TimeNow - Self.TimeStarted
  49. End Method
  50. '#End Region
  51. '#Region Method: IntervalReached
  52. '''-----------------------------------------------------------------------------
  53. ''' <summary>
  54. ''' Returns true if the given interval has been reached.
  55. ''' </summary>
  56. '''-----------------------------------------------------------------------------
  57. Method IntervalReached:Int()
  58. If Self.Enabled Then Return (Self.MiillisecondsElapsed() > Self.Interval)
  59. End Method
  60. '#End Region
  61. End Type