|
Jaggy/irregular Animation and main loop |
Locutus266
Member #7,638
August 2006
|
Hello, I need some advice on smooth animation. I tried two rendering techniques (double buffering and page flipping) and neither of them turned out to be smooth enough, even if I use vsync, the animation seems to be kind of "jaggy". I am using the following approach to a main game loop:
As you can see, I am using two different timers to do logic calculations and rendering stuff. That's because I want to be able to modify game speed and (desired) framerate seperately from each other. I have put blitting functions on top of the loop, because I might want to be able to rest() at the end of the loop, handing over some CPU time to other applications. This rest() call being a waste of time for my game, I think it's most efficient to calculate all the game logic between blit() and rest(). When I use a much simpler approach without timers, like in the Allegro example, animation is smooth. I am working under Windows where Allegro timers internally make use of threads, I guess. I am now suspecting that my two timers are interfering with each other in some way or that the timing code in Allegro is not very accurate. Thanks for any suggestions. Best regards, |
Mr. Big
Member #6,196
September 2005
|
Your objects probably have velocities that make them move, right? |
jamal
Member #3,326
March 2003
|
what speed are you setting your timers ? |
Locutus266
Member #7,638
August 2006
|
The logic timer is triggered about 250 times per sec, while the frame timer is normally at 60 times per sec. I tried to remove the frame timer for testing purposes and it didn't really change anything. I suppose the positional calculations themselves are already "jaggy". I am using floating point values as speed settings (and for screen coordinates). My objects normally have speeds between 0.0f and 1.0f, so that they never move more than one pixel at a time. They are not allowed to skip any pixels, because collision detection depends on it. Else, I'd have to work with vectors and that's complicated I guess. Best regards and thanks so far, |
Paul whoknows
Member #5,081
September 2004
|
Allegro timers sucks on windows, use a more accurate timer instead. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Trent Gamblin
Member #261
April 2000
|
In addition to what's been mentioned so far, under Windows I get frequent "blips" in animation unless I set the process to run under a higher priority. BTW, does anyone know if there is a way for the program itself to set it's priority under Windows?
|
|