News:

Welcome to RetroCoders Community

Main Menu

Timing

Started by johnno56, Sep 16, 2022, 10:14 PM

Previous topic - Next topic

johnno56

Some Basics are capable of setting the FPS of the program so that it will run at the same speed based on the hosts hardware. Is FB capable of doing that? eg: QB64 sets the FPS via the _Limit command. Set an FPS of 60: _limit 60

J
May your journey be free of incident.  Live long and prosper.

ron77

#1
hi johnno56...

to your question... freebasic doesn't have a '_Limit' command however the 'Sleep' command is used as the '_Limit" in QB64 meaning in FB dialect 'sleep 1' means "wait for one millisecond" and 'sleep 100, 1' means 'wait for every 100 milliseconds and then continue and wait for next 100 milliseconds and so on and on' look in the FB help CHM files for the command sleep...

mysoft

yes also normally people do that with a timer loop, so you can set it to the desired FPS... with or without vsync... and with/without compensation (like if a frame only did 59 fps the next would try to do 61) to compensate and keeping the good average of 60fps...

i normally use a loop like this
sub LimitFPS( iFPS as long , bVsync as byte = 0  )
  static as double dSync 
  'maximum frames to compensate (minimum should be 2/iFPS)
  if abs(timer-dSync) > (5/iFPS) then dSync = timer
  while (timer-dSync) < 1/iFPS
    if bVsync then screensync else sleep 1,1
  wend
  dSync += 1/iFPS
end sub

johnno56

Ron and mysoft,

Thanks for the tips. Much appreciated...

J
May your journey be free of incident.  Live long and prosper.

electricwalrus

It's sleep. I mean maybe its not as accurate as a fps limiter but it works in slowing the program down.

sleep 30,1

That stops the program for 30 ms. Notice the ,1 that means it won't check for a key press.
So 1000 / 30 = 33 frames per second roughly...
The execution of the program is usually negligable. So yeah.

Otherwise I think its timer? correct me