#### Archived

This topic is now archived and is closed to further replies.

# DX framerate

This topic is 6460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m working on a tile based engine, and I am having some problems with limiting the framerate. When I don''t limit the frame rate, the map scrolls smooth, when I try to limit it to 33 fps using timers, the scrolling becomes jittery. Does anyone know about this?

##### Share on other sites
Here''s a bit more info. I''m using the timeGetTime function to time. Timing setup is in the windows message loop, calling my main game function at the 33 milisecond intervals. The main game function includes all the input routines and game-logic, as demonstrated in the book Windows Game Programming for Dummies.

Wes Henwood

##### Share on other sites
Putting the timer at 33 miliseconds intervals doesn''t mean the loop will will be done 33 time per second. 1 second is 1000 milisecond so at is best, that''s if the loop has nothing in it, your loop will be done 1000/33 times by seconds. Which is about 30 times. So the system will wait 33 milisecond before continuing in your code.
So, if your code takes 10 miliseconds to execute, the time to complete a loop will go from 33 miliseconds to 43 miliseconds. So your frame rate will only be 1000/43, which is 23.
To limit your fps, you should use the function GetTickCount().
Do something like this:

NewTime = GetTickCount();
while (TickToWait > (NewTime - OldTime))
{
// Wait loop to limit the fps
}
OldTime = GetTickCount();
// Put your game functions here

I didn''t try it but it should work, I think. I''m really tired right now so I can assure you it will work 100%.

Darkening

##### Share on other sites
God damn it, don''t limit your framerate!

You have to find out another way to update your game status every X seconds (multi-threading?)

Limiting the framerate is soo stupid, especially since you might end up getting an even lower framerate on slow computers

Regards,
Laarz

##### Share on other sites
Oops, I made a mistake in my code last night.
It should be:
  NewTime = GetTickCount();while (TickToWait > (NewTime - OldTime)){// Wait loop to limit the fpsNewTime = GetTickCount(); <--- Don't forget this}OldTime = GetTickCount();// Put your game functions here// or even this without the NewTime variable:while (TickToWait > (GetTickCount() - OldTime)){// Wait loop to limit the fps}OldTime = GetTickCount();// Put your game functions here

That way, if you want to block the fps at 30, then your game will never go faster than 30 fps even on a computer capable of running it at 200. And it will go at the same speed on a computer only capable of running it at 50 or even 30.

Darkening

Edited by - Darkening on June 15, 2000 1:06:21 PM

##### Share on other sites
I need to say something,

As Laarz say, dont limit your Frame Rate, but instead use the ''Time''.

Like, if your on a Fast or Slow computer, the only difference will be the FPS, But on both computer, units will walk at same speed. On the fast computer, maybe its will take 100 frame to move a unit at a given position, perhaps on the slow one maybe its will only take 40 frames.

They things you will need to known to acheive this is the speed of a unit ( X unit / sec ). So when moving your units just * by time.

And this way, you DONT limits your frame, so on high-end computer you will wantto implent very impresive F/X, while in low-end computer you will disable them....

##### Share on other sites
There is a good document discussing this topic here:

http://www.cdx.sk/userwebs/janni/

Under the "Game Techniques tutorials" is "Game programming under Windows using CDX" click on the red light to download.

hebertjo