Qbasicnews.com
FB Timer problems/quirks? - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: FB Timer problems/quirks? (/thread-7995.html)



FB Timer problems/quirks? - barok - 08-29-2005

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.


FB Timer problems/quirks? - Z!re - 08-29-2005

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..


FB Timer problems/quirks? - barok - 08-29-2005

yeah, i know about that...

i'm running on windows xp, on an AMD Turion 64 processor. Turion's the latest thing from AMD.


FB Timer problems/quirks? - Z!re - 08-29-2005

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..


FB Timer problems/quirks? - Jofers - 08-29-2005

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.


FB Timer problems/quirks? - barok - 08-29-2005

@ 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...


FB Timer problems/quirks? - Z!re - 08-29-2005

Add SLEEP 1


The benefits with the code I posted is that you get away from the 100% CPU usage.. which you should..


FB Timer problems/quirks? - barok - 08-29-2005

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.