Framerates insane

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

Recommended Posts

Recently I made my first SDL game, Phlong(http://home.comcast.net/~joobot/Phlong.zip) and I realized it ran at different speeds on each computer. So I looked up framerates and found SDL_gfx's framrate system and put it in my program and it was very chuggy. What should I do?

Share on other sites
You need a way to control time in your game. Put this somewhere in your main loop:
// Provide time delayUint32 now;static Uint32 next_time;now = SDL_GetTicks();if(next_time > now)    SDL_Delay(next_time - now);next_time += 30;

Run it and then play around with the 30 until it's as fast as you want it. This makes the game delay 30 milliseconds between each frame. Only if needed of course.

Share on other sites
isn't using SDL_Delay() a bad idea to lock the framerate? this is because it only uses Sleep() (on windows at least), which has an 10 ms resolution. this means if you do SDL_Delay(30), it could actually delay the game for 40 milliseconds. this could lead to jerky game play.

instead, you should waste the rest of the time in an empty while() loop, or do time based movement.

Share on other sites
It still runs differently on every machine.

Share on other sites
Quote:
 Original post by graveyard fillaisn't using SDL_Delay() a bad idea to lock the framerate? this is because it only uses Sleep() (on windows at least), which has an 10 ms resolution.

Actually this is only true for version earlier than win2k. It's not the resuolution that makes Sleep() unreliable, it#s the fact that the time actually spend on other processes is at least the amount of ms you pass to it. Nevertheless some operations run even better (less jerky) if you put a Sleep(0) or a Sleep(1) (can't remember which) in you main loop.
It's also nice because some people (me included) like to run programs in the background while playing and while I can accept 100% CPU usage when Doom 3 is running, I simply don't expect that for a simple Pong clone [smile].

Share on other sites
Well I made the framerate 100 using SDL_gfx liek so:

    FPSmanager *framerate = new FPSmanager;    SDL_initFramerate(framerate);    SDL_setFramerate(framerate,100);    //Lock The screen    //main loop    //Unlock    //Flip    SDL_framerateDelay(framerate);

It runs smoothly on my newer computers and on the older computers it's smooth but much slower. Is there a way to figure out like the computers running speed and calculate the ebst framerate?

Share on other sites
Using sleep() (or just waiting for x milliseconds), is a bad idea if all you want is that the game runs equally fast on all computers. You should use time-based movement.

Share on other sites
Quote:
 Original post by KurioesUsing sleep() (or just waiting for x milliseconds), is a bad idea if all you want is that the game runs equally fast on all computers. You should use time-based movement.

Pardon the naive question, but what do you mean by time-based movement? Currently I have a game loop that does something like the following:

while(game_not_done) {

ProcessEvents();

RenderFrame();

SDL_Delay(draw_time);

DrawFrame();

}

I understand what was said about SDL_Delay()/sleep() not having a fine resolution, but what if I don't want my game to consume 100% of the CPU time and still run at a constant framerate across machines?

Share on other sites
My mini-tutorial may be what you're looking for...

Share on other sites
Quote:
Original post by Roots
Quote:
 Original post by KurioesUsing sleep() (or just waiting for x milliseconds), is a bad idea if all you want is that the game runs equally fast on all computers. You should use time-based movement.

Pardon the naive question, but what do you mean by time-based movement? Currently I have a game loop that does something like the following:

while(game_not_done) {

ProcessEvents();

RenderFrame();

SDL_Delay(draw_time);

DrawFrame();

}

I understand what was said about SDL_Delay()/sleep() not having a fine resolution, but what if I don't want my game to consume 100% of the CPU time and still run at a constant framerate across machines?

time based movement is when you move all of your objects over a period of time, NOT over a hard-coded set velocity. to do this, you calculate how much time has passed to go through a frame. then you move your objects at their velocity * time_passed. what yoru doing is locking the frame-rate with SDL_Delay, which IMO is a bad idea. at least lock the frame-rate with an empty while loop so that it doesnt get screwy (at least on some machines)

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• Forum Statistics

• Total Topics
633662
• Total Posts
3013231
×