Real FPS Value

Blitz3D Forums/Blitz3D Programming/Real FPS Value

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

You NEED to make all movement Framerate dependent (well, IMHO only). If this once works, there's only one thing left:
check if the users VSYNC works. If it works and if you can measure the user true Sync Rate, you should use that rate (or that rate divided by 2, 3 or 4) (although basicly you don't care about the rate, just sync the game with it to prevent cutting off half frames), but still as fast as you can.
When it turns out that VSYNC doesn't work on a users machine, use FLIP instead. It WILL cut frames, but at least it will run at all.

; measure time between two VWAITs
vwait
t1=millisecs()
vwait
t2=millisecs()

if (t2-t1)<3
 ; users VSYNC seems not to work, or maybe he has a 500 Hz Screen o_O
 flipmode=1 ; we will use Flip true
else
 flipmode=0 ; we will use Vwait:flip false
endif

;and in the game loop

if flipmode =1
 flip 1
else
 vwait
 flip 0
endif


Meanwhile you'll measure the time one frame takes in your game, and use this value as a generic movement multiplyer.
Prior the mainloop:
t=millisecs()-17 ; to initialize timer calculation (to prevent division by zero)

while not keydown(1) ; then inside the Game Loop:
 t_old=t
 t=millisecs()
 mainspeed#=float(t-t_old) / 16.67
 ...
 ; and for the movement of things:
 if keydown(200) then moveentity player,0,0,1.0*mainspeed#
 ...
 ;and finally adjust animation speed to the current framerate:
 UpdateWorld(mainspeed#)
 Renderworld
 if flipmode =1
  flip 1
 else
  vwait
  flip 0
 endif
wend


But with this method you won't use Tweening, BTW.