<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx</link><description>I thought I'd take a break from my book to talk about some of the trickier points of using System.Windows.Forms for gaming. If you read Tom Miller s's blog, you've probably seen him address similar issues in his lengthy discussions on game loops in Managed.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#403961</link><pubDate>Thu, 31 Mar 2005 04:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:403961</guid><dc:creator>Don Alvarez</dc:creator><description>&amp;gt; I now have my “ideal” solution for the game that will appear in my upcoming book&lt;br&gt;&lt;br&gt;Any chance you have an ISBN or some other way through which to pre-order the book?  (I tried searching for hoskinson directx on amazon.com, but that didn't work...)&lt;br&gt;&lt;br&gt;thanks,&lt;br&gt;-Don</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#403968</link><pubDate>Thu, 31 Mar 2005 05:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:403968</guid><dc:creator>Rick Hoskinson</dc:creator><description>Heh, we’re still pretty far out on the book (we’re due to print sometime after Visual Studio 2005 ships).  I’m hoping my publisher rectifies the author names and Title soon.  In the interim, the ISBN is:&lt;br&gt;&lt;br&gt;ISBN 0-672-32695-7&lt;br&gt;&lt;br&gt;Sadly, that will still bring up a book by Tom Miller.  I beleive I have a post from January that has the correct name and authors of the book listed.  SAMS hasn't listed the new information yet, so I'll definately be asking them about it next time I talk to them.</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#403985</link><pubDate>Thu, 31 Mar 2005 06:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:403985</guid><dc:creator>ShadowChaser</dc:creator><description>Sending a message (WM_PAINT) per frame still seems like a bit of a hack to me - it's like driving in a circle for a mile when you need to go next door. &lt;br&gt;&lt;br&gt;It's basically hacking the messaging system into an infinate loop so that a virtual hook can be placed into it.&lt;br&gt;&lt;br&gt;That said, there's not much we can do. I've given up and manually create my windows and message loop from scratch. If only they had a way to attach a delegate into the main application loop. I imagine that although it would be slower than actually writing the code into your own app loop, it's probably going to be faster than routing kazillion messages through windows ;-)&lt;br&gt;&lt;br&gt;Probably too late for Whidbey :(</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404035</link><pubDate>Thu, 31 Mar 2005 09:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404035</guid><dc:creator>bonk</dc:creator><description>Tom Miller told us recently at #manageddx on efnet that in the April SDK he will be having the infamous Doevents() introduced back in for the sampleframework because he recieved a lot of requests to avoid win32 completely and use windows.forms instead. He told us further that in one of the sdk updates after the april one he is going to eliminate doevents() (but still stay with windows forms).&lt;br&gt;Rick,&lt;br&gt;how does your solution relate to the one Tom Miller is planning. Are you discussing that issue with each other ?&lt;br&gt;</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404037</link><pubDate>Thu, 31 Mar 2005 09:19:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404037</guid><dc:creator>bonk</dc:creator><description>Ooops, seems I did not read carefully enough. Looks like you have been discussing that with Tom Miller. &lt;br&gt;So let me rephrase my question: &lt;br&gt;Rick,&lt;br&gt;will your gameloop be the same as the one we will see in the sampleframework of the next sdk updates ?</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404191</link><pubDate>Thu, 31 Mar 2005 19:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404191</guid><dc:creator>Rick Hoskinson</dc:creator><description>Hi Bonk, the April SDK has already been released and does in fact use a WinForms implementation and DoEvents.&lt;br&gt;&lt;br&gt;Of course this technique will be reseached further before we can commit to puting it into DXMUT.  You may find that we subtley change the idea to using a user event rather than a paint message, or a managed create message rather than a p-invoke.  So we are working on an alternative to DoEvents() in the SDK, but the April release will be using it.&lt;br&gt;&lt;br&gt;And ShadowChaser, I'm not really sure what you mean.  Are you giving up on winforms altogether (which is the speediest solution, no doubt, but you lose a lot of .Net comforts)?  Or are you implementing a PeekMessage-style loop?</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404278</link><pubDate>Thu, 31 Mar 2005 22:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404278</guid><dc:creator>ShadowChaser</dc:creator><description>I am using a combination approach.&lt;br&gt;&lt;br&gt;For apps that require &amp;quot;Rich UIs&amp;quot; (like map editors) I am using Windows Forms. Then the 'core' game engine is constructed I pass in an IntPtr to the &amp;quot;drawing&amp;quot; window so that the game knows where to initialize Direct-X Graphics.&lt;br&gt;&lt;br&gt;For the actual game itself I gave up on WinForms and I'm using a very low level approach - CreateWindowEx, etc. :(&lt;br&gt;&lt;br&gt;Your solution is definately the best one I've seen so far, but it's still a little frustrating to need to do workarounds :-)&lt;br&gt;&lt;br&gt;One change I might make when I implement your architecture into my WinForm version would be to use a custom message instead of WM_PAINT. (ie/ send a WM_USER+(whatever) and respond on both that and WM_PAINT). It's probably irrational, but WM_PAINT is so common I have this strange fear that other apps are going to hook into it and change the behavior and performance of the game in a bad way. Skinning applications might be an example.&lt;br&gt;&lt;br&gt;Take a look at: &lt;a target="_new" href="http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=bd3ecd25-1bdb-4ca2-bcde-313f86876d4c"&gt;http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=bd3ecd25-1bdb-4ca2-bcde-313f86876d4c&lt;/a&gt;&lt;br&gt;&lt;br&gt;The suggestion probably will be cancelled or delayed, but it's worth a try :-)</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404296</link><pubDate>Thu, 31 Mar 2005 23:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404296</guid><dc:creator>Mike Potter</dc:creator><description>I am certainly not an expert on the issue but:&lt;br&gt;&lt;br&gt;Have you tried putting your Frame call in OnIdle()?&lt;br&gt;I found this to have very smooth animation but, I was just toying with MDX at the time. I did not analyize it with profiler. It allowed me to avoid PInvoke calls.&lt;br&gt;&lt;br&gt;Just curious if this has been tried by someone else.       </description></item><item><title>High Performance Game Loops in Managed DirectX</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404317</link><pubDate>Thu, 31 Mar 2005 23:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404317</guid><dc:creator>dwellerville</dc:creator><description /></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404342</link><pubDate>Fri, 01 Apr 2005 01:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404342</guid><dc:creator>Rick Hoskinson</dc:creator><description>Heya ShadowChaser, you actually hit the nail on the head with the user event, and doing it that way was my first instinct.  I agree, I'm not sure how people are going to try to use my game code, and I want it to be as flexible as possible.&lt;br&gt;&lt;br&gt;One of the ideas I'm playing with is pausing both my world update when the game window loses focus.  Now the SDK samples handle this situation by throttling back thier update loop by inserting a mid-stream sleep.  That keeps the app from starving other foreground applications.  I wanted to take this a step further by pausing the world update and the render update completely, with the option to call just the rendering code if any part of the window is invalidated.  That should drop the CPU usage in the background to a true 0% while giving me a more elegant looking WndProc.  So to pseudocode:&lt;br&gt;&lt;br&gt;case WM_PAINT:&lt;br&gt;if(Foreground) WorldUpdate();&lt;br&gt;RenderWorld();&lt;br&gt;if(Foreground) SendNotify(this.Handle, WM_PAINT);&lt;br&gt;&lt;br&gt;Since the code is part of the teaching tool, this should be a realy straightforward way of acheiving the intended effect without abstracting away the Forms usage with my own code.&lt;br&gt;&lt;br&gt;&lt;br&gt;And Mike, I was wondering where you're catching the OnIdle event -- are you using the Application.Idle event or something else?</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404415</link><pubDate>Fri, 01 Apr 2005 06:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404415</guid><dc:creator>Manuel</dc:creator><description>Why this cannot be put in a Windows.Forms 2.0 method by the Winforms team? I don't believe this is a dx only issue.</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404523</link><pubDate>Fri, 01 Apr 2005 16:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404523</guid><dc:creator>Mike Potter</dc:creator><description>I just reviewed my old code. I was using the Application.Idle and calling Invalidate() to keep it circulating. It was much smoother then DoEvents() when I first started learning. &lt;br&gt;&lt;br&gt;I switched the code to use the loop you specified above. Your method added about 50 to 100 FPS to the app in a windowed mode. This is most likely the overhead for Invalidate that you mention. The test app averages about 3400 fps on my box.&lt;br&gt;&lt;br&gt;I also have the following in my OnIdle():&lt;br&gt;&lt;br&gt;if (!this.Focused)&lt;br&gt;{&lt;br&gt;     Thread.Sleep(10);&lt;br&gt;}  &lt;br&gt;&lt;br&gt;When I don't have focus, It drops my app down to about 100 FPS but, the other apps seem to run at normal speed. </description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404622</link><pubDate>Fri, 01 Apr 2005 18:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404622</guid><dc:creator>Mashiharu</dc:creator><description>I'm just wondering: Won't calling SendNotifyMessage from WndProc create recursiveness?</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404634</link><pubDate>Fri, 01 Apr 2005 19:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404634</guid><dc:creator>Donavon Keithley</dc:creator><description>Looks like it's the Control.NotifyInvalidate method that's creating InvalidateEventArgs when it calls OnInvalidated.  It's virtual, so I'm wondering if nulling it out could solve the problem.&lt;br&gt;&lt;br&gt;Spelunking a little further, OnInvalidated calls OnParentInvalidated on the children and then fires the Invalidated event.  So you'd lose those two things.&lt;br&gt;&lt;br&gt;The nice thing about invalidating the window after rendering is that it keeps the message queue clean (since WM_PAINT isn't sent until all messages have been processed).</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404728</link><pubDate>Fri, 01 Apr 2005 23:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404728</guid><dc:creator>Rick Hoskinson</dc:creator><description>&amp;quot;I'm just wondering: Won't calling SendNotifyMessage from WndProc create recursiveness?&amp;quot;&lt;br&gt;&lt;br&gt;SendMessage will, SendNotifyMessage does not block.&lt;br&gt;&lt;br&gt;&lt;br&gt;Mike, I'm glad to hear the technique had positive results in your loop.  I agree though that things will be trickier when you have children Control objects taht also need paint notification.  Though I think that by using SendNotifyMessage you won't starve out other messages since it will be in-ordered with everything else that happened in the previous frame.  I suppose Invalidate() gives a bit more deterministic state at the start of your next WM_PAINT handler.</description></item><item><title>Ideal Managed Code Game Loop</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404754</link><pubDate>Fri, 01 Apr 2005 22:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404754</guid><dc:creator>TrayGames Blog</dc:creator><description>If you are working in managed code on games you should check out this blog entry from Rick Hoskinson:...</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404863</link><pubDate>Sat, 02 Apr 2005 07:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404863</guid><dc:creator>Zman</dc:creator><description>I posted a summary of *all* the Render loop posts over the past couple of years&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;a target=&amp;quot;_new&amp;quot; href=&amp;quot;&lt;a rel="nofollow" target="_new" href="http://www.thezbuffer.com/articles/185.aspx&amp;quot;&amp;gt;http://www.thezbuffer.com/articles/185.aspx&amp;lt;/a&amp;gt;"&gt;http://www.thezbuffer.com/articles/185.aspx&amp;quot;&amp;gt;http://www.thezbuffer.com/articles/185.aspx&amp;lt;/a&amp;gt;&lt;/a&gt;&amp;lt;br&amp;gt;</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404873</link><pubDate>Sat, 02 Apr 2005 08:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404873</guid><dc:creator>Bernhard</dc:creator><description>Hello&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;I have put your renderloop in my app too and the rendering works find. Unfortunately i have problems with the mouse events now!&amp;lt;br&amp;gt;The game runs with appr 300 fps on my machine and some mouse events are lost (eg. if i do a short click).&amp;lt;br&amp;gt;On another machine i only have appr. 100 fps (because if an old graphics card). Here the problem is much bigger, sometimes i do not get mouse events for up to one second!&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Does anyone see this problem too?&amp;lt;br&amp;gt;</description></item><item><title>re: The ideal System.Windows.Forms 3D Gameloop, Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#404892</link><pubDate>Sat, 02 Apr 2005 12:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:404892</guid><dc:creator>Bernhard</dc:creator><description>hello&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;some hours ago i wrote you that i have problems with the mouse events. the information was not correct, the mouse events are fired perfectly - the problem is my mouse handling functions that are working completly different now. i have to find the problem here. sorry for that!</description></item><item><title>MDX: XBOX 360 Controller Windows Forms Application</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#531009</link><pubDate>Mon, 13 Feb 2006 19:45:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:531009</guid><dc:creator>Paul Stubbs</dc:creator><description>Now that the XBOX 360 controller works on windows I thought it would be fun to hook it up to a windows forms application using Visual C# Express and Managed DirectX (MDX). </description></item><item><title>Software Information &amp;raquo; Rick Hoskinson&amp;#8217;s Blog : The ideal System.Windows.Forms 3D Gameloop Take 15.</title><link>http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx#7229206</link><pubDate>Fri, 25 Jan 2008 02:50:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7229206</guid><dc:creator>Software Information » Rick Hoskinson’s Blog : The ideal System.Windows.Forms 3D Gameloop Take 15.</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://softwareinformation.247blogging.info/rick-hoskinsons-blog-the-ideal-systemwindowsforms-3d-gameloop-take-15/"&gt;http://softwareinformation.247blogging.info/rick-hoskinsons-blog-the-ideal-systemwindowsforms-3d-gameloop-take-15/&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>