[LIB] GameTimer: FPS / Frametime / Deltatime [Windows x64]

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

[LIB] GameTimer: FPS / Frametime / Deltatime [Windows x64]

Post by Mijikai »

I coded a small timer library in fasm to calulate the FPS, Frametime an Deltatime.
If your application or game does not have VSynce the library will take care of the timing without stressing the cpu.

Maybe someone wants to help me develop this further :)

PureBasic Example (PB 5.62 x64):

Code: Select all

EnableExplicit

;gametimer.lib / fasm / x64 / os: windows
;(c)2020 by mijikai

Import "gametimer.lib"
  GameTimerInterface.i()
  GameTimerVersion.i()
EndImport

#GAMETIMER_VERSION = $0001

Interface GAMETIMER
  Start.i()
  Stop.i()
  Time.d()
  Delay.i(Milliseconds.i)
  WaitForMS.i(Milliseconds.i,VSync.i = #False)
  WaitForFPS.i(FPS.i,VSync.i = #False)
  Wait.i()
  WaitTime.d()
  WaitDelta.d()
  WaitFPS.i()
  Resolution.i()
  Release.i()
EndInterface

Global *gametimer.GAMETIMER

If GameTimerVersion() = #GAMETIMER_VERSION
  *gametimer = GameTimerInterface()
  If *gametimer
    *gametimer\Start()
    *gametimer\Delay(100)
    *gametimer\Stop()
    Debug *gametimer\Time();<- time will return the time elapsed (start -> stop) on 100 ns units!
    Debug ""
    *gametimer\WaitForFPS(60)
    *gametimer\Wait()
    Debug *gametimer\WaitTime()
    Debug *gametimer\WaitDelta()
    ;*gametimer\WaitFPS() <- game needs to run for atleast one second to calculate fps!
    Debug ""
    *gametimer\WaitForFPS(60,#True);<- if the game has vsync set the vsync flag to #True!
    *gametimer\Delay(16);<- simulated vsync!
    *gametimer\Wait()
    Debug *gametimer\WaitTime()
    Debug *gametimer\WaitDelta()
    Debug ""
    Debug *gametimer\Resolution();<- resolution of the internal delay in 100 ns units!
    *gametimer\Release();<- cean up everthing
  EndIf
EndIf

End
Download: https://www.dropbox.com/s/hhr753b2gyw3r ... 0.zip?dl=0