<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cannontrodder's world &#187; XNA General</title>
	<atom:link href="http://www.cannontrodder.net/category/xna/xna-general/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cannontrodder.net</link>
	<description>cannontrodder - Getting nothing done since 1975.</description>
	<lastBuildDate>Sat, 06 Feb 2010 22:19:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Even more fun with PIX</title>
		<link>http://www.cannontrodder.net/2008/03/17/even-more-fun-with-pix/</link>
		<comments>http://www.cannontrodder.net/2008/03/17/even-more-fun-with-pix/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 01:43:58 +0000</pubDate>
		<dc:creator>cannontrodder</dc:creator>
				<category><![CDATA[XNA]]></category>
		<category><![CDATA[XNA General]]></category>

		<guid isPermaLink="false">http://www.cannontrodder.net/2008/03/17/even-more-fun-with-pix/</guid>
		<description><![CDATA[This is turning out to be a series in itself! Not much of an update here, more a triumphant fist in the air for when things actually work as they should.


The image on the left is a render of Suzanne from Blender, and the one on the right is a render from within the Windows [...]]]></description>
			<content:encoded><![CDATA[<p>This is turning out to be a series in itself! Not much of an update here, more a triumphant fist in the air for when things actually work as they should.</p>
<p><span id="more-77"></span></p>
<p align="center"><img height="193" alt="blender render" src="http://www.cannontrodder.net/wp-content/blender-render.png" width="228" /><img height="193" alt="xna render" src="http://www.cannontrodder.net/wp-content/xna-render.png" width="228" /></p>
<p>The image on the left is a render of Suzanne from Blender, and the one on the right is a render from within the Windows build of my current codebase. No more <a title="Link to previous progress *with* distortion" href="http://www.cannontrodder.net/2008/03/16/more-fun-with-pix/" target="_blank">distortion</a>! The distortion was caused by incorrectly creating the Quaternion rotations from the x, y and z planes in the Collada model which, when combined with my translate and scale transformations, caused <em>all kinds</em> of weirdness.</p>
<p>I would never have got this far without PIX, I think I quite like it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cannontrodder.net/2008/03/17/even-more-fun-with-pix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More fun with PIX</title>
		<link>http://www.cannontrodder.net/2008/03/16/more-fun-with-pix/</link>
		<comments>http://www.cannontrodder.net/2008/03/16/more-fun-with-pix/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 00:05:44 +0000</pubDate>
		<dc:creator>cannontrodder</dc:creator>
				<category><![CDATA[XNA]]></category>
		<category><![CDATA[XNA General]]></category>

		<guid isPermaLink="false">http://www.cannontrodder.net/2008/03/16/more-fun-with-pix/</guid>
		<description><![CDATA[Just another progress update&#8230;


The above is a screen capture from the windows version of my current code-base. Blender-heads will recognise the (slightly distorted) image of Suzanne, the built-in Blender equivalent to the teapot model.
PIX was able to show me that I was not passing my transformation matrices to the correct parameter in the vertex shader. [...]]]></description>
			<content:encoded><![CDATA[<p>Just another progress update&#8230;</p>
<p><span id="more-74"></span></p>
<p align="center"><img height="373" alt="suzanne" src="http://www.cannontrodder.net/wp-content/suzanne.png" width="210" /></p>
<p>The above is a screen capture from the windows version of my current code-base. Blender-heads will recognise the (slightly distorted) image of <a title="Wiki page showing background of Suzanne in Blender" href="http://en.wikipedia.org/wiki/Blender_(software)#Suzanne" target="_blank">Suzanne</a>, the built-in Blender equivalent to the <a title="Wiki page on the standard teapot reference model" href="http://en.wikipedia.org/wiki/Utah_teapot" target="_blank">teapot model</a>.</p>
<p>PIX was able to show me that I was not passing my transformation matrices to the correct parameter in the vertex shader. As a result they all defaulted to empty matrices and every vertex position output from it was then (0,0,0). I was simply telling my effect technique to use the wrong vertex shader in my .fx file, and that shader expected the &#8220;WorldViewProjection&#8221; parameter. Unfortunately, I was populating the &#8220;World&#8221;, &#8220;View&#8221; and &#8220;Projection&#8221; parameters!</p>
<p>After fixing the error in my .fx file, I managed to render <em>something</em>. And a quick Visual C# debug session later, I realised that I had a silly bug in the parsing code I use to pull the data out of the Collada files. And now I can render a monkey!</p>
<p>There&#8217;s clearly some work to be done to fix the distortion issues above but real progress has been made. I&#8217;ll fix those issues, tidy up the code and probably release a simple demo just for people who are interested.</p>
<p>I&#8217;ll be continuing the <a title="Blender and XNA part 1" href="http://www.cannontrodder.net/2008/03/08/blender-and-xna-part-1/" target="_blank">Blender and XNA</a> series soon which should help those who wonder how I have achieved the above.</p>
<p>I&#8217;ve posted <a title="Even More Fun With PIX" href="http://www.cannontrodder.net/2008/03/17/even-more-fun-with-pix/"> an update</a> to this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cannontrodder.net/2008/03/16/more-fun-with-pix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fun with PIX</title>
		<link>http://www.cannontrodder.net/2008/03/13/fun-with-pix/</link>
		<comments>http://www.cannontrodder.net/2008/03/13/fun-with-pix/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 22:47:07 +0000</pubDate>
		<dc:creator>cannontrodder</dc:creator>
				<category><![CDATA[XNA]]></category>
		<category><![CDATA[XNA General]]></category>

		<guid isPermaLink="false">http://www.cannontrodder.net/2008/03/13/fun-with-pix/</guid>
		<description><![CDATA[Just a quick update from my last post.

I mentioned that I was just getting the following output from my current rendering code:

I had posted on the XNA Forums that I was &#8220;completely in the dark&#8221; as to what was going on after a call to draw my model. The suggestion there was to use PIX, [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick update from my <a href="http://www.cannontrodder.net/2008/03/10/blender-and-xna-part-2/">last post</a>.</p>
<p><span id="more-72"></span></p>
<p>I mentioned that I was just getting the following output from my current rendering code:</p>
<p align="center"><img style="WIDTH: 222px; HEIGHT: 202px" alt="image-2.jpg" hspace="0" src="http://www.cannontrodder.net/wp-content/image-2.jpg" border="0" /></p>
<p>I had <a title="Link to forum post" href="http://forums.xna.com/thread/50280.aspx" target="_blank">posted</a> on the XNA Forums that I was &#8220;completely in the dark&#8221; as to what was going on after a call to draw my model. The suggestion there was to use <a title="PIX msdn article" href="http://msdn2.microsoft.com/en-us/library/bb173085(VS.85).aspx">PIX</a>, which is part of the <a title="DirectX SDK download" href="http://msdn2.microsoft.com/en-us/directx/aa937788.aspx" target="_blank">DirectX SDK</a> for Windows. Well, one 438MB download later and feeling like a challenge, it seems PIX has helped me at least identify the issue.</p>
<p>I am sending the position, normal and colour information to the graphics device plus the indices to tell it how to arrange that data into triangles. Well for testing purposes, I have told it to draw 1 triangle and I seem to be getting the right size vertex buffer to be passed to the graphics device but <strong>all its values are 0</strong>.</p>
<p>This essentially means I am drawing an object so small it has no dimensions, in black and on a black background. Working as intended then&#8230;</p>
<p>I am clearly missing the point somewhere when I construct my VertexBuffer in my ContentProcessor but at least PIX showed me the way!</p>
<p>I&#8217;ve posted <a title="More Fun With PIX" href="http://www.cannontrodder.net/2008/03/16/more-fun-with-pix/"> an update</a> to this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cannontrodder.net/2008/03/13/fun-with-pix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimising XNA Performance With Resource Pooling</title>
		<link>http://www.cannontrodder.net/2007/07/23/optimising-xna-performance-with-resource-pooling/</link>
		<comments>http://www.cannontrodder.net/2007/07/23/optimising-xna-performance-with-resource-pooling/#comments</comments>
		<pubDate>Mon, 23 Jul 2007 11:50:22 +0000</pubDate>
		<dc:creator>cannontrodder</dc:creator>
				<category><![CDATA[XNA]]></category>
		<category><![CDATA[XNA General]]></category>

		<guid isPermaLink="false">http://www.cannontrodder.net/2007/07/23/optimising-xna-performance-with-resource-pooling/</guid>
		<description><![CDATA[I&#8217;m just working on the code which will form the basis of my upcoming tutorial and it&#8217;s a huge learning experience for me. One thing I haven&#8217;t really focussed on before was optimisation of .NET code. While I&#8217;ve re-factored code because it was doing things in a &#8217;roundabout&#8217; way that could be optimised, I haven&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m just working on the code which will form the basis of my upcoming tutorial and it&#8217;s a huge learning experience for me. One thing I haven&#8217;t really focussed on before was optimisation of .NET code. While I&#8217;ve re-factored code because it was doing things in a &#8217;roundabout&#8217; way that could be optimised, I haven&#8217;t had to ever worry about real-time performance before. With XNA, a sudden pause or glitch is going to be bad for a game.</p>
<p>One thing that will cause glitches in XNA games is if the garbage collector kicks in at an inappropriate time so a strategy to avoid this needs to be adopted quite early on in development of your game engine.</p>
<p><span id="more-29"></span>An excellent <a href="http://blogs.msdn.com/shawnhar/archive/2007/07/02/twin-paths-to-garbage-collector-nirvana.aspx">post</a> by <a href="http://blogs.msdn.com/shawnhar/default.aspx">Shawn Hargreaves</a> gives an overview of two distinct strategies to reduce the impact of garbage collection on your code. By picking one of these and sticking to it, you can either ensure that when garbage collection occurs, it doesn&#8217;t affect performance adversely or avoid garbage collection altogether.</p>
<h1>Approach 1</h1>
<p>Don&#8217;t allocate <em>anything</em>. This sounds quite hard to achieve but it isn&#8217;t as difficult as it sounds. You can allocate memory still  (your game will be pretty limited if you cannot) but you allocate it all up-front.</p>
<p>The challenge with allocating everything up-front is that you have to know before-hand in your game how many objects you will need exactly. Well that&#8217;s pretty straightforward for storing something like meshes as you will know at compile time how many you need. It&#8217;s when you want to show multiple instances of those meshes on-screen at runtime that you are faced with a problem.</p>
<p>For example, if you have a car model and want to show a street scene in your game, you may wish to re-use that car model to place 3 cars on the road at night but put 20 on the road at peak times. You&#8217;ll need to allocate enough of those objects during the games initialisation to deal with all possibilities.</p>
<h1>Approach 2</h1>
<p>Allocate what you want, whenever you want but keep the managed heap simple. Each time you create a new object and store the reference, that is one more reference the GC needs to keep track of. The more references you have, the longer GC takes &#8211; bad news during a screen update. A lot of data with plenty of references to other objects is going to slow things down come GC time and the fact you are constantly allocating means that GC <em>will </em>occur sooner or later &#8211; always when you least need it.</p>
<p>To keep references to a minimum, you could use arrays to store your object collections and use a simple integer reference to link them instead. See <a href="http://blogs.msdn.com/shawnhar/archive/2007/07/02/twin-paths-to-garbage-collector-nirvana.aspx">Shawn&#8217;s post</a> for more details.</p>
<h1>My choice?</h1>
<p>I went for <strong>Approach 1</strong> &#8211; don&#8217;t allocate mid-game. The main reasons were that <strong>Approach 2</strong> required that I maintain references between objects using integer indexes to look-up a required object in a collection. That then means that I have to manage those references myself. I find that idea a little crazy as c# is more than capable of maintaining those references out-of-the-box and the idea that I would ditch that and implement my own reference management code sounds like a recipe for disaster! As soon as I destroy an object, I would then have to go through all my data structures looking for references to it to clean up. That sounds a lot like a garbage collector to me and I have to wonder whether the performance benefit of reducing object references would be cancelled out by my own &#8216;DIY&#8217; garbage collector.</p>
<p>One thing that made <strong>Approach 1</strong> easier for me was to implement resource pooling. The idea is that you allocate an arbitrary number of objects up-front and then use a resource pool class to maintain the collection. When you need a new object, rather than allocate and risk garbage collection, you simply get a &#8216;ready-rolled&#8217; one from the pool.</p>
<p>Luckily for me, <a href="http://swampthingtom.blogspot.com/">Thomas H. Aylesworth</a> has <a href="http://swampthingtom.blogspot.com/2007/06/generic-pool-collection-class.html">written</a> a pretty cool generic class to allow you to pool any type of object. The only constraint is that the object must have a parameterless constructor. The reason is that you will need to be able to get an &#8216;empty&#8217; object out of this pool and fill it with your data before it can be used. If it didn&#8217;t have a parameterless constructor, the pool would have trouble allocating all the objects you need up front as it would not know what parameters were appropriate for the constructor &#8211; it <em>is</em> a generic class after all.</p>
<p>I&#8217;ve added the class to my own engine, and you can too provided you leave his copyright and license information intact as I have done.</p>
<h1>Using the pool class</h1>
<p><code> </code></p>
<pre>
modelPool = new Pool<model>(10);
effectPool = new Pool<effect>(5);
instancePool = new Pool<modelinstance>(100);
</modelinstance></effect></model></pre>
<p>This code shows how you would initialise the pool. Note, the Effect class in XNA does not have a parameterless constructor so cannot be used directly with the Pool class. I simply created my own Effect class and wrapped the XNA Effect class up in it. To ensure my code then refers to my Effect class rather than the XNA one, I add the following uses directive to the top of each source code file:</p>
<p><code> </code></p>
<pre>
using Effect = XNAEngine.Graphics.Effect;
using XnaEffect = Microsoft.Xna.Framework.Graphics.Effect;</pre>
<p>Then I made sure my Effect class had a parameterless constructor. This was all made a lot simpler by the fact that I wanted to customise the Effect and Model classes myself anyway and while the XNA classes are useful, your own class can be less generic than theirs and ideally faster.</p>
<p><code> </code></p>
<pre>
Pool<effect>.Node effectNode = effectPool.Get();
</effect></pre>
<p>This doesn&#8217;t allocate any memory. The Get() method on the Pool object simply marks one of it&#8217;s unused pre-allocated objects as &#8216;in-use&#8217; and returns a reference to it. To access the Effect object itself, simply use the .item property.</p>
<p><code> </code></p>
<pre>
effectPool.Return(effectNode);</pre>
<p>This code returns the node back to the Pool, ready for re-use later. It isn&#8217;t destroying the object though, it&#8217;s there waiting if we need it again!</p>
<h1>Conclusion</h1>
<p>As Shawn said, &#8220;you must pick just one path and follow it to the bitter end&#8221;, which I plan on doing. I don&#8217;t think I ever would have taken the <strong>Approach 2</strong> path he describes, but there may come a time when I need it so it&#8217;s nice to know the option exists.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cannontrodder.net/2007/07/23/optimising-xna-performance-with-resource-pooling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Professional XNA Game Programming</title>
		<link>http://www.cannontrodder.net/2007/07/12/professional-xna-game-programming/</link>
		<comments>http://www.cannontrodder.net/2007/07/12/professional-xna-game-programming/#comments</comments>
		<pubDate>Thu, 12 Jul 2007 21:57:31 +0000</pubDate>
		<dc:creator>cannontrodder</dc:creator>
				<category><![CDATA[Book Reviews]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[XNA General]]></category>

		<guid isPermaLink="false">http://www.cannontrodder.net/2007/07/12/professional-xna-game-programming/</guid>
		<description><![CDATA[I&#8217;ve been carrying around £40 worth of Waterstone&#8217;s vouchers for almost two years now and decided to stop wandering in there on the off-chance I would see something I really liked to use them up. Instead, I waited for something I really wanted and ordered it into the local branch.

I stumbled across the website of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been carrying around £40 worth of <a href="http://www.waterstones.com/">Waterstone&#8217;s</a> vouchers for almost two years now and decided to stop wandering in there on the off-chance I would see something I really liked to use them up. Instead, I waited for something I really wanted and ordered it into the local branch.<br />
<span id="more-22"></span></p>
<p>I stumbled across the <a href="http://abi.exdream.com/">website</a> of Benjamin Nitschke after reading an <a href="http://blog.wired.com/games/2007/03/the_xna_challen.html">article</a> about a Microsoft competition to write an XNA game in 4 days. I think you&#8217;ll agree that the <a href="http://www.cannontrodder.net/wp-content/dungeonquest.jpg" title="Dungeon Quest Screenshot" rel="lightbox">results</a> are staggering! So, it&#8217;s Ben&#8217;s book I decided to buy and here is a mini-review of it. The book is <a href="http://www.amazon.com/Professional-XNA-Game-Programming-Windows/dp/0470126779">available now</a> and I got it at Waterstone&#8217;s for £26.99.</p>
<h1>Who is it for?</h1>
<p>The book is aimed at newcomers to XNA but NOT newcomers to programming. In my opinion, this was a good move. There are a lot of C# books out there that cover the basics and I would have been disappointed had this book dedicated the initial chapters to re-iterating the basics and leaving less room for XNA goodness.</p>
<p>If you are a beginner, I would still recommend the book if you are interested in games programming as the initial chapters focus on simple games that could serve as an excellent way to brush up on your programming skills &#8211; much more fun than &#8220;Hello World!&#8221; It would be wise to have another text on pure C# programming though.</p>
<h1>What it covers</h1>
<p>Subjects covered (and this is an abbreviated list) are:</p>
<ul>
<li>Setting up the development environment.</li>
<li>Using the Agile Method to develop games.</li>
<li>Simple 2D games such as Pong and Breakout.</li>
<li>Displaying a simple 3D model.</li>
<li>Using shaders, normal mapping and other techniques to produce professional visuals such as bloom, motion blur, glass effects etc.</li>
<li>Sound.</li>
<li>Landscape design and implementation.</li>
<li>Physics.</li>
</ul>
<p>What&#8217;s refreshing is that by leaving out elementary basics, Benjamin is able to dedicate a large chunk of the book to advanced topics.</p>
<p>Each chapter tends to focus on a particular topic by showing how to implement it in a real game. There are a number of games created in the book ranging from the simple 2D games mentioned earlier, up to a fantastic 3D racing game in which you throw your car around a track that snakes in and out of a realistic rocky landscape.</p>
<p>Ben says early on how much he prefers XNA to DirectX programming and in fairness to him, he delivers the goods to back up his claims. The games he creates throughout the book certainly have that professional polish and don&#8217;t feel amateurish or compromised  in any way.</p>
<h1>How to use the book</h1>
<p>The author does not list the code for each game in its entirety. Instead, he chooses to focus on the really important snippets of code that illustrate his point, leaving it up to the reader to download the source code from <a href="http://www.wrox.com/WileyCDA/WroxTitle/productCd-0470126779,descCd-download_code.html">Wrox</a> and read through to gain more insight. I think this is a good move on his part as I would have been just as disappointed with the book being &#8216;filled&#8217; with code dumps, as I would if it dedicated chunks of pages to explaining how variables work.</p>
<p>When it comes to 3D, he focusses more on how to get XNA to do what you need it to do rather than explaining every single aspect of 3D, such as matrices. I&#8217;ve always found such texts on 3D very dry and at least with this method, you can actually get something done <em>and</em> become more comfortable with the concepts. It&#8217;s always less frustrating when you can actually experiment with real code to get instant feedback.</p>
<h1>Agile</h1>
<p>Benjamin is a <strong>big</strong> fan of the Agile Method and it really suits game development on XNA. I must admit I was initially shocked to see it promoted so much in the book but as I have progressed, the benefits have been realised. I won&#8217;t explain it in full but the process goes a bit like this:</p>
<ul>
<li>Think about a part of the game you want to implement (eg drawing the paddle in breakout and moving it around).</li>
<li>Write a unit test which calls some (as yet uncoded) methods to accomplish this task.</li>
<li>Write the methods which actually do the work.</li>
<li>Run the unit test until you get the required result.</li>
</ul>
<p>It&#8217;s a useful way of working as you focus on just one thing at a time and gradually tick off all the functionality your game requires. At the end you still have your unit tests so you can quickly identify any new bugs you have inadvertently created by just running each in isolation. I&#8217;ve always coded by dividing a problem into small chunks but this way formalises that a bit and really helps you focus on solving one problem at a time while doing it well.</p>
<h1>Verdict</h1>
<p>As you have hopefully gathered from this article, I like the book. It&#8217;s excellent value for money as it doesn&#8217;t re-iterate programming basics, doesn&#8217;t pad out the book with endless listings but <strong>does</strong> take you from being a beginner with XNA to being able to handle some very advanced topics. My gut instinct is once you have exhausted this book, you&#8217;ll be a pretty accomplished XNA games developer in your own right.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cannontrodder.net/2007/07/12/professional-xna-game-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA Font Support</title>
		<link>http://www.cannontrodder.net/2007/07/12/xna-font-support/</link>
		<comments>http://www.cannontrodder.net/2007/07/12/xna-font-support/#comments</comments>
		<pubDate>Thu, 12 Jul 2007 19:56:33 +0000</pubDate>
		<dc:creator>cannontrodder</dc:creator>
				<category><![CDATA[XNA]]></category>
		<category><![CDATA[XNA General]]></category>

		<guid isPermaLink="false">http://www.cannontrodder.net/2007/07/12/xna-font-support/</guid>
		<description><![CDATA[With the new release of XNA Refresh, you can now easily add fonts to your projects. While it is nice to just specify a true type font in an xml file and have XNA import the resulting bitmap generated from it, I prefer to be able to edit the bitmap in photoshop to make it [...]]]></description>
			<content:encoded><![CDATA[<p>With the new release of XNA Refresh, you can now easily add fonts to your projects. While it is nice to just specify a true type font in an xml file and have XNA import the resulting bitmap generated from it, I prefer to be able to edit the bitmap in photoshop to make it look better.</p>
<p>Thankfully, someone else has <a href="http://creators.xna.com/Headlines/utilities/archive/2007/04/26/Bitmap-Font-Maker-Utility.aspx">written a nice tool</a> to create the intermediary bitmap for you. All you then need to do is select the white characters in photoshop and start applying effects!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cannontrodder.net/2007/07/12/xna-font-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
