<?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>Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx</link><description>I've never been happy with the design of the XNA Framework Guide methods. I want to write code like this: int ? button = Guide.ShowMessageBox( &amp;quot;Save Game&amp;quot; , &amp;quot;Do you want to save your progress?&amp;quot; , new string [] { &amp;quot;OK&amp;quot; , &amp;quot;Cancel&amp;quot;</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx#9726517</link><pubDate>Thu, 11 Jun 2009 16:13:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9726517</guid><dc:creator>aumfer</dc:creator><description>&lt;p&gt;What about a non-blocking version of the API?&lt;/p&gt;
&lt;p&gt;The function returns null if the user hasn't selected anything yet and I can just go about my day. &amp;nbsp;Do you need to take control of program flow here?&lt;/p&gt;
&lt;p&gt;immediate mode 4tw :)&lt;/p&gt;
</description></item><item><title>re: Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx#9727343</link><pubDate>Thu, 11 Jun 2009 21:26:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9727343</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;&amp;gt; What about a non-blocking version of the API?&lt;/p&gt;
&lt;p&gt;Wouldn't that end up looking basically the same as what we have today with the separate Begin and End calls?&lt;/p&gt;
</description></item><item><title>re: Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx#9727953</link><pubDate>Fri, 12 Jun 2009 00:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9727953</guid><dc:creator>DFHanson</dc:creator><description>&lt;p&gt;I actually like the &amp;quot;screen grab&amp;quot; idea. You wouldn't have to force every game to use it; they still have the Begin/End pattern to follow if they want. It can be explicitly acknowledged that extra memory will be allocated for the screen grab, and it can be documented that &amp;quot;extreme badness&amp;quot; will occur if the blocking call is made in a background thread.&lt;/p&gt;
&lt;p&gt;As long as you provide the normal Begin/End alternative for the games that can't handle these two problems, I think the screen grab blocking call would be a great option.&lt;/p&gt;
</description></item><item><title>re: Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx#9727963</link><pubDate>Fri, 12 Jun 2009 00:57:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9727963</guid><dc:creator>DFHanson</dc:creator><description>&lt;p&gt;Heck, you could just avoid the badness by throwing the almighty Code 4 if the blocking call is made in a background thread. :)&lt;/p&gt;
</description></item><item><title>re: Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx#9728518</link><pubDate>Fri, 12 Jun 2009 04:33:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9728518</guid><dc:creator>caleb.vear</dc:creator><description>&lt;p&gt;How about you implement the Guide functions as a component? &amp;nbsp;Then when you call a Guide function you can pass in an implementation of some interface that manages the calls to the Guide and does whatever needs to be done after the gamer has decided what they want to do.&lt;/p&gt;
&lt;p&gt;Alternatively you could just call the function on the Guide component and pass in a delegate that gets called containing the result. &amp;nbsp;I think that that could be quite good and you could implement it on top of your current implementation.&lt;/p&gt;
</description></item><item><title>re: Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx#9729463</link><pubDate>Fri, 12 Jun 2009 06:55:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9729463</guid><dc:creator>Dave Carlile</dc:creator><description>&lt;p&gt;I created a static class to simplify dealing with the async nature of XNA message boxes. &amp;nbsp;It's kind of a quickly hacked up thing in response to this post, so maybe there's a better way of handling it, but it seems like it &amp;nbsp;allows you to at least pretend you're coding with blocking message boxes.&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.crappycoding.com/2009/06/simplified-xna-message-boxes/"&gt;http://www.crappycoding.com/2009/06/simplified-xna-message-boxes/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I'm far from an expert on this kind of thing, so please feel free to poke holes in it.&lt;/p&gt;
</description></item><item><title>re: Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx#9730151</link><pubDate>Fri, 12 Jun 2009 08:19:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9730151</guid><dc:creator>Kevin Gadd</dc:creator><description>&lt;p&gt;I actually find the Guide APIs pretty straightforward to work with. I just wrap the Begin/End pairs into Futures and use cooperative threading to suspend my game logic until the Guide operations are complete. I would have had to wrap any blocking form of the APIs in a threadpool work item in order to get an asynchronous version, so I really appreciate that the XNA team decided to offer them as Begin/End pairs instead.&lt;/p&gt;
&lt;p&gt;The C# compiler's support for iterators is perfect for this since you can write your asynchronous logic in the form of an iterator, and 'yield return' an object to suspend execution until it's time to continue. No pesky state machines to write! :)&lt;/p&gt;
&lt;p&gt;Now if only creating and initializing a GamerServicesComponent didn't hang my main thread for like five seconds, I could do all my game's loading smoothly in the background while rendering frames...&lt;/p&gt;
</description></item><item><title>re: Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx#9739383</link><pubDate>Sat, 13 Jun 2009 00:25:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9739383</guid><dc:creator>sirlantis</dc:creator><description>&lt;p&gt;Well, I think there are a lot of guidelines which you want to stick to. Out of the blue I would go with this one:&lt;/p&gt;
&lt;p&gt;- Disallow all calls to Guide from background threads.&lt;/p&gt;
&lt;p&gt;- int Guide.ShowMessage(&amp;quot;Title&amp;quot;, &amp;quot;Msg&amp;quot;, {&amp;quot;Yea&amp;quot;, &amp;quot;Nay&amp;quot;})&lt;/p&gt;
&lt;p&gt;blocks the game, renders a black screen or a provided Texture2D. This one is for all those people who want to go straight forward.&lt;/p&gt;
&lt;p&gt;- If you want to use the async calls to the Guide, you have to call Guide.DoEvents() within your loops (preferably in the Update part). If you use the Game class, this could be taken care of already.&lt;/p&gt;
&lt;p&gt;- Guide.ShowMessage(&amp;quot;T&amp;quot;, &amp;quot;M&amp;quot;, o, delegate(int result) { if(result == 0) doIt(); })&lt;/p&gt;
&lt;p&gt;will then add an delegate(){callback(result);} to an internal list &amp;quot;to be called&amp;quot;. Guide.DoEvents() will then invoke all the delegates on this list, so that another call to the Guide will be from the main-thread again, to allow the regular chain of events: &lt;/p&gt;
&lt;p&gt;&amp;quot;Do you want to save&amp;quot;? &amp;quot;Yes&amp;quot; -&amp;gt; &amp;quot;Which device&amp;quot;? &amp;quot;HDD&amp;quot; -&amp;gt; Save&lt;/p&gt;
&lt;p&gt;- Drop all non-blocking calls to the Guide while the Guide is still in focus.&lt;/p&gt;
&lt;p&gt;- While the Guide is in focus, all blocking calls will stop, wait for the guide to close, then their Guide will be opened, processed and then closed.&lt;/p&gt;
&lt;p&gt;I can't really see why you would _need_ to use a background thread to popup the Guide. As I hate applications stealing my focus, background-threads should not open up modal dialogs.&lt;/p&gt;
&lt;p&gt;However you could have a legacy option: Queue class from background threads and wait for a DoEvents from the main-thread to execute them. This would then cause a &amp;quot;black-screened&amp;quot; Guide. That would also be an alternative to the &amp;quot;dropping&amp;quot; of async calls to the Guide while the Guide is in focus.&lt;/p&gt;
&lt;p&gt;Now I'm sure there is much not to like about this idea. But I think it's much easier to use for the common cases and will only cause &amp;quot;black-screen glitches&amp;quot; if you do somethink awkward. But it won't crash that easily.&lt;/p&gt;
</description></item><item><title>re: Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx#9742820</link><pubDate>Sat, 13 Jun 2009 11:31:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9742820</guid><dc:creator>Kevin Gadd</dc:creator><description>&lt;p&gt;After further consideration, I realized it was rude of me to talk about my Guide techniques without sharing them. So, I wrote an article with example source code that walks people through using my technique, and explains how it works:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.luminance.org/code/2009/06/13/asynchronous-programming-for-xna-games-with-squaredtask"&gt;http://www.luminance.org/code/2009/06/13/asynchronous-programming-for-xna-games-with-squaredtask&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hopefully people find it useful. (My pride is going to be terribly bruised if you respond and tell me how I'm misusing the XNA/.NET APIs, but I can take it, I swear.)&lt;/p&gt;
</description></item><item><title>re: Pumping the Guide</title><link>http://blogs.msdn.com/shawnhar/archive/2009/06/10/pumping-the-guide.aspx#9746394</link><pubDate>Sun, 14 Jun 2009 01:14:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9746394</guid><dc:creator>CobaltHex</dc:creator><description>&lt;p&gt;I'm working on a custom keyboard input panel, &lt;a rel="nofollow" target="_new" href="http://keyboardcontroller.codeplex.com/"&gt;http://keyboardcontroller.codeplex.com/&lt;/a&gt;, that might be extended to a full input panel&lt;/p&gt;
</description></item></channel></rss>