[.net] .net game loop
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.
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 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
Popular Topics
Advertisement