PDA

View Full Version : Frame rate limiter.



Bones
18-10-2007, 09:12 AM
Hi All

I'm doing this to limit the frame rate, but the graphics are juddering a little, and not moving smoothly also, on two machines, I have a steady 65 fps, on my brothers machine however, he gets a startling 3 fps .. Its this right or am I missing something?.



// --- Setup timer ---
Timer:= TPHXTimer.Create;
Timer.Interval:= 1 / 30;

// --- Main Loop ---
Repeat

Timer.Update;
Input.Update;
Move_All;
Timer.Wait;
Draw_All;

Until (GameOver = True) or (Screen.Visible = False);

User137
18-10-2007, 10:39 AM
Usually when it comes to fps as low as 3, it is because drawing or physics takes so much frame time. What is yours and your brothers computer specs?

Pyrogine
18-10-2007, 01:55 PM
Hi,

Maybe you should try frame-based timing. The idea is to let the game loop run as fast as your computer can run it thereby having the bast overall experience and you control the rate at which your simulation runs. Now you've decoupled your updating from rendering and have precise control over it.

In this scenario, your game loop can be running at say 60 fps on one machine and maybe 45 or something different on another, but your simulation will always run at the precise specified rate between them.

You game now is divided into two section, one to render your graphics and the other to updating your simulation. You set your desired simulation rate at game start and at the top of your game loop, you get the elapsed time. Note, this elapsed time is a time quantity based on your desired simulation rate. This value is then used as a multiplier against your game objects to keep them moving at/or very close to your desired simulation rate. For example, if you want your simulation to update at 30 fps and your game loop is currently running at 60 fps, the elapsed time value for this frame will be 0.5. When you multiply this by the speed of your moving objects it will cause them to move at 30 fps. Know that from frame to frame your game loop speed will vary greatly and frame base timing can keep your simulation running at a known and predictable rate. The result is silky smooth animation.

Google for frame-based timing for more information. I can send you some sources if you like that you can drop in.

Hope this helps.

Bones
18-10-2007, 05:14 PM
Ah ..
I see .. this is why int the demo's, the movement is being updated by an incement modified by the frame time.



if isLeft in Input.States then X:=X - FSpeed * FrameTime;
if isRight in Input.States then X:=X + FSpeed * FrameTime;


I think I understand now.

Pyrogine
18-10-2007, 06:55 PM
Correct.

Also, one thing you need to be aware of with FBT is there can be a situation where if there is a lot of activity going on in the background, the elapsed time value can be extremely large as it will calculate a value to keep those objects moving at your simulation speed. This can occur if say there is lot of hard disk activity or maybe a heavy load during a frame. What I've done to help with this is to specify a maximum elapsed time the timer object will try to keep the simulation running at. For example if I specify two for max elapsed time, the timer will try and keep the simulation running at my specified rate if the overall rate drops by two times. After this point, it gives up and let the frame rate match the game loop rate. This will minimize the huge jumps that sometime can occur for reasons specified.

Bones
19-10-2007, 07:51 PM
Thanks.

I found out why my brothers machine was getting 3 fps btw, it turns out, he had switched to 16 bit color mode to run and older game and hadn't switched back, when he returned to 32 bit mode, his FPS rocketed up to 240..

Any Idea why this should happen ?

Pyrogine
19-10-2007, 08:13 PM
Not sure.

My guess would be that your not getting acceleration in that mode for what ever reason.

arthurprs
19-10-2007, 08:37 PM
Check if phnx timer are working correctly,
using gettickcount and logging to a file for example.

Andreaz
20-10-2007, 07:04 PM
Thanks.

I found out why my brothers machine was getting 3 fps btw, it turns out, he had switched to 16 bit color mode to run and older game and hadn't switched back, when he returned to 32 bit mode, his FPS rocketed up to 240..

Any Idea why this should happen ?

Probably some driver issue for his graphics card i could imageine....

Bones
20-10-2007, 10:58 PM
Thanks.

I found out why my brothers machine was getting 3 fps btw, it turns out, he had switched to 16 bit color mode to run and older game and hadn't switched back, when he returned to 32 bit mode, his FPS rocketed up to 240..

Any Idea why this should happen ?

Probably some driver issue for his graphics card i could imageine....

I tried it on my own machine too, sure enough, my frame rate dropped to 8 fps, is there maybe something I'm doing wrong when I set up the screen ?

Andreaz
21-10-2007, 07:18 AM
Probably not, theres some info on this page;

http://3dnature.com/gltune.html

I'm afraid this has nothing to do with Phoenix or glfw, ogl may be reverting to software rendering when using 16bit.