<?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>Hazel McKendrick &#187; C++</title>
	<atom:link href="http://hazelmckendrick.com/journal/tag/c/feed" rel="self" type="application/rss+xml" />
	<link>http://hazelmckendrick.com</link>
	<description>Programming and Games Technology Portfolio</description>
	<lastBuildDate>Wed, 11 Aug 2010 10:00:17 +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>Microcell Testbed Images</title>
		<link>http://hazelmckendrick.com/journal/microcell-testbed-images</link>
		<comments>http://hazelmckendrick.com/journal/microcell-testbed-images#comments</comments>
		<pubDate>Sat, 20 Mar 2010 14:26:41 +0000</pubDate>
		<dc:creator>Hazel</dc:creator>
				<category><![CDATA[Honours Project]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[dissertation]]></category>
		<category><![CDATA[Distributed Computing]]></category>
		<category><![CDATA[microcells]]></category>
		<category><![CDATA[testbed]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://hazelmckendrick.com/?p=1922</guid>
		<description><![CDATA[For once I have something visual relating to my honours project, so it seemed appropriate to share a sample here. A major part of the project involves distributing microcells (fixed areas of the world) between a series of worker nodes both statically and dynamically. In order to test methods of achieving this, I created a [...]]]></description>
			<content:encoded><![CDATA[<p>For once I have something visual relating to my honours project, so it seemed appropriate to share a sample here.  </p>
<p>A major part of the project involves distributing microcells (fixed areas of the world) between a series of worker nodes both statically and dynamically.  In order to test methods of achieving this, I created a small testbed application which simulates the task without networking.  It is capable of using various methods to distribute cells, both at the start of the application and as it runs, both controlled by a central server and initiated by worker nodes and gives graphical and numerical feedback.</p>
<p>The images below were taken with a greatly reduced number of cells, and the work involved in processing each cell is artificial: there are no pathfinding characters yet.  However hopefully it demonstrates to some extent how division of the world takes place, and allows me to easily test distribution methods before using them in the proper simulation.</p>
<div id="attachment_1928" class="wp-caption alignleft" style="width: 160px"><a href="http://hazelmckendrick.com/wp-content/uploads/2010/03/QuantityOfChars1.jpg"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/03/QuantityOfChars1-150x150.jpg" alt="" title="QuantityOfChars" width="150" height="150" class="size-thumbnail wp-image-1928" /></a><p class="wp-caption-text">Coloured by number of characters per cell.</p></div> <div id="attachment_1932" class="wp-caption alignleft" style="width: 160px"><a href="http://hazelmckendrick.com/wp-content/uploads/2010/03/BlockDistribution2.png"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/03/BlockDistribution2-150x150.png" alt="" title="BlockDistribution" width="150" height="150" class="size-thumbnail wp-image-1932" /></a><p class="wp-caption-text">Initial block distribution.</p></div> <div id="attachment_1930" class="wp-caption alignleft" style="width: 160px"><a href="http://hazelmckendrick.com/wp-content/uploads/2010/03/RandomDistribution1.png"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/03/RandomDistribution1-150x150.png" alt="" title="RandomDistribution" width="150" height="150" class="size-thumbnail wp-image-1930" /></a><p class="wp-caption-text">Random distribution for comparison.</p></div> <div id="attachment_1924" class="wp-caption alignleft" style="width: 160px"><a href="http://hazelmckendrick.com/wp-content/uploads/2010/03/BlockDistributionGreedy11.png"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/03/BlockDistributionGreedy11-150x150.png" alt="" title="BlockDistributionGreedy1" width="150" height="150" class="size-thumbnail wp-image-1924" /></a><p class="wp-caption-text">Block distribution with dynamic passing after time.</p></div>
<p>As the actual application I am working on is written in C#, I used XNA to create the images here.  As it is possible to render XNA frames to a windows form application with little difficulty, this is also the approach I will employ for visualising the complete project.</p>
]]></content:encoded>
			<wfw:commentRss>http://hazelmckendrick.com/journal/microcell-testbed-images/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comms Library Progress</title>
		<link>http://hazelmckendrick.com/journal/comms-library-progress</link>
		<comments>http://hazelmckendrick.com/journal/comms-library-progress#comments</comments>
		<pubDate>Sun, 28 Feb 2010 21:09:02 +0000</pubDate>
		<dc:creator>Hazel</dc:creator>
				<category><![CDATA[Honours Project]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[dissertation]]></category>
		<category><![CDATA[multithreading]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[UML]]></category>

		<guid isPermaLink="false">http://hazelmckendrick.com/?p=1847</guid>
		<description><![CDATA[Unfortunately my honours project is not particularly visual, so it can be hard to update this blog with my progress when I have nothing I can really show. However, progress is being made. The first component of the project, a communications and network library, was completed almost a week ago. The most useful thing I [...]]]></description>
			<content:encoded><![CDATA[<p>Unfortunately my honours project is not particularly visual, so it can be hard to update this blog with my progress when I have nothing I can really show.  However, progress <i>is</i> being made. The first component of the project, a communications and network library, was completed almost a week ago.</p>
<p>The most useful thing I can share is the class diagram this was based on.  It&#8217;s rough, it doesn&#8217;t detail methods or member data, and it&#8217;s far from beautiful, but perfection is an easy trap to fall into.  I thought it was better to have a functioning library and an ugly diagram than a work of art demonstrating a library which I then would have no time to create.<br />
<a href="http://hazelmckendrick.com/wp-content/uploads/2010/02/CommsLibClass21.png"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/02/CommsLibClass21-300x165.png" alt="" title="CommsLibClass2" width="300" height="165" class="aligncenter size-medium wp-image-1871" /></a></p>
<p>The current phase of the project is far more interesting in my opinion, and thankfully should result in something slightly more visually interesting.  It concerns the division of the world, hierarchically, into microcells.  This spatial partitioning, and more importantly the assignment of work to specific processors is fast becoming the major focus of the project, and I hope to follow up with more on that topic shortly.</p>
<p>EDIT: I have replaced the <a href="http://hazelmckendrick.com/wp-content/uploads/2010/02/CommsLibClass1.png">original diagram</a> with a still-ugly but slightly more descriptive update (if you actually view it at a decent size, that is).  The majority of member data and functions are still missing, but hopefully the few I&#8217;ve added will make my intentions slightly clearer.</p>
]]></content:encoded>
			<wfw:commentRss>http://hazelmckendrick.com/journal/comms-library-progress/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Global Game Jam 2010</title>
		<link>http://hazelmckendrick.com/journal/global-game-jam-2010</link>
		<comments>http://hazelmckendrick.com/journal/global-game-jam-2010#comments</comments>
		<pubDate>Thu, 04 Feb 2010 15:01:20 +0000</pubDate>
		<dc:creator>Hazel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Game Jam]]></category>
		<category><![CDATA[GGJ]]></category>
		<category><![CDATA[Glasgow Caledonian]]></category>
		<category><![CDATA[Panda Dragoon]]></category>
		<category><![CDATA[SGJ]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://hazelmckendrick.com/?p=1794</guid>
		<description><![CDATA[Over the weekend, almost 50 developers in Scotland and over 1500 crazy people worldwide opted to forgo luxuries like sleep and rest by taking part in Global Game Jam. Perhaps unsurprisingly, you&#8217;re reading this because I was one of them. Scottish Game Jam, the branch of the event in which I participated, was hosted at [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://hazelmckendrick.com/wp-content/uploads/2010/02/timthumb.png"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/02/timthumb.png" alt="" title="timthumb" width="630" height="250" class="aligncenter size-full wp-image-1804" /></a><br />
Over the weekend, almost 50 developers in Scotland and over 1500 crazy people worldwide opted to forgo luxuries like sleep and rest by taking part in <a href="http://globalgamejam.org/">Global Game Jam</a>.  Perhaps unsurprisingly, you&#8217;re reading this because I was one of them. <span id="more-1794"></span></p>
<p><a href="http://hazelmckendrick.com/wp-content/uploads/2010/02/hurt.jpg"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/02/hurt-300x158.jpg" alt="" title="hurt" width="300" height="158" class="alignleft size-medium wp-image-1806" /></a><a href="http://www.jonsykes.com/sgj/">Scottish Game Jam</a>, the branch of the event in which I participated, was hosted at <a href="http://www.gcal.ac.uk/">Glasgow Caledonian University</a>, organised by the fantastic <a href="http://www.romanakhan.com/">Romana Khan</a>.  Nine teams took part in the Saltire Centre, an impressive (though bright) space, loading up on caffeine and sleeping on couches (if at all).</p>
<p>My team <a href="http://www.jonsykes.com/sgj/?p=187">&#8220;Frat Boys from the Hood&#8221;</a> consisted of Abi, Jess, Andrew and myself from Abertay joined by Alex, a third year student from Glasgow Calendonian.  Working on a theme of deception and constraints mandating that we must include &#8220;a sink, a wink or a rink&#8221;, we built the 2d side-scroller <a href="http://globalgamejam.org/2010/panda-dragoon-bees-ice">&#8220;Panda Dragoon: Bees on Ice&#8221;</a> with the aid of the <a href="http://unity3d.com/">Unity</a> engine.</p>
<p>The game places our panda protagonist in a black and white world, fighting deceptive and equally monochrome foes.  Gliding through an ice rink, the player must switch between black and white in order to see enemies of the opposite colour.  However, switching also empowers these enemies—the player must be cautious—causing them to change form and cause increasing damage.  Luckily, the player is equipped to defeat these creatures by firing bees from its mouth.  The aim is to progress as far as possible as the game increases in speed, achieving a maximum score.</p>
<p><a href="http://hazelmckendrick.com/wp-content/uploads/2010/02/screen2.jpg"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/02/screen2-300x177.jpg" alt="" title="screen2" width="300" height="177" class="alignright size-medium wp-image-1812" /></a>Although the event overall was non-competitive in nature, Scottish Game Jam welcomed judges from Denki and Real Time Worlds to critique the resulting applications and to decide on a winning game.</p>
<p>Much to our surprise <b>We Won!</b></p>
<p>It was really reassuring to make such a self indulgent game, for ourselves and not for a nominated target audience, and yet have four out of five judges award it their highest score.  Obviously the game has flaws, we made it in <i>48 hours</i>, but with another week of tweaking at some point hopefully we can create something compelling and genuinely <i>fun</i>.</p>
<p>Overall, I had a fantastic time and would encourage any developer, especially artists, to take part next year.  It&#8217;s amazing how much you can learn and achieve in just two days.</p>
<p><a href="http://globalgamejam.org/2010/panda-dragoon-bees-ice">Download and play The Game.</a><br />
<a href="http://globalgamejam.org/">Global Game Jam</a><br />
<a href="http://www.jonsykes.com/sgj/">Scottish Game Jam</a></p>
<p><a href="http://hazelmckendrick.com/wp-content/uploads/2010/02/bees.jpg"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/02/bees.jpg" alt="" title="bees" width="650" height="220" class="aligncenter size-full wp-image-1808" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://hazelmckendrick.com/journal/global-game-jam-2010/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Coding Coder Art</title>
		<link>http://hazelmckendrick.com/journal/coding-coder-art</link>
		<comments>http://hazelmckendrick.com/journal/coding-coder-art#comments</comments>
		<pubDate>Fri, 22 Jan 2010 20:46:26 +0000</pubDate>
		<dc:creator>Hazel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[Texture Generation]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://hazelmckendrick.com/?p=1775</guid>
		<description><![CDATA[Starting work on a 3D project as of yet lacking in assets, I was considering cracking open Paint.Net to create some default textures. However, being a programmer rather than an artist, I figured I&#8217;d better investigate some alternatives. I reduced my work, and made even more hideous coder art in the process! I ended up [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://hazelmckendrick.com/wp-content/uploads/2010/01/ca.bmp"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/01/ca.bmp" alt="" title="art" width="150" height="150" class="alignleft size-full wp-image-1780" /></a> Starting work on a 3D project as of yet lacking in assets, I was considering cracking open Paint.Net to create some default textures.  However, being a programmer rather than an artist, I figured I&#8217;d better investigate some alternatives.  I reduced my work, and made even more hideous coder art in the process!</p>
<p>I ended up trying two options: .Net Graphics support (which uses GDI) and everyone&#8217;s favourite image manipulation tool <a href="http://www.imagemagick.org/script/index.php">ImageMagick</a>.  My aim was to create bright an horrible images, to ensure they don&#8217;t remain in the project by mistake, with text on them to show what object my many cubes and spheres represent. <span id="more-1775"></span></p>
<p>First up, my C# script.  It created the fantastic texture you see above, and can be run from a windows command line as<br />
<code> > DefaultTexGen.exe Text_To_Write FilenameToCreate.bmp</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Drawing</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Drawing.Imaging</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Drawing.Text</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//creates a default texture with text on it</span>
<span style="color: #0600FF;">namespace</span> DefaultTexGen
<span style="color: #000000;">&#123;</span>
    <span style="color: #FF0000;">class</span> Program
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//check whether arguments were passed</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>args.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Please run with arguments for image text and output file name.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                return<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//get name and output file from arguments</span>
            <span style="color: #FF0000;">string</span> name <span style="color: #008000;">=</span> args<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> file <span style="color: #008000;">=</span> args<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//set width and height (square), could get these from args too</span>
            <span style="color: #FF0000;">int</span> dimension <span style="color: #008000;">=</span> <span style="color: #FF0000;">256</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//create the bitmap</span>
            Bitmap genmap <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Bitmap<span style="color: #000000;">&#40;</span>dimension, dimension<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//apply the colour and text</span>
            FillTexture<span style="color: #000000;">&#40;</span>genmap<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            WriteText<span style="color: #000000;">&#40;</span>name, genmap<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//output bitmap</span>
            genmap.<span style="color: #0000FF;">Save</span><span style="color: #000000;">&#40;</span>file<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Image &quot;</span> <span style="color: #008000;">+</span> file <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; created.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>This relies on two further functions.  The first of these colours the image with a simple gradient, but could be replaced with any colouring function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">//fill a bitmap with a random gradient</span>
        <span style="color: #008080; font-style: italic;">//could replace with other colouring function</span>
        <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> FillTexture<span style="color: #000000;">&#40;</span>Bitmap _target<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//set random r,g,b values between 0 and 1</span>
            Random rand <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">float</span> rCol <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">float</span><span style="color: #000000;">&#41;</span>rand.<span style="color: #0000FF;">NextDouble</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">float</span> gCol <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">float</span><span style="color: #000000;">&#41;</span>rand.<span style="color: #0000FF;">NextDouble</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">float</span> bCol <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">float</span><span style="color: #000000;">&#41;</span>rand.<span style="color: #0000FF;">NextDouble</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//fill each pixel</span>
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> x <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> x <span style="color: #008000;">&lt;</span> _target.<span style="color: #0000FF;">Width</span><span style="color: #008000;">;</span> x<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> y <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> y <span style="color: #008000;">&lt;</span> _target.<span style="color: #0000FF;">Height</span><span style="color: #008000;">;</span> y<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    Color pixColour <span style="color: #008000;">=</span> Color.<span style="color: #0000FF;">FromArgb</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">255</span> <span style="color: #008000;">*</span> rCol<span style="color: #000000;">&#41;</span>, Math.<span style="color: #0000FF;">Min</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">255</span>, <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">*</span> gCol<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, Math.<span style="color: #0000FF;">Min</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">255</span>, <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span>y <span style="color: #008000;">*</span> bCol<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    _target.<span style="color: #0000FF;">SetPixel</span><span style="color: #000000;">&#40;</span>x, y, pixColour<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The second actually writes the text to the image.  It calculates a font size to fit the given string onto the texture.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">//Fit and write text to a bitmap</span>
        <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> WriteText<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> _text, Bitmap _target<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//calculate the font size to fit the text to the image</span>
            <span style="color: #008080; font-style: italic;">//pixel width in monospaced Courier New = 0.833 point size</span>
            <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">float</span> fontReduce <span style="color: #008000;">=</span> 0.833f<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">float</span> edgePadding <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">float</span> size <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>_target.<span style="color: #0000FF;">Width</span> <span style="color: #008000;">-</span> edgePadding<span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> _text.<span style="color: #0000FF;">Length</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> fontReduce<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//set the max font size to 25</span>
            size <span style="color: #008000;">=</span> Math.<span style="color: #0000FF;">Min</span><span style="color: #000000;">&#40;</span>size, <span style="color: #FF0000;">35</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//set up font and graphics</span>
            StringFormat format <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringFormat<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            format.<span style="color: #0000FF;">Alignment</span> <span style="color: #008000;">=</span> StringAlignment.<span style="color: #0000FF;">Center</span><span style="color: #008000;">;</span>
            Font font <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Font<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Courier New&quot;</span>, size<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Graphics graphics <span style="color: #008000;">=</span> Graphics.<span style="color: #0000FF;">FromImage</span><span style="color: #000000;">&#40;</span>_target<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            graphics.<span style="color: #0000FF;">DrawString</span><span style="color: #000000;">&#40;</span>_text, font, Brushes.<span style="color: #0000FF;">Black</span>, _target.<span style="color: #0000FF;">Width</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>, _target.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">3</span>, format<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I&#8217;ll be honest, the second solution (with Imagemagick) is simpler, more flexible, and creates better looking textures.<br />
As an example:<br />
<code>convert -size 256x256 plasma:tomato-steelblue -font Arial -pointsize 20 -draw "text 10,20 Default_Texture" TextureToCreate.jpg</code><br />
Produces the following image:<br />
<a href="http://hazelmckendrick.com/wp-content/uploads/2010/01/tex.jpg"><img src="http://hazelmckendrick.com/wp-content/uploads/2010/01/tex.jpg" alt="" title="tex" width="256" height="256" class="aligncenter size-full wp-image-1790" /></a></p>
<p>Creating a batch/shell script to calculate the correct font size and run this command should be trivial, leading to some disgusting, but useful, textures.</p>
]]></content:encoded>
			<wfw:commentRss>http://hazelmckendrick.com/journal/coding-coder-art/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unity Is Free</title>
		<link>http://hazelmckendrick.com/journal/unity-is-free</link>
		<comments>http://hazelmckendrick.com/journal/unity-is-free#comments</comments>
		<pubDate>Mon, 02 Nov 2009 23:53:51 +0000</pubDate>
		<dc:creator>Hazel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Games Engines]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Rotation]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://hazelmckendrick.com/?p=1662</guid>
		<description><![CDATA[Having heard that the Unity game engine is now being offered for free, I figured I would be a fool not to take advantage and give it a go. As such, I spent a little time working through tutorials, playing with various features and starting a small game project. I figured as a quick introduction [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://hazelmckendrick.com/wp-content/uploads/2009/11/ss2.jpg"><img src="http://hazelmckendrick.com/wp-content/uploads/2009/11/ss2-300x187.jpg" alt="ss1" title="ss1" width="300" height="187" class="alignright size-medium wp-image-1668" /></a>Having heard that the <a href="http://unity3d.com/">Unity game engine</a> is now being offered for free, I figured I would be a fool not to take advantage and give it a go.  As such, I spent a little time working through tutorials, playing with various features and starting a small game project.</p>
<p>I figured as a quick introduction I would work on a clone of <a href="http://hazelmckendrick.com/demos/flash-game-rotation">Rotation</a>, an Asteroids/Duo/Space Invaders sort of game which I created in Flash a couple of years ago.  </p>
<p>Overall things went (slightly surprisingly) very smoothly.  Initially I had to cling the <a href="http://unity3d.com/support/documentation/ScriptReference/index.html">script reference</a> but once I had a better idea of the functionality available, everything started to come together.  I don&#8217;t have much experience with comprehensive game engines like this, but Unity certainly seemed to provide far fewer &#8220;Why on earth was it designed like <i>that</i>?&#8221; moments than I&#8217;ve experienced in the past; it also took far less time to get a general overview of in the first place.  I can already see how this tool could be useful for quick gameplay mock-ups as well as complete, commercial products. <span id="more-1662"></span></p>
<p>So do I wish Unity had been a possibility when we worked on <a href="http://hazelmckendrick.com/demos/prototype-game-some-assembly-required">Some Assembly Required</a> last year?  I&#8217;m not sure.  In some ways, I think it perhaps makes things too easy when it comes to games programming as a learning experience.  Sure, there are a lot of great features and we almost certainly could have created a more complete game in the short time we had available, but at the same time we wouldn&#8217;t have learned about using and integrating 3rd party libraries, structuring the application overall or converting and importing troublesome assets.  </p>
<p>That&#8217;s also a reason I&#8217;m hesitant to keep working on this project &#8211; I&#8217;m not sure I&#8217;m getting as much from it as I could by tackling something more technical or in a different language.  We&#8217;ll see what time permits though, as working on a game to completion is obviously a challenging exercise in itself and it seems possible that having the engine there would allow me to focus on difficult problems while the other stuff is taken care of.</p>
<p>Since I&#8217;m not terribly sure this project will make it any further though (I do have an honours project to take care of, amongst other things), here&#8217;s the little segment I&#8217;ve completed so far:</p>
<ul>
<li>You&#8217;ll need the <a href="http://unity3d.com/webplayer/">Unity Web Player</a>.</li>
<li>Use left and right arrows to rotate your ships.</li>
<li>Use space to shoot the cubes (asteroids. Probably thrown through space by bugs we&#8217;re at war with on some distant planet)</li>
</ul>
<p><object id="UnityObject" classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" width="675" height="450" codebase="http://webplayer.unity3d.com/download_webplayer/UnityWebPlayer.cab#version=2,0,0,0"><param name="src" value="http://hazelmckendrick.com/wp-content/uploads/2009/10/rotation.unity3d" /><embed id="UnityEmbed" src="http://hazelmckendrick.com/wp-content/uploads/2009/10/rotation.unity3d" width="675" height="450" type="application/vnd.unity" pluginspage="http://www.unity3d.com/unity-web-player-2.x" /><br />
</object></p>
<p>Anyway, if you&#8217;ve given Unity a try leave a comment below and let me know your experiences!</p>
]]></content:encoded>
			<wfw:commentRss>http://hazelmckendrick.com/journal/unity-is-free/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Experiments</title>
		<link>http://hazelmckendrick.com/journal/project-experiments</link>
		<comments>http://hazelmckendrick.com/journal/project-experiments#comments</comments>
		<pubDate>Tue, 27 Oct 2009 21:57:06 +0000</pubDate>
		<dc:creator>Hazel</dc:creator>
				<category><![CDATA[Honours Project]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[dissertation]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://hazelmckendrick.com/?p=1623</guid>
		<description><![CDATA[I&#8217;ve made some progress in the past week with my honours projects, creating small experimental programs to familiarise myself with multi-threading in .NET. Thankfully so far I&#8217;ve found the syntax clear and consistent with the terms normally involved in parallel processing. Although this doesn&#8217;t simplify the task of designing the program it certainly avoids the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://hazelmckendrick.com/wp-content/uploads/2009/10/Untitled2.png"><img src="http://hazelmckendrick.com/wp-content/uploads/2009/10/Untitled2-300x233.png" alt="Untitled2" title="Untitled2" width="300" height="233" class="alignright size-medium wp-image-1626" /></a>I&#8217;ve made some progress in the past week with my honours projects, creating small experimental programs to familiarise myself with multi-threading in .NET.  Thankfully so far I&#8217;ve found the syntax clear and consistent with the terms normally involved in parallel processing.  Although this doesn&#8217;t simplify the task of designing the program it certainly avoids the implementation overhead which has been inherent in my attempts with multi-threading in C++.</p>
<p>The programs I&#8217;ve been working on are in C#, though I&#8217;d be interested to try other .NET languages.  In each, I processed thousands of entities allowing each to rotate and bounce around a window.  Different methods of splitting up and dealing with this work in parallel were experimented with.  <span id="more-1623"></span></p>
<p>Rendering, which was performed separately and was responsible for a fair amount of overhead, could be simplified or rearranged to increase overall frame processing time.  However, as the graph below (from my first program created) shows there was a noticeable difference between using one and multiple threads.  I&#8217;m using a dual core CPU on my laptop, and with the application limited to a single core the gain was far less significant; I hope to see whether using a quad core CPU would offer a further gain in the near future.</p>
<p>Although not shown, using 32, 64 or even 1024 threads caused far less of a performance hit that I had expected.  The time spent creating the threads at the beginning of the program was notable, however, as was the increase in memory requirements.</p>
<p><a href="http://hazelmckendrick.com/wp-content/uploads/2009/10/graph.png"><img src="http://hazelmckendrick.com/wp-content/uploads/2009/10/graph.png" alt="graph" title="graph" width="645" height="427" class="aligncenter size-full wp-image-1627" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://hazelmckendrick.com/journal/project-experiments/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Next Level Dundee</title>
		<link>http://hazelmckendrick.com/journal/next-level-dundee</link>
		<comments>http://hazelmckendrick.com/journal/next-level-dundee#comments</comments>
		<pubDate>Mon, 07 Sep 2009 21:04:02 +0000</pubDate>
		<dc:creator>Hazel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Next Level]]></category>
		<category><![CDATA[Other Abertay Students]]></category>
		<category><![CDATA[Pitch]]></category>
		<category><![CDATA[Whitespace]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://killercodingninjabunny.com/?p=1384</guid>
		<description><![CDATA[This week I&#8217;m taking part in Next Level Dundee. Next Level is a digital media collaboration project, which basically means I&#8217;m meeting some new people and developing a game with them in a week. Scary idea. We pitched our games to the other participants on Friday, having only just managed to meet up the morning [...]]]></description>
			<content:encoded><![CDATA[<p>This week I&#8217;m taking part in Next Level Dundee.  Next Level is a digital media collaboration project, which basically means I&#8217;m meeting some new people and developing a game with them in a week.  Scary idea.</p>
<p><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/09/whitespace.jpg"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/09/whitespace-1024x294.jpg" alt="whitespace" title="whitespace" width="650" height="200" class="aligncenter size-large wp-image-1387" /></a></p>
<p>We pitched our games to the other participants on Friday, having only just managed to meet up the morning beforehand.  Luckily we&#8217;d managed to agree on a game design through online meetings on Skype, but there were elements that we didn&#8217;t fully decide upon until we met face to face. </p>
<p><span id="more-1384"></span></p>
<p>This morning (early this morning) we got together in Whitespace to actually start work.  The team is composed of two programmers, two artists and an audio producer, and while we have roles and some idea of what we each need to achieve it&#8217;s hard to know exactly what we will end up with until we get to know each other better.</p>
<p><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/09/IMG_2262.JPG"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/09/IMG_2262-300x225.jpg" alt="IMG_2262" title="IMG_2262" width="300" height="225" class="alignright size-medium wp-image-1392" /></a>Waj, the other coder, and I settled into development over the weekend before by developing a particle system manager and a flexible 2D game framework respectively (we, of course, couldn&#8217;t start work on the game until today).  Luckily, we have XNA at our disposal which should make a big difference to what we can get through in the timespan.  Today however, much of each our time was spent simply merging code: lacking an SVN client on the university computers we were attempting to simply use Dropbox.  Scary, and time consuming.  Hopefully tomorrow we can make use a portable command line SVN client to keep track of changes.  </p>
<p>Another issue we&#8217;re facing is in terms of work distribution and each having our own coding standards.  As you might imagine, most of the problem is with communication &#8211; to a small extent because we don&#8217;t know each other, but mostly because we barely had time to come up with a game idea, let alone come up with task lists and naming schemes.  We&#8217;re working things out the best we can as we go along though.</p>
<p>So, hopefully on friday we&#8217;ll have a simple top-down 2D game to share! Wish us luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://hazelmckendrick.com/journal/next-level-dundee/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Depth of Field</title>
		<link>http://hazelmckendrick.com/journal/depth-of-field</link>
		<comments>http://hazelmckendrick.com/journal/depth-of-field#comments</comments>
		<pubDate>Sun, 02 Aug 2009 14:41:04 +0000</pubDate>
		<dc:creator>Hazel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Dare To Be Digital]]></category>
		<category><![CDATA[Depth of Field]]></category>
		<category><![CDATA[digital colony]]></category>
		<category><![CDATA[Full Screen Effects]]></category>
		<category><![CDATA[Graphics programming]]></category>
		<category><![CDATA[HLSL]]></category>
		<category><![CDATA[pollen]]></category>
		<category><![CDATA[shaders]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://killercodingninjabunny.com/?p=1247</guid>
		<description><![CDATA[Me: &#8220;But Abi! Surely I should work on bug fixes rather than implementing Depth of Field.&#8221; Project Manager: &#8220;No, Hazel. You must work on awesome graphics effects.&#8221; Me: &#8220;Sweeeet.&#8221; Ok, so I&#8217;m paraphrasing a little but if there was a film of the actual situation I&#8217;m pretty certain this would have been the dialogue. We&#8217;d [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/08/Dof6.jpg"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/08/Dof6-1024x592.jpg" alt="Dof6" title="Dof6" width="650" height="400" class="size-large wp-image-1250" /></a></p>
<p>
<b>Me:</b> &#8220;But Abi! Surely I should work on bug fixes rather than implementing Depth of Field.&#8221;</p>
<p><b>Project Manager:</b> &#8220;No, Hazel. You must work on awesome graphics effects.&#8221;</p>
<p><b>Me:</b> &#8220;Sweeeet.&#8221;
</p>
<p><span id="more-1247"></span><br />
Ok, so I&#8217;m paraphrasing a little but if there was a film of the actual situation I&#8217;m pretty certain this would have been the dialogue. We&#8217;d been talking about macro-photography inspired depth-of-field effects for a while but I wasn&#8217;t sure we&#8217;d actually find time to get it working.  In reality, it took less than a day to implement, didn&#8217;t kill our framerate and (I think) looks fantastic.</p>
<p><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/08/Dof5.jpg"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/08/Dof5-300x179.jpg" alt="Dof5" title="Dof5" width="300" height="179" class="alignleft size-medium wp-image-1248" /></a></p>
<p><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/08/DoF4.jpg"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/08/DoF4-300x179.jpg" alt="DoF4" title="DoF4" width="300" height="179" class="alignleft size-medium wp-image-1249" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://hazelmckendrick.com/journal/depth-of-field/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Into The Deep Dark Woods: Lighting and Shading</title>
		<link>http://hazelmckendrick.com/journal/getting-a-little-dark-and-scary</link>
		<comments>http://hazelmckendrick.com/journal/getting-a-little-dark-and-scary#comments</comments>
		<pubDate>Mon, 20 Jul 2009 21:19:38 +0000</pubDate>
		<dc:creator>Hazel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Dare To Be Digital]]></category>
		<category><![CDATA[digital colony]]></category>
		<category><![CDATA[Graphics programming]]></category>
		<category><![CDATA[Lighting]]></category>
		<category><![CDATA[pollen]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://killercodingninjabunny.com/?p=1191</guid>
		<description><![CDATA[Although I&#8217;ve really only been sharing bright and shiny screenshots of our game, it actually progresses from a sunny farm through to a dark and creepy forest. Naturally, this meant it was time to focus on implementing a coherent lighting model for the level. At the moment we&#8217;re working with ambient lighting, two directional lights [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/07/DarkArea.png"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/07/DarkArea-1024x624.png" alt="DarkArea" title="DarkArea" width="650" height="400" class="aligncenter size-large wp-image-1198" /></a></p>
<p>Although I&#8217;ve really only been sharing bright and shiny screenshots of our game, it actually progresses from a sunny farm through to a dark and creepy forest.  Naturally, this meant it was time to focus on implementing a coherent lighting model for the level. At the moment we&#8217;re working with ambient lighting, two directional lights and two spot lights per short section of our game.</p>
<p>In addition, I&#8217;ve been looking at methods for shadowing and shading.  Each bee is an intricate model, but scaled down it would be easy to lose a lot of the detail.  As you can hopefully see in the following images, shading adds some depth and makes the bees appear far more three dimensional.  <span id="more-1191"></span></p>
<div id="attachment_1194" class="wp-caption alignleft" style="width: 160px"><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/07/ColourByHeight.png"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/07/ColourByHeight-150x150.png" alt="Colouring by distance from ground." title="ColourByHeight" width="150" height="150" class="size-thumbnail wp-image-1194" /></a><p class="wp-caption-text">Shade by distance from ground.</p></div> <div id="attachment_1195" class="wp-caption alignleft" style="width: 160px"><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/07/ColourByNormals.png"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/07/ColourByNormals-150x150.png" alt="Colour By Normals" title="ColourByNormals" width="150" height="150" class="size-thumbnail wp-image-1195" /></a><p class="wp-caption-text">Shade when normals point down.</p></div> <div id="attachment_1196" class="wp-caption alignleft" style="width: 160px"><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/07/Combined4.png"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/07/Combined4-150x150.png" alt="Combined Shading Techniques." title="Combined4" width="150" height="150" class="size-thumbnail wp-image-1196" /></a><p class="wp-caption-text">Combined Shading Techniques.</p></div> <div id="attachment_1197" class="wp-caption alignleft" style="width: 160px"><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/07/CombinedLit4.png"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/07/CombinedLit4-150x150.png" alt="Combined With Lighting." title="CombinedLit4" width="150" height="150" class="size-thumbnail wp-image-1197" /></a><p class="wp-caption-text">Combined With Lighting.</p></div>
<p style="clear: both">&nbsp;<br />&nbsp;Similar techniques applied across the entire scene also improves the overall appearance, with and without lighting:</p>
<p><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/07/HeightAndAO.png"><img style="clear: both" src="http://killercodingninjabunny.com/wp-content/uploads/2009/07/HeightAndAO-300x191.png" alt="HeightAndAO" title="HeightAndAO" width="300" height="191" class="alignleft size-medium wp-image-1199" /></a> <a href="http://killercodingninjabunny.com/wp-content/uploads/2009/07/HeightAndLighting.png"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/07/HeightAndLighting-300x188.png" alt="HeightAndLighting" title="HeightAndLighting" width="300" height="188" class="alignleft size-medium wp-image-1192" /></a></p>
<p style="clear: both">&nbsp;<br />&nbsp;Finally, here&#8217;s an additional happier version of the shot above, just to show the difference a change in lighting can make:</p>
<p><a href="http://killercodingninjabunny.com/wp-content/uploads/2009/07/BrighterArea.png"><img src="http://killercodingninjabunny.com/wp-content/uploads/2009/07/BrighterArea-1024x660.png" alt="BrighterArea" title="BrighterArea" width="650" height="400" class="alignleft size-large wp-image-1193" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://hazelmckendrick.com/journal/getting-a-little-dark-and-scary/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Error!</title>
		<link>http://hazelmckendrick.com/journal/error</link>
		<comments>http://hazelmckendrick.com/journal/error#comments</comments>
		<pubDate>Sun, 22 Mar 2009 17:15:23 +0000</pubDate>
		<dc:creator>Hazel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[boolean]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[error handling]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://killercodingninjabunny.com/?p=824</guid>
		<description><![CDATA[Lately I&#8217;ve been working on a several projects, a couple of which are based around a modular framework I&#8217;m developing through them. In a move to correct one of the more serious issues with my previous work, I&#8217;ve been concentrating on a more defensive programming style and taking more time to write solid applications rather [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been working on a several projects, a couple of which are based around a modular framework I&#8217;m developing through them.  In a move to correct one of the more serious issues with my previous work, I&#8217;ve been concentrating on a more defensive programming style and taking more time to write solid applications rather than rushing into getting pretty effects working. </p>
<p>In previous programs I&#8217;ve tended towards simply returning boolean variables from functions which would otherwise be void to indicate success or failure, created log files to keep track of problems and used asserts for checking critical components. Ignoring, for now, the fact that I just plain wasn&#8217;t using these methods often enough, there are several problems with this approach.  </p>
<p>First, it employs three seperate methods for dealing with error handling and recording &#8211; I can use each method to relate to the others but this results in several lines of code just dealing with something which may be an error, and could lead to inconsistancy.  </p>
<p>The second problem was that not enough information was being passed and recorded. Returning a boolean variable from a function only gives you two options &#8211; either the process succeeded or it didn&#8217;t &#8211; when in fact the situation is often more complicated than that. In particular for offering logging and debug output a more verbose output type becomes useful.</p>
<p>My solution was to create a simple result class encapsulating the information to be passed back from a function, and a seperate handler class to output or log these messages.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #0000ff;">class</span> Result <span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	Result<span style="color: #008000;">&#40;</span>ReturnResult _result, std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> _location, std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> _message<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">bool</span> success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>			<span style="color: #666666;">//A boolean representation of the result value</span>
	ReturnResult value<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>		<span style="color: #666666;">//The value/type of the result</span>
	std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> location<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>		<span style="color: #666666;">//The location string from the message</span>
	std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> message<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>		<span style="color: #666666;">//The error message</span>
	std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> valueString<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>	<span style="color: #666666;">//The value as a string for logging/output</span>
&nbsp;
	<span style="color: #0000ff;">static</span> ResultManager <span style="color: #000040;">*</span>ResultMgr<span style="color: #008080;">;</span><span style="color: #666666;">//set a result manager so results can be handled on creation</span>
&nbsp;
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
&nbsp;
	ReturnResult m_result<span style="color: #008080;">;</span>		<span style="color: #666666;">//type of result being returned success/error severity</span>
	std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> m_location<span style="color: #008080;">;</span>		<span style="color: #666666;">//class/module/function being returned from</span>
	std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> m_message<span style="color: #008080;">;</span>		<span style="color: #666666;">//description of the error/success/test</span>
&nbsp;
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//severity of any errors resulting</span>
<span style="color: #0000ff;">enum</span> ReturnResult<span style="color: #008000;">&#123;</span>
&nbsp;
	RESULT_SUCCESS,			<span style="color: #666666;">//success which happens frequently (eg every frame)</span>
	RESULT_SUCCESS_CRITICAL,	<span style="color: #666666;">//success in a critical component</span>
	RESULT_ERROR_TERMINAL,		<span style="color: #666666;">//errors required the program to quit</span>
	RESULT_ERROR,			<span style="color: #666666;">//errors which might be recovered from</span>
	RESULT_WARNING			<span style="color: #666666;">//minor errors, which may cause problems later</span>
&nbsp;
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>I think this is all pretty straight forward &#8211; the result class contains 3 pieces of data: the type of result generated (of type ReturnResult &#8211; the enumeration shown above), a string indicating where the result originated and a string with a message to give more information on the error or success.  This keeps the class to a minimal size so that creating and passing results around doesn&#8217;t become an issue, but gives enough information for interpreting, logging and tracing errors. </p>
<p>Also a member of the class is a static pointer to a result manager which will handle these messages. When set, this means that the result messages can be handled (logging, outputing immediately or even exiting the application) as they are created rather than having to get hold of and processing each one individually.  This allows for consistant decisions on how messages should be handled, and prevents error handling obscuring the actual functionality of the application.</p>
<p>Errors can be created, processed and returned in one statement like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">return</span> HError<span style="color: #008080;">::</span><span style="color: #007788;">Result</span><span style="color: #008000;">&#40;</span>HError<span style="color: #008080;">::</span><span style="color: #007788;">RESULT_ERROR</span>, <span style="color: #FF0000;">&quot;Graphics Setup&quot;</span>, <span style="color: #FF0000;">&quot;Pixel format could not be set.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>If you&#8217;d like to check out the complete code for results and the result manager, I&#8217;ve uploaded it here: <a href='http://killercodingninjabunny.com/wp-content/uploads/2009/03/herror1.zip'>Source Code</a>.  Feel free to modify and use it under the terms of the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a>, or get back to me with improvements or suggestions.</p>
<p><!-- And my boyfriend andrew is awesome ^ awesome --></p>
]]></content:encoded>
			<wfw:commentRss>http://hazelmckendrick.com/journal/error/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
