December 04, 2020, 11:51:41 AM

Author Topic: [bmx] FPS module by ninjarat [ 1+ years ago ]  (Read 384 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] FPS module by ninjarat [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : FPS module
Author : ninjarat
Posted : 1+ years ago

Description : Import and go, absolutely nothing required except Import, and call functions.  Only works in Max2D.

Code :
Code: BlitzMax
  1. Module Rat.FramesPerSecond
  2. ModuleInfo "Description: Does simple frame rate tracking in less than 50 lines of code."
  3. ModuleInfo "Author: Bill Whitacre (ninjarat)"
  4. ModuleInfo "Version: 1.0"
  5.  
  6. Private
  7.  
  8. Global fpsobject:CFps=New CFps
  9. Type CFps
  10.         Field ms#,oms#,fps#,mspf#
  11.        
  12.         Method getFps()
  13.                 ms=MilliSecs()
  14.                 mspf=ms-oms
  15.                 fps=1000*(mspf^-1)
  16.                 oms=ms
  17.         End Method
  18. End Type
  19.  
  20. Function internalUpdate()
  21.         fpsobject.getFps
  22. End Function
  23.  
  24. Function internalFPS#(update)
  25.         If update Then internalUpdate
  26.         Return fpsobject.fps
  27. End Function
  28.  
  29. Function internalMSPF#(update)
  30.         If update Then internalUpdate
  31.         Return fpsobject.mspf
  32. End Function
  33.  
  34. Public
  35.  
  36. Function FPSUpdate()
  37.         internalUpdate
  38. End Function
  39.  
  40. Function FPS#(update=True)
  41.         Return internalFPS(update)
  42. End Function
  43.  
  44. Function MSPF#(update=True)
  45.         Return internalMSPF(update)
  46. End Function


Comments :


ninjarat(Posted 1+ years ago)

 Rather than simply counting the frames in a second, it takes the amount of time in milliseconds of the frame and calculates the actual ratio.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal