Jump to content
  • Advertisement
Sign in to follow this  
Beshon

SDL Regulating frame rate

This topic is 1960 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

Hey

 

I have followed most the beginner tutorials out there I can find on SDL and am finally getting around to making my first game, something I want to include now is going from beginner standard to industry standard and the first thing is moving from controlling frame rate by ticks and start using time to do this as I have seen lots of comments with people saying this is much better.

 

I cannot however find anything like out there that explains how to do this so am posting here for a basic description on how to do it and hopefully a code snippet.

 

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement

Didn't really understand what you want... Do you want to limit your game frame rate, for instance 60 frames per second? Or could it be that you want to control your game by time (which is the standard), for instance, the movement of a character for 2 seconds be the same for someone running at  30 FPS and other running as 200 FPS?

Share this post


Link to post
Share on other sites

If you have a good level of understanding with what you have learnt so far, and feel comfortable with your language, these two articles provide quite detailed explanations of what (I assume) you would like to learn.

 

They cover the topics of using delta time in your games, implementing a fixed time-step and rendering using interpolation. I have read through them a few times in the past but have yet to put them into practice (studying Maths in my spare time atm). The logic seems quite sound but I can't recommend from a practical perspective.

 

I hope this helps,

 

Stitchs.

 

EDIT: I just realised I never linked the actual articles, I do apologise:

 

http://gafferongames.com/game-physics/fix-your-timestep/

 

http://www.koonsolo.com/news/dewitters-gameloop/

Edited by stitchs

Share this post


Link to post
Share on other sites

Eh so at the moment I am using the way in which you use GetTicks and then work out if its going too fast and then delay it if it is, the way the above tutorials show it.

 

I have read in quite a few places that its best to handle your animation and stuff like that using time passed instead of frames passed so I want to do it this way but cannot find anything on it.

 

Is that clearer? 

 

Stiches you didnt post the articles in your post, I would love to see them though!

 

Thanks again

Edited by Beshon

Share this post


Link to post
Share on other sites

GetTicks is the amount of millliseconds since the program started.

if you in your update loop save the delta

int time = GetTicks();
int delta = time - lastTime;
lastTime = time; //last time is a variable that you save

//move something 15 units per second in x

float deltaSeconds = 0.01f *  delta; //ms to sec

myObject.x += 15 * deltaSeconds ;

If you hve low fps delta time will be high, if the fps is high delta time will be low. Using delta time means the the the movent of myObject will be frame rate independatant.

Edited by HermanssoN

Share this post


Link to post
Share on other sites

Eh so at the moment I am using the way in which you use GetTicks and then work out if its going too fast and then delay it if it is, the way the above tutorials show it.

That's the way the first tutorial I linked to shows it, yes.
 

I have read in quite a few places that its best to handle your animation and stuff like that using time passed instead of frames passed so I want to do it this way but cannot find anything on it.

That's the way the second tutorial I linked to does it. smile.png

Share this post


Link to post
Share on other sites

Thanks for both your posts, I finally have something to go on! :)

 

I did go through that tutorial Servant of the Lord but it confused me because as far as I can tell the timer was not delaying anything, it was just counting and resetting.

 

I am most definitely wrong, I just didn't understand it sorry

 

Thanks again!

Share this post


Link to post
Share on other sites

No problem. If you don't understand any of it, let us know what parts and we can explain it.

I personally like to keep my 'deltas' as floats, with 1.0 being one second of time - I find them easier to manage that way.

 

 

amountToMoveThisFrame = (MovementSpeedOverOneSecond * deltaTime);

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!