<?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>Roy Triesscheijn’s Weblog</title>
	<atom:link href="http://roy-t.nl/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://roy-t.nl</link>
	<description>My programming world</description>
	<lastBuildDate>Fri, 27 Aug 2010 12:53:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Hollandia progress report #1</title>
		<link>http://roy-t.nl/index.php/2010/08/27/hollandia-progress-report-1/</link>
		<comments>http://roy-t.nl/index.php/2010/08/27/hollandia-progress-report-1/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 12:53:41 +0000</pubDate>
		<dc:creator>Roy Triesscheijn</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[General Gamedesign]]></category>
		<category><![CDATA[Hollandia]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Progres report]]></category>

		<guid isPermaLink="false">http://roy-t.nl/?p=378</guid>
		<description><![CDATA[So, it&#8217;s again time to show off a bit more Hollandia here. Today I was working on the dialogue system, very basic functionality really. A dialogue consist of a series of frames. Some frames have special actions like activating a generic trigger or by showing a couple of options, instead of just text. Of course [...]]]></description>
			<content:encoded><![CDATA[<p>So, it&#8217;s again time to show off a bit more Hollandia here. Today I was working on the dialogue system, very basic functionality really. A dialogue consist of a series of frames. Some frames have special actions like activating a generic trigger or by showing a couple of options, instead of just text. Of course the character talked too can respond to different suggestions (this is done by associating each of the options with an index to a next frame). </p>
<p>As I said pretty basic and I still need to think out a smart way to highlight a couple of words without this interfering too much with all the draw code.</p>
<p>I thought it would be very cool if the dialogue screen doesn&#8217;t just appears and disappears instantly so using our prepared effect system (some nice abstraction around the actual effect files) I quickly cooked up a new shader added a few lines and yay, there it is.</p>
<p>I&#8217;ll get more into the technicalities later (make a comment if you&#8217;re interested in any specific subsystem). For now I&#8217;ll just show you this (very much in development) sneak peak of Hollandia that I uploaded today:</p>
<p><span class="youtube">
<object width="425" height="355">
<param name="movie" value="http://www.youtube.com/v/1BABPJ3zdGM&amp;color1=3a3a3a&amp;color2=999999&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0?rel=1" />
<param name="allowFullScreen" value="true" />
<embed wmode="transparent" src="http://www.youtube.com/v/1BABPJ3zdGM&amp;color1=3a3a3a&amp;color2=999999&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0?rel=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="355"></embed>
<param name="wmode" value="transparent" />
</object>
</span><p><a href="http://www.youtube.com/watch?v=1BABPJ3zdGM">www.youtube.com/watch?v=1BABPJ3zdGM</a></p></p>
]]></content:encoded>
			<wfw:commentRss>http://roy-t.nl/index.php/2010/08/27/hollandia-progress-report-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA: Accessing ContentManager and GraphicsDevice anywhere anytime, the GameServiceContainer</title>
		<link>http://roy-t.nl/index.php/2010/08/25/xna-accessing-contentmanager-and-graphicsdevice-anywhere-anytime-the-gameservicecontainer/</link>
		<comments>http://roy-t.nl/index.php/2010/08/25/xna-accessing-contentmanager-and-graphicsdevice-anywhere-anytime-the-gameservicecontainer/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 16:33:21 +0000</pubDate>
		<dc:creator>Roy Triesscheijn</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[General Coding]]></category>
		<category><![CDATA[General Gamedesign]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[codesnippet]]></category>
		<category><![CDATA[ContentManager]]></category>
		<category><![CDATA[GameServiceContainer]]></category>
		<category><![CDATA[GraphicsDevice]]></category>

		<guid isPermaLink="false">http://roy-t.nl/?p=372</guid>
		<description><![CDATA[A quick code snippet that I produced today and wanted to share. Often you find yourself looking for a good path/way to give a certain component access to the ContentManager. Usually you will just plug it in the construct. However sometimes the object creating the new object doesn&#8217;t have access to this component as well. [...]]]></description>
			<content:encoded><![CDATA[<p><em>A quick code snippet that I produced today and wanted to share.</em></p>
<p>Often you find yourself looking for a good path/way to give a certain component access to the ContentManager. Usually you will just plug it in the construct. However sometimes the object creating the new object doesn&#8217;t have access to this component as well. Things start to become a bit more complicated then, of course you can add it to both constructors, but things often start to clutter.</p>
<p>Objects like the ContentManager and the GraphicsDevice are often needed on the craziest of places in a game&#8217;s code. They can easily be shared as they are usually in a valid state throughout the runtime of your program and usually you don&#8217;t need more than one. For these kind of objects it would be easy to create a static class so that anyone can access them.</p>
<p>A common technique is to create a static List<object> in which you can throw anything in. But this doesn&#8217;t enforce that there is only instance of a given type in the container (why add two GraphicsDevices?) and makes it hard to get the right component from.</p>
<p>Luckily XNA has the GameServiceContainer class which allows you to store elements like this:</p>
<pre class="brush: csharp;">
container = GameServicesContainer();
container.AddService(typeof(GraphicsDevice), device);
</pre>
<p>There&#8217;s also GetService and RemoveService. However this casting can make a lot of lines way longer than they need to be. Also we need to make the container static and protected access to it, so let&#8217;s create a nice little class like this:</p>
<pre class="brush: csharp;">
public static class GameServices
    {
        private static GameServiceContainer container;
        public static GameServiceContainer Instance {
            get
            {
                if (container == null)
                {
                    container = new GameServiceContainer();
                }
                return container;
            }
        }

        public static T GetService&lt;T&gt;()
        {
            return (T)Instance.GetService(typeof(T));
        }

        public static void AddService&lt;T&gt;(T service)
        {
            Instance.AddService(typeof(T), service);
        }

        public static void RemoveService&lt;T&gt;()
        {
            Instance.RemoveService(typeof(T));
        }
    }
</pre>
<p>In the Initialize method of Gam1.cs put this:</p>
<pre class="brush: csharp;">
protected override void Initialize()
        {
            base.Initialize();
            GameServices.AddService&lt;GraphicsDevice&gt;(GraphicsDevice);
            GameServices.AddService&lt;ContentManager&gt;(Content);
        }
</pre>
<p>Remember that GameServices is static so you can read, add and remove from anywhere in your code like this:</p>
<pre class="brush: csharp;">
GameServices.AddService&lt;GraphicsDevice&gt;(device);
myDevice = GameServices.GetService&lt;GraphicsDevice&gt;();
GameServices.RemoveService&lt;GraphicsDevice&gt;()
</pre>
<p>Quite a nifty way of doing this, if I may say that myself (A). However do note (as NullSoldi did on Efnet #xna) that this will increase coupling between your components as some class will start to depend on the non standard class we&#8217;ve just created while this otherwise wasn&#8217;t needed. However I personally think that the benefits greatly outweigh the small penalty on coupling.</p>
<p>Have fun with this snippet, let me know if you&#8217;re using it or found it useful for your own GameServices-like class.</p>
]]></content:encoded>
			<wfw:commentRss>http://roy-t.nl/index.php/2010/08/25/xna-accessing-contentmanager-and-graphicsdevice-anywhere-anytime-the-gameservicecontainer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hollandia and Farseer physics</title>
		<link>http://roy-t.nl/index.php/2010/08/20/hollandia-and-farseer-physics/</link>
		<comments>http://roy-t.nl/index.php/2010/08/20/hollandia-and-farseer-physics/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 17:13:20 +0000</pubDate>
		<dc:creator>Roy Triesscheijn</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Hollandia]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Farseer]]></category>
		<category><![CDATA[Physics]]></category>

		<guid isPermaLink="false">http://roy-t.nl/?p=367</guid>
		<description><![CDATA[I don&#8217;t know why I didn&#8217;t break this to everyone before. But I&#8217;ve been the lead developer of Hollandia for a few weeks already. Click the image or link to find out more . For Hollandia I&#8217;m doing a rewrite of the engine. Since it&#8217;s a platformer the characters need to be able to jump [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.hollandiagame.com"><img class="aligncenter" title="Hollandia" src="http://www.hollandiagame.com/templates/hollandia_homepage/images/headerImage.jpg" alt="The website header for Hollandia, starring Tulpje" width="862" height="425" /></a><br />
I don&#8217;t know why I didn&#8217;t break this to everyone before. But I&#8217;ve been the lead developer of <a href="http://www.hollandiagame.com">Hollandia</a> for a few weeks already. Click the image or link to find out more <img src='http://roy-t.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>For Hollandia I&#8217;m doing a rewrite of the engine. Since it&#8217;s a platformer the characters need to be able to jump onto things. So I had a choice to either write my own mini-physics-engine for this or to look for a valid alternative that I could easily plug in into the code that I had already written. Luckily I chose the last option and came across <a href="http://farseerphysics.codeplex.com/">Farseer physics</a> and I&#8217;m completely hysterical about it. After only one day of using it I&#8217;ve donated $10,- to show my support. Ok the manual pages could use a bit of work, but to aid in that I&#8217;m writing a Farseer physics platformer tutorial for the <a href="http://www.sgtconker.com">Sgt. Conker XNA Article Contest</a> in which I will put everything that I&#8217;ve found out about Farseer so far (see it as a gentle introduction, since once you &#8216;get it&#8217; Farseer is very easy).</p>
<p>Anyway some who follow my youtube channel might&#8217;ve seen this already, but I made a small video where you can see that I&#8217;ve implemented Farseer physics into the engine. Things are really starting to come together (Screen managers, Scene Graphs, Layered system etc&#8230; unfortunately you can&#8217;t see any of that in the video). Especially the artwork is really nice, but since I didn&#8217;t make the art work, I&#8217;ve turned it off for the below video. (I&#8217;m just showing the physics bodies).</p>
<p><span class="youtube">
<object width="425" height="355">
<param name="movie" value="http://www.youtube.com/v/xrQ9dJgmYkE&amp;color1=3a3a3a&amp;color2=999999&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0?rel=1" />
<param name="allowFullScreen" value="true" />
<embed wmode="transparent" src="http://www.youtube.com/v/xrQ9dJgmYkE&amp;color1=3a3a3a&amp;color2=999999&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0?rel=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="355"></embed>
<param name="wmode" value="transparent" />
</object>
</span><p><a href="http://www.youtube.com/watch?v=xrQ9dJgmYkE">www.youtube.com/watch?v=xrQ9dJgmYkE</a></p></p>
<p>And no, this is not the 4&#215;4 all terrain infinite horsepower brutal Segway of doom ©. This is actually our main character walking around. (It doesn&#8217;t look so silly if you imagine a texture of a Dutch girl moving around instead of these funny boxes <img src='http://roy-t.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . The idea to do it this way came from <a href="http://amazingretardo.simiansoftwerks.com/2010/02/17/platformer-character-control-farseer-physics-engine/">this blog article by Bryan Dismas</a> which in turn is based on <a href="http://boxycraft.wordpress.com/2009/06/30/behind-boxboy/">this blog article by Robert Dodd</a></p>
]]></content:encoded>
			<wfw:commentRss>http://roy-t.nl/index.php/2010/08/20/hollandia-and-farseer-physics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA: Preventing starvation/underflow when moving 2D objects slower than 1 pixel per frame</title>
		<link>http://roy-t.nl/index.php/2010/08/12/xna-preventing-starvationunderflow-when-moving-2d-objects-slower-than-1-pixel-per-frame/</link>
		<comments>http://roy-t.nl/index.php/2010/08/12/xna-preventing-starvationunderflow-when-moving-2d-objects-slower-than-1-pixel-per-frame/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 09:25:04 +0000</pubDate>
		<dc:creator>Roy Triesscheijn</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[General Coding]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[floating point]]></category>
		<category><![CDATA[floats]]></category>
		<category><![CDATA[moving]]></category>
		<category><![CDATA[underflow]]></category>

		<guid isPermaLink="false">http://roy-t.nl/?p=362</guid>
		<description><![CDATA[Another title for this article could be: &#8220;XNA: Preventing starvation/underflow when updating integers with less than 1 each frame&#8221;. A very naive (but usually) working method for making 2D objects move in XNA is by placing the following code in the update method. //Assume we hold position by a rectangle, since we can use that [...]]]></description>
			<content:encoded><![CDATA[<p><em>Another title for this article could be: &#8220;XNA: Preventing starvation/underflow when updating integers with less than 1 each frame&#8221;.</em></p>
<p>A very naive (but usually) working method for making 2D objects move in XNA is by placing the following code in the update method.</p>
<pre class="brush: csharp;">
//Assume we hold position by a rectangle, since we can use that so easily in the spritebatch
myCar.Y += (int)(gravity * gameTime.ElapsedGameTime.TotalSeconds);
</pre>
<p>This will make your object fall down with &#8216;gravity&#8217; pixels per second. However since rectangles use integers for positioning, and an integer can not hold information after the seperator (eg 1.5 would become 1 for an int) objects will not move when gravity is very low or updates are very frequent.</p>
<p>Although, I say very low, but since the updates are done 60 times per second (if you&#8217;re using fixed timesteps, else it might even be a lot higher), gameTime.ElapsedGameTime.TotalSeconds will usually be 1/60th. This means that for an object to move, it should move with at least 60 pixels per second. That means, depending on your game&#8217;s resolution, that would mean in full HD an object moveing from the top of the screen to the bottom of the screen has to do this in 18 seconds or less, else it won&#8217;t move (1080 high divided by 60), in SD this is even worse, 8 seconds (480/60).</p>
<p>There are two approaches here, one way is to change the way we modify integers, this is a good approach to use inside for example an object, that modifies the position of <strong>ONE</strong> other object.</p>
<pre class="brush: csharp;">
//Code inside for example a gravity class
underflowFloat += gameTime.ElapsedGameTime.TotalSeconds;
myCar.Y += (int)underflowFloat;
underflowFloat -= (int)underflowFloat;
</pre>
<p>Although this approach is simple and efficient, there are two drawbacks to this approach:</p>
<ul>
<li>If you have multiple objects that modify one other object, then you will have a lot of extra floats hanging around</li>
<li>An object will need one float per direction per object that it modifies. For a gravity class that might influence all your objects this is very inefficient.</li>
</ul>
<p>A second approach would be to modify the object itself, a handy way to do this is properties.</p>
<pre class="brush: csharp;">
public int X;
private float underflowX;
public float Xfloat
{
    get { return (X + underflowX); }
    set
    {
        X = (int)value;
        underflowX = (value - (int)value);
    }
}
//Same for Y
</pre>
<p>This approach is way more useful since it will make sure that all your code that is using integers won&#8217;t break, while you still have an accurate floating point based position if needed. Basically we store all the data after the seperator in our variable underflowX.  If the integer values get changed, we will still return the correct values as float. If the float values are changed, the integer is updated to be as precise as possible.</p>
<p><strong>Remarks</strong></p>
<p>After asking for some feedback in #XNA I got a few comments  that I bundled here, please read these!<br />
There are more options, you could store the position as a Vector2 and cast the X and Y to integers only when you need to (but you shouldn&#8217;t ever if you start from scratch). Then you can either cast to integers when drawing, or use the SpriteBatch&#8217;s overload that uses a Vector2 for position (you will see some blending/blurring if the object is not pixel-aligned). Remember that if you cast to integers, that you will lose precision when you store the values back, this may or may not be a problem (it might not even be noticeable, but if you keep casting 5.999 to 5 every frame it might become noticeable).</p>
]]></content:encoded>
			<wfw:commentRss>http://roy-t.nl/index.php/2010/08/12/xna-preventing-starvationunderflow-when-moving-2d-objects-slower-than-1-pixel-per-frame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA XML ContentImporter</title>
		<link>http://roy-t.nl/index.php/2010/08/07/xna-xml-contentimporter/</link>
		<comments>http://roy-t.nl/index.php/2010/08/07/xna-xml-contentimporter/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 11:09:43 +0000</pubDate>
		<dc:creator>Roy Triesscheijn</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[General Coding]]></category>
		<category><![CDATA[General Gamedesign]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Content Pipeline]]></category>
		<category><![CDATA[ContentImporter]]></category>
		<category><![CDATA[ContentTypeReader]]></category>
		<category><![CDATA[ContentTypeWriter]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://roy-t.nl/?p=358</guid>
		<description><![CDATA[Quite often you&#8217;d like to use XML files in your games. You can use the standard XNA XML Importer for this, however then you&#8217;d need to write specific class that serialize to and from the special XNA XML documents that have a &#60;XNAContent&#62; tree. If you&#8217;re trying to build your levels in XML or if [...]]]></description>
			<content:encoded><![CDATA[<p>Quite often you&#8217;d like to use XML files in your games. You can use the standard XNA XML Importer for this, however then you&#8217;d need to write specific class that serialize to and from the special XNA XML documents that have a &lt;XNAContent&gt; tree.</p>
<p>If you&#8217;re trying to build your levels in XML or if you&#8217;re trying to set a high volume of settings this might not be the easiest way. Easier would be to just parse a hand written XML document yourself. Luckily this is very easy to accomplish.</p>
<p>The naive way of doing this is by just writing a custom content importer that would look similar to this:</p>
<pre class="brush: csharp;">
[ContentImporter(&quot;.xml&quot;, DisplayName = &quot;XML Content Importer&quot;, DefaultProcessor = &quot;None&quot;)]  //TImport was defined as System.Xml.XmlDocument a bit higher
    public class XMLContentImporter : ContentImporter&lt;TImport&gt;
    {
        public override TImport Import(string filename, ContentImporterContext context)
        {
            XmlDocument document = new XmlDocument();
            try
            {
                document.Load(filename);
            }
            catch (Exception e)
            {
                //Write error logger here or update the exception with more information
                throw e;
            }
            return document;
        }
    }
</pre>
<p>(Don&#8217;t forget to add a reference to your content pipeline project to the<strong> Content project inside your game&#8217;s project</strong>)</p>
<p>Now the following code doesn&#8217;t work and will throw an error similar to this:</p>
<pre class="brush: plain;">
Error   1   Building content threw InvalidOperationException: Cyclic reference found while serializing System.Xml.XmlDocument. You may be missing a ContentSerializerAttribute.SharedResource flag.
</pre>
<p>Now I&#8217;m not going to be holier than the pope, I actually made the same error as you can blatantly see <a href="http://forums.xna.com/forums/p/58481/358409.aspx">here</a>.</p>
<p>Unfortunately the error message is very unhelpful in this case, and might even throw you off completely since the error is not visual from the actual content file itself. Any XML file while give you this error.</p>
<p>Luckily user Saw was sitting around in #XNA on Efnet (IRC). He told me that the error comes from the fact that I&#8217;ve written no ContentWriter (and ContentReader). This means that reflection is used to serialize the XML document.</p>
<p>An XmlDocument has a lot of XMLNodes. An XmlNode has the member variable parent, which is an XmlNode, which has the member variable &#8216;parent&#8217;, which&#8230;. Well you get the idea. Probably the recursion error comes from there.</p>
<p>He then showed me how two write a very simple reader and writer. If we extend our content importer with these two extra classes this problem is easily solved.</p>
<pre class="brush: csharp;">
[ContentTypeWriter()]
    public class CustomXmlWriter : ContentTypeWriter&lt;XmlDocument&gt;
    {
        protected override void Write(ContentWriter output, XmlDocument value)
        {
            value.Save(output.BaseStream);
        }

        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return typeof(CustomXmlReader).AssemblyQualifiedName;
        }
    }

    public class CustomXmlReader : ContentTypeReader&lt;XmlDocument&gt;
    {
        protected override XmlDocument Read(ContentReader input, XmlDocument existingInstance)
        {
            if (existingInstance == null)
            {
                existingInstance = new XmlDocument();
            }
            existingInstance.Load(input.BaseStream);
            return existingInstance;
        }
    }
</pre>
<p>The custom content writer just uses the XMLDocuments built in Save function which is aware of these cycles and deals with them properly, the other method is overload to tell XNA which content reader to use for this type. The content reader again uses the simple built in Load function, nothing special here.</p>
<p>However now compile your project again, see the errors are gone <img src='http://roy-t.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Let&#8217;s add a simple XML file to your content project, I&#8217;ve named it hello.xml.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;MyTag&gt;Hello World!&lt;/MyTag&gt;
</pre>
<p>Click the file in the solution explorer and set the build action to &#8216;Compile&#8217; and the Content Processor to &#8216;XML Content Importer&#8217; (you can change the name by changing the DisplayName attribute). Note: you might need to recompile before you can do this.</p>
<p>Load and display it like this:</p>
<pre class="brush: csharp;">
XmlDocument xml = Content.Load&lt;XmlDocument&gt;(@&quot;Tests\xmltest&quot;);
XmlNode node = xml.SelectSingleNode(&quot;//MyTag&quot;);
Console.Out.WriteLine(node.InnerText);
</pre>
<p>The expression &#8220;//MyTag&#8221; is an XPATH expression to query the XML document, you can learn more about that <a href="http://www.w3schools.com/xpath/xpath_syntax.asp">here</a>.</p>
<p>I hope you have a lot of fun with this code, and that it makes life a little bit easier for you, either by handling XML files for you, or by being a small source on how to write custom ContentTypeWriters and readers.</p>
]]></content:encoded>
			<wfw:commentRss>http://roy-t.nl/index.php/2010/08/07/xna-xml-contentimporter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vacation time is over</title>
		<link>http://roy-t.nl/index.php/2010/07/24/vacation-time-is-over/</link>
		<comments>http://roy-t.nl/index.php/2010/07/24/vacation-time-is-over/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 20:51:46 +0000</pubDate>
		<dc:creator>Roy Triesscheijn</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[vacation]]></category>

		<guid isPermaLink="false">http://roy-t.nl/?p=356</guid>
		<description><![CDATA[Just a quick post to let everyone know that I&#8217;m back from vacation . Gotta expect at least one interesting article in the comming weeks. Or wel&#8230; I should really write some. As always ideas are welcome!]]></description>
			<content:encoded><![CDATA[<p>Just a quick post to let everyone know that I&#8217;m back from vacation <img src='http://roy-t.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Gotta expect at least one interesting article in the comming weeks. Or wel&#8230; I should really write some.</p>
<p>As always ideas are welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://roy-t.nl/index.php/2010/07/24/vacation-time-is-over/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>More A* improvements</title>
		<link>http://roy-t.nl/index.php/2010/06/27/more-a-improvements/</link>
		<comments>http://roy-t.nl/index.php/2010/06/27/more-a-improvements/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 13:27:42 +0000</pubDate>
		<dc:creator>Roy Triesscheijn</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[General Gamedesign]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[A start]]></category>
		<category><![CDATA[A*]]></category>
		<category><![CDATA[A* 3D]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Pathfinding]]></category>

		<guid isPermaLink="false">http://roy-t.nl/?p=351</guid>
		<description><![CDATA[As you might know I&#8217;ve written quite a lot of articles on the A* algorithm. This week I was contacted by Roman Kazakov (fourfor[AT]hotmail.com). He had a look at my previous A* articles and came up with a number of ways to speed up my latest version even more! Unfortunately he doesn&#8217;t have a blog, [...]]]></description>
			<content:encoded><![CDATA[<p>As you might know I&#8217;ve written <a href="http://roy-t.nl/index.php/2009/07/07/new-version-a-pathfinding-in-3d/">quite</a> <a href="http://roy-t.nl/index.php/2009/07/07/a-3d-update/">a</a> <a href="http://roy-t.nl/index.php/2009/06/29/3d-and-2d-a-pathfinding-in-cxna-new-and-cleaner-code/">lot</a> <a href="http://roy-t.nl/index.php/2009/06/29/upcomming-a-pathfinding-in-2d-and-3d-code-updated/">of</a> <a href="http://roy-t.nl/index.php/2009/02/24/implementing-a-path-finding-in-c-and-xna-source-code-can-we-cut-the-corner/">articles</a> <a href="http://roy-t.nl/index.php/2009/02/22/implementing-a-into-xna/">on</a> the A* algorithm.</p>
<p>This week I was contacted by Roman Kazakov (fourfor[AT]hotmail.com). He had a look at my previous A* articles and came up with a number of ways to speed up my latest version even more! Unfortunately he doesn&#8217;t have a blog, so he asked me to publish his enhancements here, so that everyone can use them. So I&#8217;ll forego the rest of this introduction and let the man speak.</p>
<p><em>(Note: the following quote is the last unedited part of an e-mail of Roman Kazakov).</em></p>
<blockquote><p>Hi Roy, my name is Roman Kazakov and I am Russian guy, but live in Latin America. My Spanish is perfect, but my English is &#8220;so so&#8221;, I hope you understand me. <img src='http://roy-t.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I am not a professional programmer. This is just my hobby from university. And as &#8220;free lancer&#8221; I work with VS 2008 C# + DevXpress + SQL Server 2008.<br />
I would like to present you my optimization for you program AStar. Oh, by the way, my game is 2D, and this example is in 2D dimension, but this version will by work and 3D too and more faster.<br />
Here is code of FindPathReversed:</p>
<pre class="brush: csharp;">
 private static BreadCrumb3 FindPathReversed5Final(bool[,] worldBlocked, Point2D start, Point2D end)
        {
            // Here we dont use the class Poin2D. It is bad idea use Class just for two int values (X Y)
            List&lt;BreadCrumb3&gt; openList2 = new List&lt;BreadCrumb3&gt;(256);
            BreadCrumb3[,] brWorld = new BreadCrumb3[worldBlocked.GetLength(0), worldBlocked.GetLength(1)];
            BreadCrumb3 node;
            int t1, t2;
            int tmpX, tmpY;
            int cost;
            int diff;
            t1 = worldBlocked.GetLength(0);
            t2 = worldBlocked.GetLength(1);
            BreadCrumb3 current = new BreadCrumb3(start.X, start.Y);
            current.cost = 0;

            BreadCrumb3 finish = new BreadCrumb3(end.X, end.Y);
            brWorld[current.X, current.Y] = current;
            openList2.Add(current);

            while (openList2.Count &gt; 0)
            {
                //Find best item and switch it to the 'closedList'
                current = openList2[0];
                openList2.RemoveAt(0);
                int position = 0;
                cost = openList2.Count;
                do
                {
                    int left = ((position &lt;&lt; 1) + 1);
                    int right = left + 1;
                    int minPosition;

                    if (left &lt; cost &amp;&amp; openList2[left].cost &lt; openList2[position].cost)
                    {
                        minPosition = left;
                    }
                    else
                    {
                        minPosition = position;
                    }

                    if (right &lt; cost &amp;&amp; openList2[right].cost &lt; openList2[minPosition].cost)
                    {
                        minPosition = right;
                    }

                    if (minPosition != position)
                    {
                        node = openList2[position];
                        openList2[position] = openList2[minPosition];
                        openList2[minPosition] = node;
                        position = minPosition;
                    }
                    else
                    {
                        break;
                    }

                } while (true);

                current.onClosedList = true;

                //Find neighbours
                for (int i = 0; i &lt; 8; i++)
                {
                    tmpX = current.X + surrounding2[i, 0];
                    tmpY = current.Y + surrounding2[i, 1];
                 //   tmp = current.position + surrounding[i]; //This is is a really slow!!!
                    /*if (tmp.X &gt;= 0 &amp;&amp; tmp.X &lt; t1 &amp;&amp;
                tmp.Y &gt;= 0 &amp;&amp; tmp.Y &lt; t2 &amp;&amp;
                !worldBlocked[tmp.X, tmp.Y])*/
                    if (tmpX &gt;= 0 &amp;&amp; tmpX &lt; t1 &amp;&amp;
             tmpY &gt;= 0 &amp;&amp; tmpY &lt; t2 &amp;&amp;
             !worldBlocked[tmpX, tmpY])
                    {
                        //Check if we've already examined a neighbour, if not create a new node for it.
                        if (brWorld[tmpX, tmpY] == null)
                        {
                          //  node = new BreadCrumb3(tmpX,tmpY);
                           // brWorld[tmpX, tmpY] = node;
                            brWorld[tmpX, tmpY] = node = new BreadCrumb3(tmpX, tmpY); // This is more fast!
                        }
                        else
                        {
                            node = brWorld[tmpX, tmpY];
                        }

                        //If the node is not on the 'closedList' check it's new score, keep the best
                        if (!node.onClosedList)
                        {
                            diff = 0;
                            if (current.X != node.X)
                            {
                                diff += 1;
                            }
                            if (current.Y != node.Y)
                            {
                                diff += 1;
                            }
                            cost = current.cost + diff + ((node.X - end.X) * (node.X - end.X)) + ((node.Y - end.Y) * (node.Y - end.Y));//node.position.GetDistanceSquared(end);

                            if (cost &lt; node.cost)
                            {
                                node.cost = cost;
                                node.next = current;
                            }

                            //If the node wasn't on the openList yet, add it
                            if (!node.onOpenList)
                            {
                                //Check to see if we're done
                               // if (node.Equals(finish)) // This is slow too!!!
                                if (node.X == finish.X &amp;&amp; node.Y == finish.Y)
                                {
                                    node.next = current;
                                    return node;
                                }
                                node.onOpenList = true;
                                openList2.Add(node);

                                int position2 = openList2.Count - 1;

                                int parentPosition = ((position2 - 1) &gt;&gt; 1);

                                while (position2 &gt; 0 &amp;&amp; openList2[parentPosition].cost &gt; openList2[position2].cost)
                                {
                                    node = openList2[position2];
                                    openList2[position2] = openList2[parentPosition];
                                    openList2[parentPosition] = node;
                                    position2 = parentPosition;
                                    parentPosition = ((position2 - 1) &gt;&gt; 1);
                                }

                            }
                        }
                    }
                }
            }
            return null; //no path found
        }
</pre>
<p>Comments:<br />
Look in my screenshots which i made it for you. For looking performance I used ANTS Performance Profiler 5.2. This is a great &#8220;stuff&#8221;!<br />
Also you can use your benchmark. Check the file zip attached. There is all source and information for compiled.<br />
Comments about code:<br />
The general &#8220;thing&#8221; in programming in C# is do not use Obj Class and etc. where really dont need to use that! The best performance is just &#8220;Value type&#8221; and List&lt;&gt;<br />
Array, maybe Struct.<br />
In my optimized code I deleting class MinHeap where T : IComparable. Why?! Because is really slow, and I dont know why. Also use class Point2D just for 2(3) types X and Y( and Z),  it was a bad idea. And many thing more. Looked my code and you understand which changes I made it. I hope this is help you. And please put this optimization on you wonderful web page http://roy-t.nl, as New Optimized Version A*.<br />
When we made the games, we looking for more faster algorithm and code. This article will be help a many people as us.<br />
We made the games of our dreams&#8230;</p></blockquote>
<p><em>Roman also included a couple of pictures to show the speed gain of his code</em><br />
Original code (by me)<br />
<a href="http://roy-t.nl/wp-content/uploads/2010/06/OriginalRoyFindPath.jpg"><img class="alignnone size-medium wp-image-354" title="OriginalRoyFindPath" src="http://roy-t.nl/wp-content/uploads/2010/06/OriginalRoyFindPath-300x240.jpg" alt="" width="300" height="240" /></a><br />
New implementations (by Roman)<br />
<a href="http://roy-t.nl/wp-content/uploads/2010/06/MyOptimizedFindPath4.jpg"><img class="alignnone size-medium wp-image-352" title="MyOptimizedFindPath4" src="http://roy-t.nl/wp-content/uploads/2010/06/MyOptimizedFindPath4-300x240.jpg" alt="" width="300" height="240" /></a><br />
<a href="http://roy-t.nl/wp-content/uploads/2010/06/MyOptimizedFindPath5_-No-Point2D.jpg"><img class="alignnone size-medium wp-image-353" title="MyOptimizedFindPath5_ No Point2D" src="http://roy-t.nl/wp-content/uploads/2010/06/MyOptimizedFindPath5_-No-Point2D-300x240.jpg" alt="" width="300" height="240" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://roy-t.nl/index.php/2010/06/27/more-a-improvements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Re: Writing a book ????</title>
		<link>http://roy-t.nl/index.php/2010/06/21/writing-a-book-reply/</link>
		<comments>http://roy-t.nl/index.php/2010/06/21/writing-a-book-reply/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 19:49:26 +0000</pubDate>
		<dc:creator>Roy Triesscheijn</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[publishing]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://roy-t.nl/?p=349</guid>
		<description><![CDATA[Some of you might look a but strange at the title, it is the exact same title as TheZman&#8217;s latest blog post. His post got me to think again about a project I&#8217;d like to start on *(Oh god, this makes me think of the oh so many projects that I want to start on!). [...]]]></description>
			<content:encoded><![CDATA[<p>Some of you might look a but strange at the title, it is the exact same title as <a href="http://www.indiegameguy.com/blogs/zman/archive/2010/06/21/writing-a-book.aspx" target="_blank">TheZman&#8217;s</a> latest blog post.</p>
<p>His post got me to think again about a project I&#8217;d like to start on *(Oh god, this makes me think of the oh so many projects that I want to start on!). Writing a book? It takes quite a lot of courage and determination to write a good technical book. Hell I know that I haven&#8217;t yet acquired the technical skills for it. (Maybe I haven&#8217;t even mastered English  enough yet). So obviously I&#8217;m not think about writing a technical book.</p>
<p>However I would like to write a book for people who are not into (game-) programming or maybe even games in general. I would like to introduce readers to a kind of &#8216;ambiance&#8217; that gives us developers such a comfortable feeling when developing for games. I would like to tell people how difficult game programming is, what games really are (in my opinion that is). And what some games with attention to detail, and attention to the real world, can bring to people.</p>
<p>Hell it would be a book worthy of a game-evangely. Of course there should be added technical parts, but the book I&#8217;d like to write would also contain parts that you could take a good sit for and read for pleasure.</p>
<p>This however brings me to how to actually release a book. Of course I could just put it up here as a pdf and be done with it, but that&#8217;s not really what I had in mind. Publishing a game, getting your name on there somewhere is also something that could thrive me into making a  book.</p>
<p>Oh well, first back to spell and style checking my blog posts I guess. But maybe I could do a small primer someday, say 50 pages, and see what people think. (And count the number of mistakes, to see how long it would take to correct a full book&#8230;).</p>
]]></content:encoded>
			<wfw:commentRss>http://roy-t.nl/index.php/2010/06/21/writing-a-book-reply/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Thoughts: automatic tests and user interfaces</title>
		<link>http://roy-t.nl/index.php/2010/06/07/thoughts-automatic-tests-and-user-interfaces/</link>
		<comments>http://roy-t.nl/index.php/2010/06/07/thoughts-automatic-tests-and-user-interfaces/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 19:55:30 +0000</pubDate>
		<dc:creator>Roy Triesscheijn</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[General Coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[unit test]]></category>
		<category><![CDATA[Unit tests]]></category>
		<category><![CDATA[user interfaces]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://roy-t.nl/?p=345</guid>
		<description><![CDATA[Lately I’ve been working on a rather large project (software web shop that automatically adds and updates products). The customer required that a large part of the software was automatically tested. We accomplished this by using PHPUnit (somewhat quirky, but it got the job done). However there was one big problem. The problem The web [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I’ve been working on a rather large project (software web shop that automatically adds and updates products). The customer required that a large part of the software was automatically tested. We accomplished this by using PHPUnit (somewhat quirky, but it got the job done). However there was one big problem.</p>
<h2>The problem</h2>
<p>The web shop was built with the Zend Framework in true MVC fashion. This meant that it was very easy to write unit tests for the model. However the model wasn’t that complex, just a bunch of queries and some massaging of the fetched data. The most interesting things happened in the views and we had no clue how to test the views automatically. Because we had a hard deadline, and didn’t have time to fully dive into this problem, one of our testers committed himself to test all the views every day. This was feasible because we didn’t have too many views.</p>
<h2>Current approaches</h2>
<p>Automatically testing user interfaces is hard, especially in web languages. In a C# or Java application you can at least fill in text boxes and ‘press’ some buttons via code, although this will require you to (temporarily) make a lot of stuff public. In web languages you don’t have this amount of direct control; the closest thing would be to write a lot of Javascript. However Javascript’s state is lost on page transitions so you’d have to write the state to a file, fetch it on the next page, continue testing there, and so on. This seems like a really big bunch of work, with not much gain. However maybe there is a framework out there, which does just this thing. Maybe you can tune it to navigate the web shop for you, however there is still another big problem.</p>
<h2>Presentation is important</h2>
<p>For a user interface it is very important how everything looks. In web apps a small typo can make a page totally unreadable. A possible approach would be to strictly specify where a control should appear (maybe in pixels relative to the browser’s borders). But this is not possible to check with any Javascript or any other web front-end language I know. Maybe an application can make a screenshot and compare this with a screenshot that was deemed correct? Even this approach might not work very well as this would already give an error when the text on a label was partially changed.</p>
<h2>Possible solution</h2>
<p>I’ve come up with the following solution so far. This is just an idea which I’ve just cooked up (and the reason for this post) but I believe that it would work. Unfortunately there is no product available on the market yet that does these things.</p>
<p>In my opinion a good user interface tester would test in two steps. One test focused on content correctness and one focused on visual correctness.</p>
<p>The content correctness test would roughly follow the following steps:</p>
<p>•	Request a page from the server</p>
<p>•	Fill in controls and click buttons, following a predefined ‘test path’</p>
<p>•	Verify that returned pages contains correctly filled in elements (does the label with name label1 contain the text “hello world”?). This could be done by adding a special identifier to each control that needs to be tested. The identifier can be hidden in ‘comments’ so that even during testing the web application stays compatible with normal browsers.</p>
<p>For every step a screenshot is made from the render output in the most popular web browsers. If the content correctness test succeeds the visual correctness test is executed, which contains the following test.</p>
<p>•	Record control positions and sizes by ‘scanning’ the screenshots using OCR techniques. Might be aided by cross referencing the page’s source code.</p>
<p>•	Test if controls are inside predefined ‘control locations’. Think of setting this up by dragging rectangular boxes over a screenshot to specify where a control should approximately be.</p>
<p>•	If a control is not entirely on the correct location calculate a badness percentage.</p>
<p>•	If the accumulated badness percentage is too high: fail the test and generate a nice picture, clearly marking the deviations.</p>
<p>•	Also give the tester the option to select a failed test as the new correct references. This is useful for quickly updating tests when larger parts of the interface are changed.</p>
<p>Of course this approach doesn’t solve all the problems of testing user interfaces. And user interfaces will also have to be checked manually once in a while. However I think an application capable of performing the above tests would be very handy. Most of the above is also applicable to non-web applications btw.</p>
<p>I would very much like to hear everyone’s thoughts on this. How do you currently test user interfaces, have you come up with a feasible way to test large user interfaces?</p>
]]></content:encoded>
			<wfw:commentRss>http://roy-t.nl/index.php/2010/06/07/thoughts-automatic-tests-and-user-interfaces/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Busy busy busy</title>
		<link>http://roy-t.nl/index.php/2010/05/15/busy-busy-busy/</link>
		<comments>http://roy-t.nl/index.php/2010/05/15/busy-busy-busy/#comments</comments>
		<pubDate>Sat, 15 May 2010 09:46:05 +0000</pubDate>
		<dc:creator>Roy Triesscheijn</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://roy-t.nl/?p=341</guid>
		<description><![CDATA[As you might&#8217;ve noticed by the lack of updates. I&#8217;m rather busy because I&#8217;m stil working on the ISEP project for the Rijksuniversiteit Groningen. It&#8217;s quite a lot of work and we&#8217;re currently busy with the final 3 week crunch to get everything  done. I hope life goes back to normal after that and that [...]]]></description>
			<content:encoded><![CDATA[<p>As you might&#8217;ve noticed by the lack of updates. I&#8217;m rather busy because I&#8217;m stil working on the ISEP project for the Rijksuniversiteit Groningen. It&#8217;s quite a lot of work and we&#8217;re currently busy with the final 3 week crunch to get everything  done. I hope life goes back to normal after that and that I can blog some interesting stuff again. If not it will probably be quite silent here till the start of the summer vacation, in which I have some really cool projects planned which I&#8217;m planning to show you guys!</p>
<p>Kind regards,</p>
<p>Roy Triesscheijn</p>
]]></content:encoded>
			<wfw:commentRss>http://roy-t.nl/index.php/2010/05/15/busy-busy-busy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
