[.net] .net game loop

Started by
7 comments, last by Dave Hunt 19 years ago
In case someone's interested, there's a blog post by someone perhaps on DirectX team at Microsoft on efficient game loops. Basically he overrides Control.WndProc, advances the world in WM_PAINT, and uses P/Invoke to call SendNotifyMessage to trigger another WM_PAINT.

Advertisement
Yeah, thanks! This same topic seems to keep on coming up.
Don't shoot! I'm with the science team.....
Yes! Thank you for the find! Now I can finally skip DoEvents in my applications!
That is the 2nd worst way *possible* to run your game loop. It's only slightly better than using a timer message.
I'm curious, since I have yet to write any game loop in .NET, how is it the 2nd worst? He considers memory allocations in comparing different methods, and states that "memory overhead was undetectable over 1,000,000 frames when compared to the Form setup and cleanup code". He also says this method is "consistently 10 to 15 times faster than Invalidate() and 3 to 6 times faster than DoEvents() over 100,000 frames".

Microsoft stopped using WM_PAINT/DoEvents in the managed framework and moved to using P/Invoke with a "traditional" message loop. I took that as a hint and switched, as well. For me, it felt more natural (coming from C++) than the VB-feeling DoEvents. I haven't had any problems or complaints about performance with this method.
I would like to see real benchmarks, but that blog is quite a find!
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
I guess I should have read the blog before posting. I didn't realize they were retracting their previous decision to use PeekMessage. However, I'm going to stick with that method because I don't care if it fits the .NET ideal or not.

This topic is closed to new replies.

Advertisement