http://www.freebasic.net/forum/viewtopi ... 4741#44741
I've decided to make it a macro (untested). Only updateTimer() once per frame. Get FPS through getFPS. FPS defaults to 60.
Code: Select all
'' MACRO
dim shared as integer __globalFPS = 60
dim shared as integer __frames = 0
dim shared as integer __calcFPS = 60
dim shared as double __curTime = 0
dim shared as double __lastTime = 0
#define setFPS(_fps_) __globalFPS = _fps_
#define getFPS __calcFPS
#macro initTimer()
__lastTime = timer()
#endmacro
#macro updateTimer()
__frames += 1
if( __frames >= __globalFPS ) then
__curTime = timer()
__calcFPS = __frames/(__curTime - __lastTime)
__lastTime = __curTime
__frames = 0
end if
#endMacro
'' MAIN
while( len(inkey() ) <> 0 ) '' clear stray input before main loop
wend
initTimer() '' to prevent ridiculously high/low FPS
while( len(inkey() ) = 0 ) '' hit any key to exit
screenlock()
cls()
print "[ANY KEY]=quit FPS:" & Str( getFPS )
screenunlock()
updateTimer()
wend