Exposed: 5 methods to create game loop: which is the best?


Edit: fixed broken links


What is the best method to create a game loop?


I created a small experiment comparing 5 different animation methods.


The results, along with code samples and test screenshots are summarized in this document:


5 Game Loops in Silverlight: Which is the best? (PDF)


5 Game Loops in Silverlight: Which is the best? (DOCX)


Sample test app (requires reading the document above to understand the setup): http://nokola.com/gamelooptest


This is part of the test app startup screen before measurements begin:


 


Contents of the doc:
Welcome
What Are Some Things Important For A Game?
Why Are We Discussing Game Loops?
Methods
Test Setup
Test Results
  MaxFrameRate Unset (Defaults to 60):
    Analysis of the 60 FPS default case:
  MaxFrameRate=300:
    Analysis of the 300 FPS case:
  Additional Tips
  Quick Comparison Chart
Summary & Conclusion


 


I hope this will shed some light on Silverlight game loop that several people on this blog asked so far!


Please let me know what you think!

gameloop.jpg

Comments (8)

  1. Isak says:

    Nikola, I’m anxious to see what you have found, but the links to your document seem to be broken.

  2. Hmm… I get 404 errors when I try to download either version of the documents.

  3. John Sietsma says:

    I can’t reach livefilestore.com. Can you make the docs available somewhere else?

  4. nikola says:

    Thank you all for the note! The broken links are fixed now – please try again!

    Thanks,

    Nikola

  5. SharpGIS says:

    I have much much lower aveage with CompositionTarget.Rendering than any of the other examples, probably because it runs with a greater framerate for me. But thats the great thing about that loop… you only set the translate when you need to, and as often as you need to; no more, no less.

    Also I noticed that if I drag the browser window around, the stability of the other methods are all over the place, while CompositionTarget stays constant.

  6. Isak says:

    This is good to know, thanks for doing this research!

    About method 5, though – that method is a little different from what the Farseer physics sample uses. They use the same concept as you, except they do not have this line:

    _sbTrigger.Duration = TimeSpan.FromMilliseconds(10);

    So they don’t set a duration. I compiled your project commenting out this line, and the results changed. With this method, the

    "Storyboard as trigger" method has the same time between frames as CompositionTarget.Rendering. CompositionTarget.Rendering still has a little lower variance of time between frames, however.

    I think I’ll go with Storyboard as Trigger, then. (I’m working on a space shooter) It is very close to being as smooth as CompositionTarget.Rendering, and seems to be easier to implement. (at least if one wants to avoid the problem you had with your first starfield)

  7. J says:

    Your links are broken… again.  Would really like to have this information.  Is it possible to just cut-and-paste the info straight to the blog and not worry about it?

  8. nikola says:

    Hi J,

    I’m sorry that the links didn’t work for you. I just tried them now and they take me to the right .docx/pdf file- what is the error message that you see?

    I’d like to just be able to copy-paste the info in the blog too, but unfortunately this blog has a restriction – 1 picture per post and some other formatting restictions which makes this very hard…

    Thanks for the patience and sorry that the links didn’t work! Please let me know if they work OK now?