[.net] .NET message loop
We had a developer from Microsoft lecture at our school about game programming in C#, and he said that the OnPaint should be used.
From memory the OnApplicationIdle was compared (by Tom Miller) against the other methods and turned out to be the best solution. IIRC it's in his last blog entry on the managed render loop.
In the idle event you call PeekMessage and loop until there is a message waiting, then return and let it be handled by System.Windows.Forms.Application.Run()'s event loop, then your idle event will be called again once the messages have been processed.
In the idle event you call PeekMessage and loop until there is a message waiting, then return and let it be handled by System.Windows.Forms.Application.Run()'s event loop, then your idle event will be called again once the messages have been processed.
I've used both the while loop with Application.DoEvents() and a Timer, with both giving pretty much comparable results. I prefer the syntax of the Timer, so I will stick to it.
Check out the Managed DirectX 9 creator's latest post on render loops: clickity. Hint: Invalidate and DoEvents both have a lot of overhead, affecting both memory and performance.
Quote:Original post by Swamii
Check out the Managed DirectX 9 creator's latest post on render loops: clickity. Hint: Invalidate and DoEvents both have a lot of overhead, affecting both memory and performance.
excellent find. by my rough calculations from hacking this into some existing code, this is at least 20% faster than using a Timer or a while loop with Application.DoEvents. The timer and app.doevents are roughly equivalent.
Quote:Original post by Swamii
Check out the Managed DirectX 9 creator's latest post on render loops: clickity. Hint: Invalidate and DoEvents both have a lot of overhead, affecting both memory and performance.
Feels like a hack, what's the point of using .NET if you still have to use win32 functions...
you can use only managed methods if you want, you just wont have as good performance (as the win32 loop is concerned) as using native methods.
the DoEvents() and OnPaint() methods just do too many memory allocations/deallocations, and thats something you dont want in a game (where performance is too important).
the DoEvents() and OnPaint() methods just do too many memory allocations/deallocations, and thats something you dont want in a game (where performance is too important).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement