Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Calculating Framerate in SDL

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 Yart   Members   

100
Like
0Likes
Like

Posted 11 March 2012 - 08:45 PM

So I'm going through LazyFoo.net's tutorials and I wanted to make my program keep a constant framerate of 60FPS while displaying the framerate on the top caption of the window.

I can achieve it! ...but only one at a time.

The code acts differently depending on where I place two of my timers. (They are classes)

This code makes the framerate unregulated but provides a framerate counter that's accurate.
//Start the frame and update timers.
update.start();
fps.start();

while(quit == false){
while( SDL_PollEvent(&event)){
if( event.type == SDL_QUIT ){
//Quit the program
quit = true;
}



And this code makes the framerate regulated but the counter stays at 0.
while(quit == false){

//Start the frame and update timers.
update.start();
fps.start();

while( SDL_PollEvent(&event)){
if( event.type == SDL_QUIT ){
//Quit the program
quit = true;
}



If I separate both of the timer classes the program crashes.

Now I can see where my problem may lie. In my timer class, if I "start" it, it resets the ticker thingamabob. Later on in the code, after 1000 ticks on the update (for the caption) class's timer, it returns the amount of time and then resets it. But if I put it at the start of the loop, it keeps resetting before it can even count thus always being 0.

The update timer also relies on the fps class' timer to make it's calculations. Oops! So if the fps class (which also ACTUALLY regulates the framerate) is outside of the loop, there is no control, and if it is inside, there is, but the update class has to be with it or else it crashes.

I don't know what I should do to solve this. Any suggestions?

I included my whole source (with executable) as an attachment.

Keys: Left and Right arrows to subtract and add balls.

Thanks!

Attached Files






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.