Dropping Frames to regulate game speed

Started by
11 comments, last by DividedByZero 12 years, 11 months ago
Problem:
My game currently lags pretty bad at some points.
The game is still getting 60FPS meaning that the actual speed of the game slows.
I think this is making the lag appear worse than it actually is (I hope).

I know I have to time the frames and somehow drop frames.
What I want is the frame rate to drop to allow the processing to catch up.
How do I go about doing this?

I have something to regulate FPS >60 down to 60:
while (fps->get_ticks() < 1000 / FRAMES_PER_SECOND)
{
while (world0->taskPerform()==false) {}
}

Now I need something to check weither or not the time has went over 1000 / FRAMES_PER_SECOND right?

Thanks,
Walker
If this post was helpful please +1 or like it !

Webstrand
Advertisement
What is fps? How is getticks implemented?
I trust exceptions about as far as I can throw them.
get_ticks() returns the amount of milliseconds since the timer was reset, and I reset it before drawing the frame.
FPS Frames Per Second
If this post was helpful please +1 or like it !

Webstrand
What are you using for your timer though?

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

SDL_GetTicks()

then later

SDL_GetTicks() - first amount
...to get milliseconds passed.
If this post was helpful please +1 or like it !

Webstrand
while (app_is_running)
{
// the condition must be chacked each frame because the application is already a loop.
if ( (get_ticks() - last_ticks) > 1000/FPS)
{
update_state_without_drawing(); // Updates whatever data
last_ticks = get_ticks();
}

draw_either_scene_changed_or_not(); // Draws everything each frame, if it didn't change it'd look the same for some milliseconds.
}




EDIT: Input management should go outside the if.
[size="2"]I like the Walrus best.
I generally do the opposite.

I let the program render flat out and regulate things by checking the time since last frame.

So, on a basic scene my rig can put out 8000 FPS and another PC might do 1000 to 2000 FPS but the timing is still fine and objects move at the same rate on any system.
Obligatory link:
http://gafferongames.com/game-physics/fix-your-timestep/

Obligatory link:
http://gafferongames...-your-timestep/


Great article.
[size="2"]I like the Walrus best.

I generally do the opposite.

I let the program render flat out and regulate things by checking the time since last frame.

So, on a basic scene my rig can put out 8000 FPS and another PC might do 1000 to 2000 FPS but the timing is still fine and objects move at the same rate on any system.


I have noticed dropping frames really causes no speed-up what-so-ever.
Can you elaborate more on your method, or post some source?
If this post was helpful please +1 or like it !

Webstrand

This topic is closed to new replies.

Advertisement