|
Game Timing |
Felix-The-Ghost
Member #9,729
April 2008
|
I'm not sure when or why I started doing this, but I've timed my games like this: while(counter > 0) { check_keys(); player.update(); game.draw(&player); counter = 0; } I noticed this is different than what is taught in the Allegro wiki: while (counter == 0) rest(1); while(counter > 0) { check_keys(); player.update(); counter--; } game.draw(&player); Is there a drawback to the way I'm doing it? They both at least appear to be working the same, but perhaps one method is more reliable across different speeds? I'd like to know because the method I currently use uses less code and avoids the rest call. Or maybe that's bad? rest()... rests the CPU doesn't it? But does it make timing non-fluid? Hmm. |
Trent Gamblin
Member #261
April 2000
|
Your method will 1) burn cpu pointlessly until the while condition is true, and 2) it doesn't separate logic and drawing so if things bog down, it'll run like crap. The wiki method is much better if you analyze it. Also to prudent, your while could be replaced with an if and nothing would change, so you know somethings wrong. Double edit, in fact an if would be better .
|
Felix-The-Ghost
Member #9,729
April 2008
|
Actually I wondered about the if thing myself I remember seeing this a long time ago on the wiki. Missed it here: if(old_ticks <= ticks)//logic is taking too long: abort and draw a frame break;
I'm gonna read into this, though I don't know when logic could ever take too long. |
Trent Gamblin
Member #261
April 2000
|
Ya. That's good to have in there too. I do it this way myself: int count = logic_counter; while (count--) { //... } Same thing though pretty much.
|
|