Jump to content
  • Advertisement
Sign in to follow this  
Yamian

Framerates insane

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
You need a way to control time in your game. Put this somewhere in your main loop:

// Provide time delay
Uint32 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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by graveyard filla
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.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Kurioes
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.


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();

UpdateStatus();

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 this post


Link to post
Share on other sites
Quote:
Original post by Roots
Quote:
Original post by Kurioes
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.


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();

UpdateStatus();

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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!