A Better Silverlight Game Loop?

I've had a problem with my timers in my games.  Basically the problem is that when the loop happens too quickly I get a loop that has 0 ticks elapsed.  I am of the belief that there is an issue with resolution from the DateTime.Now which I use to tell how much time has elapsed between a game frame.  You can read more about the problem in this thread on the Silverlight site (I'm pretty innarticulate in it).  The higher the frame rate, the stranger my games appeared to behave and the more occurances of bugs (divide by zero, etc...).  This was less of a problem in Silverlight 2 because it had a limited frame rate at 60 frames.  In Silverlight 3, framerates can go much higher.

In my "Game Engine" I use different loop classes that were originally derived from the Silverlight Games 101 blog.  I've made some modifications from that original code and they all (DispatcherTimer, StoryBoardTimer and CompositionTarget) inherit from the base GameLoop class.

In order to fix my problem, I added a queue that keeps track of the last ten times and returns and average time elapsed.  The result has been very positive as I have not experienced a lot of the errors I used to have, and the games appear to be smoother. More...

Copyright © 2010 DDtMM

Powered by BlogEngine.NET 1.5.0.7