The Ideal Game Loop (again!)
Well, looks like Tom's managed to find something that works far, far better than the loop I presented in my last post. After my last couple entries, we'd had some feedback from some internal developers who have been using MDX in their own projects. One of the groups had adopted a gameloop so wonderfully simple, I actually was a little ticked at myself for not seeing it earlier. Anyways, check out Tom's blog post about this fantastic game loop.
If there's a drawback to this loop, is that it still requires a P/Invoke call to PeekMessage. There's no significant performance penatly resulting from the PeekMessage call, but for those looking to avoid p/invoke altogether, my last post contains a game loop that does not require interop.
Here's some quick and dirty statistics after running the loop for 10 seconds in my profiling application. I was a bit surprised too: >20000% improvement in frame overhead. Now granted, I wasn't sending a great deal of messages that would break out of the Idle-while loop, but as a theoretical best, it's an impressive performance boost.
Idle-While loop (best case scenario):
Average Frame Time: 5.328125E-08
Times Collected at complete (gen 0): 0
Times Collected at complete (gen 1): 0
Times Collected at complete (gen 2): 0
Paint Capture loop (the loop in my blog):
Average Frame Time: 1.240625E-05
Times Collected at complete (gen 0): 0
Times Collected at complete (gen 1): 0
Times Collected at complete (gen 2): 0
DoEvents loop (the old SDK loop):
Average Frame Time: 1.5953125E-05
Times Collected at complete (gen 0): 1893
Times Collected at complete (gen 1): 2
Times Collected at complete (gen 2): 0
Update: Here's the worst-case scenario (new message every frame) results for 1000000 minimal frames:
Idle-While loop (Worst Case)
00:00:17.4745636
Average Frame Time: 1.74745636E-05
Paint Capture Loop(Worst Case)
00:00:26.4619286
Average Frame Time: 2.64619286E-05
DoEvents() Loop (Worst case)
00:00:35.1366896
Average Frame Time: 3.51366896E-05
Comments
- Anonymous
August 17, 2006
There may be a post with more XNA news on The XNA Team Blog sometime today. The whole keynote video from...