Ooops
January 15, 2021, 06:00:17 PM

Author Topic: [bb] Tickers by Jams [ 1+ years ago ]  (Read 1360 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Tickers by Jams [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : Tickers
Author : Jams
Posted : 1+ years ago

Description : Simple ticking/timing code, not meant for heavy duty stuff.

Example:

Code: [Select]
Local Tick% = Ticker_New( 1000 )
Repeat
If Ticker_HasTicked( Tick% )
Print "Tick!"
Endif
Until Keyhit( 1 )
Ticker_Dispose( Tick% )


Code :
Code: BlitzBasic
  1. ;EXAMPLE USAGE:
  2. ;
  3. Local Tick% = Ticker_New( 1000 )
  4. Repeat
  5.         If Ticker_HasTicked( Tick% )
  6.                 Print "Tick!"
  7.         EndIf
  8. Until KeyHit( 1 )
  9. Ticker_Dispose( Tick% )
  10.  
  11.  
  12. ;!====================================================================================================
  13. ; Ticker type.
  14. ;!====================================================================================================
  15. Type Ticker
  16.         Field LastTick%
  17.         Field Frequency%
  18. End Type
  19.  
  20. Function Ticker_New%( NewFrequency%=1000 )
  21.         Local this.Ticker       = New Ticker
  22.  
  23.         thisLastTick%           = MilliSecs()
  24.         thisFrequency%          = NewFrequency%
  25.  
  26.         Return Handle( this )
  27. End Function
  28.  
  29. Function Ticker_Dispose%( HND% )
  30.         Local this.Ticker = Object.Ticker( HND% )
  31.  
  32.         Delete this
  33. End Function
  34.  
  35. Function Ticker_Frequency%( HND%, NewFrequency%=-1 )
  36.         Local this.Ticker = Object.Ticker( HND% )
  37.  
  38.         If ( NewFrequeny% = -1 )
  39.                 Return thisFrequency%
  40.         Else
  41.                 If NewFrequency% > 0
  42.                         thisFrequency% = NewFrequency%
  43.                 EndIf
  44.         EndIf
  45. End Function
  46.  
  47. Function Ticker_HasTicked%( HND% )
  48.         Local this.Ticker = Object.Ticker( HND% )
  49.  
  50.         If ( MilliSecs() > ( thisLastTick% +thisFrequency% ) )
  51.                 thisLastTick% = MilliSecs()
  52.                 Return True
  53.         EndIf
  54.  
  55.         Return False
  56. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal