Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FB Timer problems/quirks?
#1
In my program that I am working on, I Antoni's fps regulator to keep a steady fps.

Code:
delay! = 1/fps
t!=timer+delay!


[draw everything to the screen]

  do :loop until timer>t!:t!=timer+delay!

However, I found that if the variable fps is 85 or lower, the FPS will stick at 64-65 FPS. However, once the varibale fps hits 86, the FPS will suddenly shoot up to 126 FPS. Right now, it seems impossible for me to achieve say 70 fps, 80 fps or anything else. Could someone please explain to me what is happening here, if anyone understand this? Help is highly appreciated.
Jumping Jahoolipers!
Reply
#2
What OS are you using, and what CPU?

FB Timer uses the HighPrecisionCounter flux capacitator.. it doesent exist on older CPUs

If no flux thingy is found, FB relies on the OS timer, for Windows 9x it's 50ms accuracy, for WinXP it's 15 (or 10, I keep forgetting)

I have no idea about DOS or Linux..
Reply
#3
yeah, i know about that...

i'm running on windows xp, on an AMD Turion 64 processor. Turion's the latest thing from AMD.
Jumping Jahoolipers!
Reply
#4
You could always initialize SDL and use SDL_GetTicks, which returns milliseconds, at a pretty high resolution..

I have no idea why timer doesent work for you, then again, i dont use it very much as SDL_GetTicks does what i want..

If nothing else, make a test program using SDL_GetTicks and see if the reults are the same..


Or even sleep.. which is a better idea anyways so your prog doesent devour 100% CPU..

Code:
delay = 1000/fps
do
  
  tDelay = TIMER*1000+delay
  
  '[Do stuff here]
  
  
  tDelay -= TIMER*1000
  if tDelay > 0 then Sleep tDelay
  
loop
Try it..

Sometimes when you have 100% CPU loops you get weird results..
Reply
#5
Every CPU since the Pentium has supported QueryPerformanceCounter(), it would take an oooold computer not to support it.

If you go to http://freebasic.net/forum in the "Tips & Tricks" forum, there are a bunch of FPS formulas, if you're interested.
Reply
#6
@ Z!re: I already found an alternative, but thanks!

@Jofers: Actually, I did that yesterday. Dumbleydore's routine seems to work fine for me. CPU useage is back up to 100% unfortunately, but I guess it can't be helped. Changing the priority to below normal or low doesn't really seem to help cpu useage...
Jumping Jahoolipers!
Reply
#7
Add SLEEP 1


The benefits with the code I posted is that you get away from the 100% CPU usage.. which you should..
Reply
#8
I know all about sleep 1... unfortunately sleep isn't working for me. Sleep 1 brings the fps down to about 60 from anything else i put in.
Jumping Jahoolipers!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)