• Advertisement
Sign in to follow this  

[.net] .net game loop

This topic is 4713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Yes! Thank you for the find! Now I can finally skip DoEvents in my applications!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
That is the 2nd worst way *possible* to run your game loop. It's only slightly better than using a timer message.

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement