Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualEctara

Posted 10 July 2013 - 05:47 PM


Have a look here for sample code of how you should be structuring your game loop:

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

That's a perfect article to explain this.

 

 

 


One question about this article though, is the integrate() function basically the Update() function i'm trying to use?

Putting it simply, yes. It is using mathematical terminology.

 

 

 


it checks to see if a second in time has passed, and if so, updates the title bar.

What I was saying, is that the code is broken if that's what you're expecting it to do.

 

 

 


updateCount++;

time = SDL_GetTicks();

if(time - timeBase > 1000) {

UPS = updateCount * 1000.0 / (time - timeBase);

FPS = frameCount * 1000.0 / (time - timeBase);

timeBase = time;

updateCount = 0;

frameCount = 0;

}


While this might not be 100% related, this is a more correct way to tell if a second has passed since the last update, regardless of why you're doing it.

 

 

 


the FPS is about 270, while the UPS is about 7000. This seems a little off, but I could be wrong.

This is perfectly normal. While I don't quite see how the two snippets fit together, it is very obvious how in the update loop it is possible to update more than once before it finishes and the rendering begins, and this is the way it should be. If it is updating once or less before rendering, I'd start to show concern, because if the world isn't crawling along, a spike in activity from another process could easily cause the game to border on unplayable.


#1Ectara

Posted 10 July 2013 - 05:46 PM


Have a look here for sample code of how you should be structuring your game loop:

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

That's a perfect article to explain this.

 


One question about this article though, is the integrate() function basically the Update() function i'm trying to use?

Putting it simply, yes. It is using mathematical terminology.

 


it checks to see if a second in time has passed, and if so, updates the title bar.

What I was saying, is that the code is broken if that's what you're expecting it to do.

 


updateCount++;

time = SDL_GetTicks();

if(time - timeBase > 1000) {

UPS = updateCount * 1000.0 / (time - timeBase);

FPS = frameCount * 1000.0 / (time - timeBase);

timeBase = time;

updateCount = 0;

frameCount = 0;

}


While this might not be 100% related, this is a more correct way to tell if a second has passed since the last update, regardless of why you're doing it.

 


the FPS is about 270, while the UPS is about 7000. This seems a little off, but I could be wrong.

This is perfectly normal. While I don't quite see where in the new code you increment frame count, or how the two snippets fit together, it is very obvious how in the update loop it is possible to update more than once before it finishes and the rendering begins, and this is the way it should be. If it is updating once or less before rendering, I'd start to show concern, because if the world isn't crawling along, a spike in activity from another process could easily cause the game to border on unplayable.


PARTNERS