0

Hello.

A couple of years ago I developed a game using C with the GLUT library. I originally developed it on an older machine on which the game ran fine. Now when I have a newer and faster machine the game runs so fast that it's impossible to actually play it. I was wondering how the game could be modified so that the running speed is constant on all systems (more or less).

I would assume that I would have to implement some kind of sleep function to be called during the main loop or is there some other kind of technique normally used?

Thanks in advance.

4
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by klemmerj
0

You are correct. I usually sleep for about 10 ms, that should be enough. I have been thinking about another way too, if your game relies heavily on graphics (your scene takes long to draw), then maybe it's a good thing to try calculate movements etc based on how long it takes to draw your scene. Example:

while(true) // Main loop
{
   xPosition += movement_per_ms * ms_since_last_time;
   draw_scene();
}

I haven't tested this technique yet though.

Regards,
Emil Olofsson

0

If you are on Windows, there is a function that will help you manage frame counts - C:\Program Files\Microsoft SDKs\Windows\v7.0\Include\WinBase.h\GetTickCount() You'd use it like this -

long start = GetTickCount();

if (GetTickCount() - start >= 30)
{
    //reset timing
    start = GetTickCount();

    <your code to move things here>
}

I'm fairly sure that this kind of functionality exists under other OS/Frameworks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.