Posts: 1,688
Threads: 119
Joined: Jun 2003
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!
Posts: 3,522
Threads: 189
Joined: Dec 2003
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..
Posts: 1,688
Threads: 119
Joined: Jun 2003
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!
Posts: 3,522
Threads: 189
Joined: Dec 2003
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..
Posts: 979
Threads: 27
Joined: Aug 2001
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.
Posts: 1,688
Threads: 119
Joined: Jun 2003
@ 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!
Posts: 3,522
Threads: 189
Joined: Dec 2003
Add SLEEP 1
The benefits with the code I posted is that you get away from the 100% CPU usage.. which you should..
Posts: 1,688
Threads: 119
Joined: Jun 2003
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!