<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://xna-uk.net/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>XNA UK User Group</title><link>http://xna-uk.net/blogs/</link><description>A helping hand for bedroom coders throughout the land.</description><dc:language>en-US</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Generic XNA - Threading for Windows &amp; XBox 360</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/08/15/generic-xna-threading-for-windows-amp-xbox-360.aspx</link><pubDate>Fri, 15 Aug 2008 10:55:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:2126</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;OK, I went back to my old threading code to port it to the 360 so I could start playing about with processor affinity (as promised last time) and found the compact framework for the 360 was a bit thin on the ground for parameterized threading, so I have re written the whole thing and it will now play on both the PC and the 360 and also included processor affinity for your 360 projects and there is very little interface change so if you were using the code for your Windows games you can just replace the threading code wit this and you wont have to alter any of your calls to it.&lt;/p&gt;
&lt;p&gt;So, what did I do??&lt;/p&gt;
&lt;p&gt;Pretty much ripped the lot out and started again. The ThreadManagers innards have been totally re done, now instead of having a shed load of Dictionaries holding mutex&amp;#39;s and the like we now just have three, one for the thread starters, one for the threaded code and one for the threads them selves.&lt;/p&gt;
&lt;div style="BORDER-RIGHT:black 1pt solid;BORDER-TOP:black 1pt solid;OVERFLOW:auto;BORDER-LEFT:black 1pt solid;BORDER-BOTTOM:black 1pt solid;HEIGHT:200pt;"&gt;&lt;pre class="code"&gt;    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;This is the Thread manager.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public class &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadManager &lt;/span&gt;: &lt;span style="COLOR:#2b91af;"&gt;GameComponent
    &lt;/span&gt;{

        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;List of ThreadStart used to start the treads.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;private &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;ThreadStart&lt;/span&gt;&amp;gt; threadStarters = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;ThreadStart&lt;/span&gt;&amp;gt;();
        &lt;span style="COLOR:blue;"&gt;private &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;ThreadCodeObj&lt;/span&gt;&amp;gt; threadedCodeList = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;ThreadCodeObj&lt;/span&gt;&amp;gt;();
        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;List of runnign threads.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;private &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;Thread&lt;/span&gt;&amp;gt; threads = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;Thread&lt;/span&gt;&amp;gt;();

        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Managers GameTime to be passed onto the threads.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;static &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;GameTime &lt;/span&gt;gameTime;
        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;ctor
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;game&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;Calling game class&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public &lt;/span&gt;ThreadManager(&lt;span style="COLOR:#2b91af;"&gt;Game &lt;/span&gt;game) : &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;(game)
        { }

        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Overiden Update call, loads manager gameTime varaible.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;gameTime&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public override void &lt;/span&gt;Update(&lt;span style="COLOR:#2b91af;"&gt;GameTime &lt;/span&gt;gameTime)
        {
            &lt;span style="COLOR:#2b91af;"&gt;ThreadManager&lt;/span&gt;.gameTime = gameTime;

            &lt;span style="COLOR:blue;"&gt;for &lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;t = 0; t &amp;lt; threadedCodeList.Count; t++)
                threadedCodeList[t].Update(gameTime);

            &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;.Update(gameTime);
        }

        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Method to add a thread to the maanger.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;threadCode&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;Code to be executed in the thread.&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;
        /// &amp;lt;param name=&amp;quot;threadInterval&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;Time period between each call in miliseconds&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;Index of thread, first one added will be 0 next 1 etc..&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;#if &lt;/span&gt;XBOX
        &lt;span style="COLOR:gray;"&gt;public int AddThread(ThreadCode threadCode, int threadInterval,int affinityIndex)
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;#else
        public int &lt;/span&gt;AddThread(&lt;span style="COLOR:#2b91af;"&gt;ThreadCode &lt;/span&gt;threadCode, &lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;threadInterval)
&lt;span style="COLOR:blue;"&gt;#endif
        &lt;/span&gt;{
            &lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;retVal = threads.Count;

&lt;span style="COLOR:blue;"&gt;#if &lt;/span&gt;XBOX
            &lt;span style="COLOR:gray;"&gt;ThreadCodeObj thisThread = new ThreadCodeObj(threadCode, threadInterval,affinityIndex);
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;#else
            &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadCodeObj &lt;/span&gt;thisThread = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadCodeObj&lt;/span&gt;(threadCode, threadInterval);
&lt;span style="COLOR:blue;"&gt;#endif

            &lt;/span&gt;threadedCodeList.Add(threadedCodeList.Count, thisThread);
            threadStarters.Add(threadStarters.Count, &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadStart&lt;/span&gt;(thisThread.Worker));
            threads.Add(threads.Count, &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Thread&lt;/span&gt;(threadStarters[threads.Count]));

            threads[threads.Count - 1].Start();

            &lt;span style="COLOR:blue;"&gt;return &lt;/span&gt;retVal;
        }

        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Method to kill a single thread.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;index&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public void &lt;/span&gt;KillThread(&lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;index)
        {
            threadedCodeList[index].KillThread(threads[index]);
        }

        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Method to start a thread
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;threadCode&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
        /// &amp;lt;param name=&amp;quot;threadInterval&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
        /// &amp;lt;param name=&amp;quot;index&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public void &lt;/span&gt;StartThread(&lt;span style="COLOR:#2b91af;"&gt;ThreadCode &lt;/span&gt;threadCode, &lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;threadInterval, &lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;index)
        {
            &lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(threadedCodeList[index].stopThread)
            {
                threads[index] = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Thread&lt;/span&gt;(threadStarters[index]);
                threadedCodeList[index].stopThread = &lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;;
                threads[index].Start();
            }
        }

        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Method to tidy up unfinished threads.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;disposing&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;protected override void &lt;/span&gt;Dispose(&lt;span style="COLOR:blue;"&gt;bool &lt;/span&gt;disposing)
        {
            &lt;span style="COLOR:blue;"&gt;for &lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;t = 0; t &amp;lt; threads.Count; t++)
                KillThread(t);

            &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;.Dispose(disposing);
        }
    }&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;The real change has been in the ThreadCodeObj, this now holds most of your threading information. &lt;/p&gt;
&lt;div style="BORDER-RIGHT:black 1pt solid;BORDER-TOP:black 1pt solid;OVERFLOW:auto;BORDER-LEFT:black 1pt solid;BORDER-BOTTOM:black 1pt solid;HEIGHT:200pt;"&gt;&lt;pre class="code"&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;This is the delegate to be used for passing the code to be called in the tread.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;gameTime&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;GameTime&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public delegate void &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadCode&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;GameTime &lt;/span&gt;gameTime);

    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;This class holds the required data for the code to be called in the thread.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;internal class &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadCodeObj
    &lt;/span&gt;{
        &lt;span style="COLOR:blue;"&gt;public &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadCode &lt;/span&gt;CodeToCall = &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;;

        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Mutex to stop thread clashes.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;private static &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Mutex &lt;/span&gt;mutex = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Mutex&lt;/span&gt;();
        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Used to make the thread wait.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;private &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ManualResetEvent &lt;/span&gt;threadStopEvent = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ManualResetEvent&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;);
        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Bool to control imediate stopping of thread loop.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;        
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public bool &lt;/span&gt;stopThread = &lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;;
        &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Interval thread will wait befoer next cycle.
        &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;        
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;private int &lt;/span&gt;threadIntervals = 1;

&lt;span style="COLOR:blue;"&gt;#if &lt;/span&gt;XBOX 
        &lt;span style="COLOR:gray;"&gt;int processorAffinity;
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;#endif

        public &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;GameTime &lt;/span&gt;gameTime;

&lt;span style="COLOR:blue;"&gt;#if &lt;/span&gt;XBOX
        &lt;span style="COLOR:gray;"&gt;public ThreadCodeObj(ThreadCode code,int interval,int affinity)
        {
            CodeToCall = code;
            threadIntervals = interval;
            processorAffinity = affinity;
        }
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;#else
        public &lt;/span&gt;ThreadCodeObj(&lt;span style="COLOR:#2b91af;"&gt;ThreadCode &lt;/span&gt;code, &lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;interval)
        {
            CodeToCall = code;
            threadIntervals = interval;
        }
&lt;span style="COLOR:blue;"&gt;#endif
        public void &lt;/span&gt;Update(&lt;span style="COLOR:#2b91af;"&gt;GameTime &lt;/span&gt;gameTime)
        {
            &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.gameTime = gameTime;
        }
        &lt;span style="COLOR:blue;"&gt;public void &lt;/span&gt;Worker()
        {
&lt;span style="COLOR:blue;"&gt;#if &lt;/span&gt;XBOX
            &lt;span style="COLOR:gray;"&gt;Thread.CurrentThread.SetProcessorAffinity(new int[] { processorAffinity });
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;#endif
            do
            &lt;/span&gt;{
                &lt;span style="COLOR:blue;"&gt;try
                &lt;/span&gt;{
                    mutex.WaitOne();

                    &lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(gameTime != &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;)
                        CodeToCall(gameTime);

                }
                &lt;span style="COLOR:blue;"&gt;finally
                &lt;/span&gt;{
                    mutex.ReleaseMutex();
                }
            }
            &lt;span style="COLOR:blue;"&gt;while &lt;/span&gt;(!threadStopEvent.WaitOne(threadIntervals, &lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;) &amp;amp;&amp;amp; !stopThread);
        }
        &lt;span style="COLOR:blue;"&gt;public void &lt;/span&gt;KillThread(&lt;span style="COLOR:#2b91af;"&gt;Thread &lt;/span&gt;thread)
        {
            &lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(!stopThread)
            {
                mutex.WaitOne();
                stopThread = &lt;span style="COLOR:blue;"&gt;true&lt;/span&gt;;
                thread.Join(0);
                mutex.ReleaseMutex();
            }
        }
    }&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;At the top of the source file I have also included an affinity map so you know what processors you have access to, or should be using. XNA does not stop you from using a CPU/Core but you don&amp;#39;t want to be running your threads on CPU cores that are already busy, it&amp;#39;s why you are threading in the first place, because you have to.&lt;/p&gt;
&lt;div style="BORDER-RIGHT:black 1pt solid;BORDER-TOP:black 1pt solid;OVERFLOW:auto;BORDER-LEFT:black 1pt solid;BORDER-BOTTOM:black 1pt solid;HEIGHT:100pt;"&gt;&lt;pre class="code"&gt;&lt;span style="COLOR:blue;"&gt;#if &lt;/span&gt;XBOX
    &lt;span style="COLOR:gray;"&gt;///
    /// Processor affinity map.
    /// Index CPU CORE Comment
    /// -----------------------------------------------------------------------
    ///   0    1    1  Please avoid using. (used by 360)
    ///   1    1    2  Game runs here by default, so avoid this one too.
    ///   2    2    1  Please avoid using. (used by 360)
    ///   3    2    2  Part of Guide and Dashboard live here so usable in game.
    ///   4    3    1  Live market place downloads use this so usable in game.
    ///   5    3    2  Part of Guide and Dashboard live here so usable in game.
    /// -----------------------------------------------------------------------  
    ///
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;#endif&lt;/span&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;The sample solution is the same as the last one, but just uses this method now and you can download this &lt;a class="" title="Source" href="http://xna-uk.net/files/folders/randomchaos/entry2128.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=2126" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Source/default.aspx">Source</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XBox+360/default.aspx">XBox 360</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Threading/default.aspx">Threading</category></item><item><title>A visible collection of particles of water or ice suspended in the air, usually at an elevation above the earth's surface in XNA</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/08/08/a-visible-collection-of-particles-of-water-or-ice-suspended-in-the-air-usually-at-an-elevation-above-the-earth-s-surface-in-xna.aspx</link><pubDate>Fri, 08 Aug 2008 11:30:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:2099</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;Well if I had just put, &amp;quot;Another Cloud Clip!&amp;quot; you would not have looked at this post. Anyway, her is some more of the same, but not quite the same, well, almost the same. In this clip I show multiple cloud layers each with differing tones of gray (I think it gives the cloud fields depth), also a splattering of around 100 clouds and then the cloud fields again but with some basic formation and dissipation effects in there.&lt;/p&gt;
&lt;p&gt;[Go to the site to view embedded media]&lt;/p&gt;
&lt;p&gt;Now as ever it looks a little laggy, I can&amp;#39;t help this, but what I intend to do next time is to try and dig out my camera and film the cloud system off my TV to show how quick it is in my XBox 360, I would have done that this time around but it is dead... No RROD, it powered up, I get the normal green lights, one for power the other for my controller but I get no sound or video, which kind of detracts from game play a bit... &lt;/p&gt;
&lt;p&gt;So next time,&amp;nbsp; I hope to have a 360 clip up, quality will suck as it will be taken on my hand held camera, but with any luck you will see it run without lag.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=2099" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Clouds/default.aspx">Clouds</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category></item><item><title>Gamefest 2008</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/08/08/gamefest-2008.aspx</link><pubDate>Fri, 08 Aug 2008 10:32:05 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:2098</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Well managed to go! It was great, well the bits I saw as I didn&amp;#39;t get there till around 11:00, but got to see most of Frank Savages talk on Threading in XNA which was interesting and threw up a few tips, also the talk on Live networking by Mitch Walker was very insightful. &lt;/p&gt; &lt;p&gt;Now one talk that I did find changed my out look on an area of XNA was Frank Savages talk on the Content Pipeline. Now I knew you could do a fair bit with it, have played a little with it my self, but WOW! There is SO much in there to play with. An example he gave was when creating your levels in your modelling tool, use spheres for markers in the level for things like spawn points, event triggers etc.. label these spheres so you know what they are pertaining to, then you can write your own content override to get this data out of the model, use the centre of the sphere to mark the point, store it in an array of points and then store it in the tag of the Model (remember to remove this excess data prior to passing it on to the base class) It was so obvious yet I had not even thought about it, so much other stuff we could do in there too, I have been using it to store bounding box data as well as vertex data (not needed since 2.0 I don&amp;#39;t think), but this could also include collision normals, further bounding data, breaking the model up into a number of spheres for greater collision accuracy, and that&amp;#39;s just models, anything else that falls under the content project can be manipulated, this is still all pretty basic stuff, but I am sure you can imagine how much control we now have over our content.&lt;/p&gt; &lt;p&gt;Well after all that exciting stuff, we had a break for lunch, I then went to the Community Games on XBox Live talk (after debating with myself if I should stay for the XBLA talk) and it was quite informative, nothing there I didn&amp;#39;t really know or heard about already, other than the, &amp;quot;If your games kills anyone who plays it, it&amp;#39;s your fault!&amp;quot; bit, well they didn&amp;#39;t put it quite like that, but you are liable for your game I guess, being the publisher and the developer all in one... As you can imagine a lot of people in the room seemed to be industry folk and so there questions were more around the realms of IPR infringement and how they will now stop there developers moon lighting to make money with XNA. Oh and someone asked about people writing XBox time bomb&amp;#39;s, malicious code that would get through the peer review as it only goes off at Christmas or Halloween, what I find odd about that is the limited access you have to both the network and the hardware on the 360, guess you could fill a hard drive or maybe flash up naughty pictures for a day, but I guess that&amp;#39;s going to get you and your 360&amp;#39;s mac address banned&amp;nbsp; for life....but then I guess there are some odd folk out there...you know who I mean....yes you there...no, not you, you...&lt;/p&gt; &lt;p&gt;So then came the party after....I say party, but was just a gathering of the attendees for free booze and food, oh a blast on Geometry Wars and other titles around the room to, no Schitzoid which I found odd, would have thought they would have had a copy of that running at an XNA conference. Met some guys from &lt;a href="http://beatnickgames.co.uk/" target="_blank"&gt;Beatnick Games Ltd&lt;/a&gt; (Hi Robin) who are a start up writing a game in XNA, think they want us to play test the beta, so guess we are waiting for them to give us access now so we can rip it apart...&lt;/p&gt; &lt;p&gt;Shame I missed the keynote and the What&amp;#39;s new in XNA 3.0 talk, would have been good to catch those.&lt;/p&gt; &lt;p&gt;All in all good stuff, I think I may now have an addiction to games dev conferences....ah, my personality flaws shining out again, first XNA now this....&lt;/p&gt; &lt;p&gt;Thanks to Leaf and Robin for sorting stuff out and making sure I did not get lost on the tube ride back to St Pancs...&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=2098" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Conferences/default.aspx">Conferences</category></item><item><title>Unplanned 5 Hour Xna Game</title><link>http://xna-uk.net/blogs/conkerjoe/archive/2008/07/31/unplanned-5-hour-xna-game.aspx</link><pubDate>Thu, 31 Jul 2008 10:45:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:2078</guid><dc:creator>conkerjoe</dc:creator><slash:comments>7</slash:comments><description>&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; As many of you already know, I am working franticly with Seloc on our game SBARG, which we hope will put up a good fight in the DBP competition.&amp;nbsp;And believe it or not I have ANOTHER project on the go called IceCream which I will blog about some other time. If the name intrigues you, join us on IRC channel #xna and ask about IceCream and Milkshake, we&amp;#39;ll know what you mean :).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Because we&amp;#39;re so busy I don&amp;#39;t have time to blog as much as I&amp;#39;d like to, but I felt I could sanction a few spare minutes to blog about an awesome journey we had last night.&amp;nbsp;So picture the scene, we&amp;#39;re discussing all things SBARG, we&amp;#39;re very tired from the last few weeks work, as well as a day job,&amp;nbsp;we&amp;#39;re often working through the night and on a slacking night it can be 3am before we decide to call it in, so yeah, we&amp;#39;re tired, we&amp;#39;re hungry and we&amp;#39;re not exactly getting much done.&amp;nbsp;So to spice ourselves up we started to chat about our next game, you know, the one after SBARG, we started to look at old Amiga games and Mega Drives games we&amp;nbsp;used to play, it was good just to remind us why we&amp;#39;re doing this, for fun, I love games, even the ones that sucked I loved something about them usually.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then we got onto a discussion about how quick you can prototype games to get a feel for something, A few hours are usually enough, anything longer probably requires a budget and a lot of planning before deciding to go ahead.&amp;nbsp;I&amp;#39;m going to take credit for this bit that I&amp;#39;m not going to tell you about but I came up with this genius idea for a game, which lead to the discussion about an even simpler game&amp;nbsp;which you should all know called Rock, Paper Scissors. If you don&amp;#39;t know what it is check it out here &lt;a href="http://en.wikipedia.org/wiki/Rock-paper-scissors"&gt;http://en.wikipedia.org/wiki/Rock-paper-scissors&lt;/a&gt;. Brilliantly simple game.&amp;nbsp;We only had to discuss it for 2-3 minutes before we realised it HAD to be done, so while Seloc was still talking, I cranked up Visual Studio and started working on the simple mechanics of a Rock, Paper Scissors game.&amp;nbsp;I stupidly made a comment along the lines of, &amp;quot;You make a brew, and ill have this working by the time im finished drinking it&amp;quot; While I didn&amp;#39;t get my brew, i had single player Rock, Paper Scissors working in under 20 minutes, So I believe Seloc still owes me a brew, and an extra brew for winning. &lt;/p&gt;
&lt;p&gt;I just implemented a simple up/down arrow to choose your selection, the computer randomly selected its choice and after a countdown of 3 seconds the winner would be chosen and displayed on screen.&amp;nbsp;So I turn to my right to show Seloc how amazing I am, and I see he&amp;#39;s got a screen up with a fancy rock, a pair of scissors, and a piece of paper. He&amp;#39;s only gone and generated some cool artwork for our new game.&amp;nbsp;So we have a quick chat about how ridiculous this was and decided to continue :D we are English after all. So I&amp;#39;m waiting around playing against the computer, and winning.. YES!!! But I want to play against Seloc and beat him.&amp;nbsp;So I decided to consider making it live compatible.&amp;nbsp;At this point, I knew we were crazy, but I had not done any xna networking before so I thought worst case, it&amp;#39;s a bit of experience so I gave it a shot. I already knew of the brilliant NetworkState sample on creators&amp;nbsp;so I decided to start with that, remember this is just a prototype so using someone else&amp;#39;s already working code saved me tons of time. I initially got a little stuck about what to actually do about networking and what structure to put my code in,&lt;br /&gt;I looked at the Netrumble code to see how they implemented it, and when I say looked, it was a 3 minute glance, its midnight now, I don&amp;#39;t have time to read reams of code and luckily, it was really simple.&amp;nbsp;I adopted their method of passing the packettype before the packet data. So I had an enum which contained Timer, GamerScores, GamerSelection, and GameState. For each type of data I wanted to pass I would pass in the relevant enum value first,&amp;nbsp;then the data. For example I would pass the GamerSelection enum then the current selection of the local player.&amp;nbsp;Then each player would read this data, and if it found a GamerSelection value, it would read the next packet and assume it was the other player&amp;#39;s selection.&amp;nbsp;This did get a bit fiddly, and I&amp;#39;m quite sure I haven&amp;#39;t got it quite right yet, but my networking code, not including the sample im using is about 20 lines of code on top of my existing single player game. Brilliant.&amp;nbsp;So i swap out the AI, for another pad controlled player and gave it a try. Getting Seloc to pull away from his drawing to test it with me was hard work, once he&amp;#39;s in the zone, he&amp;#39;s in the zone. &lt;br /&gt;&amp;nbsp;But i persevered and eventually after a few iterations of bug fixing and debugging we had a working game.&amp;nbsp;It was brilliant; stupid, but brilliant. So the only thing left to do was put some more trapping in and get it looking nice.&amp;nbsp;That didn&amp;#39;t take too long, by this time Seloc almost had all the art ready, so we imported this and began loosely positioning it on screen.&amp;nbsp;It looked fun; it looked like a game believe it or not. There was merely 2 more things to try.&amp;nbsp;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Try it on the Xbox:- right click project, create Xbox copy, wait 15 seconds, hit build. Done!! &lt;/li&gt;
&lt;li&gt;Try it on Xbox live:- in theory there shouldn&amp;#39;t be any code differences right? The sample should have taken care of it for me. Shawn if this was you. Thanks man. Zero code changes.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;So I built a ccgame and popped a message in the #xna IRC channel, asking if anyone was willing to play this with me over Xbox live, I didn&amp;#39;t have to wait long before Borealis offered his time.&amp;nbsp;Within a few minutes we were in a lobby, and in the game, we were playing Rock Paper Scissors over Xbox live, and it was fun.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;There was only one thing for it now, we had to publish it to Creators Club Community Games, so at 2:30 am this morning i hit publish, i&amp;#39;ve not seen the results yet but &lt;/p&gt;
&lt;p&gt;I&amp;#39;m praying it didn&amp;#39;t fail. I can&amp;#39;t see the site at work :(&lt;br /&gt;&amp;nbsp;&lt;br /&gt;But just to recap, in about 3-4 hours we went from blank project, to using a sample, to having a game, to having it on creators site to download&amp;lt;subject to it passing&amp;gt;&lt;br /&gt;This, i hope you agree, is an astonishing thought. While my game is only Paper Scissors Stone, it&amp;#39;s the simple ones that are the best, &lt;br /&gt;So a few more hours of your time and you could make something a bit more substantial than RPS, but small enough to be a 1 night project.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Heres a teaser screenshot, check it out on Creators Club and if you really want to play and you&amp;#39;re not in the USA, just drop me an email or a comment.&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img height="453" alt="Rock Paper Scissors" src="http://conkerjoe.ziggyware.com/Untitled.jpg" width="777" border="0" /&gt;&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=2078" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/conkerjoe/archive/tags/XNA+GAME+CREATORS/default.aspx">XNA GAME CREATORS</category></item><item><title>Earn Cash with XNA!</title><link>http://xna-uk.net/blogs/news/archive/2008/07/22/earn-cash-with-xna.aspx</link><pubDate>Tue, 22 Jul 2008 20:19:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:2056</guid><dc:creator>leaf</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Apologies for the cheesy headline, but this news was just calling out for it. Microsoft have announced Xbox Live Community Games, you make them, peers review them and delighted customers pay you (and Microsoft) for them. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&amp;quot;&lt;span style="font-size:10pt;"&gt;As a Premium
member in the XNA Creators Club, you’ll be able to submit any complete Xbox 360
game you’ve created in XNA Game Studio to the Creators Club community at &lt;a href="http://creators.xna.com/" target="_blank"&gt;http://creators.xna.com&lt;/a&gt;, for peer review.
Other Premium Creators will check to make sure your game is safe to play. If it
is, you’ll set a price point – between 200 and 800 Points – that people will
pay to download your game.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:10pt;"&gt;Once the game is
reviewed and the price point set, you’re done. The game is listed on Xbox LIVE
Marketplace, and you’ll get a check every quarter, for up to 70% of the game’s
total revenue in your own currency. Depending on your game’s success, you may
even have your game advertised on Xbox 360 and other Microsoft online
properties.&amp;quot;&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Although it wont go live until &amp;quot;Holiday 08&amp;quot;, whenever that is, there&amp;#39;s nothing stopping you from working on your games now. &lt;br /&gt;&lt;/p&gt;

&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=2056" width="1" height="1"&gt;</description></item><item><title>Anyone getting sick of clouds yet?</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/07/18/anyone-getting-sick-of-clouds-yet.aspx</link><pubDate>Fri, 18 Jul 2008 14:45:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:2046</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>13</slash:comments><description>&lt;p&gt;[Go to the site to view embedded media]&lt;/p&gt;
&lt;p&gt;So, here is the system (still not finished) with the skysphere and&amp;nbsp;my infantile physics system. Again footage taken on my poop laptop so bit slow, but on my 360 it&amp;#39;s a steady 60FPS. &lt;/p&gt;
&lt;p&gt;I think the flying ship gives a better perspective than the terrain, also I have altered the cloud shader to take into account the time of day, you will see at night fall the clouds are no longer bright white.&lt;/p&gt;
&lt;p&gt;As ever comment and ratings welcome.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=2046" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/SkySphere/default.aspx">SkySphere</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Clouds/default.aspx">Clouds</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Physics/default.aspx">Physics</category></item><item><title>Speech in you Windows XNA Games</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/07/17/speech-in-you-windows-xna-games.aspx</link><pubDate>Thu, 17 Jul 2008 13:44:53 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:2042</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;I found this while messing about with the media player in XNA, just noticed there is some legacy code in the download from it :( Anyway, how to get speech into your games, it&amp;#39;s dead easy really, you just need to have .NET Framework 3.0 and you have all you need. &lt;/p&gt; &lt;p&gt;&lt;strong&gt;NOTE: You don&amp;#39;t need XNA 3.0 for this just the .NET 3.0 Framework on your system.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;First off you need to add the System.Speech assembly to your project references, then in your Game1.cs add the following:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Speech.Synthesis;&lt;/pre&gt;
&lt;p&gt;and in your Game1 class add:&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#2b91af;"&gt;SpeechSynthesizer &lt;/span&gt;synth = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SpeechSynthesizer&lt;/span&gt;();&lt;/p&gt;
&lt;p&gt;Now, all you have to do is call the synth.SpeackAsync() method passing the text you want to have spoken. I used this:&lt;/p&gt;&lt;pre class="code"&gt;synth.SpeakAsync(&lt;span style="color:#a31515;"&gt;&amp;quot;Hello, Welcome to the Random Chaos Generic X N A Speech Sample.&amp;quot; &lt;/span&gt;+
                                &lt;span style="color:#a31515;"&gt;&amp;quot; This sample is hosted by; the X N A U K User Group. Thanks &amp;quot; &lt;/span&gt;+
                                &lt;span style="color:#a31515;"&gt;&amp;quot;to Leaf and Robin for letting me host my blog here and I hope &amp;quot; &lt;/span&gt;+
                                &lt;span style="color:#a31515;"&gt;&amp;quot;you find my samples useful.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;This will use the default voice that is set up on your PC (see Control Panel-&amp;gt;Speech). But you can also access the other two voice types that ship with the OS (XP, not sure about Vista). To do this try any one of these:&lt;/p&gt;&lt;pre class="code"&gt;synth.SelectVoice(&lt;span style="color:#a31515;"&gt;&amp;quot;LH Michael&amp;quot;&lt;/span&gt;);
synth.SelectVoice(&lt;span style="color:#a31515;"&gt;&amp;quot;LH Michelle&amp;quot;&lt;/span&gt;);
synth.SelectVoice(&lt;span style="color:#a31515;"&gt;&amp;quot;Microsoft Sam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;I prefer &amp;quot;LH Michael&amp;quot;, reminds me of Stephen Hawking and I think it&amp;#39;s a little clearer than the other two.&lt;/p&gt;
&lt;p&gt;I know, not the best chat in the world, but it&amp;#39;s free lol&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=2042" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Speech/default.aspx">Speech</category></item><item><title>Yes, more clouds...</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/07/03/yes-more-clouds.aspx</link><pubDate>Thu, 03 Jul 2008 21:59:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:2020</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;[Go to the site to view embedded media]&lt;/p&gt;
&lt;p&gt;Yes, been playing some more with the clouds. I have had the last clip playing on the 360 and it not drop below 60 fps, on my laptop I get about 7fps, and yes, my laptop sux!!&lt;/p&gt;
&lt;p&gt;So I have now put it with my dynamic sky sphere, and I think it looks pretty good. In the clip I am showing a few large clouds in a huge bounding volume against the sky sphere, then a large cloud field against the sky sphere showing the transfer from day to night and back again. I have not implemented lighting on the clouds but I think it still looks nice, the final bit of the clip is both bits together with an added mushroom cloud in the middle.&lt;/p&gt;
&lt;p&gt;Still much to do and as ever, very little time, but I am getting there I think, all though slowly :)&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=2020" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Clouds/default.aspx">Clouds</category></item><item><title>3D Clouds in XNA - Another Update</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/06/12/3d-clouds-in-xna-another-update.aspx</link><pubDate>Thu, 12 Jun 2008 22:41:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1993</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>5</slash:comments><description>&lt;p&gt;[Go to the site to view embedded media]&lt;/p&gt;
&lt;p&gt;Well I have kind of been letting this code sit for a while, not looked at it as of late, then this week decided to have another play with it, kind of hoping I can put it to bed.&lt;/p&gt;
&lt;p&gt;So I have not started to use Ninians sprite sheet, the sheet is full of alphas, so instead of getting them off the sheet and then just sending them to the screen, set the base colour of the sprite then multiply its alpha by the RGB returned from the sprite sheet. This I think gives a more natural cloud look. I still have some performance issues, but have managed to speed up the draw order sort and that has helped a little. I have also put in some terrain so you have a point of reference, was a bit odd just looking at clouds hanging there in the sky..&lt;/p&gt;
&lt;p&gt;I still have tones I want to do with this yet. I think the next thing will be imposters, then an editor so you can create a cloud field or set of clouds and be able to save them to disk and re use them as an when you like. Naturally more optimizations and some lighting in the shader. &lt;/p&gt;
&lt;p&gt;Hop you like the clip, ratings, and comments are welcome as ever.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1993" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Clouds/default.aspx">Clouds</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category></item><item><title>Generic XNA - Threading for Windows</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/06/01/generic-xna-threading-for-windows.aspx</link><pubDate>Sun, 01 Jun 2008 18:23:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1978</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;&lt;a class="" href="http://xna-uk.net/photos/screen_shots/images/1979/original.aspx"&gt;&lt;img height="200" alt="" hspace="150" src="http://xna-uk.net/photos/screen_shots/images/1979/original.aspx" width="300" border="0" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Well I have done some basic threading in my job, basic stuff and thought I would try and put the basic threading I have done into an XNA Game Component. I am not saying this is how you should do your threading, my method is certainly not the only way to thread processes either and more than likely not the best. I think though that if you are new to development and you want to thread part of your game then I think this may be of some use to you.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is a thread?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;OK, there are a few links out there that describe what a thread is better than I could, so here are a few links for reference:-&lt;/p&gt;
&lt;p&gt;&lt;a href="http://research.microsoft.com/~birrell/papers/ThreadsCSharp.pdf" target="_blank"&gt;Research Microsoft Andrew D. Birrel&lt;/a&gt; (not read this yet, looks v good though)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa645740(VS.71).aspx" target="_blank"&gt;MSDN&lt;/a&gt; (Again, I should read this too...)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ThreadManager&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is a simple manager, you can pass methods to it that you want to have processed in a thread of there own. You can have as many threads as you like, BUT, it&amp;#39;s probably best to keep your threads down to as few as possible, don&amp;#39;t go threading processes because you can.&lt;/p&gt;
&lt;p&gt;So, on to the code. The ThreadManager class is derived from (as most my samples) from GameComponent. The threading method I use requires four components, ParameterizedThreadStart if you don&amp;#39;t need to pass parameters to your thread start method then you can use ThreadStart; these are how we bind our method to a Thread, Thread this is the actual thread class used to start and stop the thread, ManualResetEvent this class is used to manage the call interval for the thread and the Mutex class which is used to ensure there are no thread clashes. I wanted to be able to add as many threads as I wanted in my ThreadManager so I have put these class instances into Dictionaries. Also in this implementation I wanted to be able to manage how often the thread code was ran and also to be able to kill a thread at will. To do this I added two other dictionaries to hold what threads I want to stop and one for the interval between thread calls.&lt;/p&gt;
&lt;div style="BORDER-RIGHT:black 1pt solid;BORDER-TOP:black 1pt solid;OVERFLOW:auto;BORDER-LEFT:black 1pt solid;BORDER-BOTTOM:black 1pt solid;HEIGHT:200pt;"&gt;&lt;pre class="code"&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;This is the Thread manager.
&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public class &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadManager &lt;/span&gt;: &lt;span style="COLOR:#2b91af;"&gt;GameComponent
&lt;/span&gt;{
    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;List of ParameterizedThreadStart used to start the treads.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;private &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;ParameterizedThreadStart&lt;/span&gt;&amp;gt; threadStarters = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;ParameterizedThreadStart&lt;/span&gt;&amp;gt;();
    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;List of runnign threads.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;private &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;,&lt;span style="COLOR:#2b91af;"&gt;Thread&lt;/span&gt;&amp;gt; threads = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;,&lt;span style="COLOR:#2b91af;"&gt;Thread&lt;/span&gt;&amp;gt;();
    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Used to make the thread wait.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public static &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;ManualResetEvent&lt;/span&gt;&amp;gt; threadStopEvent = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;ManualResetEvent&lt;/span&gt;&amp;gt;();
    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Mutex&amp;#39;s to stop thread clashes.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public static &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;Mutex&lt;/span&gt;&amp;gt; mutexs = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;Mutex&lt;/span&gt;&amp;gt;();
    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;List of bools to control imediate stopping of thread loops.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public static &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:blue;"&gt;bool&lt;/span&gt;&amp;gt; stopThreads = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:blue;"&gt;bool&lt;/span&gt;&amp;gt;();
    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;List of intervals threads will wait befoer next cycle.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public static &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;&amp;gt; threadIntervals = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;, &lt;span style="COLOR:blue;"&gt;int&lt;/span&gt;&amp;gt;();
    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Managers GameTime to be passed onto the threads.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;static &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;GameTime &lt;/span&gt;gameTime;

    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;ctor
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;game&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;Calling game class&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public &lt;/span&gt;ThreadManager(&lt;span style="COLOR:#2b91af;"&gt;Game &lt;/span&gt;game) : &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;(game)
    { }

    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Overiden Update call, loads manager gameTime varaible.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;gameTime&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public override void &lt;/span&gt;Update(&lt;span style="COLOR:#2b91af;"&gt;GameTime &lt;/span&gt;gameTime)
    {
        &lt;span style="COLOR:#2b91af;"&gt;ThreadManager&lt;/span&gt;.gameTime = gameTime;

        &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;.Update(gameTime);
    }

    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Method to add a thread to the maanger.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;threadCode&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;Code to be executed in the thread.&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;param name=&amp;quot;threadInterval&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;Time period between each call in miliseconds&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;Index of thread, first one added will be 0 next 1 etc..&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public int &lt;/span&gt;AddThread(&lt;span style="COLOR:#2b91af;"&gt;ThreadCode &lt;/span&gt;threadCode, &lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;threadInterval)
    {
        &lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;retVal = threads.Count;

        threadStarters.Add(threadStarters.Count, &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ParameterizedThreadStart&lt;/span&gt;(ThreadWorker));
        threads.Add(threads.Count, &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Thread&lt;/span&gt;(threadStarters[threads.Count]));
        threadStopEvent.Add(threadStopEvent.Count, &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ManualResetEvent&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;));
        mutexs.Add(mutexs.Count, &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Mutex&lt;/span&gt;());
        threadIntervals.Add(threadIntervals.Count, threadInterval);
        stopThreads.Add(stopThreads.Count, &lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;);

        threads[threads.Count-1].Start(&lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadCodeObj&lt;/span&gt;(threadCode,threads.Count-1));

        &lt;span style="COLOR:blue;"&gt;return &lt;/span&gt;retVal;
    }

    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Method to kill a single thread.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;index&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public void &lt;/span&gt;KillThread(&lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;index)
    {
        mutexs[index].WaitOne();
        stopThreads[index] = &lt;span style="COLOR:blue;"&gt;true&lt;/span&gt;;
        threads[index].Join(0);
        mutexs[index].ReleaseMutex();
    }
    
    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Method to start a thread
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;threadCode&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;param name=&amp;quot;threadInterval&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    /// &amp;lt;param name=&amp;quot;index&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public void &lt;/span&gt;StartThread(&lt;span style="COLOR:#2b91af;"&gt;ThreadCode &lt;/span&gt;threadCode,&lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;threadInterval,&lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;index)
    {
        &lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(threads[index].ThreadState == &lt;span style="COLOR:#2b91af;"&gt;ThreadState&lt;/span&gt;.Stopped)
        {
            threads[index] = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Thread&lt;/span&gt;(threadStarters[index]);
            threadIntervals[index] =  threadInterval;
            stopThreads[index] = &lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;;
            threads[index].Start(&lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadCodeObj&lt;/span&gt;(threadCode, index));
        }
    }

    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;This is the method that is called per thread.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;ThreadCodeObject&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;Instance of ThreadCodeObj to execute.&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;private static void &lt;/span&gt;ThreadWorker(&lt;span style="COLOR:blue;"&gt;object &lt;/span&gt;ThreadCodeObject)
    {
        &lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;index = ((&lt;span style="COLOR:#2b91af;"&gt;ThreadCodeObj&lt;/span&gt;)ThreadCodeObject).threadIndex;

        &lt;span style="COLOR:blue;"&gt;do
        &lt;/span&gt;{
            &lt;span style="COLOR:blue;"&gt;try
            &lt;/span&gt;{
                mutexs[index].WaitOne();
                &lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(gameTime != &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;)
                    ((&lt;span style="COLOR:#2b91af;"&gt;ThreadCodeObj&lt;/span&gt;)ThreadCodeObject).CodeToCall(gameTime);

            }
            &lt;span style="COLOR:blue;"&gt;finally
            &lt;/span&gt;{
                mutexs[index].ReleaseMutex();
            }
        }
        &lt;span style="COLOR:blue;"&gt;while &lt;/span&gt;(!threadStopEvent[index].WaitOne(threadIntervals[index], &lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;) &amp;amp;&amp;amp; !stopThreads[index]);
    }

    &lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;Method to tidy up unfinished threads.
    &lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;disposing&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;protected override void &lt;/span&gt;Dispose(&lt;span style="COLOR:blue;"&gt;bool &lt;/span&gt;disposing)
    {
        &lt;span style="COLOR:blue;"&gt;for &lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;t = 0; t &amp;lt; threads.Count; t++)
            KillThread(t);

        &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;.Dispose(disposing);
    }
}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;As you can see in the code snippet above, there are 4 methods that are not native to the GameComponent, AddThread, KillThread, StartThread, ThreadWorker.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;AddThread&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Well, guess what this method does...yep, adds a thread to the manager. So each thread needs one of the base thread elements to, I also set the interval and if the thread is stopped. I set the flag to say this thread has been stopped, then call the threads Join method, this stops (blocks) this thread from running until the thread terminates, this won&amp;#39;t happen until the threads loop in ThreadWorker exits and is why I set the stop flag for the thread so that it will terminate. You will see in this call I use another class ThreadCodeObj.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ThreadCodeObj&lt;/strong&gt;&lt;/p&gt;
&lt;div style="BORDER-RIGHT:black 1pt solid;BORDER-TOP:black 1pt solid;OVERFLOW:auto;BORDER-LEFT:black 1pt solid;BORDER-BOTTOM:black 1pt solid;HEIGHT:100pt;"&gt;&lt;pre class="code"&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;This is the delegate to be used for passing the code to be called in the tread.
&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;gameTime&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="COLOR:green;"&gt;GameTime&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;&amp;lt;/param&amp;gt;
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public delegate void &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadCode&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;GameTime &lt;/span&gt;gameTime);

&lt;span style="COLOR:gray;"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="COLOR:green;"&gt;This class holds the required data for the code to be called in the thread.
&lt;/span&gt;&lt;span style="COLOR:gray;"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;internal class &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadCodeObj
&lt;/span&gt;{
    &lt;span style="COLOR:blue;"&gt;public &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;ThreadCode &lt;/span&gt;CodeToCall = &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;;
    &lt;span style="COLOR:blue;"&gt;public int &lt;/span&gt;threadIndex = -1;

    &lt;span style="COLOR:blue;"&gt;public &lt;/span&gt;ThreadCodeObj(&lt;span style="COLOR:#2b91af;"&gt;ThreadCode &lt;/span&gt;code, &lt;span style="COLOR:blue;"&gt;int &lt;/span&gt;index)
    {
        CodeToCall = code;
        threadIndex = index;
    }
}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;This class stores the code to be called in the thread and the index of the thread it is to be used in.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;KIllThread&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Yep, you got it, kills a running thread. First off the treads mutex calls it&amp;#39;s WaitOne method, this method holds this thread up until it&amp;#39;s free to do it&amp;#39;s work.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;StartThread&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Restarts a killed thread. First check if this thread has been stopped, if it has then re initialise the threads elements.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ThreadWorker&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Well this I guess is where it all happens, first we get the index of the thread we are in, then we kick off the threads loop, get the mutex for this thread to tell us when it is safe to call the delegate, then we make sure the gameTime instance is not null and call the delegate. We then get the mutex for this thread to signal that we are done and then check if we need to leave the loop and if not wait for the given interval for this thread index.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So as with most of my samples (I like to think) it&amp;#39;s simple to add a method to a thread. First of all set up the ThreadManager and add it to the Game.Components list, now simply call the ThreadManager.AddThread method, passing it the method you want to put in the thread via the ThreadCode delegate along with the interval you want for the thread. I guess most of the threads you will create will have a time span of 0 so they are executed immediately.&lt;/p&gt;
&lt;p&gt;You will also notice I have not bothered with &lt;a href="http://en.wikipedia.org/wiki/Processor_affinity" target="_blank"&gt;affinity&lt;/a&gt; (the ability to request the processor the thread will run on) in this sample, this is because on a PC, you wont know how many CPU&amp;#39;s your application will be running on so it&amp;#39;s probably best left up to the OS to sort it out. &lt;/p&gt;
&lt;p&gt;My next post on threading will be for the XBox, it will be almost identical with this source but will have affinity included, we know where we stand with the 360, we know what processors, how many cores and which ones we can put threads on.&lt;/p&gt;
&lt;p&gt;The sample code shows this working in a very simplistic manor, I simply add three methods to the thread manager that populate a variable that holds the game time each time it is called. You can kill the thread and then re start them with an interval of 0.&lt;/p&gt;
&lt;p&gt;Source solution can be found &lt;a class="" href="http://xna-uk.net/files/folders/randomchaos/entry1980.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1978" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Source/default.aspx">Source</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Threading/default.aspx">Threading</category></item><item><title>Generic XNA - Movies in your Windows games</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/05/28/generic-xna-movies-in-your-windows-games.aspx</link><pubDate>Wed, 28 May 2008 14:38:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1962</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;&lt;a href="http://xna-uk.net/photos/screen_shots/images/1961/original.aspx" target="_blank"&gt;&lt;img height="200" src="http://xna-uk.net/photos/screen_shots/images/1961/original.aspx" width="268" align="right" alt="" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Well, I started looking into this after a friend of mine asked if it could be done. I remembered the other week on Ziggyware that someone got a web cam to stream in an XNA app and so thought that the principle should be the same, taking the output, rendering it as a texture then applying it as you required. So started to try and do it myself, well I came a cropper as the examples I came across were for the old MDX and not XNA (I am not bright enough to do a full port), having to use unsafe code to get handles to the Game.Graphics device etc... but then I came across &lt;a href="http://www.codeplex.com/XNADSPlayer" target="_blank"&gt;this&lt;/a&gt; post on codeplex as well as a few others which gives a class in XNA to do just this using &lt;a href="http://directshownet.sourceforge.net/" target="_blank"&gt;DirectShow&lt;/a&gt;. Now all the examples I found seem to have originated from &lt;a href="http://www.codeproject.com/KB/game/VidTextureClassWebcamApp.aspx?fid=441427&amp;amp;df=90&amp;amp;mpp=25&amp;amp;noise=3&amp;amp;sort=Position&amp;amp;view=Quick&amp;amp;fr=26&amp;amp;select=2175249" target="_blank"&gt;this&lt;/a&gt; post on CodeProject, as does the class I am using here.&lt;/p&gt;
&lt;p&gt;Now you may be wondering, where is the movie clip for this....well fraps does not seem to play well with the method I am using to do this and so does not generate a nice clip for me to put up, wish it did because I think it&amp;#39;s pretty cool.&lt;/p&gt;
&lt;p&gt;Anyway, all I have done is got this lovely class&amp;#39;s output image on a 3D surface. This means you can have movies playing in your games in a virtual cinema, have adverts playing on an advertising billboard as you race past in your racer game, have a television like in GTA IV (I love the cartoons!)&lt;/p&gt;
&lt;p&gt;Clip of the Web Cam in XNA done by &lt;a href="http://www.youtube.com/user/MirageProject" target="_blank"&gt;MirageProject&lt;/a&gt; on YouTube, this gives you an idea of what my implementation looks like, but instead of giving it a device to read from you give it a *.wmv, *.mpg or any other supported format. Also, notice in my image above that the clip on the left is in black and white, this is down to the shader effect applied, not the clip.&lt;/p&gt;
&lt;p&gt;[Go to the site to view embedded media]&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can get the solution zip &lt;a class="" title="Source" href="http://xna-uk.net/files/folders/randomchaos/entry1973.aspx"&gt;here&lt;/a&gt;. (You have to supply your own clips or the zip would have been huge!!)&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1962" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Source/default.aspx">Source</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Games/default.aspx">Games</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+Movie+Player/default.aspx">XNA Movie Player</category></item><item><title>Show &amp; Tell Report</title><link>http://xna-uk.net/blogs/news/archive/2008/05/21/show-amp-tell-report.aspx</link><pubDate>Wed, 21 May 2008 11:36:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1929</guid><dc:creator>leaf</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;We had a &lt;a class="" href="http://xna-uk.net/blogs/news/archive/2008/04/20/show-amp-tell-at-microsoft-s-cardinal-place-victoria-london-friday-may-16th-2008.aspx"&gt;Show &amp;amp; Tell last week&lt;/a&gt;, the turnout wasn&amp;#39;t as good as we hoped (where were you all?) but everyone who came along had something to show and it meant more chocolate brownies for us. We had a little technical trouble with the high tech lighting systems in Microsoft&amp;#39;s office, they refused to turn off, but after shifting to an auditorium with a nice big projection screen, everything went well.&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="http://mercenaryspacepotatoes.blogspot.com/"&gt;Gaz&lt;/a&gt; and &lt;a class="" href="http://yourfurryfiend.blogspot.com/"&gt;Dan&lt;/a&gt; (creators of the award winning Herriman) showed us an early version of their latest venture, a smooth 2D platformer with great character graphics (send me some screen shots!).&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="http://mattdavey.blogspot.com/"&gt;Matt&lt;/a&gt; of &lt;a class="" href="http://www.codeplex.com/mpe"&gt;Project Mercury&lt;/a&gt; fame, gave a demonstration of the latest version of his particle engine and talked about how easy it was to customise (how&amp;#39;d the competition go Matt?)&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="http://aaronkm.blogspot.com/"&gt;Aaron&lt;/a&gt; demonstrated the latest build of his &lt;a class="" href="http://www.codeplex.com/wsx/"&gt;WSX GUI&lt;/a&gt; system and ran through a couple of tutorials on using it in your own code.&lt;/p&gt;
&lt;p&gt;And last but not least, Duncan from the &lt;a class="" href="http://www.warwickgamedesign.co.uk/"&gt;Warwick Game Society&lt;/a&gt;&amp;nbsp;showed us his latest Insane Game 3, which looked like exceptionally good&amp;nbsp;four player fun but he only had a Windows build and we didn&amp;#39;t have&amp;nbsp;a wireless adaptor for the gamepads. Shame, still what we did see was very smooth,&amp;nbsp;multi-player mayhem with some very clever game design elements that lifted it far above the average &lt;em&gt;&amp;#39;Ooh, look it&amp;#39;s a multi-player Gravity wars&amp;#39; &lt;/em&gt;clone.&lt;/p&gt;
&lt;p&gt;Our own Nemo Krad was there too and would have talked about his cloud system but we ran out of time, sorry about that!&lt;/p&gt;
&lt;p&gt;Afterwards, we visited some of the fine drinking establishments near Victoria Station (for those of you who don&amp;#39;t know Victoria, that was meant to be ironic).&lt;/p&gt;
&lt;p&gt;Many thanks to all that came along and a special thank you to Ginger at Microsoft for staying late and looking after us so well.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1929" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/news/archive/tags/events/default.aspx">events</category></item><item><title>RandomChaos Physics</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/05/20/randomchaos-physics.aspx</link><pubDate>Tue, 20 May 2008 13:21:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1924</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;[Go to the site to view embedded media]&lt;/p&gt;
&lt;p&gt;So I have started work on a simple physics engine. I intend to have it serve both 2D and 3D development. I guess it wont have all the lovely bits and bobs that engines like BulletX have, but what the hell, it&amp;#39;s going to help me understand how a Physics Engine works. Not sure about all the others, but this will naturally be exclusively for XNA and so written in C#. As ever I will put the full source up here once I have finished it so you can improve or add to it.&lt;/p&gt;
&lt;p&gt;So needless to say, other things may well be held up; Nova Wars and the Volumetric Cloud system being just two of them. As I think I have mentioned before; my goal now with the blog is to take all the samples I have put up and get them into an engine. This will also help me debug the samples as I will know what plays well with others and what does not. So I kind of think a Physics Engine, no matter how basic, will be a great addition.&lt;/p&gt;
&lt;p&gt;The clip in this post just shows where I currently am with the Physics Engine which is basic Force Generators. There is so much to do, not to mention adding 2D Physics too...I really have become an XNA junkie....help.....I don&amp;#39;t seem to be able to stop..&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1924" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Collision+Detection/default.aspx">Collision Detection</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Physics/default.aspx">Physics</category></item><item><title>Generic XNA - Fire 2D &amp; 3D Shaders</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/05/19/generic-xna-fire-2d-amp-3d-shaders.aspx</link><pubDate>Mon, 19 May 2008 20:50:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1922</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;[Go to the site to view embedded media]&lt;/p&gt;
&lt;p&gt;Well, this should be the final post on these flame shaders. As you have seen in the previous posts I have created 2D and 3D flame shaders based on the flame shader that comes with the NVIDIA SDK. When I initially created the 2D shader I found there was an issue with it when drawn with the 3D effect, turns out the issue was in the FireEmitterBase class, it was fixed by me setting the effect save state in the Begin call. Once that was done it all rendered fine.&lt;/p&gt;
&lt;p&gt;The only issue with the 2D flame shader is that you have to make a draw call per flame as an index.offset has to be passed per flame or the flame animations will all look the same.&lt;/p&gt;
&lt;p&gt;I have put them all in the same project, just added a new class for the 2D flame, as well as the shader it&amp;#39;s self and a floor class.&lt;/p&gt;
&lt;p&gt;Solution can be found &lt;a class="" title="source" href="http://xna-uk.net/files/folders/randomchaos/entry1923.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1922" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Fire/default.aspx">Fire</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Source/default.aspx">Source</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/2D+Pixel+Shaders/default.aspx">2D Pixel Shaders</category></item><item><title>Generic XNA - Fire 2D</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/05/18/generic-xna-fire-2d.aspx</link><pubDate>Sun, 18 May 2008 21:42:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1915</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;[Go to the site to view embedded media]&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Well, just posting my first attempt at getting the flame shader into 2D. It&amp;#39;s not perfect, but as it stands at the moment, will give you 2D flames. When played with the 3D flames it does not seem to render well, but on it&amp;#39;s own, as you can see it seems to be working. I am going to give it a bit of testing before I put the source out, but think it should be fine for pure 2D implementation, also still need to move the code into it&amp;#39;s own solution....&lt;/p&gt;
&lt;p&gt;As ever C&amp;amp;C welcome.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1915" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Fire/default.aspx">Fire</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category></item><item><title>Generic XNA - 3D Fire Sample</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/05/09/generic-xna-3d-fire-sample.aspx</link><pubDate>Fri, 09 May 2008 19:42:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1891</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;Hope the music is acceptable this time...&lt;/p&gt;
&lt;p&gt;[Go to the site to view embedded media]&lt;/p&gt;
&lt;p&gt;Sorry about the quality of the clip, it was a 20MB clip, but I think youtube has crunched it up adn so it has lost some quality....&lt;/p&gt;
&lt;p&gt;OK, here is the code sample for the flame shader I have adapted from NVIDIA&amp;#39;s Volumetric Flame shader. The emitter class is pretty much the same as the billboard particle samples in my earlier posts, the real work is in the shader. I took the original NVIDIA flame shader and merged it with my billboard shader resulting in the sample you see here.&lt;/p&gt;
&lt;p&gt;Now the emitter given in this sample is very basic, but I am sure you will be able either derive from it or use it as a template for your own flame emitter.&lt;/p&gt;
&lt;p&gt;I have had a few requests regarding a 2D version of the shader so I am going to look at applying it to a 2D context.&lt;/p&gt;
&lt;p&gt;Solution can be located &lt;a class="" href="http://xna-uk.net/files/folders/randomchaos/entry1892.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1891" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Fire/default.aspx">Fire</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Source/default.aspx">Source</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/HLSL/default.aspx">HLSL</category></item><item><title>SkyBox Shader Fix</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/05/09/skybox-shader-fix.aspx</link><pubDate>Fri, 09 May 2008 19:18:01 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1889</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I have found my skybox shader has a bug in it, the shader displays the cubemap as a reflection, the following shader code will give a better result.  &lt;p&gt;So, if you have used my skybox sample then replace the shader with this code:&lt;/p&gt; &lt;div style="border-right:black 1pt solid;border-top:black 1pt solid;overflow:auto;border-left:black 1pt solid;border-bottom:black 1pt solid;height:200pt;"&gt;&lt;pre class="code"&gt;Texture surfaceTexture;
samplerCUBE TextureSampler = sampler_state 
{ 
    texture = &amp;lt;surfaceTexture&amp;gt; ; 
    magfilter = LINEAR; 
    minfilter = LINEAR; 
    mipfilter = LINEAR; 
    AddressU = Mirror;
    AddressV = Mirror;
};

float4x4 World : World;
float4x4 View : View;
float4x4 Projection : Projection;

float3 EyePosition : CameraPosition;

struct VS_INPUT 
{
    float4 Position    : POSITION0;
    float3 Normal : NORMAL0;    
};

struct VS_OUTPUT 
{
    float4 Position    : POSITION0;
    float3 ViewDirection : TEXCOORD2;
        
};

float4 CubeMapLookup(float3 CubeTexcoord)
{    
    return texCUBE(TextureSampler, CubeTexcoord);
}

VS_OUTPUT Transform(VS_INPUT Input)
{
    float4x4 WorldViewProjection = mul(mul(World, View), Projection);
    float3 ObjectPosition = mul(Input.Position, World);
    
    VS_OUTPUT Output;
    Output.Position    = mul(Input.Position, WorldViewProjection);
    
    
    Output.ViewDirection = ObjectPosition - EyePosition;    
    
    return Output;
}

struct PS_INPUT 
{    
    float3 ViewDirection : TEXCOORD2;
};

float4 BasicShader(PS_INPUT Input) : COLOR0
{    
    float3 ViewDirection = normalize(Input.ViewDirection);    
    ViewDirection.x *= -1;
    return CubeMapLookup(ViewDirection);
}

technique BasicShader 
{
    pass P0
    {
        VertexShader = compile vs_2_0 Transform();
        PixelShader  = compile ps_2_0 BasicShader();
    }
}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Sorry for giving you a crappy shader in the first place :P&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1889" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/SkyBox/default.aspx">SkyBox</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/HLSL/default.aspx">HLSL</category></item><item><title>Generic XNA - Fire</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/05/07/generic-xna-fire.aspx</link><pubDate>Tue, 06 May 2008 23:10:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1878</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>11</slash:comments><description>&lt;p&gt;&lt;a class="" href="http://xna-uk.net/photos/screen_shots/images/1877/original.aspx"&gt;&lt;img height="200" alt="" hspace="150" src="http://xna-uk.net/photos/screen_shots/images/1877/original.aspx" width="300" border="0" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes, I have been playing with fire! I have had this flame shader by NVIDIA (from the SDK) for ages now. I tried to implement in my olf RC3D Engine but it was a poor attempt and was of no real use to anyone, but I think I may have the beginnings of a decent implementation now. I have mixed the NVIDIA shader based on Yury Uralsky&amp;#39;s &amp;quot;Volumetric Fire&amp;quot; with my billboard shader and billboard particle system and it seems to be playing quite well.&lt;/p&gt;
&lt;p&gt;Take a look at the clip and let me know what you think.&lt;/p&gt;
&lt;p&gt;[Go to the site to view embedded media]&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1878" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Fire/default.aspx">Fire</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category></item><item><title>Generic XNA - Ocean II</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/05/05/generic-xna-ocean-ii.aspx</link><pubDate>Mon, 05 May 2008 20:00:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1871</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>7</slash:comments><description>&lt;p&gt;&lt;strong&gt;&amp;quot;Water, Water everywhere and not a drop to drink...&amp;quot;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;[Go to the site to view embedded media]&lt;/p&gt;
&lt;p&gt;Yes more water. This is the fix to my original Ocean class. I found a fair few errors in the class, the shader was fine, just me as usual. As you can see the performance is better and is comparable with Anirudh S Shastry&amp;#39;s shader I posted last time.&lt;/p&gt;
&lt;p&gt;Not much else to add so you can locate the solution &lt;a class="" title="source" href="http://xna-uk.net/files/folders/randomchaos/entry1873.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1871" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Water/default.aspx">Water</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category></item><item><title>Generic XNA - Water</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/04/29/generic-xna-water.aspx</link><pubDate>Tue, 29 Apr 2008 20:12:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1856</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;[Go to the site to view embedded media]&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes, I know, I have already put up the NVIDIA ocean shader, but after a member of the community had some issue with it, mostly how it played with the SkySphere sample I found that in my naive XNA days (I know, I am still learning) I made a shed load of errors in the implementation of the class. This I am going to remedy in my next post, so expect the Ocean Shader II post to be next.&lt;/p&gt;
&lt;p&gt;During my investigation of the issues David Reilly was having with the combination of Ocean and SkySphere I came across a water shader that I found ages ago. I cant for the life of me remember where I got it from, but I am glad I found it. It&amp;#39;s written by Anirudh S Shastry and it does all the stuff the NVIDIA shader does but I personally think that it has better performance. I guess putting them both up here gives you the choice when it comes to water shaders. I also plan to come up with my own water shader at some point, but for now here are the third party shaders I have.&lt;/p&gt;
&lt;p&gt;As far as the shader goes, I have not changed much, there was a redundant routine or two, but other than that it is pretty much as I found it. As with the NVIDIA shader, all I have done is provided an XNA class that gives access to the shader and it&amp;#39;s parameters.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hope you find it useful. Solution can be found &lt;a class="" href="http://xna-uk.net/files/folders/randomchaos/entry1857.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1856" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Water/default.aspx">Water</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category></item><item><title>Generic XNA - Wiring your own Events</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/04/29/generic-xna-wiring-your-own-events.aspx</link><pubDate>Tue, 29 Apr 2008 11:00:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1851</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>5</slash:comments><description>&lt;p&gt;&lt;a href="http://xna-uk.net/blogs/randomchaos/WindowsLiveWriter/GenericXNAWiringyourownEvents_A19D/GenericXNAEvents.jpg"&gt;&lt;img style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-RIGHT-WIDTH:0px;" height="182" alt="GenericXNAEvents" src="http://xna-uk.net/blogs/randomchaos/WindowsLiveWriter/GenericXNAWiringyourownEvents_A19D/GenericXNAEvents_thumb.jpg" width="233" align="left" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;As I mentioned in one of the post responses on this blog here is an examples of how you can wire up events in your game object. As usual I have tried to keep this as simple as I can to try and make it clear whats going on.&lt;/p&gt;
&lt;p&gt;I guess the first thing to do is describe what an event is, well an event can be anything that occurs during the execution of your game, an enemy shoots, a bomb detonates, the player passes the mouse over a game object (as in this example) but rather than checking ALL your objects each loop you just want to be told when this happens so you can do what you need to do to handle the event. I guess this is a pretty basic C# skill, but if you are not a C# developer you may not know how to do this, so here is my example of Events and how I wire them up.&lt;/p&gt;
&lt;p&gt;So off to the code, I created a new project called GenericXNAEvents, off this project I created the object I am going to use in this example, a simple object that will display a coloured rectangle and have events attached to it that tell me when the mouse is passed over it, clicked on it and when the mouse leaves it. The first thing I do is create a delegate that defines my event, I make this public so it is accessible outside of my class as this dictates how the event handler will be written by those &amp;quot;subscribing&amp;quot; to the events. This done I then create my events, these are logical instances of the delegate that are going to be used to &amp;quot;Fire&amp;quot; my events when they occur, &amp;quot;Subscribers&amp;quot; will also be able to attach (wire) them selves to these events.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="BORDER-RIGHT:black 1pt solid;BORDER-TOP:black 1pt solid;OVERFLOW:auto;BORDER-LEFT:black 1pt solid;BORDER-BOTTOM:black 1pt solid;HEIGHT:100pt;"&gt;&lt;span style="COLOR:green;"&gt;// Delegate definition of an event.&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public delegate void &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;FiredEvent&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;object &lt;/span&gt;sender);&lt;br /&gt;&lt;br /&gt;&lt;span style="COLOR:green;"&gt;// Instances of delegate event.&lt;br /&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;public &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;FiredEvent &lt;/span&gt;OnMouseOver;&lt;br /&gt;&lt;span style="COLOR:blue;"&gt;public &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;FiredEvent &lt;/span&gt;OnMouseOut;&lt;br /&gt;&lt;span style="COLOR:blue;"&gt;public &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;FiredEvent &lt;/span&gt;OnMouseClick; 
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;As you can see I have three events, one for when the mouse is over this object, one for when it moves off this object and one for when this object is clicked.&lt;/p&gt;
&lt;p&gt;Now, I create the conditions that fire my events in the Update method.&lt;/p&gt;
&lt;div style="BORDER-RIGHT:black 1pt solid;BORDER-TOP:black 1pt solid;OVERFLOW:auto;BORDER-LEFT:black 1pt solid;BORDER-BOTTOM:black 1pt solid;HEIGHT:150pt;"&gt;&lt;pre class="code"&gt;&lt;span style="COLOR:green;"&gt;// Is the mouse over me?
&lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Point &lt;/span&gt;mouseCoord = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Point&lt;/span&gt;(&lt;span style="COLOR:#2b91af;"&gt;Mouse&lt;/span&gt;.GetState().X,&lt;span style="COLOR:#2b91af;"&gt;Mouse&lt;/span&gt;.GetState().Y);
&lt;span style="COLOR:#2b91af;"&gt;Rectangle &lt;/span&gt;mouseRec = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Rectangle&lt;/span&gt;(mouseCoord.X, mouseCoord.Y, 1, 1);

&lt;span style="COLOR:#2b91af;"&gt;Rectangle &lt;/span&gt;me = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;Rectangle&lt;/span&gt;(left,top,width,height);

&lt;span style="COLOR:green;"&gt;// Check for mouse over and moust out.
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(me.Intersects(mouseRec))
{
    moueOver = &lt;span style="COLOR:blue;"&gt;true&lt;/span&gt;;
    
    &lt;span style="COLOR:green;"&gt;// If someone has subscribed to this event, tell them it has fired.
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(OnMouseOver != &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;)
        OnMouseOver(&lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;);
}
&lt;span style="COLOR:blue;"&gt;else
&lt;/span&gt;{
    &lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(moueOver)
    {
        moueOver = &lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;;
        &lt;span style="COLOR:green;"&gt;// If someone has subscribed to this event, tell them it has fired.
        &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(OnMouseOut != &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;)
            OnMouseOut(&lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;);
    }
}

&lt;span style="COLOR:green;"&gt;// Check for mouse clicked.
&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(moueOver &amp;amp;&amp;amp; &lt;span style="COLOR:#2b91af;"&gt;Mouse&lt;/span&gt;.GetState().LeftButton == &lt;span style="COLOR:#2b91af;"&gt;ButtonState&lt;/span&gt;.Pressed)
{
    &lt;span style="COLOR:green;"&gt;// If someone has subscribed to this event, tell them it has fired.
    &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(OnMouseClick != &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;)
        OnMouseClick(&lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;);
}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;First thing I do is create the rectangles that will be used to check for intersection with the mouse, if the mouse intersects the object then I set my boolean flag marking that the mouse is over me to true, then check to see if anyone has subscribed to my OnMouseOver event, if they have I call there event handlers. If I am not intersecting the mouse and the mouse has been over me, then the mouse must have moved off of me, so I set my flag to false, check to see if anyone has subscribed to my OnMouseOut event, if they have I call there event handlers. Finally, if the mouse is over me and it has been clicked I check if anyone has subscribed to my OnMouseClick event and if they have, call there event handlers.&lt;/p&gt;
&lt;p&gt;So that&amp;#39;s the mechanics of it, how do I now subscribe to these events??&lt;/p&gt;
&lt;p&gt;In the constructor of my Game1 Class I create three instances of my EventObjects, placed at different locations on the screen with different names and colours, I then &amp;quot;wire&amp;quot; up my event handlers.&lt;/p&gt;
&lt;div style="BORDER-RIGHT:black 1pt solid;BORDER-TOP:black 1pt solid;OVERFLOW:auto;BORDER-LEFT:black 1pt solid;BORDER-BOTTOM:black 1pt solid;HEIGHT:150pt;"&gt;&lt;pre class="code"&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject &lt;/span&gt;obj1 = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;, &lt;span style="COLOR:#a31515;"&gt;&amp;quot;Obj1&amp;quot;&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Red, 100, 150, 32, 32);
&lt;span style="COLOR:#2b91af;"&gt;EventObject &lt;/span&gt;obj2 = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;, &lt;span style="COLOR:#a31515;"&gt;&amp;quot;Obj2&amp;quot;&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Gold, 100, 500, 64, 32);
&lt;span style="COLOR:#2b91af;"&gt;EventObject &lt;/span&gt;obj3 = &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;, &lt;span style="COLOR:#a31515;"&gt;&amp;quot;Obj3&amp;quot;&lt;/span&gt;, &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt;.Silver, 400, 200, 64, 64);

&lt;span style="COLOR:green;"&gt;// Wire up mouse over events.
&lt;/span&gt;obj1.OnMouseOver += &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;FiredEvent&lt;/span&gt;(MouseOver);
obj2.OnMouseOver += &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;FiredEvent&lt;/span&gt;(MouseOver);
obj3.OnMouseOver += &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;FiredEvent&lt;/span&gt;(MouseOver);

&lt;span style="COLOR:green;"&gt;// Wire up mouse out events.
&lt;/span&gt;obj1.OnMouseOut += &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;FiredEvent&lt;/span&gt;(MouseOut);
obj2.OnMouseOut += &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;FiredEvent&lt;/span&gt;(MouseOut);
obj3.OnMouseOut += &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;FiredEvent&lt;/span&gt;(MouseOut);

&lt;span style="COLOR:green;"&gt;// Wire up mouse click events
&lt;/span&gt;obj1.OnMouseClick += &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;FiredEvent&lt;/span&gt;(MouseClick);
obj2.OnMouseClick += &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;FiredEvent&lt;/span&gt;(MouseClick);
obj3.OnMouseClick += &lt;span style="COLOR:blue;"&gt;new &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;.&lt;span style="COLOR:#2b91af;"&gt;FiredEvent&lt;/span&gt;(MouseClick);&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;I now need to create my event handlers, these handlers MUST have the same pattern (return value and parameters) as the FiredEvent delegate defined earlier or you will get a compile error. Also note that I have appended (+=) the event handlers to the objects events, this means you can have a single event fire more than one event handler, you can associate a single handler if you like (=), and this will replace ALL previously set handlers to the one you specify.&lt;/p&gt;
&lt;div style="BORDER-RIGHT:black 1pt solid;BORDER-TOP:black 1pt solid;OVERFLOW:auto;BORDER-LEFT:black 1pt solid;BORDER-BOTTOM:black 1pt solid;HEIGHT:150pt;"&gt;&lt;pre class="code"&gt;&lt;span style="COLOR:blue;"&gt;public void &lt;/span&gt;MouseOver(&lt;span style="COLOR:blue;"&gt;object &lt;/span&gt;sender)
{
    &lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(sender &lt;span style="COLOR:blue;"&gt;is &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;)
    {
        message = &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt;.Format(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;Mouse is over {0}&amp;quot;&lt;/span&gt;, ((&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;)sender).Name);
    }
}

&lt;span style="COLOR:blue;"&gt;public void &lt;/span&gt;MouseOut(&lt;span style="COLOR:blue;"&gt;object &lt;/span&gt;sender)
{
    message = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;No Message.&amp;quot;&lt;/span&gt;;
}

&lt;span style="COLOR:blue;"&gt;public void &lt;/span&gt;MouseClick(&lt;span style="COLOR:blue;"&gt;object &lt;/span&gt;sender)
{
    &lt;span style="COLOR:blue;"&gt;if &lt;/span&gt;(sender &lt;span style="COLOR:blue;"&gt;is &lt;/span&gt;&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;)
    {
        message = &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt;.Format(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;Mouse clicked {0}&amp;quot;&lt;/span&gt;, ((&lt;span style="COLOR:#2b91af;"&gt;EventObject&lt;/span&gt;)sender).Name);
    }
}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;As you can see I am checking to see what the sender is before I do anything with it, you could have objects with a similar event definition call this event handler also, but in this case we just have the one.&lt;/p&gt;
&lt;p&gt;So effectively you can have an event call multiple event handlers and have event handler called by multiple objects and object types. Pretty cool eh?! Thanks Microsoft :)&lt;/p&gt;
&lt;p&gt;Full solution example can be found &lt;a class="" href="http://xna-uk.net/files/folders/randomchaos/entry1852.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Any questions, please post them here and I will do my best to answer them.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1851" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category></item><item><title>Progress made with CreamX Studio</title><link>http://xna-uk.net/blogs/conkerjoe/archive/2008/04/22/progress-made-with-creamx-studio.aspx</link><pubDate>Tue, 22 Apr 2008 20:57:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1843</guid><dc:creator>conkerjoe</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Im quite pleased with the progress of CreamX Studio with the recent changes i posted about. Its back up and running and the majority of it actually still working.&amp;nbsp; I was feeling so motivated i thought i would start work on a tile editor. Shown below with a couple of other screens.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;img src="http://img403.imageshack.us/img403/9241/screenycz3.png" alt="CreamX Studio" align="" border="" height="247" hspace="" width="399" /&gt;&lt;/p&gt;&lt;p&gt;I have also tidied up the namespaces of CreamX so the starter kits are not quite building just yet. Hopefully not much more to do till its safe to check-in. &lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1843" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/conkerjoe/archive/tags/CREAMX+XNA+GAME+DEVELOPMENT/default.aspx">CREAMX XNA GAME DEVELOPMENT</category></item><item><title>CreamX on the iTouch? ITS COMMING!!!!</title><link>http://xna-uk.net/blogs/conkerjoe/archive/2008/04/21/creamx-on-the-itouch-its-comming.aspx</link><pubDate>Mon, 21 Apr 2008 17:41:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1838</guid><dc:creator>conkerjoe</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;I had quite a crazy moment about a week ago. I convinced myself that it would be &amp;quot;cool&amp;quot; if my CreamX game engine for XNA would work on other platforms other than Windows and the Xbox 360. This would include linux distributions and Mac OS and possibly even the iPod Touch / iPhone. 3-4 long days later i manage it, I can now build multiple versions of CreamX to run on Windows with XNA or Open GL, for the Xbox 360 using XNA, and for linux using OpenGL. A Windows/XNA and a Linux/OGL screenshot are below.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;img src="http://uaktkw.blu.livefilestore.com/y1pWwpNsTGjkuJesW3JA_LB19kKdrZq7vKBEW-cSXXtQRQEOh17cqxtifQAHxEi4NEW1C6G4Lgk0iXnaZ9yil3npA/suse.png" alt="CreamX" align="" border="" height="198" hspace="" width="487" /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;Apologies for the quality of screenshot but there is the engine loading a simple scene file and executing on Windows, and on a linux distro running against mono and OpenGL with zero code differences in the actual game code. The only thing different is the version of the CreamX assembly it gets deployed with. You can see the VMWare which is running the latest version of the openSuse distro from mono. nothing extra needed to be installed. &lt;/p&gt;&lt;p&gt;Iv only got basic rendering implemented at the moment, but CreamX fully loads the
scene data and runs the update loop as normal. Im rushing to implement
something quickly on the OpenGL side but the xna side should run as
normal fairly soon. Unfortunatly iv broken the editor. But it shouldnt be too much to fix up, and the editor will still require XNA, im going to contiue to prioritise XNA and its the easiest way to keep the editor up to speed, but its not out of the question to think the editor could be ported too. &lt;/p&gt;&lt;p&gt;I used OpenTK as the substitue for XNA on the linux side which runs against mono.&amp;nbsp; Eventually CreamX Studio will allow you to click a build button similar to Visual Studio and it will seamlessly create 3 distributions for your games.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I will be checking this latest build into codeplex soon so you can see how i did it. :)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1838" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/conkerjoe/archive/tags/XNA+GAME+C_2300_+CREAMX+SBARG/default.aspx">XNA GAME C# CREAMX SBARG</category></item><item><title>Show &amp; Tell at Microsoft's Cardinal Place, Victoria, London - Friday May 16th 2008</title><link>http://xna-uk.net/blogs/news/archive/2008/04/20/show-amp-tell-at-microsoft-s-cardinal-place-victoria-london-friday-may-16th-2008.aspx</link><pubDate>Sun, 20 Apr 2008 20:46:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1831</guid><dc:creator>leaf</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Just to let you know, we&amp;#39;ve got a concrete date for the next user group meeting. See this &lt;a class="" href="http://xna-uk.net/forums/t/696.aspx"&gt;forum thread&lt;/a&gt; for details and make sure to reply if you&amp;#39;re interested in coming along.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1831" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/news/archive/tags/events/default.aspx">events</category></item><item><title>RandomChaos Game State Manager Source Release</title><link>http://xna-uk.net/blogs/randomchaos/archive/2008/04/07/randomchaos-game-state-manager-source-release.aspx</link><pubDate>Mon, 07 Apr 2008 20:49:00 GMT</pubDate><guid isPermaLink="false">cc259236-b685-459d-9e21-6c78c60b874c:1816</guid><dc:creator>Nemo Krad</dc:creator><slash:comments>7</slash:comments><description>&lt;p&gt;So, as I said in my last post, I have decided to put up the source code for the GSM. To use it in your projects, either add the project to your solution and add the reference from the project tab of the Add Reference window or, build it and brows for it when adding it as a reference. Then you need to make sure the built content folders and there contents are in the build folder of your project or you will get build errors.&lt;/p&gt;
&lt;p&gt;I am also including a game written using the GSM to show how you can simply inherit from it to build a quick and easy menu system for your game. In this case I chose something I knew would be quick to write as a demo, Space Invaders. All assets, both image and sound are courtesy of &lt;a class="" href="http://www.classicgaming.cc/classics/spaceinvaders/index.php"&gt;Classic Arcade Games&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;All in all it took me about 3 days to code the game with the GSM, so that&amp;#39;s about a hour and a half a night,hmm, maybe 2, so say 6 hours to do this. Now the assets are pre built so did not have to do those, well broke them up a little and formatted them, but not much really. Anyway, I think it shows how fast you can create a simple demo.&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="http://xna-uk.net/photos/screen_shots/images/1813/original.aspx"&gt;&lt;img height="150" alt="" src="http://xna-uk.net/photos/screen_shots/images/1813/original.aspx" width="200" border="0" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a class="" href="http://xna-uk.net/photos/screen_shots/images/1814/original.aspx"&gt;&lt;img height="150" alt="" src="http://xna-uk.net/photos/screen_shots/images/1814/original.aspx" width="200" border="0" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a class="" href="http://xna-uk.net/photos/screen_shots/images/1815/original.aspx"&gt;&lt;img height="150" alt="" src="http://xna-uk.net/photos/screen_shots/images/1815/original.aspx" width="200" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s pretty simple stuff, I have not put any nice animation, the bunkers can&amp;#39;t be damaged and the invaders are not animated.. I know, half a job... Oh well, you have the GSM source now and my half done Space Invaders....enjoy.&lt;/p&gt;
&lt;p&gt;If you have any queries or issues using the GSM, give me a shout, just remember, it comes&amp;nbsp;warts and all...&lt;/p&gt;
&lt;p&gt;Download located &lt;a class="" href="http://xna-uk.net/files/folders/randomchaos/entry1817.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://xna-uk.net/aggbug.aspx?PostID=1816" width="1" height="1"&gt;</description><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Generic+XNA/default.aspx">Generic XNA</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/XNA+2.0/default.aspx">XNA 2.0</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/Game+State+Manager/default.aspx">Game State Manager</category><category domain="http://xna-uk.net/blogs/randomchaos/archive/tags/2D+Pixel+Shaders/default.aspx">2D Pixel Shaders</category></item></channel></rss>