Sign in to follow this  
DarioMicera

[Directx9] Frame rate Management

Recommended Posts

DarioMicera    126
I'm trying to manage the frame rate of my game and wish to ask for some direction because i think i'm not doing it right:

NOTE: lasttime=timeGetTime();

[code]while (msg.message!=WM_QUIT)
{
elapsedtime=timeGetTime();
if(elapsedtime-lasttime > (1000/60))
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{

controls();
draw();
Sleep(0);
lasttime=elapsedtime;
}
}
}
clear();
return (int)msg.wParam;
}[/code]


This is my loop message. The first if statement "filter" the rate at which the frames gets drawn. The problem is that its behaviour changes depending on the Present parameter (but that may be normal).

The weird thing is that the game doesn't run that smoothly: it seems to be fluid but while moving my ship (it's a 2d space invader style game) to the left or right, the first frames are smooth while after few more, it isn't that fluid (like i can see the interval between rendering but in a really fast way).

I know that i have to adjust the update speeds (like ship movement speed, bullets movement speed, and enemy movement speed) but first i wish to have some direction:

Is there a better and more polished way to achieve what i want?

Many thanks in advance [img]http://public.gamedev.net/public/style_emoticons/default/smile.gif[/img]

Share this post


Link to post
Share on other sites
wolfscaptain    200
I only recently implemented an article that explains how and why to have a fixed frame rate for your logic code, and I can say this is just the right way.

I suggest you to read it here gafferongames.com/game-physics/fix-your-timestep/

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this