<?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>#AltDevBlogADay</title>
	<atom:link href="http://www.altdevblogaday.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.altdevblogaday.com</link>
	<description>Each day a little more #gamedev love</description>
	<lastBuildDate>Wed, 22 May 2013 11:16:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>C/C++ Low Level Curriculum Part 12: Multiple Inheritance</title>
		<link>http://www.altdevblogaday.com/2013/05/22/cc-low-level-curriculum-part-12-multiple-inheritance/</link>
		<comments>http://www.altdevblogaday.com/2013/05/22/cc-low-level-curriculum-part-12-multiple-inheritance/#comments</comments>
		<pubDate>Wed, 22 May 2013 11:16:20 +0000</pubDate>
		<dc:creator>Alex Darby</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[education]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[low level]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29405</guid>
		<description><![CDATA[<p>Hello, and welcome to the 12th part of the C / C++ low level curriculum. Really soon after part 11! (No, of course part 11 didn&#8217;t get too big and need to be split. Why would you ask?)</p>
<p><a href="http://www.altdevblogaday.com/2013/05/22/cc-low-level-curriculum-part-12-multiple-inheritance/" class="more-link">Read more on C/C++ Low Level Curriculum Part 12: Multiple Inheritance&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Hello, and welcome to the 12th part of the C / C++ low level curriculum. Really soon after part 11! (No, of course part 11 didn&#8217;t get too big and need to be split. Why would you ask?)</p>
<p>Last time we looked at the basics of how inheritance was implemented at the low level; and this time we&#8217;re going to examine how using multiple inheritance affects this picture (<em><strong>note:</strong> </em>we&#8217;re leaving the keyword <em><strong>virtual</strong></em> til next time).<img title="More..." alt="" src="http://www.altdevblogaday.com/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" /></p>
<p><span id="more-29405"></span></p>
<h2>Before We Begin</h2>
<p>I will assume that you have already read the previous posts in the series, but I will also put in-line links to any important terms or concepts that you might need to know about to make sense of what you&#8217;re reading. I&#8217;m helpful like that.</p>
<p>Another big assumption I&#8217;m going to make is that you&#8217;re already very familiar with the language features of C++ and  comfortable using the language features we&#8217;re discussing. If I need to demonstrate anything out of the ordinary I&#8217;ll explain it &#8211; or at least link to an explanation.</p>
<p>In this series I discuss what happens with vanilla unoptimised win32 debug code generated by the VS 2010 compiler &#8211; whilst the specifics will differ on other platforms (and probably with other compilers) the general sweep of the code should be basically the same &#8211; because it&#8217;s assembly that has been generated by a C++ compiler &#8211; and so following the same examples given here with a source / disassembly debugger on your platform of choice should provide you with the same insights we get here.</p>
<p>With this in mind, in case you missed them, here are the backlinks to the previous posts in the series:</p>
<ol>
<li><a href="http://www.altdevblogaday.com/2011/11/09/a-low-level-curriculum-for-c-and-c/" rel="nofollow">http://altdevblogaday.com/2011/11/09/a-low-level-curriculum-for-c-and-c/</a></li>
<li><a href="http://www.altdevblogaday.com/2011/11/24/c-c-low-level-curriculum-part-2-data-types/" rel="nofollow">http://altdevblogaday.com/2011/11/24/c-c-low-level-curriculum-part-2-data-types/</a></li>
<li><a href="http://www.altdevblogaday.com/2011/12/14/c-c-low-level-curriculum-part-3-the-stack/">http://altdevblogaday.com/2011/12/14/c-c-low-level-curriculum-part-3-the-stack/</a></li>
<li><a href="http://www.altdevblogaday.com/2011/12/24/c-c-low-level-curriculum-part-4-more-stack/">http://altdevblogaday.com/2011/12/24/c-c-low-level-curriculum-part-4-more-stack/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/02/07/c-c-low-level-curriculum-part-5-even-more-stack/">http://altdevblogaday.com/2012/02/07/c-c-low-level-curriculum-part-5-even-more-stack/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/03/07/c-c-low-level-curriculum-part-6-conditionals/">http://altdevblogaday.com/2012/03/07/c-c-low-level-curriculum-part-6-conditionals/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/04/10/cc-low-level-curriculum-part-7-more-conditionals/">http://www.altdevblogaday.com/2012/04/10/cc-low-level-curriculum-part-7-more-conditionals/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/05/07/cc-low-level-curriculum-part-8-looking-at-optimised-assembly/">http://www.altdevblogaday.com/2012/05/07/cc-low-level-curriculum-part-8-looking-at-optimised-assembly/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/09/04/cc-low-level-curriculum-part-9-loops/">http://www.altdevblogaday.com/2012/09/04/cc-low-level-curriculum-part-9-loops/</a></li>
<li><a href="http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/">http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/</a></li>
<li><a href="http://www.altdevblogaday.com/2013/05/03/cc-low-level-curriculum-part-11-inheritance/">http://www.altdevblogaday.com/2013/05/03/cc-low-level-curriculum-part-11-inheritance/</a></li>
</ol>
<p>I won&#8217;t lie &#8211; it&#8217;s not light reading :)</p>
<p>&nbsp;</p>
<h2>I&#8217;ve just read post 11 and it all seemed pretty obvious&#8230;</h2>
<p>Good! It should do!</p>
<p>In my experience, most good solutions to problems appear obvious when explained well ;)</p>
<p>Now we&#8217;ve got an understanding of how single inheritance behaves, let&#8217;s examine how multiple inheritance affects this picture&#8230;</p>
<p>&nbsp;</p>
<h2>Multiple Inheritance</h2>
<p>Sample time!</p>
<p>Like last time I have <a href="http://www.altdevblogaday.com/wp-content/uploads/2013/05/ADBAD_CCPPLLC_12_00.zip">lovingly zipped up a hand-crafted VS2010 solution / project / source code combo</a> to go with this sample which contains the following 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">class CTestBaseOne
<span style="color: #009900;">&#123;</span>
public<span style="color: #339933;">:</span>
    <span style="color: #993333;">int</span> _iA<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> _iB<span style="color: #339933;">;</span>
&nbsp;
    CTestBaseOne<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> iA<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> iB <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">:</span> _iA<span style="color: #009900;">&#40;</span> iA <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">,</span> _iB<span style="color: #009900;">&#40;</span> iB <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #993333;">int</span> SumBase<span style="color: #009900;">&#40;</span> <span style="color: #993333;">void</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> _iA <span style="color: #339933;">+</span> _iB<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
class CTestBaseTwo
<span style="color: #009900;">&#123;</span>
public<span style="color: #339933;">:</span>
    <span style="color: #993333;">int</span> _iC<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> _iD<span style="color: #339933;">;</span>
&nbsp;
    CTestBaseTwo<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> iC<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> iD <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">:</span> _iC<span style="color: #009900;">&#40;</span> iC <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">,</span> _iD<span style="color: #009900;">&#40;</span> iD <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #993333;">int</span> SumBaseTwo<span style="color: #009900;">&#40;</span> <span style="color: #993333;">void</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> _iC <span style="color: #339933;">+</span> _iD<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
class CTestDerived
<span style="color: #339933;">:</span> public CTestBaseOne
<span style="color: #339933;">,</span> public CTestBaseTwo
<span style="color: #009900;">&#123;</span>
public<span style="color: #339933;">:</span>
    <span style="color: #993333;">int</span> _iE<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> _iF<span style="color: #339933;">;</span>
&nbsp;
    CTestDerived<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> iA<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> iB<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> iC<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> iD <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">:</span> CTestBaseOne <span style="color: #009900;">&#40;</span> iA<span style="color: #339933;">,</span> iB <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">,</span> CTestBaseTwo <span style="color: #009900;">&#40;</span> iC<span style="color: #339933;">,</span> iD <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">,</span> _iE <span style="color: #009900;">&#40;</span> iB <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">,</span> _iF <span style="color: #009900;">&#40;</span> iD <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #993333;">int</span> SumDerived<span style="color: #009900;">&#40;</span> <span style="color: #993333;">void</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #b1b100;">return</span> SumBase<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> SumBaseTwo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>_iE <span style="color: #339933;">+</span> _iF<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    CTestBaseOne    cTestBaseOne<span style="color: #009900;">&#40;</span> argc<span style="color: #339933;">,</span> argc <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CTestBaseTwo    cTestBaseTwo<span style="color: #009900;">&#40;</span> argc<span style="color: #339933;">,</span> argc <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CTestDerived    cTestDerived<span style="color: #009900;">&#40;</span> argc<span style="color: #339933;">,</span> argc <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> argc <span style="color: #339933;">+</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> argc <span style="color: #339933;">+</span> <span style="color: #0000dd;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span>      cTestBaseOne.<span style="color: #202020;">SumBase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  <span style="color: #339933;">+</span> cTestBaseTwo.<span style="color: #202020;">SumBaseTwo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
            <span style="color: #339933;">+</span>   cTestDerived.<span style="color: #202020;">SumBase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  <span style="color: #339933;">+</span> cTestDerived.<span style="color: #202020;">SumBaseTwo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> cTestDerived.<span style="color: #202020;">SumDerived</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Once you&#8217;ve unzipped it, go ahead and build it.</p>
<p>Don&#8217;t forget to pay attention to the build output &#8211; it shows the memory layout which we&#8217;re going to talk about next.</p>
<p>&nbsp;</p>
<h2>Memory Layout</h2>
<p>As you can see, we now have two base classes, and one class that derives from both of them.</p>
<p>When you build the project, you should see that the memory layout of these classes looks like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="txt" style="font-family:monospace;">1&gt;  class CTestBaseOne	size(8):
1&gt;  	+---
1&gt;   0	| _iA
1&gt;   4	| _iB
1&gt;  	+---
1&gt;  
1&gt;  class CTestBaseTwo	size(8):
1&gt;  	+---
1&gt;   0	| _iC
1&gt;   4	| _iD
1&gt;  	+---
1&gt;   
1&gt;  class CTestDerived	size(24):
1&gt;  	+---
1&gt;  	| +--- (base class CTestBaseOne)
1&gt;   0	| | _iA
1&gt;   4	| | _iB
1&gt;  	| +---
1&gt;  	| +--- (base class CTestBaseTwo)
1&gt;   8	| | _iC
1&gt;  12	| | _iD
1&gt;  	| +---
1&gt;  16	| _iE
1&gt;  20	| _iF
1&gt;  	+---</pre></td></tr></table></div>

<p>This is all as we might expect &#8211; given what we found out <a href="http://www.altdevblogaday.com/2013/05/03/cc-low-level-curriculum-part-11-inheritance/">last time</a>.</p>
<p>In particular note that:</p>
<ul>
<li>the memory layout of both base classes is embedded into <em><strong>CTestDerived</strong></em></li>
<li><em><strong>CTestBaseOne</strong></em> and <em><strong>CTestBaseTwo</strong></em> appear in the memory layout <em>in the same order they are declared in the base-specifier-list of</em> <em><strong>CTestDerived.</strong></em></li>
</ul>
<p>n.b. the base-specifier-list is the part of the declaration of a class where the base classes are specified.</p>
<p>In the simple case of single inheritance we considered in the <a href="http://www.altdevblogaday.com/2013/05/03/cc-low-level-curriculum-part-11-inheritance/">last post</a>, we saw that the functions of a base class <em><strong>B</strong></em> could be called on instances of a derived class <em><strong>D</strong></em> because:</p>
<ul>
<li>the memory layout of <em><strong>D</strong></em> contains a literal instance of <em><strong>B</strong></em> at an offset of 0 bytes within itself and&#8230;</li>
<li>&#8230;this means that the member data of an instance of <em><strong>B</strong></em> is at the same offset relative to the memory layout of an instance of <em><strong>D</strong></em>&#8230;</li>
<li>&#8230;and so the hard coded offsets used to access these members within functions belonging to <em><strong>B</strong></em> are also valid for instances of <em><strong>D</strong></em></li>
</ul>
<p>Looking at the memory layout for this multiply inherited class we can see that:</p>
<ol>
<li>this relationship still holds for <em><strong>CTestBaseOne</strong></em> and <em><strong>CTestDerived -</strong></em> <em><strong>CTestBaseOne</strong></em> is an an offset of 0 bytes within the memory layout of <em><strong>CTestDerived</strong></em></li>
<li>however, this same relationship is not true of <em><strong>CTestBaseTwo</strong></em> and <em><strong>CTestDerived</strong></em></li>
</ol>
<p>Given this situation, how do functions of <em><strong>CTestBaseTwo</strong></em> work with instances of <em><strong>CTestDerived</strong></em>?</p>
<p>As usual the best thing to do do is take a look&#8230;</p>
<p>&nbsp;</p>
<h2>Calling a function of CTestBaseTwo on CTestDerived</h2>
<p>Put a breakpoint on the return statement from <em><strong>main()</strong></em>, run the code, and when it stops right click then choose &#8216;Go To Disassembly&#8217;.</p>
<p>Rather than paste the disassembly as text this time, I&#8217;ve inserted a screenshot of my debugger window &#8211; this allows more formatting and highlighting options.</p>
<p><em>N.B. in this screenshot I have &#8220;Show symbol names&#8221; checked under viewing options. Whilst this typically makes it easier to relate disassembly to C or C++ code, it does hide detail (i.e. the addresses of the symbols) .</em></p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/05/CCPPLLC_12Inheritance_P2_MultipleInheritance_00.png"><img class="alignnone  wp-image-29432" alt="CCPPLLC_12Inheritance_P2_MultipleInheritance_00" src="http://www.altdevblogaday.com/wp-content/uploads/2013/05/CCPPLLC_12Inheritance_P2_MultipleInheritance_00.png" width="632" height="484" /></a></p>
<p>Let&#8217;s pick this apart then, starting at the current line indicator where the breakpoint is and working down:</p>
<ul>
<li>we can see that (following the x86 <em>thiscall</em> convention) before each function is called, the address of the corresponding object is stored into <em><strong>ecx</strong></em><em><strong> </strong></em>using <em><strong>lea</strong></em>.</li>
<li>First it loads the address of <em><strong>cTestDerived</strong> </em>into <em><strong>ecx</strong> </em>and then calls <em><strong>CTestDerived::SumDerived()</strong></em>&#8230;</li>
<li>then it&#8230;</li>
<li>Oh, wait&#8230; it&#8217;s loading the address <em><strong>[ebp-20h]</strong></em> into <em><strong>ecx&#8230;</strong></em></li>
<li>that symbol isn&#8217;t resolving in the disassembly window, so what witchcraft is this!?</li>
</ul>
<p>I have helpfully highlighted the most salient areas of the screenshot with red boxes :)</p>
<p>If you look at the function calls made in the disassembly, and compare them to the calls in the C++ code, you will see that all of the high level function calls have an analogue at the assembly level except for <em><strong>cDerived.SumBaseTwo()</strong></em>.</p>
<p><em><strong>CTestBaseTwo::SumBaseTwo </strong></em>is getting called, but with <em><strong>[ebp-20h]</strong></em> as the <em><strong>this</strong></em> pointer in <em><strong>ecx</strong></em>, not <em><strong>[cTestDerived] </strong></em>(n.b. see the top red box in the screenshot).</p>
<p><em><strong></strong></em>So, the question is: how does the address <em><strong>[ebp-20h]</strong></em> related to the address of <em><strong>cTestDerived</strong></em>?</p>
<p>This would be a good time to reiterate that the watch window is your friend. We can use the watch window to Sherlock Holmes our way to an answer.</p>
<p>If you look in the watch window below the disassembly view (shown again below by itself for those of you who are vertical resolution challenged) you can see that I have used watch window expression evaluation to find out some information about these values:</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/05/CCPPLLC_12Inheritance_P2_MultipleInheritance_WatchCasting_00.png"><img class="alignnone  wp-image-29434" alt="CCPPLLC_12Inheritance_P2_MultipleInheritance_WatchCasting_00" src="http://www.altdevblogaday.com/wp-content/uploads/2013/05/CCPPLLC_12Inheritance_P2_MultipleInheritance_WatchCasting_00.png" width="782" height="112" /></a></p>
<p>This shows us that:</p>
<ul>
<li>the address of<strong></strong><em><strong> </strong><strong>cTestDerived</strong></em> is 0x0048fa84&#8230;</li>
<li>&#8230; and the address of <em><strong>cTestDerived</strong> </em>cast to a pointer to <em><strong>CTestBaseOne</strong></em> has the same address, &#8230;</li>
<li>&#8230;but when the address of <em><strong>cTestDerived</strong></em> is cast to <em><strong>CTestBaseTwo</strong></em> we get 0x0048fa8c&#8230;</li>
<li>&#8230;which is the same value as <em><strong>[ebp-20h]&#8230;</strong></em></li>
<li>&#8230;or an 8 byte offset from the address of <em><strong>cTestDerived&#8230;</strong></em></li>
<li><em><strong></strong></em>&#8230;which is the offset of <em><strong>CTestBaseTwo</strong></em> within <em><strong>CTestDerived</strong></em></li>
</ul>
<p>&nbsp;</p>
<h2>Should this be surprising?</h2>
<p>Here&#8217;s the memory layout of <em><strong>CTestDerived </strong></em>again:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="txt" style="font-family:monospace;">1&gt;  class CTestDerived	size(24):
1&gt;  	+---
1&gt;  	| +--- (base class CTestBaseOne)
1&gt;   0	| | _iA
1&gt;   4	| | _iB
1&gt;  	| +---
1&gt;  	| +--- (base class CTestBaseTwo)
1&gt;   8	| | _iC
1&gt;  12	| | _iD
1&gt;  	| +---
1&gt;  16	| _iE
1&gt;  20	| _iF
1&gt;  	+---</pre></td></tr></table></div>

<p>Since we know that:</p>
<ul>
<li>(within non-static member functions) member variables are accessed via constant offsets from their <em><strong>this</strong> </em>pointer</li>
</ul>
<ul>
<li>the memory for <em><strong>CTestBaseTwo</strong></em> starts at an offset of 8 bytes from the start of the memory layout of an instance of <em><strong>CTestDerived</strong></em></li>
</ul>
<p>it follows that <em><strong>CTestBaseTwo::SumBaseTwo()</strong></em> wouldn&#8217;t work if the compiler passed the address of an instance of <em><strong>CTestDerived </strong></em>because the constant offsets used to access the members of <em><strong>CTestBaseTwo</strong></em> would be off by 8 bytes.</p>
<p>Consequently, any time a <em><strong>CTestBaseTwo</strong></em> member function is called on an instance of <em><strong>CTestDerived</strong></em> the compiler must ensure that a compatible this pointer is generated<em><strong> </strong></em>to pass to the function - i.e. pointing at the start address of <em><strong>CTestBaseTwo </strong></em>within<strong> </strong>the instance of <em><strong>CTestDerived.</strong></em></p>
<p>Frighteningly obvious once you know isn&#8217;t it?</p>
<p>I honestly don&#8217;t think it should be surprising though &#8211; given the way that we know data within user defined types is accessed at the assembly level (see <a href="http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/">part 10</a>), it pretty much had to work like this.</p>
<p>&nbsp;</p>
<h2>&#8230;one more little thing</h2>
<p>In the example above, <em><strong>cTestDerived</strong> </em>is a <a href="http://www.altdevblogaday.com/2011/12/14/c-c-low-level-curriculum-part-3-the-stack/">Stack</a> variable &#8211; so the compiler knows exactly where it is located in the current <a href="http://www.altdevblogaday.com/2011/12/14/c-c-low-level-curriculum-part-3-the-stack/">Stack Frame</a>.</p>
<p>This means that the compiler can calculate the address of the instance of <em><strong>CTestBaseTwo</strong></em> within <em><strong>cTestDerived</strong></em> at compile time, and can therefore access it at no extra cost compared to any other Stack variable.</p>
<p>We should probably check whether this is this any different when we&#8217;re dealing with a pointer to a <em><strong>CTestDerived </strong></em>at an arbitrary point in memory, just to be thorough.</p>
<p>Luckily I have already thought of this :)</p>
<p>If you place a breakpoint on the return statement of <em><strong>CTestDerived::SumDerived</strong></em><strong> </strong> you can check the disassembly yourself, but here are the relevant lines from my disassembly window:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;">   <span style="color: #ff0000;">52</span><span style="color: #339933;">:</span>     <span style="color: #00007f; font-weight: bold;">int</span> SumDerived<span style="color: #009900; font-weight: bold;">&#40;</span> void <span style="color: #009900; font-weight: bold;">&#41;</span>
    <span style="color: #ff0000;">53</span><span style="color: #339933;">:</span>     <span style="color: #009900; font-weight: bold;">&#123;</span>
<span style="color: #adadad; font-style: italic;">001010A0</span>  <span style="color: #00007f; font-weight: bold;">push</span>        <span style="color: #46aa03; font-weight: bold;">esi</span>  
<span style="color: #adadad; font-style: italic;">001010A1</span>  <span style="color: #00007f; font-weight: bold;">mov</span>         <span style="color: #46aa03; font-weight: bold;">esi</span><span style="color: #339933;">,</span><span style="color: #46aa03; font-weight: bold;">ecx</span>  
<span style="color: #adadad; font-style: italic;">001010A3</span>  <span style="color: #00007f; font-weight: bold;">push</span>        <span style="color: #46aa03; font-weight: bold;">edi</span>  
    <span style="color: #ff0000;">54</span><span style="color: #339933;">:</span>         return SumBase<span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #009900; font-weight: bold;">&#41;</span> <span style="color: #339933;">+</span> SumBaseTwo<span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #009900; font-weight: bold;">&#41;</span> <span style="color: #339933;">+</span>_iE <span style="color: #339933;">+</span> _iF<span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">001010A4</span>  <span style="color: #00007f; font-weight: bold;">lea</span>         <span style="color: #46aa03; font-weight: bold;">ecx</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">esi</span><span style="color: #339933;">+</span><span style="color: #ff0000;">8</span><span style="color: #009900; font-weight: bold;">&#93;</span>  
<span style="color: #adadad; font-style: italic;">001010A7</span>  <span style="color: #00007f; font-weight: bold;">call</span>        CTestBaseTwo<span style="color: #339933;">::</span>SumBaseTwo <span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #ff0000;">101050h</span><span style="color: #009900; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<p>As you should be able to see by now, the code in this function is adding a constant offset of 8 bytes onto the this pointer it is passed to generate the this pointer it is passing to <em><strong>CTestBaseTwo::SumBaseTwo</strong></em></p>
<p>If you&#8217;re having trouble seeing it, remember that the &#8216;<em>thiscall</em>&#8216; win32 member function calling convention uses <em><strong>ecx</strong> </em>to pass the <em><strong>this</strong> </em>pointer.</p>
<p>Most significantly, looking back to the <a href="http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/">last post</a>, we can see that this is essentially the same way that member variables of user defined types are accessed when we had a pointer to an instance of  a user defined type &#8211; in fact, <em>at the level of the assembly code</em>, <em>there is really no difference between a member variable and a base class</em>; this distinction is really only meaningful at the level of the C++ code.</p>
<p>We now also know that multiple inheritance can cause your code a small additional cost in pointer arithmetic when calling member functions of any of its base types that has a non-zero offset within its memory layout.</p>
<p>&nbsp;</p>
<h2>What was that earlier? about declaration order?</h2>
<p>If you&#8217;re paying attention, you should have noticed that when we looked at the memory layout of <em><strong>CTestDerived </strong></em>I mentioned in passing that the ordering of  <em><strong>CTestBaseOne</strong></em> and <em><strong>CTestBaseTwo </strong></em>within it matches the textual order they were listed in its base-specifier-list.</p>
<p>This is obviously significant, since it implies that if the textual order in which <em><strong>CTestBaseOne</strong></em> and <em><strong>CTestBaseTwo </strong></em>are listed changes, then the memory layout of <em><strong>CTestDerived </strong></em>will change to reflect this.</p>
<p>If you swap the order of <em><strong>CTestBaseOne</strong></em> and <em><strong>CTestBaseTwo </strong></em>around here&#8217;s the memory layout printed during the build process:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="txt" style="font-family:monospace;">1&gt;  class CTestDerived	size(24):
1&gt;  	+---
1&gt;  	| +--- (base class CTestBaseTwo)
1&gt;   0	| | _iC
1&gt;   4	| | _iD
1&gt;  	| +---
1&gt;  	| +--- (base class CTestBaseOne)
1&gt;   8	| | _iA
1&gt;  12	| | _iB
1&gt;  	| +---
1&gt;  16	| _iE
1&gt;  20	| _iF
1&gt;  	+---
1&gt;</pre></td></tr></table></div>

<p>Given what we have discovered so far, we can see that this new memory layout means that <em><strong>CTestDerived</strong> </em>can now be treated as an instance of <em><strong>CTestBaseTwo</strong></em>.</p>
<p>We can also see that with this new layout, the compiler would need to adjust <em><strong>CTestDerived</strong> </em>pointers in order to call <em><strong>CTestOne</strong> </em>functions.</p>
<p>I leave it as an exercise for you, o budding expert reader of x86 disassembly, to check this for yourself :)</p>
<p>&nbsp;</p>
<h2>Aside: construction and destruction with single inheritance</h2>
<p>Something we entirely skipped past in last post was construction and destruction of inherited types.</p>
<p>This was intentional &#8211; construction and destruction behaviour is straightforward with single inheritance.</p>
<p>We all should know the expected high level behaviour for single inheritance (of arbitrary depth) - in summary:</p>
<ul>
<li>each constructor calls the constructor of its base class before it does the work of its own function definition &#8211; i.e. classes are constructed in order &#8221;<em>from inside to out</em>&#8221; or &#8220;<em>least to most derived</em>&#8220;.</li>
<li>destructors do the opposite, each destructor does its own work before calling the destructor of its base class &#8211; i.e. classes are destructed in order &#8220;<em>from outside to in</em>&#8221; or &#8220;<em>most to least derived</em>&#8220;.</li>
</ul>
<p>The disassembly matches the high level behaviour in a very straightforward way and I leave it as an exercise for the reader to step through the disassembly of construction &amp; destruction in some test code to see this in action.</p>
<p>Like the rest of the behaviour we&#8217;ve discovered so far, when you think about it, it&#8217;s actually pretty obvious that this sort of &#8216;stack-like&#8217; construction / destruction behaviour is required in order to make inheritance work correctly.</p>
<p>&nbsp;</p>
<h2>Construction and destruction with multiple inheritance</h2>
<p>It was pretty obvious that we were coming to this, right?</p>
<p>What happens with construction and destruction when multiple inheritance is involved is less simple.</p>
<p>For example, what order do the constructors of multiple base classes get called in? &#8230; and what order do their destructors get called in?</p>
<p>We also assume that &#8211; since the constructor and destructor are member functions &#8211; there must be some fiddling with this pointers during this process too.</p>
<p>Luckily, this is very easy to empirically determine: we can just add some text output into the constructors and destructors of the sample classes to print the name of the function and the value of their <em><strong>this </strong></em>pointer.</p>
<p>Here&#8217;s a <a href="http://www.altdevblogaday.com/wp-content/uploads/2013/05/ADBAD_CCPPLLC_12_01.zip">link to a VS2010 project I prepared earlier to do just that</a>, I&#8217;ve just added a little extra code to the original example code.</p>
<p>Below is the command line output produced when it is run:</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/05/CCPPLLC_12Inheritance_P2_ConDestructionThisPointerFixing00.png"><img class="alignnone  wp-image-29450" alt="CCPPLLC_12Inheritance_P2_ConDestructionThisPointerFixing00" src="http://www.altdevblogaday.com/wp-content/uploads/2013/05/CCPPLLC_12Inheritance_P2_ConDestructionThisPointerFixing00.png" width="569" height="287" /></a></p>
<p>You can see that:</p>
<ul>
<li>constructors are called in the textual order they appear in the class declaration for <strong><em>CTestDerived</em></strong> - from least derived (i.e. <strong><em>CTestBaseOne</em></strong>) to most (<strong><em>CTestDerived</em></strong>).</li>
</ul>
<ul>
<li>destructors are called in the opposite order &#8211; this is to ensure that work done in the constructors is un-done in the opposite order.</li>
</ul>
<ul>
<li>this also shows that the <em><strong>this</strong> </em>pointers are changed for the constructor and destructor of <em><strong>CTestBaseTwo</strong></em> just as they did when we were calling regular member functions</li>
</ul>
<p>At this point you should feel free to swap around the order of <em><strong>CTestBaseOne</strong></em> and <em><strong>CTestBaseTwo</strong></em> in <em><strong>CTestDerived</strong></em>&#8216;s base-specifier-list to check that construction and destruction follow the same rules as the ordering of base types in derived type&#8217;s memory layout (they do, I promise).</p>
<p>&nbsp;</p>
<h2>Summary</h2>
<p>That&#8217;s it for this time and it was massive! I bet you&#8217;re glad I split this off from post 11 now :)</p>
<p>The astute amongst you will have noticed that we have not looked at any code using the keyword <em><strong>virtual. </strong></em>This is entirely deliberate, and that&#8217;s for next time.</p>
<p>So, let&#8217;s recap what we&#8217;ve discovered so far about inheritance&#8230;</p>
<p>First, what we learned about single inheritance in <a href="http://www.altdevblogaday.com/2013/05/03/cc-low-level-curriculum-part-11-inheritance/">part 11</a>:</p>
<p style="padding-left: 30px;">1) We know that the memory layout of user defined types is fixed at compile time&#8230;</p>
<p style="padding-left: 30px;">2) &#8230;and so code accessing a data member of a user defined type can use a constant offset relative to the start address of an instance of the type (see <a href="http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/">part 10</a>).</p>
<p style="padding-left: 30px;">3) In single inheritance, the memory layout of a derived type <em><strong>D</strong></em> literally extends that of its base type <em><strong>B.</strong></em></p>
<p style="padding-left: 30px;">4) This ensures that the inherited members of <em><strong>B</strong></em> are at the same constant offsets relative to the start address of an instance of <em><strong>D</strong></em> as they would be relative to the start address of an instance of <em><strong>B</strong></em>&#8230;</p>
<p style="padding-left: 30px;"><em><strong></strong></em>5) &#8230;which means that a pointer to an instance of type <em><strong>D</strong> </em>can safely be treated as a pointer to an instance of type <em><strong>B</strong></em>&#8230;</p>
<p style="padding-left: 30px;">6) &#8230;which in turn guarantees that member functions of type <em><strong>B</strong></em> can safely be called on instances of type <em><strong>D.</strong></em></p>
<p>&nbsp;</p>
<p>We&#8217;ve also discovered that if a derived class <em><strong>D</strong></em> class inherits from multiple base types <em><strong>A</strong></em> and <em><strong>B</strong></em>, then this multiple inheritance breaks the convenience of the single inheritance approach somewhat:</p>
<p style="padding-left: 30px;">7) As with single inheritance, the memory layout of an instance of <em><strong>D</strong></em> contains the member data of both <em><strong>A</strong></em> and <em><strong>B</strong></em>, laid out exactly as it was in each base class.</p>
<p style="padding-left: 30px;">8) Member functions of both type <em><strong>A</strong> </em>and type <em><strong>B</strong> </em>will use constant offsets relative to the their this pointers to access their data members.</p>
<p style="padding-left: 30px;">9) Logically; only either <em><strong>A</strong></em> or <em><strong>B</strong></em> may have an offset of 0 bytes within the memory layout of an instance of <em><strong>D</strong></em>&#8230;</p>
<p style="padding-left: 30px;">10) &#8230; consequently a pointer to an instance of type <em><strong>D</strong></em> can only be safely treated as a pointer to whichever of <em><strong>A</strong> </em>or <em><strong>B</strong></em> has a 0 byte offset within its memory layout</p>
<p style="padding-left: 30px;">11) Which base type has a 0-byte offset is determined by the textual ordering of the <em><strong>A</strong></em> and <em><strong>B</strong></em> types within the base-specifier-list of <em><strong>D</strong></em>&#8216;s class declaration</p>
<p style="padding-left: 30px;">12) &#8230;if <em><strong>A</strong></em> were at the 0 byte offset within <em><strong>D</strong></em>, the compiler would need to calculate a compatible &#8216;this&#8217; pointer whenever a member function of <em><strong>B</strong></em> called on an instance of <em><strong>D </strong></em>(and vice versa)</p>
<p style="padding-left: 30px;">13) &#8230;when an instance of <strong><em>D</em></strong> is created, the instances of <em><strong>A</strong></em> and <em><strong>B</strong></em> contained within its memory layout will be constructed by their own constructors before the constructor for <em><strong>D</strong> </em>is called, and&#8230;</p>
<p style="padding-left: 30px;">14) &#8230;the order in which <em><strong>A</strong> </em>and <em><strong>B</strong></em> are constructed depends on their textual ordering within the base-specifier-list in <em><strong>D</strong></em>&#8216;s class declaration (i.e. they will be constructed in memory offset order).</p>
<p>&nbsp;</p>
<h3 style="padding-left: 30px;">Disclaimer</h3>
<p style="padding-left: 30px;">The above numbered bullet points are facts we have discovered empirically by examining the behaviour of win32 x86 code created by the Visual Studio 2010 compiler.</p>
<p style="padding-left: 30px;">Do not assume that code generated by other platforms / compilers will behave identically. It should behave very similarly, but you should check.</p>
<p style="padding-left: 30px;">In general, for any <a href="http://en.wikipedia.org/wiki/C%2B%2B11#Modification_to_the_definition_of_plain_old_data">POD type</a> you should be able to save out its memory to file as binary and load it back into the memory of a different instance of the same type.</p>
<p style="padding-left: 30px;">Obviously, this will hold true <a href="http://en.wikipedia.org/wiki/If_and_only_if">iff</a> you don&#8217;t change target platform, compiler, compiler options, alignment specifications, or the declaration of the type.</p>
<h3 style="padding-left: 60px;"></h3>
<h3 style="padding-left: 30px;">Thanks</h3>
<p style="padding-left: 30px;">Thanks for peer review go out to Bruce Dawson and Amir Embrahimi; and for general #altdevblogaday admin assistance to Luke Dicken.</p>
<p>&nbsp;</p>
<h2>Appendix: What does the C++ standard have to say about all this?</h2>
<p>I spent some time reading the C++11 ISO standard (or a near final revision of it at least), but even after consulting the source it is not 100% clear to me exactly what is and what isn&#8217;t guaranteed by the standard &#8211; see the below for more information.</p>
<p><span style="font-size: 13px;">Below is a collection of snippets of  information I found in </span><a style="font-size: 13px;" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf">this near-final draft of the ISO C++ 11 standard</a><span style="font-size: 13px;"> document  when I was looking up various bits for this post (you have to pay ANSI for the actual one!). </span></p>
<p><span style="font-size: 13px;">If you want more information on any of the points below, click the link above to download the .pdf and search for the indented text &#8211; that will get you to the page it was on. This document does not make for light reading!</span></p>
<p>&nbsp;</p>
<h3><strong>1. Ordering of base classes in memory within a multiply inherited class.</strong></h3>
<p>As far as I can tell, this is not guaranteed by the standard &#8211; in fact the draft standard says this:</p>
<p style="padding-left: 30px;"><strong>10.1 Multiple base classes [class.mi]</strong><br />
1 A class can be derived from any number of base classes. [Note: The use of more than one direct base class<br />
is often called multiple inheritance. — end note ] [Example:<br />
class A { /∗ ... ∗/ };<br />
class B { /∗ ... ∗/ };<br />
class C { /∗ ... ∗/ };<br />
class D : public A, public B, public C { /∗ ... ∗/ };<br />
— end example ]</p>
<p style="padding-left: 30px;">2 [Note: The order of derivation is not signiﬁcant except as speciﬁed by the semantics of initialization by<br />
constructor (12.6.2), cleanup (12.4), and storage layout (9.2, 11.1). — end note ]</p>
<p>which more or less says that it&#8217;s not guaranteed.</p>
<p>&nbsp;</p>
<h3><strong>2. Ordering of data members within a class.</strong></h3>
<p>So, it appears that a C++ compiler <em><strong>is</strong> </em>allowed to reorder data members of a class in memory vs. their textual declaration order if (and only if) their access control (i.e. public, private, protected) is different:</p>
<p style="padding-left: 30px;"><strong>15</strong> Nonstatic data members of a (non-union) class with the same access control (Clause 11) are allocated so that later members have higher addresses within a class object. The order of allocation of non-static data members with diﬀerent access control is unspeciﬁed (11). Implementation alignment requirements might cause two adjacent members not to be allocated immediately after each other;</p>
<p>I can&#8217;t imagine this would ever be a problem for you unless you&#8217;re writing a reflection library or similar.</p>
<p>&nbsp;</p>
<p><strong>3. Ordering of constructor calls when constructing types with base types</strong></p>
<p>Thankfully, there does appear to be some sanity remaining in the universe; as I managed to find the part of the standard that specifies the order in which constructors are called for types that use inheritance:</p>
<p style="padding-left: 30px;">In a non-delegating constructor, initialization proceeds in the following order:<br />
— First, and only for the constructor of the most derived class (1.8), virtual base classes are initialized in the order they appear on a depth-ﬁrst left-to-right traversal of the directed acyclic graph of base classes, where “left-to-right” is the order of appearance of the base classes in the derived class base-speciﬁer-list.<br />
— Then, direct base classes are initialized in declaration order as they appear in the base-speciﬁer-list (regardless of the order of the mem-initializers).<br />
— Then, non-static data members are initialized in the order they were declared in the class deﬁnition (again regardless of the order of the mem-initializers).<br />
— Finally, the compound-statement of the constructor body is executed.<br />
[Note: The declaration order is mandated to ensure that base and member subobjects are destroyed in the<br />
reverse order of initialization. — end note ]</p>
<p>TL;DR &#8211; (if you are not using virtual base classes) each constructor initialises its base classes in declaration order, then the class members in declaration order, then the constructor&#8217;s body is executed called.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/05/22/cc-low-level-curriculum-part-12-multiple-inheritance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Life can be better (part 2 of 3)</title>
		<link>http://www.altdevblogaday.com/2013/05/19/life-can-be-better-part-2-of-3/</link>
		<comments>http://www.altdevblogaday.com/2013/05/19/life-can-be-better-part-2-of-3/#comments</comments>
		<pubDate>Sun, 19 May 2013 21:34:24 +0000</pubDate>
		<dc:creator>Amir Ebrahimi</dc:creator>
				<category><![CDATA[General Interest]]></category>
		<category><![CDATA[burnout]]></category>
		<category><![CDATA[crunch]]></category>
		<category><![CDATA[depression]]></category>
		<category><![CDATA[health]]></category>
		<category><![CDATA[nutrition]]></category>
		<category><![CDATA[quality of life]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29418</guid>
		<description><![CDATA[<p dir="ltr">In the <a href="http://www.altdevblogaday.com/2013/04/22/life-can-be-better-part-1-of-3/">previous article</a>, I set the context of a personal journey of health within the backdrop of larger issues of quality of life in our industry. In this article, I continue that journey with my own personal experience of burnout and depression and what it took me to regain my own health, vitality, and enthusiasm for the work that we all do. My personal wish is to not see any more <a href="http://mashable.com/2013/01/15/aaron-swartz-tech-world-depression/">bright</a>, <a href="http://dreadfulblog.wordpress.com/2012/11/25/remembering-matt-hughes-depression-in-the-games-industry/">creative</a> people <a href="http://indiegames.com/2013/04/dealing_with_depression_during.html">suffer</a> from work-related stress. Extended stress has odd effects on both the <a href="http://www.nimh.nih.gov/health/publications/stress/fact-sheet-on-stress.shtml">body</a> and the <a href="http://www.rockefeller.edu/labheads/mcewen/stressEffects.php">mind</a>.</p>
<p><a href="http://www.altdevblogaday.com/2013/05/19/life-can-be-better-part-2-of-3/" class="more-link">Read more on Life can be better (part 2 of 3)&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p dir="ltr">In the <a href="http://www.altdevblogaday.com/2013/04/22/life-can-be-better-part-1-of-3/">previous article</a>, I set the context of a personal journey of health within the backdrop of larger issues of quality of life in our industry. In this article, I continue that journey with my own personal experience of burnout and depression and what it took me to regain my own health, vitality, and enthusiasm for the work that we all do. My personal wish is to not see any more <a href="http://mashable.com/2013/01/15/aaron-swartz-tech-world-depression/">bright</a>, <a href="http://dreadfulblog.wordpress.com/2012/11/25/remembering-matt-hughes-depression-in-the-games-industry/">creative</a> people <a href="http://indiegames.com/2013/04/dealing_with_depression_during.html">suffer</a> from work-related stress. Extended stress has odd effects on both the <a href="http://www.nimh.nih.gov/health/publications/stress/fact-sheet-on-stress.shtml">body</a> and the <a href="http://www.rockefeller.edu/labheads/mcewen/stressEffects.php">mind</a>.</p>
<p dir="ltr"><em>NOTE: Please consult with a health professional before making any changes with your own health. I am certainly not a doctor and will assume that you are an adult that will ultimately be responsible for his or her own health. I’ve done my best to portray this post as personal truth and not accepted science. I realize that every person’s body is different and therefore may respond differently to a specific health regimen.</em></p>
<p dir="ltr"><strong>Background</strong></p>
<p dir="ltr">I grew up playing role-playing games (RPGs) like other hackers, geeks, nerds, and escapists out there. However, fantastical worlds like that of Dungeons &amp; Dragons didn&#8217;t grab my interest as much as sci-fi did. Although I remember getting lost in the dark, gritty world of Shadowrun on my Super Nintendo (based on the RPG), for some reason I chose Cyberpunk 2.0.2.0. (a different RPG) when it came time to run a campaign. I loved the idea of a futuristic world where man and machine could meld. Through Cyberpunk, I became acquainted with the use of the term “meat,” crassly used to describe the human body. “Cyberspace” was the place where netrunners existed, while their &#8220;meat&#8221; resided in &#8220;meat-space,&#8221; otherwise known as the physical world. Essentially, a netrunner could bring consciousness into an alternate world without reliance on the body.</p>
<p>I connected with Cyberpunk as a teenager mainly because of my growing interest in computers. As I tried to figure things out with computers, I found that my mind gravitated towards combing through my thoughts to better process them, as a memory manager might do to defragment allocations. I also found that I was entertained simply with thought itself, traversing different paths to see where my mind would end up. I realize that these behaviors are what primarily distinguish introversion from extroversion and as a result, believe that they lend the identification of self to the thoughts and processing of the brain. Instead of “I am what I can do” it becomes “I am what I can think”. I also think that those same behaviors help us become better software engineers. Even though I enjoyed skateboarding, football, baseball, paintball, and other physical activities, I somehow managed early on to form a mental model where the brain/mind and body had little, if nothing at all, to do with each other.</p>
<p>Oddly enough, my naivety around health later in life didn’t stray far from that teenage fascination with cyber-augmented posthumanism. In the last article, I mentioned that after starting to work out w/ co-workers at lunch, I was able to get into the best physical shape that I had been in since high school football (hey, in Alabama, we did two-a-days). Unfortunately, even with having increased strength, my energy, mood, and mental health were declining. At age 25, I thought that health had more to do with the way I looked than how I felt. In all honesty, I’d rather have a sexy mind rather than trying to look sexy. Well, during the summer of 2005, in the midst of my third extended crunch for a console game, I finally hit rock bottom and decided that I needed help.</p>
<p dir="ltr"><strong>Depression</strong></p>
<p dir="ltr">I used to think that it was shameful to talk about depression and/or any mental impairment. I believed that this was one thing that I was supposed to figure out on my own. In my judgment, sitting with shame around depression let me run circles around questions of “Why?”, rather than looking at the “What?”. As I wrote in my previous article, I did notice the warning signs of feeling chronically tired, feeling “heavy” to move around even though I wasn’t grossly overweight, and starting to think that most things I had to get done were weighty tasks. For me, this was a dramatic change from how I remember feeling when I got my first internship in the industry. I went to a general practitioner for a check up and when the blood work came back inconclusive I decided that I just had to push on. I continued that way until things got worse and I didn’t know what else to do, so I finally decided to see a psychologist.</p>
<p dir="ltr">According to the National Institute of Mental Health (NIMH), “<a href="http://www.nimh.nih.gov/health/publications/depression/what-causes-depression.shtml">depression is caused by a combination of genetic, biological, environmental, and psychological factors</a>”. In other words, we don’t quite know the causes. Trying to answer those questions of “Why do I feel this way?” or “How did I come to this place?” resulted in many years of sitting with different psychologists. I think a good psychologist can provide temporary help to calm acute anxiety or depression with talk-therapy, but dialogue is less useful at resolving any root physiological cause(s) of emotional disturbance when they exist. While I’ll agree that psychotherapy has its own benefit to healing emotional wounds and looking at long-standing issues, on a practical level of my day-to-day experience it didn’t provide the answers.</p>
<p dir="ltr">Let’s be clear about one thing: I am not saying that stress in our industry causes depression for everyone. Some level of stress is actually <a href="http://en.wikipedia.org/wiki/Yerkes%E2%80%93Dodson_law">healthy in helping us to achieve our goals</a>. Chronic stress, on the other hand, seems to show up in <a href="http://www.nimh.nih.gov/news/science-news/2009/research-shows-how-chronic-stress-may-be-linked-to-physical-and-mental-ailments.shtml">different ways for different people</a>. Separate from major health problems, I have seen stress have impact in minor ways, too, such as frequent irritability or negativity, relationship problems, or motivational challenges to name a few. What I can say is that, at the time I experienced depression, I was working more (including weekends), sleeping less, had little time to socialize, and eating outside for most of my meals if not skipping them altogether. My worst night was working until 6 am on a build that we had to send off to magazine reviewers and being asked to come back in around 10 am. Most crunches I experienced at different companies from 2003-2008 lasted for more than 4 months out of the year. Even though there was some time off and a slower pace following the release of a game, somehow my batteries were not getting recharged.</p>
<p>Moving past the shame allowed me to see the questions of “What can I do?”. Well, in parallel with psychotherapy, I also met with a psychiatrist to hear another point of view. I worked through different SSRIs, SNRIs, and anti-anxiety medications; battling different side-effects in an effort to find the “right one for me”. My judgment of these drugs are that they can work as a crutch, but in the same way that caffeine can keep me operating out of touch with my natural energy levels. The drugs provided relief and got me back on my feet, however, in the end they pale in comparison to my current experience at a holistic level.</p>
<p>When I experienced depression, it was damn near impossible to distinguish that <em><strong>I was not my thoughts</strong></em>. At work, I was unhappy with most of what I was tasked with doing, irritable with requests from others, not motivated to get my work done, and negatively thinking about what the company was doing and the manner in which we were doing it. Now, I’m not saying that some form of each of those thoughts/feelings/behaviors aren’t welcome in order to alert me to doing or suggesting something better. However, preponderance of these thoughts/feelings/behaviors as my M.O. led me to believe that I am a negative, unhappy, and unmotivated person. My invitation to you if you’re in that space: don’t draw conclusions there. From my experience, I can attribute more of the ways I was thinking at that point in my life to my overall physical health.</p>
<p>After experiencing a gradual decline in my state of being over the years, I realize now what negligence towards health in the face of stress has afforded me. I also carry deep concern for any others that, like me, are/were not as well equipped to deal with stress. As an employer, I think it is ever important to protect our employees from burnout. In the process of learning about my own health, I’ve come to a rudimentary understanding of how stress works in the body.</p>
<p dir="ltr"><strong>Stress</strong></p>
<p dir="ltr">The PAT (pituitary-adrenal-thyroid) axis is an important system that regulates the hormones in the body in order to keep the body in balance. I think of them as good friends who have my back during good and bad times (regulators, mount up!). When stress comes and goes, each gland does their part. Everything I encounter in the day impacts my PAT axis from my alarm clock in the morning to the traffic on the way to work to the tasks I’m trying to complete on any given day. Additionally, how I <em>choose to react</em> to those stressors can also tax my system. All of these stressors deplete the stores of hormones and endorphins in my body, which is why I&#8217;m sometimes exhausted by the end of the day and not able to handle much more. The food I eat helps replenish what has been used after being digested and synthesized into what the body needs. However, under chronic stress the body is producing elevated and continued levels of hormones and endorphins in an attempt to keep the body in balance. Unfortunately, the immune and digestive systems are suppressed, among other things that are affected, which can lead to a non-optimal state for both energy absorption and <em>perception</em> of well-being.</p>
<p>I mentioned perception in the previous article because I wanted to allude to the possibility of being stuck in a fearful, anxious, doubtful, exhausted, etc. state that elevated stress levels can help bring about. To put this in perspective, I consider what happens when adrenaline rushes through my body and how much my thinking can change in the moment. I’ve experienced this while driving when I am in a happy, easy-going mood and with a flash of a potentially dangerous situation with another car I have both a physical and emotional/mental reaction. The world I was seeing as beautiful only moments ago has now become “out to get me.” In a similar way, I see elevated levels of stress having effects on my perception of how I’m performing, the relevance or efficacy of what I’m working on, how others are doing, and so on.</p>
<p dir="ltr"><strong>Beyond Depression</strong></p>
<p dir="ltr">Even though I got back on my feet eventually, I somehow never felt as good as I did when I entered the industry. I no longer felt terribly bad, but I didn’t feel energized or great either. Unrelated to energy levels, stress, depression, or any other things I’ve spoken to already, about a year and a half ago I had started working with a nutritionist in preparation for a surgery. The belief was that I would have a quicker recovery from the surgery if I was in a healthier state. So, laughably now, I considered “getting healthy” as something I’d do for a short while up until the surgery. Gradually, I changed my diet, started drinking more water (which was up from almost none at all), reduced my caffeine intake, took tailored supplements and started to feel radically different in the first three months. I think it is more a testament to the shoddy state I was in more than any one thing that I was doing in particular. I started noticing that when I woke up I had energy to boot and was ready to take on the day. I also noticed that my brain function seemed to change. I no longer would get stuck worrying about something incessantly. My brain processing was becoming razor sharp again and my focus improved. When I started to feel the anxiety that I carried around ease up and become more manageable, I became dumbfounded. I realized only after feeling much better that the one question I recall none of the health professionals asking me from 2005 all the way up until 2011: what was I actually eating?</p>
<p dir="ltr"><strong>Food for Thought (and Energy!)</strong></p>
<p dir="ltr">If I try to remember what my meals looked like when I started working professionally in 2003 (and to some extent all the way back to 1999 at GaTech) up until a year and a half ago:</p>
<p dir="ltr"><em>Breakfast</em></p>
<p dir="ltr"><em></em>Cereal w/ milk, muffin, or bagel w/ peanut butter or almond butter; pancakes or eggs, bacon on the weekends</p>
<p><em>Lunch</em></p>
<p dir="ltr">Usually Mexican/Indian/Thai food (varied over the years depending on where I was working), burger w/ fries, occasional salad, sandwich with chips</p>
<p dir="ltr"><em>Dinner</em></p>
<p dir="ltr">If working late, then whatever food was brought in if the company catered; otherwise, whatever food was close around (likely the same places I ate at during lunch); or skipping dinner and eating some kind of snack at home later in the evening (usually another bowl of cereal or PBJ or whatever could be made quick)</p>
<p dir="ltr">When not working late &#8211; frozen pizzas or pre-packaged food that could be warmed up (sometimes in microwave, sometimes in oven, sometimes in saucepan); pasta w/ tomato sauce; mac and cheese; thai/indian take-out</p>
<p dir="ltr"><em>Fluids</em></p>
<p dir="ltr">Orange juice in the morning<br />
Coffee many times throughout the day, which also killed my appetite<br />
Very little water if none at all (would drink water during workout sessions)<br />
Occasional soda</p>
<p dir="ltr">Certainly anyone can look at this and say, yeah, that doesn’t look like the healthiest diet, but at first glance I wouldn’t think someone would say there was anything particularly wrong with it either. However, there is one thing that is missing in significant quantity &#8211; <em><strong>vegetables</strong></em>. There would rarely be any sort of vegetable or green on my plate unless it snuck onto the plate (luckily, Thai or Indian food usually has vegetables).</p>
<p dir="ltr">Fast forward to today and I now consume the following:</p>
<p dir="ltr"><em>Before breakfast</em></p>
<p dir="ltr">10 oz. of carrot juice (used to buy this in the store and then decided to simply buy my own 5 lb bags for the week and get a juicer); I recently started juicing the leftover stalks of whatever green I’ve been eating in addition to the carrot juice</p>
<p dir="ltr"><em>Breakfast</em></p>
<p dir="ltr">Two eggs, parsnips w/ cinnamon or seasoned cauliflower / rutabagas w/ diced onions + some sort of green sauteed in butter (chard, spinach, kale, or collard), two slices of toast</p>
<p dir="ltr"><em>Before lunch</em></p>
<p dir="ltr">I usually try to drink 1-2 quarts of water before lunch. I have a stainless steel water bottle that is close to a quart that I keep filled at my desk. I don’t usually have any liquids when I’m eating a meal to aid in digestion. I’ll drink something before or an hour after my meal.</p>
<p dir="ltr"><em>Lunch</em></p>
<p dir="ltr">Usually, this is some form of leftover from dinner the previous night(s) that I bring to work and warm up in a toaster oven. Occasionally, I eat something from around the office, but this was difficult initially because I find that most places don&#8217;t include fresh vegetables or greens with a good sized portion of protein</p>
<p dir="ltr"><em>Dinner</em></p>
<ul>
<li>
<p dir="ltr">Two small lamb loin chops (pan-fried, then broiled) w/ brussel sprouts (sauteed)</p>
</li>
<li>
<p dir="ltr">Ground lamb and sweet potato (steamed and mashed w/ butter) tacos w/ onions, garlic, and chard, collard greens, or kale (sauteed) in a brown rice or corn tortilla + additional sweet potato, onions, garlic, and greens on the side</p>
</li>
<li>
<p dir="ltr">Turkey burger w/ broccoli, cauliflower, beets (both gold and purple), or whatever else I have left in the fridge</p>
</li>
<li>
<p dir="ltr">Seasoned, baked chicken breast w/ blanched and then sauteed green beans</p>
</li>
<li>
<p dir="ltr">Turkey meatloaf w/ kale chips, baked cauliflower or turnips/rutabagas</p>
</li>
</ul>
<p dir="ltr"><em>Miscellany</em></p>
<ul>
<li>
<p dir="ltr">Occasionally, I mix whole grains in: brown rice, quinoa, millet</p>
</li>
<li>
<p dir="ltr">I’ll eat fish and beef occasionally</p>
</li>
<li>
<p dir="ltr">Dairy products come and go in my diet and when I do eat them I go for the whole fat, raw versions when available (or at least vat or low-heat pasteurized)</p>
</li>
<li>
<p dir="ltr">I’ll have fruits occasionally as a dessert or a snack</p>
</li>
</ul>
<p dir="ltr">All of these meals are makeable in about 30 minutes. When I am eating later than I like or have to run to Whole Foods to pick up groceries, then I’ll usually grab stuff from the hot food bar &#8212; again, loading up on vegetables; including ones that I don&#8217;t buy regularly, such as bok choy.</p>
<p dir="ltr">The key here is that I eat vegetables now in significant quantity due to the mix of vitamins and minerals present. Two-thirds of my plate will be vegetables and only a third will be a hand-sized amount of protein/fat (some vitamins that come from vegetables need fat to be absorbed) and occasionally some starch such as brown rice or quinoa. If I’m eating out somewhere, I’ll usually request for them to double whatever vegetables come on my plate.</p>
<p dir="ltr">My cupboard is bare for the most part &#8211; no more cereals, potato chips, dry pastas, crackers, etc.</p>
<p dir="ltr">My fridge is full of organic vegetables and meat.</p>
<p dir="ltr">I’m mindful of <a href="http://youtu.be/dBnniua6-oM">sugar</a>.</p>
<p dir="ltr">I cook with butter usually for breakfast and olive oil (on low/med heat; there are better oils for high heat) for all other meals.</p>
<p dir="ltr">I drink lots of water (3 quarts) and usually only water during the day (occasionally a kombucha or decaf tea) &#8212; not during meals.</p>
<p dir="ltr">I use a rice-cooker w/ a steam basket to steam most of my vegetables (quicker and easier than the stove top) &#8211; I bought one from a Japanese food store</p>
<p dir="ltr">I still enjoy an occasional coffee, sweets, pasta, pizza, etc. from time-to-time, however, the key is that I keep none of that in the house.</p>
<p dir="ltr">My grocery bill for the workweek is roughly $75 with some carry-over to the weekends. The most expensive items are meat, eggs, and carrots (because I’m buying those in 5 lb bags). Vegetables are for the most part cheap in their individual quantities.</p>
<p dir="ltr">I didn’t eat this way before because I considered food to be a nuisance. Even though I had enjoyed great meals in restaurants or cooked by others, I treated that as a luxury. My relationship with food was that I needed to be doing something else other than preparing a meal or taking time to enjoy it calmly. So, when I was hungry, my intention was simply to eat something as quick as possible and get back to what I was doing. One way I could characterize my prior understanding of food is that I could eat anything and produce anything. My new understanding is <em><strong>garbage in == garbage out</strong></em>. Now, that’s not entirely true because I know that I was still able to develop working code under extreme stress even though I was not eating well. However, I also know now that I was not producing at my optimal performance.</p>
<p dir="ltr">I see food as potential energy. Whatever food I am taking into my body is, ultimately, a stored form of energy from the sun. It goes through millions of chemical processes to reach the stage that it is at when I ingest it. That potential energy gets used either for physical or creative work. To me, <a href="http://www.npr.org/blogs/thesalt/2013/02/20/172403779/calorie-counts-fatally-flawed-or-our-best-defense-against-pudge">a calorie is no longer a calorie</a> and I don’t view things in a simple “bad” food vs “good” food dichotomy. I choose organic because I’m looking to <a href="http://www.ncbi.nlm.nih.gov/pubmed/11327522">maximize the nutrients</a> in my food, not simply because non-organic is “bad” (and yes, I’m aware that the term “organic” is prone to abuse in efforts for companies to make more money). I choose specific foods over others for the same reason. I prepare my food and use whole ingredients because I like knowing what I&#8217;m putting into my body.</p>
<p dir="ltr"><strong>Summary</strong></p>
<p dir="ltr">I could go on about a lot more things, such as how the body needs healthy levels of <a href="http://www.ncbi.nlm.nih.gov/pubmed/7903674">certain amino acids</a> and minerals for the optimal functioning of the brain, the glycemic index, or what foods are nutrient rich. However, the most valuable guiding strategy that I have learned from all of this is that nutrition is more about how I feel and less about how I look, which is why I misunderstood and took no interest. I knew that eating healthy was important; however, I had never experienced first-hand the effects, nor did I have a reason to. I think that nutrition is even more important than exercise and that physical activity comes naturally as an effect of having more potential energy in my body. My invitation to you is to find out what works for you. Become the patient observer. Pay attention to how you feel after meals. Notice what improves your moods. Take time to prepare your own food and enjoy it stress-free, so you can maximize the nutrients you are taking into your body. What motivates me to continue is twofold: I don’t want to go back to feeling the way I used to feel and, more importantly, I want to see what’s possible.</p>
<p dir="ltr">I&#8217;ll also add that everything isn’t perfect today. I get irritable at times. I wake up on the occasional morning and feel sluggish. I still battle with anxiety. I’m exhausted sometimes at the end of the day. I’m frustrated occasionally with the performance of my own work or with what we’re doing as a team. However, all of those things are blips now where before they were part of my routine, daily experience. Having a programming background, I simply see this as an optimization problem to figure out what can be done better. However, optimizing the human body is a bit more difficult than shaving cycles off of a routine. Maybe in a cyber-augmented posthuman world of the future, we’ll have the equivalent of a software profiler for the human body.</p>
<p dir="ltr">In the next article, I’ll shift focus to the changes I’ve made that impact how work gets done both at a studio and individual level, talk a bit about what I’ve changed in regards to sleep, some practical things I do to conserve willpower throughout the day, and tie up any loose ends with this series.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/05/19/life-can-be-better-part-2-of-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C/C++ Low Level Curriculum Part 11: Inheritance</title>
		<link>http://www.altdevblogaday.com/2013/05/03/cc-low-level-curriculum-part-11-inheritance/</link>
		<comments>http://www.altdevblogaday.com/2013/05/03/cc-low-level-curriculum-part-11-inheritance/#comments</comments>
		<pubDate>Fri, 03 May 2013 21:06:20 +0000</pubDate>
		<dc:creator>Alex Darby</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[education]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[low level]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29256</guid>
		<description><![CDATA[<p>Hello, and welcome to the 11th part of the C / C++ low level curriculum. About time? Definitely!</p>
<p><a href="http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/">Last time</a> we looked at the basics of User Defined Types: how structs, classes, and unions are laid out in memory; and (some of) the implications of memory alignment on this picture.</p>
<p><a href="http://www.altdevblogaday.com/2013/05/03/cc-low-level-curriculum-part-11-inheritance/" class="more-link">Read more on C/C++ Low Level Curriculum Part 11: Inheritance&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Hello, and welcome to the 11th part of the C / C++ low level curriculum. About time? Definitely!</p>
<p><a href="http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/">Last time</a> we looked at the basics of User Defined Types: how structs, classes, and unions are laid out in memory; and (some of) the implications of memory alignment on this picture.</p>
<p>In part 11 we&#8217;re going to look at how inheritance affects this picture, in particular the implications for memory layout of derived types and also for their behaviour during construction and destruction (<em><strong>note:</strong> </em>we&#8217;re leaving multiple inheritance and the keyword <em><strong>virtual</strong></em> out of this picture to start with).<span id="more-29256"></span></p>
<p>&nbsp;</p>
<h2>Before We Begin</h2>
<p>I will assume that you have already read the previous posts in the series, but I will also put in-line links to any important terms or concepts that you might need to know about to make sense of what you&#8217;re reading. I&#8217;m helpful like that.</p>
<p>Another big assumption I&#8217;m going to make is that you&#8217;re already very familiar with the C++ language and  comfortable using the language features we&#8217;re discussing, as well as the accepted usage limitations of those features etc. If I need to demonstrate anything out of the ordinary I&#8217;ll explain it &#8211; or at least link to an explanation.</p>
<p>In this series I discuss what happens with vanilla unoptimised win32 debug code generated by the VS 2010 compiler &#8211; whilst the specifics will differ on other platforms (and probably with other compilers) the general sweep of the code should be basically the same &#8211; because it&#8217;s assembly that has been generated by a C++ compiler &#8211; and so following the same examples given here with a source / disassembly debugger on your platform of choice should provide you with the same insights we get here.</p>
<p>With this in mind, in case you missed them, here are the backlinks to the previous posts in the series:</p>
<ol>
<li><a href="http://www.altdevblogaday.com/2011/11/09/a-low-level-curriculum-for-c-and-c/" rel="nofollow">http://altdevblogaday.com/2011/11/09/a-low-level-curriculum-for-c-and-c/</a></li>
<li><a href="http://www.altdevblogaday.com/2011/11/24/c-c-low-level-curriculum-part-2-data-types/" rel="nofollow">http://altdevblogaday.com/2011/11/24/c-c-low-level-curriculum-part-2-data-types/</a></li>
<li><a href="http://www.altdevblogaday.com/2011/12/14/c-c-low-level-curriculum-part-3-the-stack/">http://altdevblogaday.com/2011/12/14/c-c-low-level-curriculum-part-3-the-stack/</a></li>
<li><a href="http://www.altdevblogaday.com/2011/12/24/c-c-low-level-curriculum-part-4-more-stack/">http://altdevblogaday.com/2011/12/24/c-c-low-level-curriculum-part-4-more-stack/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/02/07/c-c-low-level-curriculum-part-5-even-more-stack/">http://altdevblogaday.com/2012/02/07/c-c-low-level-curriculum-part-5-even-more-stack/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/03/07/c-c-low-level-curriculum-part-6-conditionals/">http://altdevblogaday.com/2012/03/07/c-c-low-level-curriculum-part-6-conditionals/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/04/10/cc-low-level-curriculum-part-7-more-conditionals/">http://www.altdevblogaday.com/2012/04/10/cc-low-level-curriculum-part-7-more-conditionals/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/05/07/cc-low-level-curriculum-part-8-looking-at-optimised-assembly/">http://www.altdevblogaday.com/2012/05/07/cc-low-level-curriculum-part-8-looking-at-optimised-assembly/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/09/04/cc-low-level-curriculum-part-9-loops/">http://www.altdevblogaday.com/2012/09/04/cc-low-level-curriculum-part-9-loops/</a></li>
<li><a href="http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/">http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/</a></li>
</ol>
<p>I won&#8217;t lie &#8211; it&#8217;s not light reading :)</p>
<p>&nbsp;</p>
<h2>Class vs. Struct: a Gentle Reminder</h2>
<p>The C++ keywords struct and class define types that are identical in implementational detail and what you can do with them (the only difference being at the language level: the <em>default</em> access specifier if none is specified is <em>private</em> for class, and <em>public</em> for struct).</p>
<p>So, whilst I will be using the keyword <em><strong>class</strong></em> throughout this article please take it as read that anything we talk about here applies equally to types defined using the keyword <strong>struct</strong>.</p>
<p>&nbsp;</p>
<h2>What happens when we derive from another type?</h2>
<p>So, what <em>does</em> happen when you derive a user defined type from another non built-in type?</p>
<p>Clearly the data members you specify in the declarations have to go somewhere, and so do all those specified in the type(s) you are deriving from.</p>
<p>At the level of C++ there is nothing other than the standard to tell you how this works &#8211; and nothing other than looking at what happens with the code generated by the compiler you are using will tell you for definite.</p>
<p>As in the last post, we will be relying heavily on the frankly awesome secret 007 compiler flag /d1reportSingleClassLayout in order to tell us exactly how the (Visual Studio 2010 win32 x86) compiler has decided to lay our example structures out in memory.</p>
<p>It&#8217;s about time to look at some example code, so, rather than have you go through the usual rigmarole of setting up your project I have kindly set one up for you.</p>
<p>The zip file <a href="http://www.altdevblogaday.com/wp-content/uploads/2013/05/ADBAD_CCPPLLC_11_00.zip">in this link</a> contains a VS2010 solution with a single project and .cpp file lovingly set up to run the code shown below, which is in <em><strong>00_Inheritance.cpp</strong></em></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
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">class CTestBase
<span style="color: #009900;">&#123;</span>
public<span style="color: #339933;">:</span>
    <span style="color: #993333;">int</span> _iA<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> _iB<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
class CTestDerived
<span style="color: #339933;">:</span> public CTestBase
<span style="color: #009900;">&#123;</span>
public<span style="color: #339933;">:</span>
    <span style="color: #993333;">int</span> _iC<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> _iD<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When you compile this project you should get the following in your &#8220;Build&#8221; output window (the magic of /d1reportSingleClassLayout!) :</p>
<pre>1&gt; class CTestBase size(8):
1&gt;   +---
1&gt; 0 | _iA
1&gt; 4 | _iB
1&gt;   +---
1&gt; 
1&gt; class CTestDerived size(16):
1&gt;    +---
1&gt;    | +--- (base class CTestBase)
1&gt;  0 | | _iA
1&gt;  4 | | _iB
1&gt;    | +---
1&gt;  8 | _iC
1&gt; 12 | _iD
1&gt;    +---</pre>
<p>Looking at this, it should be fairly obvious that the data members of <em><strong>CTestDerived</strong> </em>have just been concatenated onto the end of the memory layout of <em><strong>CTestBase </strong></em>- and, more importantly, that the memory layout of <em><strong>CTestBase</strong></em> within <em><strong>CTestDerived</strong></em> is identical to that when it&#8217;s not a base class.</p>
<p>It&#8217;s that simple!  (for certain definitions of &#8216;it&#8217; and &#8216;simple&#8217;&#8230;)</p>
<p>Armed with this information from last post:</p>
<p style="padding-left: 30px;">&#8220;A guarantee is given in both the C and C++ language specifications that memory address of each member will be higher than that of the one declared before it (see this post on <a href="http://stackoverflow.com/questions/281045/do-class-struct-members-always-get-created-in-memory-in-the-order-they-were-decl">Stack Overflow</a> for more detail of the wording).&#8221;</p>
<p>it is obvious that &#8211; since <em><strong>CTestDerived</strong> </em>inherits all of the members of <em><strong>CTestBase</strong> </em>- its members must appear after those of <em><strong>CTestBase</strong> </em>in memory.</p>
<p>I remember when I had this explained this to me - not long after having started my first job in the industry as a fresh faced graduate &#8211; I did the internal equivalent of a double-take, because the information I had just received was so bleedingly obvious that I couldn&#8217;t believe I&#8217;d ever not known it.</p>
<p>&nbsp;</p>
<h2>If it&#8217;s that easy, why post about it?</h2>
<p>Good question!</p>
<p>The fact that the memory layout of a type is identical in all situations is required by the standard &#8211; and also by logic &#8211; let&#8217;s see why&#8230;</p>
<p>First, download and open the <a href="http://www.altdevblogaday.com/wp-content/uploads/2013/05/ADBAD_CCPPLLC_11_01.zip">second zipped VS2010 project file</a> - this contains the code below in <em><strong>01_InheritanceWithFunctions.cpp</strong></em>:</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
41
42
43
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">class CTestBase
<span style="color: #009900;">&#123;</span>
public<span style="color: #339933;">:</span>
    <span style="color: #993333;">int</span> _iA<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> _iB<span style="color: #339933;">;</span>
&nbsp;
    CTestBase<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> iA<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> iB <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">:</span> _iA<span style="color: #009900;">&#40;</span> iA <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">,</span> _iB<span style="color: #009900;">&#40;</span> iB <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #993333;">int</span> SumBase<span style="color: #009900;">&#40;</span> <span style="color: #993333;">void</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> _iA <span style="color: #339933;">+</span> _iB<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
class CTestDerived
<span style="color: #339933;">:</span> public CTestBase
<span style="color: #009900;">&#123;</span>
public<span style="color: #339933;">:</span>
    <span style="color: #993333;">int</span> _iC<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> _iD<span style="color: #339933;">;</span>
&nbsp;
    CTestDerived<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> iA<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> iB<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> iC<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> iD <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">:</span> CTestBase <span style="color: #009900;">&#40;</span> iA<span style="color: #339933;">,</span> iB <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">,</span> _iC <span style="color: #009900;">&#40;</span> iC <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">,</span> _iD <span style="color: #009900;">&#40;</span> iD <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #993333;">int</span> SumDerived<span style="color: #009900;">&#40;</span> <span style="color: #993333;">void</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> _iA <span style="color: #339933;">+</span> _iB <span style="color: #339933;">+</span> _iC <span style="color: #339933;">+</span> _iD<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    CTestBase       cTestBase   <span style="color: #009900;">&#40;</span> argc<span style="color: #339933;">,</span> argc <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CTestDerived    cTestDerived<span style="color: #009900;">&#40;</span> argc<span style="color: #339933;">,</span> argc <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> argc <span style="color: #339933;">+</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> argc <span style="color: #339933;">+</span> <span style="color: #0000dd;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> cTestBase.<span style="color: #202020;">SumBase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> cTestDerived.<span style="color: #202020;">SumBase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> cTestDerived.<span style="color: #202020;">SumDerived</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Put a breakpoint on the return statement from main, and then compile and run the <em><strong>release</strong> </em>build configuration.</p>
<p>The first thing to note is that the memory layouts printed to the output window during the build are unaffected by the addition of these functions.</p>
<p>This is what you would expect, as we know that non-virtual member function calls are resolved at compile time just like regular non-member and static member functions.</p>
<p>Since <em><strong>CTestDerived</strong> </em>is derived from <em><strong>CTestBase</strong></em>, we know from our high level knowledge about C++ that we can call both of these functions on an instance of <em><strong>CTestDerived</strong></em> &#8211; what we&#8217;re looking at right now is how this is implemented.</p>
<p>When the breakpoint is hit, right click and choose &#8220;Go To Disassembly&#8221;.</p>
<p>I&#8217;ve pasted the part I&#8217;d like to discuss below&#8230;</p>
<p>(N.B. to get the same disassembly as this you should have the following Viewing Options checked in the disassembly window: &#8216;Show source code&#8217;, &#8216;Show line numbers&#8217;, &#8216;Show address&#8217;, and &#8216;Show symbol names&#8217;)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;">    <span style="color: #ff0000;">44</span><span style="color: #339933;">:</span>     return cTestBase<span style="color: #339933;">.</span>SumBase<span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #009900; font-weight: bold;">&#41;</span> <span style="color: #339933;">+</span> cTestDerived<span style="color: #339933;">.</span>SumBase<span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #009900; font-weight: bold;">&#41;</span> <span style="color: #339933;">+</span> cTestDerived<span style="color: #339933;">.</span>SumDerived<span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #009900; font-weight: bold;">&#41;</span><span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">0129109A</span>  <span style="color: #00007f; font-weight: bold;">lea</span>         <span style="color: #46aa03; font-weight: bold;">ecx</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span>cTestDerived<span style="color: #009900; font-weight: bold;">&#93;</span>  
<span style="color: #adadad; font-style: italic;">0129109D</span>  <span style="color: #00007f; font-weight: bold;">call</span>        CTestDerived<span style="color: #339933;">::</span>SumDerived <span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #ff0000;">1291060h</span><span style="color: #009900; font-weight: bold;">&#41;</span>  
<span style="color: #adadad; font-style: italic;">012910A2</span>  <span style="color: #00007f; font-weight: bold;">lea</span>         <span style="color: #46aa03; font-weight: bold;">ecx</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span>cTestDerived<span style="color: #009900; font-weight: bold;">&#93;</span>  
<span style="color: #adadad; font-style: italic;">012910A5</span>  <span style="color: #00007f; font-weight: bold;">mov</span>         <span style="color: #46aa03; font-weight: bold;">esi</span><span style="color: #339933;">,</span><span style="color: #46aa03; font-weight: bold;">eax</span>  
<span style="color: #adadad; font-style: italic;">012910A7</span>  <span style="color: #00007f; font-weight: bold;">call</span>        CTestBase<span style="color: #339933;">::</span>SumBase <span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #ff0000;">1291020h</span><span style="color: #009900; font-weight: bold;">&#41;</span>  
<span style="color: #adadad; font-style: italic;">012910AC</span>  <span style="color: #00007f; font-weight: bold;">lea</span>         <span style="color: #46aa03; font-weight: bold;">ecx</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span>cTestBase<span style="color: #009900; font-weight: bold;">&#93;</span>  
<span style="color: #adadad; font-style: italic;">012910AF</span>  <span style="color: #00007f; font-weight: bold;">add</span>         <span style="color: #46aa03; font-weight: bold;">esi</span><span style="color: #339933;">,</span><span style="color: #46aa03; font-weight: bold;">eax</span>  
<span style="color: #adadad; font-style: italic;">012910B1</span>  <span style="color: #00007f; font-weight: bold;">call</span>        CTestBase<span style="color: #339933;">::</span>SumBase <span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #ff0000;">1291020h</span><span style="color: #009900; font-weight: bold;">&#41;</span>  
<span style="color: #adadad; font-style: italic;">012910B6</span>  <span style="color: #00007f; font-weight: bold;">pop</span>         <span style="color: #46aa03; font-weight: bold;">edi</span>  
<span style="color: #adadad; font-style: italic;">012910B7</span>  <span style="color: #00007f; font-weight: bold;">add</span>         <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #46aa03; font-weight: bold;">esi</span></pre></td></tr></table></div>

<p>We&#8217;ve <a href="http://www.altdevblogaday.com/2012/02/07/c-c-low-level-curriculum-part-5-even-more-stack/">previously covered</a> that the win32 calling convention for member functions (&#8216;thiscall&#8217;) passes <em><strong>this</strong></em> to member functions in the <em><strong>ecx</strong></em> register.</p>
<p>Correspondingly, you&#8217;ll notice that the address of <em><strong>cTestBase</strong></em> and <em><strong>cTestDerived</strong></em> are being stored in <em><strong>ecx</strong></em> using <em><strong>lea</strong></em> (&#8216;load effective address&#8217;) immediately before calling their member functions.</p>
<p>Specifically, note that the address of <em><strong>cTestDerived</strong> </em>is passed un-tampered with in <em><strong>ecx</strong></em> when calling the base class function <em><strong>CTestBase::SumBase</strong></em>. Remember this for later (and for the next post!).</p>
<p>So, let&#8217;s look at the disassembly for <em><strong>CTestBase::SumBase </strong></em>and <em><strong>CTestDerived::SumDerived </strong></em>- I tend to single step the disassembly and step into them, but putting breakpoints in them is more reliable :)</p>
<p><em><strong>CTestBase::SumBase </strong></em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;">    <span style="color: #ff0000;">14</span><span style="color: #339933;">:</span>     <span style="color: #00007f; font-weight: bold;">int</span> SumBase<span style="color: #009900; font-weight: bold;">&#40;</span> void <span style="color: #009900; font-weight: bold;">&#41;</span>
    <span style="color: #ff0000;">15</span><span style="color: #339933;">:</span>     <span style="color: #009900; font-weight: bold;">&#123;</span>
    <span style="color: #ff0000;">16</span><span style="color: #339933;">:</span>         return _iA <span style="color: #339933;">+</span> _iB<span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">01291020</span>  <span style="color: #00007f; font-weight: bold;">mov</span>         <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ecx</span><span style="color: #339933;">+</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span>  
<span style="color: #adadad; font-style: italic;">01291023</span>  <span style="color: #00007f; font-weight: bold;">add</span>         <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ecx</span><span style="color: #009900; font-weight: bold;">&#93;</span>  
    <span style="color: #ff0000;">17</span><span style="color: #339933;">:</span>     <span style="color: #009900; font-weight: bold;">&#125;</span>
<span style="color: #adadad; font-style: italic;">01291025</span>  <span style="color: #00007f; font-weight: bold;">ret</span></pre></td></tr></table></div>

<p><em><strong>CTestDerived::SumDerived </strong></em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;">    <span style="color: #ff0000;">33</span><span style="color: #339933;">:</span>     <span style="color: #00007f; font-weight: bold;">int</span> SumDerived<span style="color: #009900; font-weight: bold;">&#40;</span> void <span style="color: #009900; font-weight: bold;">&#41;</span>
    <span style="color: #ff0000;">34</span><span style="color: #339933;">:</span>     <span style="color: #009900; font-weight: bold;">&#123;</span>
    <span style="color: #ff0000;">35</span><span style="color: #339933;">:</span>         return _iA <span style="color: #339933;">+</span> _iB <span style="color: #339933;">+</span> _iC <span style="color: #339933;">+</span> _iD<span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">01291060</span>  <span style="color: #00007f; font-weight: bold;">mov</span>         <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ecx</span><span style="color: #339933;">+</span><span style="color: #ff0000;">0Ch</span><span style="color: #009900; font-weight: bold;">&#93;</span>  
<span style="color: #adadad; font-style: italic;">01291063</span>  <span style="color: #00007f; font-weight: bold;">add</span>         <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ecx</span><span style="color: #339933;">+</span><span style="color: #ff0000;">8</span><span style="color: #009900; font-weight: bold;">&#93;</span>  
<span style="color: #adadad; font-style: italic;">01291066</span>  <span style="color: #00007f; font-weight: bold;">add</span>         <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ecx</span><span style="color: #339933;">+</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span>  
<span style="color: #adadad; font-style: italic;">01291069</span>  <span style="color: #00007f; font-weight: bold;">add</span>         <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ecx</span><span style="color: #009900; font-weight: bold;">&#93;</span>  
    <span style="color: #ff0000;">36</span><span style="color: #339933;">:</span>     <span style="color: #009900; font-weight: bold;">&#125;</span>
<span style="color: #adadad; font-style: italic;">0129106B</span>  <span style="color: #00007f; font-weight: bold;">ret</span></pre></td></tr></table></div>

<p>We can see that all offsets from <strong>ecx</strong> used in both functions correspond to the memory layouts we have in the build output for the type that the function belongs to.</p>
<p>Since <em><strong>_iA</strong> </em>and <em><strong>_iB</strong></em> are at the same offset within both <em><strong>CTestBase</strong> </em>and <em><strong>CTestDerived </strong></em>(i.e. 0 and 4 bytes respectively), <em><strong>CTestBase::SumBase</strong></em> can safely be called on instances of <em><strong>CTestDerived</strong></em>.</p>
<p>We already know that this is possible from our high level understanding of C++, but now we know the implementational detail that makes it possible.</p>
<p>Whilst the specifics of the disassembly will probably differ from platform to platform, the principles underlying its operation should not.</p>
<p>&nbsp;</p>
<h2>Summary</h2>
<p>To summarise what we&#8217;ve established so far :</p>
<p style="padding-left: 30px;"><em><strong>1)</strong></em> in member functions, member data of a class is accessed via specific offsets from the <em><strong>this</strong></em> pointer</p>
<p style="padding-left: 30px;"><em><strong>2)</strong></em> these offsets are constants at compile time and are baked into the assembly code for the member functions</p>
<p style="padding-left: 30px;"><em><strong>3)</strong></em> this means that the memory layout of the members of a given class must always be identical or the member functions won&#8217;t work</p>
<p>&nbsp;</p>
<p>If we follow this logic through, we can see that:</p>
<p style="padding-left: 30px;"><em><strong>4)</strong></em> the memory layout of a class <em><strong>B</strong> </em>that inherits from another class <em><strong>A</strong> </em>must contain class <em><strong>A</strong></em>&#8216;s members in the same memory layout as class <em><strong>A</strong></em></p>
<p style="padding-left: 30px;"><em><strong>5)</strong></em> the memory layout of any given class <em><strong>A</strong></em> is identical regardless of whether it is an instance of <em><strong>A,</strong></em> or it is included in the memory of some type derived from <em><strong>A. </strong></em></p>
<p style="padding-left: 30px;"><em><strong></strong><strong>6)</strong></em> <em>note:</em> this behaviour is required by the standard, and (more significantly) by <em><strong>logic.</strong></em></p>
<p><em><strong> </strong></em></p>
<p>Finally, it follows that (because each member of a struct must have a higher address than those declared before it):</p>
<p style="padding-left: 30px;"><em><strong>7)</strong></em> the extra memory required by derived class <em><strong>B</strong> </em>will be concatenated onto the end of the memory layout of its base class <em><strong>A</strong></em></p>
<p>&nbsp;</p>
<p>That&#8217;s all for now &#8211; next time we&#8217;ll look at how multiple inheritance affects this picture.</p>
<p>I know it&#8217;s pretty short, but this just means the next one will get here more quickly :)</p>
<p>&nbsp;</p>
<h2>Epilogue &#8211; for those who wondered what I changed in the project settings</h2>
<p>There&#8217;s quite  few changes to the default VS2010 win32 console app project properties in the projects I&#8217;ve zipped up for this post.</p>
<p>The changes have to do with making the optimised release build configuration leave the code structure alone (i.e. not strip out or &#8216;fold&#8217; functions to save exe size, prevent functions being inlined), and prevent extraneous &#8216;debug checking&#8217; code being inserted (makes function calls slower, and code less easy to follow in disassembly)</p>
<ul>
<li>turning off &#8216;Whole Program Optimisation&#8217; (Configuration Properties-&gt;General)</li>
<li>turning off &#8216;Inline Function Expansion&#8217; (Configuration Properties-&gt;C/C++ -&gt;Optimisation)</li>
<li>turning off &#8216;Basic Runtime Checks&#8217; (Configuration Properties-&gt;C/C++ -&gt;Code Generation)</li>
<li>getting rid of pre-compiled headers to streamline the number of files (Configuration Properties-&gt;C/C++ -&gt;Precompiled Headers)</li>
<li>turning off &#8216;Enable COMDAT folding&#8217; (Configuration Properties-&gt;Linker-&gt; Optimization)</li>
</ul>
<p>Essentially, this makes the Release configuration assembly have the same structure as the Debug one WRT function calls.</p>
<p>Also, I use the <em><strong>argc</strong></em> parameter to main as input to the code, and return value computed from that so that the optimiser can&#8217;t assume constant input or output values.</p>
<p>If you use constant inputs, or don&#8217;t output a value computed from the inputs then it&#8217;s pretty hard to convince the optimiser not to optimse the entire .exe to &#8216;return 0;&#8217;&#8230; ;)</p>
<p>&nbsp;</p>
<h2>Shout out</h2>
<p>Thanks (again) to Bruce &#8211; king (or at the very least duke) of advice and peer review.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/05/03/cc-low-level-curriculum-part-11-inheritance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Share: Source Censoring, Part 2</title>
		<link>http://www.altdevblogaday.com/2013/04/30/code-share-source-censoring-part-2/</link>
		<comments>http://www.altdevblogaday.com/2013/04/30/code-share-source-censoring-part-2/#comments</comments>
		<pubDate>Tue, 30 Apr 2013 15:38:24 +0000</pubDate>
		<dc:creator>Niklas Frykholm</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29389</guid>
		<description><![CDATA[<p>A while ago I shared the tool we use for <a class="link" href="http://www.altdevblogaday.com/2011/11/22/code-share-source-censoring/">censoring source code</a> in the Bitsquid engine.</p>
<p>Quick recap: We need to censor the code in our source distributions because there are parts of the code that are covered by NDAs to third parties and cannot be publicly disclosed. We do this with a tool that strips out the secret code and replaces it with blank lines, based on preprocessor definitions.</p>
<p><a href="http://www.altdevblogaday.com/2013/04/30/code-share-source-censoring-part-2/" class="more-link">Read more on Code Share: Source Censoring, Part 2&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>A while ago I shared the tool we use for <a class="link" href="http://www.altdevblogaday.com/2011/11/22/code-share-source-censoring/">censoring source code</a> in the Bitsquid engine.</p>
<p>Quick recap: We need to censor the code in our source distributions because there are parts of the code that are covered by NDAs to third parties and cannot be publicly disclosed. We do this with a tool that strips out the secret code and replaces it with blank lines, based on preprocessor definitions.</p>
<p>The stripping tool is only part of the solution, though. It works well if you only distribute code drops. You take a snapshot of the code, run the stripping tool to strip out secrets, zip it up. Done!</p>
<p>But frankly this is a <em>terrible</em> way of distributing source code. There is no history, no indication of what has changed from version to version and keeping local changes merged with the mainline is a constant pain in the ass.</p>
<p>The only sane way of distributing source code is to expose a <em>mercurial</em> (or <em>git)</em> source repository that you can pull changes from. This lets customers examine the history, find out which version introduced a particular bug, maintain their own branches that they merge with the mainline at their convenience, etc.</p>
<p>But of course, we cannot just share our own internal repository (because it contains secrets).</p>
<h2>hg-clone.rb</h2>
<p>We handle this with another tool, that we have inventively decided to call <em>hg-clone.rb</em>.</p>
<p>What <em>hg-clone.rb</em> does is pretty straight forward. Given two repositories as argument, a <em>SOURCE</em> and a <em>DESTINATION</em>, it checks out each revision in the <em>SOURCE</em> repository, runs a <em>filter</em> program (to strip out any secrets) and checks the result into the destination repository.</p>
<pre>SRC:    0  --&gt; 1  --&gt; 2  --&gt; 3  --&gt; 4  --&gt; 5  --&gt; ...
    	|      |      |      |      |      |
    	F      F      F      F      F      F
    	|      |      |      |      |      |
        v      v      v      v      v      v
DST:    0' --&gt; 1' --&gt; 2' --&gt; 3' --&gt; 4' --&gt; 5' --&gt; ...</pre>
<p>You call the program as</p>
<pre>hg-clone SOURCE DESTINATION --filter FILTER --target TARGET-REV --cutoff CUTOFF-REV</pre>
<p><em>SOURCE</em> and <em>DESTINATION</em> are the source and destination repositories. <em>DESTINATION</em> does not need to exist, if it doesn&#8217;t it will be created. <em>FILTER</em> is the filter program, it will be run once in the destination directory before each revision is committed.</p>
<p><em>TARGET-REV</em> is the target revision that should be copied from the source to the destination. <em>hg-clone</em> will first transfer the parent(s) of the target revision to the destination repository (if they haven&#8217;t already been transfered), then it will transfer the target revision. This process is applied recursively, so if the parents&#8217; parents haven&#8217;t been transferred, they will be transferred first, etc. Only the revisions that are ancestors of <em>TARGET-REV</em> will be transferred, so you can have secret development branches that won&#8217;t be copied to the destination until they have been merged with your release branch.</p>
<p>If you don&#8217;t specify a <em>TARGET-REV</em>, the last revision in the source repository will be used.</p>
<p><em>CUTOFF-REV</em> can be used to cutoff the recursive parent transfer at a specific revision. If you set the cutoff to revision 1000, then any revision that has a parent before revision 1000 will be reparented to revision 1000 in the destination repository. Essentially, in the destination repository, history will start at revision 1000. This can be used to hide a shady past.</p>
<p><em>hg-clone</em> tries its best to preserve authors, dates, messages, branches, etc between the source and destination repositories. It cannot however preserve version numbers, since those are based on a content hash, which changes when the filter is applied. What it does instead is to insert a marker <em>[clonedfrom:116:91fe33c1a569]</em> in the commit message that specifies which revision in the source repository the current revision in the destination repository was cloned from. This commitment marker is also used to determine the mapping between revisions in the source and the destination and whether a particular revision has already been copied over or not.</p>
<p>To use this in practice, you would typically set up one external repository for each customer with a corresponding filter program for stripping out the things that customer is not allowed to see. Then you would set up a <em>cron</em> job to run <em>hg-clone</em> and copy revisions from the main repository to the customer&#8217;s.</p>
<p>Instead of having one repository per customer, you could alternatively have one repository for each possible NDA combination (e.g., +PS3 +PS4 -X360). However, this can be problematic, because if a customer becomes disclosed for a platform you will have to switch them over to a new repository, which might be painful. If you have one repository per customer you can just change the filter function.</p>
<p>The <em>hg-clone</em> program is available from <a class="link" href="https://bitbucket.org/bitsquid/hg_clone">our bitbucket repository</a>.</p>
<p>This has also been posted to <a class="link" href="http://bitsquid.blogspot.com">The Bitsquid blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/04/30/code-share-source-censoring-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;App Of The Day&#8221; type apps can help indies with app discovery</title>
		<link>http://www.altdevblogaday.com/2013/04/26/app-of-the-day-type-apps-can-help-indies-with-app-discovery/</link>
		<comments>http://www.altdevblogaday.com/2013/04/26/app-of-the-day-type-apps-can-help-indies-with-app-discovery/#comments</comments>
		<pubDate>Fri, 26 Apr 2013 23:11:45 +0000</pubDate>
		<dc:creator>Kyle-Kulyk</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Bizdev]]></category>
		<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29384</guid>
		<description><![CDATA[<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/04/Let-Me-Give-You-A-Boost.jpg"><img class=" wp-image-29385 alignright" alt="Let-Me-Give-You-A-Boost" src="http://www.altdevblogaday.com/wp-content/uploads/2013/04/Let-Me-Give-You-A-Boost.jpg" width="300" height="224" /></a>App discovery has to be one of the biggest hurdles that independent developers will face in the mobile marketplace. When limited marketing budgets butt up against a crowded app space, it’s difficult for small devs to attract attention to their work. This is one of our primary obstacles we’re facing with our new release, <a title="Vex Blocks" href="http://www.itzyinteractive.com/vexblocks" target="_blank">Vex Blocks</a> for Android. We’ve made the game, people seem to like the game, how do we get people to notice the game with our marketing budget as constrained as it is? I’d had a successful mobile developer recommend to me in the past that when you launch a new game, all you need to do is to pay the Russians $5,000-10,000 to get you to the top of the app charts and then see if you stay there. If your app doesn&#8217;t stay there, move on. That wasn’t the particular answer we were looking for with this game release and that’s where App Turbo helped out.</p>
<p><a href="http://www.altdevblogaday.com/2013/04/26/app-of-the-day-type-apps-can-help-indies-with-app-discovery/" class="more-link">Read more on &#8220;App Of The Day&#8221; type apps can help indies with app discovery&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/04/Let-Me-Give-You-A-Boost.jpg"><img class=" wp-image-29385 alignright" alt="Let-Me-Give-You-A-Boost" src="http://www.altdevblogaday.com/wp-content/uploads/2013/04/Let-Me-Give-You-A-Boost.jpg" width="300" height="224" /></a>App discovery has to be one of the biggest hurdles that independent developers will face in the mobile marketplace. When limited marketing budgets butt up against a crowded app space, it’s difficult for small devs to attract attention to their work. This is one of our primary obstacles we’re facing with our new release, <a title="Vex Blocks" href="http://www.itzyinteractive.com/vexblocks" target="_blank">Vex Blocks</a> for Android. We’ve made the game, people seem to like the game, how do we get people to notice the game with our marketing budget as constrained as it is? I’d had a successful mobile developer recommend to me in the past that when you launch a new game, all you need to do is to pay the Russians $5,000-10,000 to get you to the top of the app charts and then see if you stay there. If your app doesn&#8217;t stay there, move on. That wasn’t the particular answer we were looking for with this game release and that’s where App Turbo helped out.</p>
<p>About a week and a half after we launched the paid version of Vex Blocks on Google Play, Yuhao Zeng of the Paris based App Turbo contacted me to ask if we’d be interested in promoting Vex Blocks with their “App of the Day” app. They expressed interest in our game and thought their users would too. The idea was simple enough. We make a full copy of our paid game available for 24 hours, free, and they’d promote it. As we had our hands full with free version of Vex Blocks, our app marketing had at that point consisted of a few press releases (where we could afford them) and emails to review sites who had historically ignored us. We received the details, talked them over among ourselves and ultimately decided on “What the hell?”</p>
<p>I don’t want to sound like an advertisement for their service, but I like when others share their indie development experiences and if I can help another dev in our shoes, I’m going to pass it along. Yuhao was fantastic throughout the process, quickly answering any and all questions I threw his way. The “App of the Day” app is regional, covering a good chunk of Europe as well as Russia, Canada, Australia, Mexico, Brazil and Japan. Prior to the promotion, the free version of Vex Blocks was managing roughly 100 downloads a day in the 2 weeks since it’s release. We were hoping that perhaps this promotion might give us a boost of a couple of thousand users and help us get the ball rolling a bit.</p>
<p><a href="http://www.itzyinteractive.com/vexblocks"><img class="alignleft" style="margin: 5px" alt="" src="http://itzyinteractive.com/wp-content/uploads/2013/04/Icon-128.png" width="128" height="128" /></a></p>
<p>When all was said and done, over 90,000 users downloaded and played our game in the 24 hours the promotion ran this week, of which roughly 80% have so far stayed as active users. I&#8217;m sure that’s nothing to some developers, but for an indie team like ours this is a huge step forward. The next day, the free version of Vex Blocks jumped from it’s regular 100 a day to roughly 6000 where it’s stayed so far. The paid version of Vex Blocks is also experiencing a nice spike. For an English only game, I&#8217;m pleasantly surprised that so many decided to give us a try in non-English speaking countries and the feedback from users has been fantastic. The goal was to help Vex Blocks find it’s way into the hands of gamers and raise awareness, and in that this exercise was a complete success. It also served as an excellent opportunity to help narrow the list of the 2000 some Android devices that the game was available on and weed out a few devices that were incapable of playing our game.</p>
<p>There are a number of “Free App” type applications like “App of the Day” (<a href="http://appturbo.it/">http://appturbo.it/</a>) out there but in our inexperience we didn&#8217;t even consider reaching out to them. Although I haven’t used a similar service to promote our titles, I’ll certainly contact the App Turbo team again for this type of service. If you’re a developer with a mobile app to promote, it certainly couldn&#8217;t hurt to send a quick email to Yuhao (yuhao@appturbo.it) and see what they can do for you. I know I’ll be partnering up with them again for the iOS release of Vex Blocks and hopefully for future releases after that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/04/26/app-of-the-day-type-apps-can-help-indies-with-app-discovery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Life can be better (part 1 of 3)</title>
		<link>http://www.altdevblogaday.com/2013/04/22/life-can-be-better-part-1-of-3/</link>
		<comments>http://www.altdevblogaday.com/2013/04/22/life-can-be-better-part-1-of-3/#comments</comments>
		<pubDate>Mon, 22 Apr 2013 17:03:25 +0000</pubDate>
		<dc:creator>Amir Ebrahimi</dc:creator>
				<category><![CDATA[General Interest]]></category>
		<category><![CDATA[burnout]]></category>
		<category><![CDATA[crunch]]></category>
		<category><![CDATA[health]]></category>
		<category><![CDATA[htma]]></category>
		<category><![CDATA[nutrition]]></category>
		<category><![CDATA[nutritional balancing]]></category>
		<category><![CDATA[quality of life]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29301</guid>
		<description><![CDATA[<p dir="ltr">TL;DR &#8211; If you’re happy, healthy, and have energy to make things happen <em>most</em> of the time, then keep doing what you’re doing. If not, or if you used to be and now aren’t, then you may be interested in what I have to say.</p>
<p><a href="http://www.altdevblogaday.com/2013/04/22/life-can-be-better-part-1-of-3/" class="more-link">Read more on Life can be better (part 1 of 3)&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p dir="ltr">TL;DR &#8211; If you’re happy, healthy, and have energy to make things happen <em>most</em> of the time, then keep doing what you’re doing. If not, or if you used to be and now aren’t, then you may be interested in what I have to say.</p>
<p dir="ltr">This May will mark the tenth year that I have worked in the video game industry. Technically, I could be classified as a “veteran”. However, whenever I think of that term &#8212; <em>veteran</em> &#8212; I conjure up images of other great developers, some of whom I have had the good fortune of working with, that are senior to me. Regardless of the appropriate use of the term veteran, I’m calling attention to it because one out of every three of us who came into the industry were not expected to be around after 5 years. Extend that period to ten years and it would either be you or the guy / gal next to you that would leave behind an empty chair.</p>
<p dir="ltr">I’m citing these numbers from a <a href="http://www.igda.org/quality-life-white-paper-info">Quality of Life Survey</a> put out by the IGDA that I remember coming across back in 2004; only a year after joining the video game industry. I was disheartened to read that attrition was a concern in our industry and that, among all the reasons given, long hours and crunch were omnipresent. In other words, people weren’t leaving the industry because it was unfulfilling as a career. No; people were leaving because it was a choice between their health / sanity / relationship / family / social life / etc. and a creative endeavor that was bleeding them dry.</p>
<p dir="ltr">My experience at that time with others in the industry was that neither the IGDA, nor it’s report on quality of life were to be taken seriously. In my judgment, there was cowboy bravado at play that took pride in the fact that we worked ourselves to the bone; all of which was “necessary” to produce the next hit title. If you couldn’t keep up with that pace, then you weren’t cut out for the industry. I even had a senior manager tell me in an exit interview that he was surprised I was headed to work for another company in the industry instead of leaving altogether.</p>
<p dir="ltr">I remember sifting through pages of the <a href="http://www.dir.ca.gov/dlse/DLSEManual/dlse_enfcmanual.pdf">Department of Labor’s Enforcement Policies</a> to understand the legalities around working <em>unpaid</em>, and for all effective purposes, obligatory, overtime. For reference, I’ve managed to dig up the original highlighted sections from my files as I’m writing this blog post: 49.1.2, 49.1.5, 49.2.1, 50.3, 50.6, 50.7, 51.5.2, 51.6.3.2, 51.6.4.1, 51.6, 54.1, 54.4, 54.5. If this stuff bores you to tears, then I’ll inform you that the crux of all questions around overtime as it comes specifically to “computer software workers” is whether you are classified as an exempt (as in from overtime pay) or non-exempt employee. See, California, being a hot-bed of software innovation, for reasons not known to me, decided to single us out for protection. One of the three criteria, of which <em>all</em> must apply, for an employee to be exempt is that you are <a href="http://www.dir.ca.gov/iwc/computerSoftwareEmployees.html">paid at least a minimum hourly rate for your time</a>.</p>
<p dir="ltr">You may be wondering why I would be interested about an IGDA whitepaper, legalities of overtime, and classification for pay only after a year of being in the industry. Well, although I didn’t have much awareness about my well-being back then as I do now, I did know something was wrong. My first indicator was health; noticing that my overall energy level day-to-day had declined. I found that I was chronically tired, felt “heavy” to move around even though I wasn’t grossly overweight, and started to think that most things I had to get done were weighty tasks. The second indicator was my mood; noticing that the enthusiasm and optimism that I entered into the industry with had been replaced with irritability and negativity.</p>
<p dir="ltr">I decided to see a doctor for a health check up to see if anything was gravely wrong. Oddly enough, the blood work that was done indicated that nothing was awry. In fact, the results even showed that I had a high level of “good” cholesterol (HDL) and a low level of “bad” cholesterol (LDL). Nothing the doc found was abnormal and I was told to get better sleep and exercise more (which I eventually did start doing during lunch with coworkers). Had I had the awareness that I have now to understand that health was <em>my responsibility</em>, I would not have accepted the blood work as conclusive. My current understanding of doctors is that they aren’t in the business of making us healthier; they’re there to make sure we don’t get any sicker than we already are.</p>
<p>Over the next year, I worked on my third console title, lifted weights and exercised multiple times a week with co-workers, ate salads occasionally during lunch, and, unfortunately, was also drinking numerous cups of coffee during the day to fuel the work that I was doing. Commonly said, I was working hard and playing hard. Sure enough, at some point during development, we entered our multiple-month crunch during the project and sleep and free-time became a luxury. What’s odd about that time is that I was in the best physical shape I had been in since my years playing football in high school, yet my energy level, mood, and mental health were getting worse.</p>
<p>In parallel, a <a href="http://ea-spouse.livejournal.com/274.html">letter</a> from a disgruntled ‘EA spouse’ and a class-action lawsuit against EA by a collection of artists both emerged in late 2004. Both spoke to the unfair working conditions that employees faced at EA. In 2005, the class-action lawsuit was settled for $15.6M and would later be succeeded by a separate class-action lawsuit composed of programmers (also settled out of court). In comparison to the film and television industry, the labor practices of the video game industry were and in some cases still are juvenile. For film and television, professionals get paid for overtime and although the health effects of crunch aren’t mitigated, at least the costs are made material.</p>
<p>I experienced overtime pay firsthand, when I joined a visual effects company, The Orphanage, here in San Francisco in 2008. I learned quickly how volatile the film industry could be &#8212; projects came and went, hours went up and down, and staff increased and decreased on a week-to-week basis. However, even with the volatility, there was a fundamental understanding that everyone would get paid for his or her time. The California Department of Industrial Relations released a <a href="http://www.dir.ca.gov/iwc/IWCArticle12.pdf" target="_blank">working order</a> in 2001 <em>specifically</em> for the film industry. The working order dictated how overtime would work within a single workday and workweek, required minimum days off, alternative workweeks, meal and rest periods, and even the <em>temperature</em> for working conditions. Even though I had a salary, I logged every hour that I worked against different projects at the company for budgeting purposes. What I found so cool about this process is that, not only would I be paid overtime when I worked longer hours for a specific project &#8212; it would show up in the cumulative costs for that specific project. Essentially, accountability was built into the process, since having people work longer hours resulted in more costs for the project. Unfortunately, I joined the company almost immediately after the Writers Guild of America (WGA) strike concluded, which left the film industry on shaky ground. Our goals as a company to re-build the VFX pipeline from the ground up were thwarted when a major project of ours was lost and multiple rounds of lay-offs ensued.</p>
<p>The awareness of unspoken quality of life issues in the video game industry that 2004 brought us was much needed. In my judgment, we’ve seen some improvements come out of that awareness, such as flexible working hours and smaller studios that attempt to treat their employees better. However, there is still a prevalence of <a href="http://gamasutra.com/view/feature/188671/game_developer_qualityoflife_.php?page=2">crunch time</a> across the video game industry. I see an opportunity here to spend more of my own energy inviting others in the industry to consider the awesome effects of what a happy, healthy, and energetic workforce would bring. In that regard, I’m doing my part as a studio owner to have reasonable working hours, minimize unhealthy levels of stress with projects, and respect our employees. My hope is that at the very least I will not perpetuate the cannibalism of creatives in our industry.</p>
<p>However, my attention right now and the purpose of these articles is to heal the damage that has already been done at a personal, individual level of health. My story continues past 2005 with more crunch periods, stress on relationships, and more health problems (including mental health). If any of what I’ve said so far resonates with you and you’ve come to accept as “normal” the sub-optimal ways you feel, think, and view life, then know that <em>life can be better</em>. Whatever you’ve been getting out of your body and mind under extended periods of stress comes at a cost. I wholeheartedly believe that whatever has been taken requires replenishing.</p>
<p>Over the past year and a half, I have focused on improving my own health. I have noticed that changes in the health of my body have resulted in improvements with the way I think and the performance of my mind. Another benefit is that with more energy, things that I wouldn&#8217;t have considered to do in the past come easier now, such as riding my bicycle to work. My hope for us all is to feel good in our bodies at a physical level, happy at an emotional level, and energized at a creative/intellectual level. Together, we’ll be able to make our industry a <em>sustainable</em> outlet for human creativity.</p>
<p>In the <a href="http://www.altdevblogaday.com/2013/05/19/life-can-be-better-part-2-of-3/">next article</a>, I will go deeper into the health side of things as best as I have come to understand. I will share briefly a few anecdotes of my naivety as it relates to health and some of the things that I have done in an effort to make improvements. I will explain a bit about the PAT (pituary-adrenal-thyroid) axis and why it is so important to your overall well-being and your <em>perception</em> of well-being. If I find that there is more information to share or that this next article is too lengthy, then I may continue with further articles.</p>
<p><em>EDIT: I am a (hu)man, therefore I am imperfect. I have revised this article to remove references to what, unbeknownst to me, could be considered controversial &#8212; hair testing mineral analysis. I&#8217;ve become aware of arguments on both sides and would be happy to share with you the information, so that you can make your own educated decision. I have had my own positive experiences with hair testing/nutritional balancing, tailored supplements (as opposed to a catch-all or taking supplements that my body doesn&#8217;t need), a healthier diet, reduction of caffeine, drinking much more water than I thought was necessary, and a variety of other things. My goal is to raise awareness about health in our industry, provide one story as a reference point to others that may have had a similar experience, and offer some <strong>suggestions</strong> on how you <strong>may</strong> be able to improve your own health. My intention is not to back myself into a position of having to defend a specific approach to nutrition. What I have come to understand is that health and nutrition are not a simple thing. Simply Google &#8216;improve health&#8217; and see all the various approaches and opinions that are returned. As to the Game Developer Performance Challenge that was originally linked here, I&#8217;d still like to challenge you to improve your own health if your day-to-day experience is sub-optimal.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/04/22/life-can-be-better-part-1-of-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Fast, Type-safe &amp; Minimal String Formatting Library, miniformat</title>
		<link>http://www.altdevblogaday.com/2013/04/13/a-fast-type-safe-minimal-string-formatting-library-miniformat/</link>
		<comments>http://www.altdevblogaday.com/2013/04/13/a-fast-type-safe-minimal-string-formatting-library-miniformat/#comments</comments>
		<pubDate>Sat, 13 Apr 2013 04:37:13 +0000</pubDate>
		<dc:creator>Jaewon Jung</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[miniformat]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[printf]]></category>
		<category><![CDATA[string formatting]]></category>
		<category><![CDATA[stringencoders]]></category>
		<category><![CDATA[type-safe]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29323</guid>
		<description><![CDATA[<p>The inspiration for <a href="https://bitbucket.org/jj1/miniformat">this</a> came from <a href="https://github.com/c42f/tinyformat">tinyformat</a>. Unfortunately it relies on the C++ iostream, basically std::cout, which is somewhat slow and definitely not everyone&#8217;s favorite. So I bit the bullet and got around to implement my own with minimal dependency and speed in mind.</p>
<p><a href="http://www.altdevblogaday.com/2013/04/13/a-fast-type-safe-minimal-string-formatting-library-miniformat/" class="more-link">Read more on A Fast, Type-safe &#38; Minimal String Formatting Library, miniformat&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>The inspiration for <a href="https://bitbucket.org/jj1/miniformat">this</a> came from <a href="https://github.com/c42f/tinyformat">tinyformat</a>. Unfortunately it relies on the C++ iostream, basically std::cout, which is somewhat slow and definitely not everyone&#8217;s favorite. So I bit the bullet and got around to implement my own with minimal dependency and speed in mind.</p>
<h3>Origin</h3>
<p>I didn&#8217;t want to implement all the nitty-gritty of formatting a floating-point number to a string. Fortunately there was an awesome library called <a href="http://code.google.com/p/stringencoders/">stringencoders</a>, so I used it for the number-to-string part. <a href="https://bitbucket.org/jj1/miniformat_old">The original miniformat</a> came out like that(By the way, you can find the latest code of miniformat with improvements mentioned in this article in <a href="https://bitbucket.org/jj1/miniformat">the new repository</a>. I created the new one with git back-end to use <a href="http://www.sourcetreeapp.com/">SourceTree</a>, which currently doesn&#8217;t support Mercurial on Windows). Its usage was like:</p>
<pre style="font-family: Consolas;font-size: 13;font-weight: bold;color: #839496;background: #002b36"><span style="color: green">std</span><span style="color: #d33682">::</span><span style="color: #2b91af">string</span> <span style="color: yellow">str</span><span style="color: #d33682">;</span>
<span style="color: green">mini</span><span style="color: #d33682">::</span><span style="color: olive">format</span><span style="color: #d33682">(</span><span style="color: yellow">str</span><span style="color: #d33682">,</span> <span style="color: #2aa198">"String: %1 Int: %0, Float: %(.3)2\n"</span><span style="color: #d33682">,</span> <span style="color: #2aa198">100</span><span style="color: #d33682">,</span> <span style="color: #2aa198">"JJ"</span><span style="color: #d33682">,</span> <span style="color: #2aa198">3.141592</span><span style="color: #d33682">);</span></pre>
<p>Originally it supported only std::string as an output type by default, although one can support other string types by specializing function templates in string_adaptor namespace. By the way, keep in mind the caveat that it&#8217;s not supporting all the features of printf format specifiers(for instance, no hexadecimal/octal integer support).</p>
<h3>Improvements</h3>
<p>Recently I saw <a href="https://www.facebook.com/notes/facebook-engineering/three-optimization-tips-for-c/10151361643253920">Andrei Alexandrescu&#8217;s great post on C++ optimizations</a>(<a href="https://vimeo.com/55639112">video</a>, <a href="http://www.slideshare.net/andreialexandrescu1/three-optimization-tips-for-c-15708507">slides</a>) and decide to apply the lessons there (as for number-to-string conversion) to the formatting library and see how it fares. I also wanted to add a support for raw char arrays as an output type by default since a potential heap allocation cannot be an option in some situations.</p>
<p>Here&#8217;s the original code for converting 32bit unsigned integer to a string:</p>
<pre style="font-family: Consolas;font-size: 13;font-weight: bold;color: #839496;background: #002b36"><span style="color: #719a07">template</span> <span style="color: #d33682">&lt;</span><span style="color: #719a07">typename</span> <span style="color: #2b91af">String</span><span style="color: #d33682">&gt;</span>
<span style="color: #719a07">void</span> <span style="color: green">miniformat</span><span style="color: #d33682">::</span><span style="color: green">detail</span><span style="color: #d33682">::</span>render<span style="color: #d33682">(</span><span style="color: #2b91af">String</span><span style="color: #d33682">&amp;</span> wstr<span style="color: #d33682">,</span> <span style="color: #2b91af">uint32_t</span> value<span style="color: #d33682">,</span> <span style="color: #719a07">int</span> width<span style="color: #d33682">,</span> <span style="color: #719a07">int</span><span style="color: #d33682">)</span>
<span style="color: #d33682">{</span>
    <span style="color: #719a07">int</span> beginIndex <span style="color: #d33682">=</span> string_adaptor<span style="color: #d33682">::</span>length<span style="color: #d33682">(</span>wstr<span style="color: #d33682">);</span>
    <span style="color: #756e58">// Conversion. Number is reversed.</span>
    <span style="color: #719a07">do</span> 
    <span style="color: #d33682">{</span>
        string_adaptor<span style="color: #d33682">::</span>append<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> <span style="color: #2aa198">1</span><span style="color: #d33682">,</span> <span style="color: #d33682">(</span><span style="color: #719a07">char</span><span style="color: #d33682">)(</span><span style="color: #2aa198">48</span> <span style="color: #d33682">+</span> <span style="color: #d33682">(</span>value <span style="color: #d33682">%</span> <span style="color: #2aa198">10</span><span style="color: #d33682">)));</span> 
    <span style="color: #d33682">}</span>
    <span style="color: #719a07">while</span> <span style="color: #d33682">(</span>value <span style="color: #d33682">/=</span> <span style="color: #2aa198">10</span><span style="color: #d33682">);</span>

    <span style="color: #756e58">// Handle the 'width' parameter.</span>
    <span style="color: #719a07">int</span> spaceCnt <span style="color: #d33682">=</span> width <span style="color: #d33682">-</span> <span style="color: #d33682">(</span>string_adaptor<span style="color: #d33682">::</span>length<span style="color: #d33682">(</span>wstr<span style="color: #d33682">)-</span>beginIndex<span style="color: #d33682">);</span>
    <span style="color: #719a07">if</span><span style="color: #d33682">(</span>spaceCnt <span style="color: #d33682">&gt;</span> <span style="color: #2aa198">0</span><span style="color: #d33682">)</span>
        string_adaptor<span style="color: #d33682">::</span>append<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> spaceCnt<span style="color: #d33682">,</span> <span style="color: #2aa198">' '</span><span style="color: #d33682">);</span>

    <span style="color: #719a07">int</span> endIndex <span style="color: #d33682">=</span> string_adaptor<span style="color: #d33682">::</span>length<span style="color: #d33682">(</span>wstr<span style="color: #d33682">)-</span><span style="color: #2aa198">1</span><span style="color: #d33682">;</span>
    <span style="color: #756e58">// Reverse string.</span>
    strreverse<span style="color: #d33682">(</span>string_adaptor<span style="color: #d33682">::</span>at<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> beginIndex<span style="color: #d33682">),</span> string_adaptor<span style="color: #d33682">::</span>at<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> endIndex<span style="color: #d33682">));</span>
<span style="color: #d33682">}</span></pre>
<p>Pretty straightforward, other than the consideration for the &#8216;width&#8217; parameter(the unnamed fourth parameter is a precision value, which is irrelevant for integers).</p>
<p>Here is the one after Andrei&#8217;s optimizations applied:</p>
<pre style="font-family: Consolas;font-size: 13;font-weight: bold;color: #839496;background: #002b36"><span style="color: #719a07">inline</span> <span style="color: #719a07">int</span> <span style="color: green">miniformat</span><span style="color: #d33682">::</span><span style="color: green">detail</span><span style="color: #d33682">::</span><span style="color: olive">digits10</span><span style="color: #d33682">(</span><span style="color: #2b91af">uint32_t</span> <span style="color: gray">v</span><span style="color: #d33682">)</span>
<span style="color: #d33682">{</span>
    <span style="color: #719a07">static</span> <span style="color: #719a07">const</span> <span style="color: #2b91af">uint32_t</span> <span style="color: yellow">P01</span> <span style="color: #d33682">=</span> <span style="color: #2aa198">10</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">static</span> <span style="color: #719a07">const</span> <span style="color: #2b91af">uint32_t</span> <span style="color: yellow">P02</span> <span style="color: #d33682">=</span> <span style="color: #2aa198">100</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">static</span> <span style="color: #719a07">const</span> <span style="color: #2b91af">uint32_t</span> <span style="color: yellow">P03</span> <span style="color: #d33682">=</span> <span style="color: #2aa198">1000</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">static</span> <span style="color: #719a07">const</span> <span style="color: #2b91af">uint32_t</span> <span style="color: yellow">P04</span> <span style="color: #d33682">=</span> <span style="color: #2aa198">10000</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">static</span> <span style="color: #719a07">const</span> <span style="color: #2b91af">uint32_t</span> <span style="color: yellow">P05</span> <span style="color: #d33682">=</span> <span style="color: #2aa198">100000</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">static</span> <span style="color: #719a07">const</span> <span style="color: #2b91af">uint32_t</span> <span style="color: yellow">P06</span> <span style="color: #d33682">=</span> <span style="color: #2aa198">1000000</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">static</span> <span style="color: #719a07">const</span> <span style="color: #2b91af">uint32_t</span> <span style="color: yellow">P07</span> <span style="color: #d33682">=</span> <span style="color: #2aa198">10000000</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">static</span> <span style="color: #719a07">const</span> <span style="color: #2b91af">uint32_t</span> <span style="color: yellow">P08</span> <span style="color: #d33682">=</span> <span style="color: #2aa198">100000000</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">static</span> <span style="color: #719a07">const</span> <span style="color: #2b91af">uint32_t</span> <span style="color: yellow">P09</span> <span style="color: #d33682">=</span> <span style="color: #2aa198">1000000000</span><span style="color: #d33682">;</span>

    <span style="color: #719a07">if</span><span style="color: #d33682">(</span><span style="color: gray">v</span> <span style="color: #d33682">&lt;</span> <span style="color: yellow">P01</span><span style="color: #d33682">)</span> <span style="color: #719a07">return</span> <span style="color: #2aa198">1</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">if</span><span style="color: #d33682">(</span><span style="color: gray">v</span> <span style="color: #d33682">&lt;</span> <span style="color: yellow">P02</span><span style="color: #d33682">)</span> <span style="color: #719a07">return</span> <span style="color: #2aa198">2</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">if</span><span style="color: #d33682">(</span><span style="color: gray">v</span> <span style="color: #d33682">&lt;</span> <span style="color: yellow">P03</span><span style="color: #d33682">)</span> <span style="color: #719a07">return</span> <span style="color: #2aa198">3</span><span style="color: #d33682">;</span>
    <span style="color: #719a07">if</span><span style="color: #d33682">(</span><span style="color: gray">v</span> <span style="color: #d33682">&lt;</span> <span style="color: yellow">P08</span><span style="color: #d33682">)</span>
    <span style="color: #d33682">{</span>
        <span style="color: #719a07">if</span><span style="color: #d33682">(</span><span style="color: gray">v</span> <span style="color: #d33682">&lt;</span> <span style="color: yellow">P06</span><span style="color: #d33682">)</span>
        <span style="color: #d33682">{</span>
            <span style="color: #719a07">if</span><span style="color: #d33682">(</span><span style="color: gray">v</span> <span style="color: #d33682">&lt;</span> <span style="color: yellow">P04</span><span style="color: #d33682">)</span> <span style="color: #719a07">return</span> <span style="color: #2aa198">4</span><span style="color: #d33682">;</span>
            <span style="color: #719a07">return</span> <span style="color: #2aa198">5</span> <span style="color: #d33682">+</span> <span style="color: #d33682">(</span><span style="color: gray">v</span> <span style="color: #d33682">&gt;=</span> <span style="color: yellow">P05</span><span style="color: #d33682">);</span>
        <span style="color: #d33682">}</span>
        <span style="color: #719a07">return</span> <span style="color: #2aa198">7</span> <span style="color: #d33682">+</span> <span style="color: #d33682">(</span><span style="color: gray">v</span> <span style="color: #d33682">&gt;=</span> <span style="color: yellow">P07</span><span style="color: #d33682">);</span>
    <span style="color: #d33682">}</span>
    <span style="color: #719a07">return</span> <span style="color: #2aa198">9</span> <span style="color: #d33682">+</span> <span style="color: #d33682">(</span><span style="color: gray">v</span> <span style="color: #d33682">&gt;=</span> <span style="color: yellow">P09</span><span style="color: #d33682">);</span>
<span style="color: #d33682">}</span></pre>
<pre style="font-family: Consolas;font-size: 13;font-weight: bold;color: #839496;background: #002b36"><span style="color: #719a07">template</span> <span style="color: #d33682">&lt;</span><span style="color: #719a07">typename</span> String<span style="color: #d33682">&gt;</span>
<span style="color: #719a07">void</span> miniformat<span style="color: #d33682">::</span>detail<span style="color: #d33682">::</span>render<span style="color: #d33682">(</span>String<span style="color: #d33682">&amp;</span> wstr<span style="color: #d33682">,</span> uint32_t value<span style="color: #d33682">,</span> <span style="color: #719a07">int</span> width<span style="color: #d33682">,</span> <span style="color: #719a07">int</span><span style="color: #d33682">)</span>
<span style="color: #d33682">{</span>
    <span style="color: #719a07">static</span> <span style="color: #719a07">const</span> <span style="color: #719a07">char</span> digits<span style="color: #d33682">[</span><span style="color: #2aa198">201</span><span style="color: #d33682">]</span> <span style="color: #d33682">=</span>
        <span style="color: #2aa198">"0001020304050607080910111213141516171819"</span>
        <span style="color: #2aa198">"2021222324252627282930313233343536373839"</span>
        <span style="color: #2aa198">"4041424344454647484950515253545556575859"</span>
        <span style="color: #2aa198">"6061626364656667686970717273747576777879"</span>
        <span style="color: #2aa198">"8081828384858687888990919293949596979899"</span><span style="color: #d33682">;</span>

    <span style="color: #719a07">int</span> next <span style="color: #d33682">=</span> string_adaptor<span style="color: #d33682">::</span>length<span style="color: #d33682">(</span>wstr<span style="color: #d33682">);</span>
    <span style="color: #719a07">const</span> <span style="color: #719a07">int</span> length <span style="color: #d33682">=</span> digits10<span style="color: #d33682">(</span>value<span style="color: #d33682">);</span>

    <span style="color: #756e58">// Handle the 'width' parameter.</span>
    <span style="color: #719a07">int</span> spaceCnt <span style="color: #d33682">=</span> width <span style="color: #d33682">-</span> length<span style="color: #d33682">;</span>
    <span style="color: #719a07">if</span><span style="color: #d33682">(</span>spaceCnt <span style="color: #d33682">&gt;</span> <span style="color: #2aa198">0</span><span style="color: #d33682">)</span>
    <span style="color: #d33682">{</span>
        string_adaptor<span style="color: #d33682">::</span>append<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> spaceCnt<span style="color: #d33682">,</span> <span style="color: #2aa198">' '</span><span style="color: #d33682">);</span>
        next <span style="color: #d33682">+=</span> spaceCnt<span style="color: #d33682">;</span>
    <span style="color: #d33682">}</span>

    string_adaptor<span style="color: #d33682">::</span>append<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> length<span style="color: #d33682">,</span> <span style="color: #2aa198">'0'</span><span style="color: #d33682">);</span>
    next <span style="color: #d33682">+=</span> length<span style="color: #d33682">-</span><span style="color: #2aa198">1</span><span style="color: #d33682">;</span>

    <span style="color: #719a07">while</span><span style="color: #d33682">(</span>value <span style="color: #d33682">&gt;=</span> <span style="color: #2aa198">100</span><span style="color: #d33682">)</span>
    <span style="color: #d33682">{</span>
        <span style="color: #719a07">const</span> uint32_t i <span style="color: #d33682">=</span> <span style="color: #d33682">(</span>value <span style="color: #d33682">%</span> <span style="color: #2aa198">100</span><span style="color: #d33682">)</span> <span style="color: #d33682">*</span> <span style="color: #2aa198">2</span><span style="color: #d33682">;</span>
        value <span style="color: #d33682">/=</span> <span style="color: #2aa198">100</span><span style="color: #d33682">;</span>
        <span style="color: #d33682">*</span>string_adaptor<span style="color: #d33682">::</span>at<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> next<span style="color: #d33682">)</span> <span style="color: #d33682">=</span> digits<span style="color: #d33682">[</span>i<span style="color: #d33682">+</span><span style="color: #2aa198">1</span><span style="color: #d33682">];</span>
        <span style="color: #d33682">*</span>string_adaptor<span style="color: #d33682">::</span>at<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> next<span style="color: #d33682">-</span><span style="color: #2aa198">1</span><span style="color: #d33682">)</span> <span style="color: #d33682">=</span> digits<span style="color: #d33682">[</span>i<span style="color: #d33682">];</span>
        next <span style="color: #d33682">-=</span> <span style="color: #2aa198">2</span><span style="color: #d33682">;</span>
    <span style="color: #d33682">}</span>

    <span style="color: #756e58">// Handle last 1-2 digits.</span>
    <span style="color: #719a07">if</span><span style="color: #d33682">(</span>value <span style="color: #d33682">&lt;</span> <span style="color: #2aa198">10</span><span style="color: #d33682">)</span>
    <span style="color: #d33682">{</span>
        <span style="color: #d33682">*</span>string_adaptor<span style="color: #d33682">::</span>at<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> next<span style="color: #d33682">)</span> <span style="color: #d33682">=</span> <span style="color: #2aa198">'0'</span><span style="color: #d33682">+</span><span style="color: #719a07">static_cast</span><span style="color: #d33682">&lt;</span><span style="color: #719a07">char</span><span style="color: #d33682">&gt;(</span>value<span style="color: #d33682">);</span>
    <span style="color: #d33682">}</span>
    <span style="color: #719a07">else</span>
    <span style="color: #d33682">{</span>
        <span style="color: #719a07">const</span> uint32_t i <span style="color: #d33682">=</span> <span style="color: #719a07">static_cast</span><span style="color: #d33682">&lt;</span>uint32_t<span style="color: #d33682">&gt;(</span>value<span style="color: #d33682">)</span> <span style="color: #d33682">*</span> <span style="color: #2aa198">2</span><span style="color: #d33682">;</span>
        <span style="color: #d33682">*</span>string_adaptor<span style="color: #d33682">::</span>at<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> next<span style="color: #d33682">)</span> <span style="color: #d33682">=</span> digits<span style="color: #d33682">[</span>i<span style="color: #d33682">+</span><span style="color: #2aa198">1</span><span style="color: #d33682">];</span>
        <span style="color: #d33682">*</span>string_adaptor<span style="color: #d33682">::</span>at<span style="color: #d33682">(</span>wstr<span style="color: #d33682">,</span> next<span style="color: #d33682">-</span><span style="color: #2aa198">1</span><span style="color: #d33682">)</span> <span style="color: #d33682">=</span> digits<span style="color: #d33682">[</span>i<span style="color: #d33682">];</span>
    <span style="color: #d33682">}</span>
<span style="color: #d33682">}</span></pre>
<p>It now consists of two passes(and two corresponding functions) instead of one, but due to strength reduction, array writes minimization and other optimizations from Andrei&#8217;s post, should perform faster than before.</p>
<p>Here are timings of converting some random integers into std::string, before &amp; after this optimization:</p>
<table style="border: 1px solid #000">
<tbody>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">Win32</th>
<th style="border: 1px solid #000">Release/before</th>
<th style="border: 1px solid #000">Release/after</th>
<th style="border: 1px solid #000">Debug/before</th>
<th style="border: 1px solid #000">Debug/after</th>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">uint32_t</th>
<td style="border: 1px solid #000">0.85</td>
<td style="border: 1px solid #000">0.57(<b>1.5x</b>)</td>
<td style="border: 1px solid #000">4.64</td>
<td style="border: 1px solid #000">2.44(<b>1.9x</b>)</td>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">int32_t</th>
<td style="border: 1px solid #000">0.89</td>
<td style="border: 1px solid #000">0.62(<b>1.4x</b>)</td>
<td style="border: 1px solid #000">4.63</td>
<td style="border: 1px solid #000">2.44(<b>1.9x</b>)</td>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">uint64_t</th>
<td style="border: 1px solid #000">1.47</td>
<td style="border: 1px solid #000">1.03(<b>1.4x</b>)</td>
<td style="border: 1px solid #000">4.71</td>
<td style="border: 1px solid #000">2.5(<b>1.9x</b>)</td>
</tr>
<tr>
<th style="border: 1px solid #000">int64_t</th>
<td style="border: 1px solid #000">1.49</td>
<td style="border: 1px solid #000">1.08(<b>1.4x</b>)</td>
<td style="border: 1px solid #000">4.71</td>
<td style="border: 1px solid #000">2.5(<b>1.9x</b>)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<table style="border: 1px solid #000">
<tbody>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">x64</th>
<th style="border: 1px solid #000">Release/before</th>
<th style="border: 1px solid #000">Release/after</th>
<th style="border: 1px solid #000">Debug/before</th>
<th style="border: 1px solid #000">Debug/after</th>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">uint32_t</th>
<td style="border: 1px solid #000">0.93</td>
<td style="border: 1px solid #000">0.54(<b>1.7x</b>)</td>
<td style="border: 1px solid #000">1.38</td>
<td style="border: 1px solid #000">0.78(<b>1.8x</b>)</td>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">int32_t</th>
<td style="border: 1px solid #000">0.94</td>
<td style="border: 1px solid #000">0.56(<b>1.7x</b>)</td>
<td style="border: 1px solid #000">1.39</td>
<td style="border: 1px solid #000">0.77(<b>1.8x</b>)</td>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">uint64_t</th>
<td style="border: 1px solid #000">0.93</td>
<td style="border: 1px solid #000">0.57(<b>1.6x</b>)</td>
<td style="border: 1px solid #000">1.43</td>
<td style="border: 1px solid #000">0.79(<b>1.8x</b>)</td>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">int64_t</th>
<td style="border: 1px solid #000">0.94</td>
<td style="border: 1px solid #000">0.63(<b>1.5x</b>)</td>
<td style="border: 1px solid #000">1.45</td>
<td style="border: 1px solid #000">0.82(<b>1.8x</b>)</td>
</tr>
</tbody>
</table>
<ul>
<li>Numbers are in seconds.</li>
<li>Iteration count: 10,000,000 for Release, 1,000,000 for Debug</li>
<li>Compiler used: VS2012</li>
<li>One can find the code for this in benchmark2() function template of miniformat.cpp in <a href="https://bitbucket.org/jj1/miniformat">the project repository</a>.</li>
</ul>
<p>One can observe 1.4x ~ 1.9x performance improvements overall. Not bad. You can also notice that the performance degrades very much in Debug(keep in mind that the iteration count differs between Release and Debug), especially in Win32. It seems mainly due to the fact that I used std::string as an output in this benchmark, which has much more overhead in Debug.</p>
<p>As I said, I had bolted on a support for raw char arrays recently, but it wasn&#8217;t very efficient because I had originally structured the code on the implicit assumption that getting a length of a string is a constant operation. This holds true for std::string and similars, but not for a raw char array. For that, one should pass the current length of the output string through functions. You can see that the render() code above calls string_adaptor::length() in the beginning to get the current length. That&#8217;s far from optimal. So <a href="https://bitbucket.org/jj1/miniformat/commits/9bdb6c0f547b0486cd1238bfa2cf9c3d49304540">I fixed it</a>.</p>
<p>Here are some timings of a benchmark comparing sprintf vs. miniformat(for the both cases of outputting to std::string and to char array), before &amp; after this fix:</p>
<table style="border: 1px solid #000">
<tbody>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">Win32</th>
<th style="border: 1px solid #000">Release/before</th>
<th style="border: 1px solid #000">Release/after</th>
<th style="border: 1px solid #000">Debug/before</th>
<th style="border: 1px solid #000">Debug/after</th>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">Speed-up when outputting to std::string</th>
<td style="border: 1px solid #000">4.42</td>
<td style="border: 1px solid #000"><b>4.20</b></td>
<td style="border: 1px solid #000">0.26</td>
<td style="border: 1px solid #000"><b>0.24</b></td>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">Speed-up when outputting to char array</th>
<td style="border: 1px solid #000"><i>2.59</i></td>
<td style="border: 1px solid #000"><i><b>3.84</b></i></td>
<td style="border: 1px solid #000">1.58</td>
<td style="border: 1px solid #000"><b>1.27</b></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<table style="border: 1px solid #000">
<tbody>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">x64</th>
<th style="border: 1px solid #000">Release/before</th>
<th style="border: 1px solid #000">Release/after</th>
<th style="border: 1px solid #000">Debug/before</th>
<th style="border: 1px solid #000">Debug/after</th>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">Speed-up when outputting to std::string</th>
<td style="border: 1px solid #000">3.81</td>
<td style="border: 1px solid #000"><b>3.81</b></td>
<td style="border: 1px solid #000">1.13</td>
<td style="border: 1px solid #000"><b>1.06</b></td>
</tr>
<tr style="border: 1px solid #000">
<th style="border: 1px solid #000">Speed-up when outputting to char array</th>
<td style="border: 1px solid #000"><i>2.19</i></td>
<td style="border: 1px solid #000"><i><b>5.13</b></i></td>
<td style="border: 1px solid #000">3.91</td>
<td style="border: 1px solid #000"><b>3.51</b></td>
</tr>
</tbody>
</table>
<ul>
<li>Numbers mean a speed-up factor of miniformat compared to sprintf.</li>
<li>Compiler used: VS2012</li>
<li>One can find the code for this in benchmark() function of miniformat.cpp in <a href="https://bitbucket.org/jj1/miniformat">the project repository</a>.</li>
</ul>
<p>Before this fix, the speed-ups in the case of outputting to char array were less than the ones in the case of outputting to std::string because of the inefficiency mentioned above(4.42 vs 2.59 on Win32/Release, 3.81 vs 2.19 on x64/Release). With the fix, the speed-ups of outputting to char array has come close to or exceeded the ones of outputting to std::string. Again, you can see the inefficiency of std::string on Debug, which actually makes the speed-up factor of miniformat less than one on Win32/Debug.</p>
<h3>Conclusion</h3>
<p>I think miniformat is now in a decent state. As I said, it&#8217;s not exactly functionally equivalent to sprintf and some people don&#8217;t like possible code bloat that an extensive use of C++ template brings. I definitely won&#8217;t say benchmarks above are scientific. Still, it brings type-safety and speed-up of up to 4~5x (than sprintf) as just a header-only library with no dependency.</p>
<p>It&#8217;s not yet using C++11 stuff. In a related node, one should still append .c_str() when putting std::string as an input argument. I tried to do without it, but without move constructor stuff in C++11, it seemed very difficult to not introduce any copying. <a href="http://en.cppreference.com/w/cpp/utility/functional/ref">std::ref</a>)(also, available in C++11) can do the trick, but it requires more typing than adding .c_str()! If anyone knows a solution for this without introducing a dependency, please enlighten me.</p>
<p>I welcome suggestions!</p>
<p>(I posted this article to<a href="http://scriptogr.am/jj"> my personal blog</a>, too.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/04/13/a-fast-type-safe-minimal-string-formatting-library-miniformat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android piracy still sucks</title>
		<link>http://www.altdevblogaday.com/2013/04/11/android-piracy-still-sucks/</link>
		<comments>http://www.altdevblogaday.com/2013/04/11/android-piracy-still-sucks/#comments</comments>
		<pubDate>Thu, 11 Apr 2013 22:37:02 +0000</pubDate>
		<dc:creator>Kyle-Kulyk</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Bizdev]]></category>
		<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29314</guid>
		<description><![CDATA[<p><span style="font-size: small"><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/04/you_are_a_pirate.jpg"><img class="alignleft  wp-image-29315" style="margin: 5px" alt="you_are_a_pirate" src="http://www.altdevblogaday.com/wp-content/uploads/2013/04/you_are_a_pirate.jpg" width="240" height="179" /></a></span>I don’t consider myself naive.  I understand piracy is rampant; I’ve known this for years and when I decided that I’d form an indie studio two years ago I like to think that I did so with my eyes open.  Deciding to switch careers and go indie wasn’t a decision that was made lightly and my family and I knew beforehand that it wasn’t going to be a walk in the park.  The reward of creating even a modestly successful business would be worth it.  I still believe that.  Still, with the release of our new mobile puzzler, <a title="Vex Blocks" href="http://itzyinteractive.com/vexblocks/" target="_blank">Vex Blocks</a>, there’s an emotional, open-handed slap across the ear to be had when you realize that your release is being pirated at a rate of 20:1.  On the Android market, a developer&#8217;s hard work is so devalued that 95% of gamers would rather pirate your game by the thousands than pay a dollar to help support what you’re doing and enable you to feed your family.  Even though I was aware that piracy on Android was bad, it’s a soul shaking realization when it hits in relation to your own product and it left me to question if it’s even possible to make a living as an independent developer.  All piracy sucks and the Android market isn&#8217;t alone in fighting this scourge, but what can be done and how has it impacted the games we make?</p>
<p><a href="http://www.altdevblogaday.com/2013/04/11/android-piracy-still-sucks/" class="more-link">Read more on Android piracy still sucks&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p><span style="font-size: small"><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/04/you_are_a_pirate.jpg"><img class="alignleft  wp-image-29315" style="margin: 5px" alt="you_are_a_pirate" src="http://www.altdevblogaday.com/wp-content/uploads/2013/04/you_are_a_pirate.jpg" width="240" height="179" /></a></span>I don’t consider myself naive.  I understand piracy is rampant; I’ve known this for years and when I decided that I’d form an indie studio two years ago I like to think that I did so with my eyes open.  Deciding to switch careers and go indie wasn’t a decision that was made lightly and my family and I knew beforehand that it wasn’t going to be a walk in the park.  The reward of creating even a modestly successful business would be worth it.  I still believe that.  Still, with the release of our new mobile puzzler, <a title="Vex Blocks" href="http://itzyinteractive.com/vexblocks/" target="_blank">Vex Blocks</a>, there’s an emotional, open-handed slap across the ear to be had when you realize that your release is being pirated at a rate of 20:1.  On the Android market, a developer&#8217;s hard work is so devalued that 95% of gamers would rather pirate your game by the thousands than pay a dollar to help support what you’re doing and enable you to feed your family.  Even though I was aware that piracy on Android was bad, it’s a soul shaking realization when it hits in relation to your own product and it left me to question if it’s even possible to make a living as an independent developer.  All piracy sucks and the Android market isn&#8217;t alone in fighting this scourge, but what can be done and how has it impacted the games we make?</p>
<p>We launched the paid, full version of Vex Blocks on Google Play first for the simple fact that it was finished first.  We knew the market for paid apps on Android was limited compared to others, but I don’t think we were really conscious of just how big a role piracy played.  Our first release, <a title="Itzy3d" href="http://itzyinteractive.com/itzy3d/" target="_blank">Itzy3d</a>, marked our first steps into the world of mobile game development.  When we released Itzy3d, our plan was to have a full, paid version and then a free, lite version.  The paid version of Itzy3d was all but ignored on the Android marketplace, as we suspected it would be while the lite version was downloaded considerably more than its iOS counterpart, by roughly 5:1.  There was at least an appetite for our products on Android so skipping out on a Google Play release didn&#8217;t even occur to us with our follow-up title.</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/04/android_1.jpg"><img class="alignright" style="margin: 5px" alt="android_1" src="http://www.altdevblogaday.com/wp-content/uploads/2013/04/android_1.jpg" width="216" height="162" /></a>What we didn&#8217;t know with Itzy3d was actual numbers on how many copies of the game were installed on devices compared to how many we sold via Google Play.  With Vex Blocks, we’re able to see how many copies are out in the wild compared to how many copies we’ve sold.  These statistics don’t change our approach to Android releases.  The impact is more of an emotional toll when you realize the bulk of gamers out there on Android you’re trying to reach with your product don’t have any interest in supporting that product, even if they use it.</p>
<p>Over the years I’ve heard plenty of arguments trying to justify why piracy isn&#8217;t really an issue for developers.  The main one you always hear is, “Those people would have never bought the game in the first place.  No money is lost.”</p>
<p>The idea that certain people just never buy games is ridiculous.  Arguing that pirate gamers would just cease gaming if they couldn&#8217;t pirate is utter nonsense.  Add to that the cost barrier for mobile gaming is generally so low, and it just boils down to pirates are cheap.  Full stop.  Pirates who can’t spend half the price of a large cup of coffee to support a game they want to play shouldn&#8217;t make excuses or try to rationalise their actions.  They’re cheap and they’d rather open themselves up to malware infected copies found in the gutters of the internet than compensate developers for their work.  Now I&#8217;m sympathetic to the fact that in some countries, due to government restrictions, the only way you can access television shows, music and, yes, mobile games is through illegal sites, but the bulk of pirated copies we’re seeing of our game aren&#8217;t coming from these countries.</p>
<p>Pirates will argue that nothing is stolen as the product is only copied, so it’s not even a crime, but of course the reality is every pirated copy of a game removes that person from the pool of potential customers and with 95% of your customers not willing to pay for your product, that doesn&#8217;t leave developers much room to work with on Android.  So, the piracy ship has sailed and aside from becoming bitter old men who rant on blogs and shake their fist at kids who walk in front of their house too slowly, what can be done?  Price competition isn&#8217;t a factor.  The race to the bottom is already over and, surprisingly, no one came out the victor.  Daring to even charge a dollar your game is in itself an invitation to pirate now.  The ease with which pirates can copy a developers work has fundamentally changed the way developers cope and the end result is a diminished product for all.</p>
<p>There are numerous ways a developer can attempt to limit the impact of piracy issues.  You could simply avoid developing for Android, but there is still a market consisting of legitimate Android users out there and it’s not that other platforms are immune to piracy.  I love creating games for Android devices and I&#8217;m humbled by the support we’ve received from our players.  I wouldn&#8217;t ignore the gamers who do support our products.  Many of the other methods to deal with piracy involve lessening the experience for legitimate gamers on mobile (and on other platforms).  DRM is one route.  The general thinking is, the harder you make it to pirate your work, the more chance that some pirates might actually pay to play your game due to the effort involved in cracking or finding a pirated version.  There’s certainly some validity to that approach but as we’ve witnessed with a few recent, high profile examples of digital rights management such as launch issues surrounding Diablo 3 and SimCity, this has the potential to backfire and hurt your paying users.</p>
<p>You can require mandatory sign-up as well, but this has a tendency to alienate those who simply want to buy a game and play, hassle free.  That leaves the freemium method of releasing your game filled with upgrades, advertisements or both.  It’s certainly the route that more mobile developers are choosing, including ourselves, but again this can lead to a lesser experience as advertisements throughout a game become tiresome quickly, and an over reliance of micro-transactions can also turn gamers away.</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/04/monkey_island_codewheel.jpg"><img class="alignleft" style="margin: 5px" alt="monkey_island_codewheel" src="http://www.altdevblogaday.com/wp-content/uploads/2013/04/monkey_island_codewheel.jpg" width="180" height="180" /></a>Alternately developers can choose to embrace piracy.  There’s the chance that a happy pirate may promote your game simply through word of mouth.  For indie developers, creating a great product is job one, but getting noticed is by far the real battle.  The next great novel could be sitting in a pile of thousands of books but if no one picks it up to read it in the first place the author could very likely die in obscurity.  Similarly, great games need to be played in the first place for anyone to discover them and if they’re played as a result of piracy and discovered in that fashion, the argument can be made that the pirates did the developer a service.  Of course it’s only a service if the pirates tell enough gamers from the 5-10% of Android gamers who legitimately support developers &#8211; ideally before those developers are forced to close their doors.</p>
<p>But hey, why should developers going under matter to pirates?  By that point they&#8217;ve already moved on to helping themselves to the next game.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/04/11/android-piracy-still-sucks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designing a game to behave in ways for which it was not designed</title>
		<link>http://www.altdevblogaday.com/2013/04/09/designing-a-game-to-behave-in-ways-for-which-it-was-not-designed/</link>
		<comments>http://www.altdevblogaday.com/2013/04/09/designing-a-game-to-behave-in-ways-for-which-it-was-not-designed/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 01:04:03 +0000</pubDate>
		<dc:creator>Alex Norton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29289</guid>
		<description><![CDATA[<h2>Prologue</h2>
<p>I’d like to start this article by pointing out that it is merely a documenting of my own personal experience and thoughts that led from it, and in no way is a treatise on what I think everyone should do. Please take it with a grain of salt.</p>
<p><a href="http://www.altdevblogaday.com/2013/04/09/designing-a-game-to-behave-in-ways-for-which-it-was-not-designed/" class="more-link">Read more on Designing a game to behave in ways for which it was not designed&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<h2>Prologue</h2>
<p>I’d like to start this article by pointing out that it is merely a documenting of my own personal experience and thoughts that led from it, and in no way is a treatise on what I think everyone should do. Please take it with a grain of salt.</p>
<p>&nbsp;</p>
<h2>Introduction</h2>
<p>Emergent behaviour is something that has really surprised and fascinated me in the past with gaming communities. A particularly clean-cut example is Minecraft. Despite being designed as a sandbox game, the game’s community has grown to accomplish some incredible feats including <a title="A computer in Minecraft" href="https://www.youtube.com/watch?v=pnZ0ZFxBg0s">a working computer</a> as well as people <a title="Minecraft Pong" href="https://www.youtube.com/watch?v=20HQOwDCbWs">making games within the game</a>, which – to my mind – is just incredible. Given enough momentum, and given the right design choices in a game project, people will start to play a game in ways that it was not designed for – sometimes to very interesting effect.</p>
<p>So naturally, when this sort of thing started happening – albeit in a less grandiose fashion – within my own game’s community, I really found it astounding, and it led to some interesting revelations and thoughts for expansion, which I will go into later.</p>
<p>&nbsp;</p>
<h2>My own experience with emergent player behaviour</h2>
<p>First, let me explain what happened within my own community to lead to these revelations, and to the eventual typing of this article. Some of you may know me for my main project, <a title="Malevolence Homepage" href="http://www.malevolencegame.com/">Malevolence: The Sword of Ahkranox</a>. Among those who know and play the game, it has become infamous for its difficulty – which it was designed for – and the sheer effort required just to stay alive in the game when everything in it tries to kill you in the most creative way possible. This factor alone has led to its small, but dedicated fan-base to have a somewhat gleefully masochistic view towards playing, and many community requests for expansion to the game have revolved around this mentality, including making dungeons darker and more difficult to traverse, making traps deadlier, combat less forgiving and primarily the addition of a perma-death option to greatly multiply the sense of risk.</p>
<p>The emergent player behaviour that led from this started out fairly simply. People wanted to know how long they could survive in the game’s hostile environment, which only gets more difficult the longer you stay alive, and so, competitions arose to see who could live the longest. To my mind, this was inevitable and very much tied into the base competitive nature of the modern gamer.</p>
<p>However, it soon escalated from there with the addition of functionality to be able to “claim” locations as being the first to discover it. The game world in Malevolence is infinite, and everyone is in an exact copy of the same world, so people can travel as far as they like to discover new locations which are procedurally generated by the game, but still exist in everyone else’s copy.</p>
<div class="wp-caption aligncenter" style="width: 356px"><a href="http://4.bp.blogspot.com/-k6O364sqC6w/UMSYm_BgJcI/AAAAAAAABuo/5fEaPUOfnXQ/s1600/02.jpg"><img class=" " alt="" src="http://4.bp.blogspot.com/-k6O364sqC6w/UMSYm_BgJcI/AAAAAAAABuo/5fEaPUOfnXQ/s1600/02.jpg" width="346" height="215" /></a><p class="wp-caption-text">The procedural nature of Malevolence means there&#8217;s<br />always something new to find. This makes players feel<br />a sense of ownership if they&#8217;re the first to find something.</p></div>
<p>This has led to certain players making it their entire goal to just wander the game world claiming as many places as they can get their digital hands on. One player has already found and claimed over 1100 unique locations, and the community as a whole has claimed over 10,000. It quickly became a mark of status on the forums to have claimed the most locations, and certain players would become minor celebrities for their efforts. I marvel to think what people will manage to accomplish once the quick-travel system is implemented later this month.</p>
<p>But this sort of digital achievement was not enough for the community, and &#8211; just recently – a forum member posted a challenge request for four others to join. He had found a particularly difficult level and wanted to challenge a handful of other players – on perma-death – to reach the end of the level alive (no small feat, given the difficulty). A section of the forum was dedicated to the exercise, and many hundreds of members watched along eagerly as the characters battled it out to survive (they documented their progress with screenshots and narrated videos). The entire ordeal became somewhat of a grand spectacle amongst fans of the game – a bit like reality TV in RPG form – and people even went so far as to place bets on how long people would last. Play strategies and tactics were discussed at length and equipment was debated over across many posts.</p>
<p>The popularity of this exercise, of course, led to more tournaments – of varying types &#8211; being organised and participated in, eventually leading to a thriving sub-culture within the community. This, in turn, led to the most recent piece of emergent player psychology which really caught my attention: Legendary Items.</p>
<p>Many games have legendary items in them – weapons or armour which have phenomenal properties which players actively seek out for their own – however, these items are only legendary because they have been written by a game designer to be legendary. What has been happening in my own community is that certain players are managing, through quite impressive play skill, to survive exceptional levels of in-game adversity, and when they have finished their challenges (to much community fanfare) they have been distributing their (procedurally generated – and thus, unique) equipment to the community through the game’s internal item sharing system. These armour items and weapons have become highly sought-after legendary items not because they have been written to be valuable, but because actual people have made them famous through very public shows of in-game heroism and skill. To the best of my knowledge, this is unique in video games (though I could be wrong – I don’t profess to know every game and its contents). Regardless, it is fascinating to see these purely digital items gain a real sense of perceived value not due to rarity in the game, or clever writing, but by actual achievement by real people.</p>
<p>I am sure that other bits of emergent player behaviour will appear over time, but thus far, the above is what I have experienced. This alone has led to some very interesting thoughts, which I felt that I should share.</p>
<div class="wp-caption aligncenter" style="width: 333px"><a href="http://4.bp.blogspot.com/--ztUiLq_wD4/UMcgn8BcTPI/AAAAAAAABzA/nCoGexQYTck/s1600/Day2_1.jpg"><img class="  " alt="" src="http://4.bp.blogspot.com/--ztUiLq_wD4/UMcgn8BcTPI/AAAAAAAABzA/nCoGexQYTck/s1600/Day2_1.jpg" width="323" height="201" /></a><p class="wp-caption-text">Players congregate around well-known discovered places,<br />such as The View of Inca, because of its abundance of<br />resources. But the heavy visitor traffic simply begets more<br />visitor traffic as word spreads.</p></div>
<p>&nbsp;</p>
<h2>Designing a game to behave in ways for which it was not designed</h2>
<p>It’s no new revelation that a strong community is a valuable asset to an indie game project, but how can one work to strengthen that community?</p>
<p>From my own experience, a community is often strengthened by a sense of ownership over the title. This – at least for me – was achieved by leaving the gameplay style quite open and not pigeon-holing people’s playing angle. An open world with procedurally generated content affords people the feeling that there is always something that only they could have found before – be it an item or location. This makes people feel that it is “theirs”. Naturally, this leads to a desire to show off their “acquisition” to help aid their social standing within the community.</p>
<p>This factor, and the emergent tournaments, has led me to begin serious planning to start implementing in-game functionality which will allow people to set up their own challenges for people to take on and handle for them, as well as showing off their character and gear that they’ve found, but it’s interesting how this could be applied to other projects as well.</p>
<p>If a game project is a solitary experience, then it will remain so in the player’s mind, however, if you add in a sense of unique accomplishment – separate to normal game goals which everyone is doing – and make something an experience for which they can know that no-one else has done, then that makes them want to share it and talk about it. This communication builds community bonding, and the community talks about it, leading to more people hearing about the project. People start discussing their achievements as though it was an actual thing that they, themselves, personally did on the weekend.</p>
<p>&nbsp;</p>
<h2>Conclusion</h2>
<p>In an industry that has an ever-increasing indie push, the importance of marketing and publicity is becoming more and more relevant, and that onus is usually placed on the developer at the early stage, as marketing departments and publicists are expensive for independent developers. As such, anything that can help word spread about a project is a good thing. Talk is cheap, and with a little bit of clever design and forethought regarding emergent player behaviour, this can be turned into a very valuable part of your game’s functionality.</p>
<p>Thank you for taking the time to read about my personal experiences. I hope they’ve helped!</p>
<p>&nbsp;</p>
<h2>Addendum</h2>
<p>After publishing this I had a developer friend make an interesting point which I thought I&#8217;d add to the end of this article.</p>
<p>&nbsp;</p>
<p><em>One interesting observation made about “emergent” behaviour is that players latch onto it due to the very fact that what they’re doing is outside the realms of “what has been designed”.</em></p>
<p><em>Case in point:</em></p>
<p><em>Look at all the stunt videos for Codename Eagle, Battlefield etc… communities pop up with people breaking the game in marvellous ways.  Now compare that to the videos from a game like Crackdown2, in which the “stunts” have been designed into the game structure, ie “park your car here and work out how to flip it to here”… (tip: There probably are none).</em></p>
<p><em>By writing that stuff into the game you’ve transferred ownership away from the players.</em></p>
<p><em>If Quake 2 came with a tutorial on corner-jumping, how many people would care?</em></p>
<p><em>A good developer needs to act as an amplifier… when people do cool stuff, they should use their power over the codebase to amplify the players&#8217; cool stuff. Provide the Lego bricks for them to build with, but be careful not to try and show them what or how to build it.</em></p>
<p>&nbsp;</p>
<p>This is, precisely, what I aim to do, given recent developments on my project, and what I will aim to do for future projects as well :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/04/09/designing-a-game-to-behave-in-ways-for-which-it-was-not-designed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designing &#8220;10000000&#8243; as a Free To Play Game</title>
		<link>http://www.altdevblogaday.com/2013/04/05/designing-10000000-as-a-free-to-play-game/</link>
		<comments>http://www.altdevblogaday.com/2013/04/05/designing-10000000-as-a-free-to-play-game/#comments</comments>
		<pubDate>Fri, 05 Apr 2013 22:38:18 +0000</pubDate>
		<dc:creator>Raul Aliaga Diaz</dc:creator>
				<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29279</guid>
		<description><![CDATA[<p dir="ltr">1000000 [<a href="https://itunes.apple.com/se/app/10000000/id544385071?l=en&#38;mt=8">iOS</a>, <a href="https://play.google.com/store/apps/details?id=com.eightyeightgames.tenmillion">Android</a>, <a href="http://store.steampowered.com/app/227580/">Steam</a>] is a <a href="http://toucharcade.com/2012/07/26/10000000-review/">puzzle-runner-rpg-like</a> game developed by <a href="http://eightyeightgames.com/">Eightyeight Games</a>. If you haven’t played it, I seriously recommend to check it out since it’s awesome, and its story of <a href="http://www.wired.co.uk/news/archive/2012-09/04/luca-redwood">development</a> and <a href="http://pockettactics.com/2012/12/05/wordpuzzle-game-of-the-year-2012-10000000/">success</a> is as amazing and inspiring as the game itself.</p>
<p><a href="http://www.altdevblogaday.com/2013/04/05/designing-10000000-as-a-free-to-play-game/" class="more-link">Read more on Designing &#8220;10000000&#8243; as a Free To Play Game&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p dir="ltr">1000000 [<a href="https://itunes.apple.com/se/app/10000000/id544385071?l=en&amp;mt=8">iOS</a>, <a href="https://play.google.com/store/apps/details?id=com.eightyeightgames.tenmillion">Android</a>, <a href="http://store.steampowered.com/app/227580/">Steam</a>] is a <a href="http://toucharcade.com/2012/07/26/10000000-review/">puzzle-runner-rpg-like</a> game developed by <a href="http://eightyeightgames.com/">Eightyeight Games</a>. If you haven’t played it, I seriously recommend to check it out since it’s awesome, and its story of <a href="http://www.wired.co.uk/news/archive/2012-09/04/luca-redwood">development</a> and <a href="http://pockettactics.com/2012/12/05/wordpuzzle-game-of-the-year-2012-10000000/">success</a> is as amazing and inspiring as the game itself.</p>
<div id="attachment_29280" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/04/10000000_pc.jpg"><img class=" wp-image-29280 " alt="The game in its PC/Mac port." src="http://www.altdevblogaday.com/wp-content/uploads/2013/04/10000000_pc.jpg" width="500" height="281" /></a><p class="wp-caption-text">The game in its PC/Mac port.</p></div>
<p dir="ltr">What’s also interesting is that the game allows itself to be designed as a Free to play game. It is a particularly good example because is indisputably a great game, is accessible for any platform you’d like to play it and we can use it as an example for this thought experiment of making it Free to play.</p>
<p dir="ltr">So here we will discuss a brief overview on how the game can be tweaked and expanded in its design to suit a Free to play strategy, and what would imply doing so, changing from a defined product to an ongoing service. From this point, we’ll assume you have played the game. If you feel like just reading, check <a href="http://www.modojo.com/features/10000000_cheats_and_tips">here</a> or <a href="http://www.giantbomb.com/10000000/3030-39155/">here</a> (not recommended).</p>
<p dir="ltr"><em><strong>Design changes and expansions</strong></em></p>
<p dir="ltr">Using the <a href="http://www.whatgamesare.com/2012/10/the-free-to-play-triangle-game-economics.html">Free to play triangle lens</a> we can discuss three venues for monetization: Skips, Unlocks and Boosts. They are based on traditional “sim management” games, so we can adapt the triangle here to Content, Unlocks and Boosts.</p>
<ul>
<li>
<p dir="ltr"><strong>Content</strong>: Pretty much all the game’s content is available behind locks achievable through gameplay and achievements, but the game could include more dungeons, sets of tiles, new achievements, episodic content or new heroes. Also, maybe just selling the <a href="http://www.youtube.com/watch?v=Jf3EMLEQPnM">music</a> can be a good and simple trick.</p>
</li>
<li>
<p dir="ltr"><strong>Unlocks</strong>: All the locks on things that are accessible through “repairs”, the list of upgrades, access to dungeons, the alchemist potions. An additional element could be putting caps or limits on the amount of resources (wood, rock, coins and XP) that can be had at a time and unlock them through monetization/other resources. In 10000000, you can carry at most 4 items on a run: another potential source of revenue could be selling the ability to increase that limit so players can carry more.</p>
</li>
<li>
<p dir="ltr"><strong>Boosts</strong>: This is relatively straightforward, since when you’re playing you receive weapons, food, keys, orbs and scrolls that you can carry to the next run and act as boosts. All of these can be sold separately.</p>
</li>
</ul>
<p dir="ltr">There are also two key areas for feature expansion. The first is a storage room that can hold any extra boosts the player found while running or purchased at the store. This causes the player to manage more effectively how they proceed on each run. These limits could be expanded through purchases.</p>
<p dir="ltr">Second, the Alchemist room enables a particular effect at the cost of a trade off. This should be changed to a boost fashion in which these alchemist effects can last only for one run, possibly with less strict tradeoffs and also stored in your storage room.</p>
<div id="attachment_29281" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/04/Alchemist.png"><img class=" wp-image-29281 " alt="The Alchemist’s room" src="http://www.altdevblogaday.com/wp-content/uploads/2013/04/Alchemist-225x300.png" width="300" height="400" /></a><p class="wp-caption-text">The Alchemist’s room</p></div>
<p dir="ltr">A third, possibly controversial expansion would be “crafting”. Retention is a <a href="http://cristinajcordova.com/post/36553000358/the-biggest-problem-in-mobile-retention">huge issue</a> in mobile, and something that could help to promote players to craft a plan to come back can be precisely the tradeoff of time versus money for alchemist effects, in which traditional game resources can be used so their “resource flow” closes. This is particularly important since puzzle/running games might have <a href="http://techcrunch.com/2012/12/14/engagement-mobile-games/">good retention but low frequency of use per week</a>. Hence, this add-on would allow players to increase their chances to move through an engagement/monetization <a href="http://www.slideshare.net/betable/its-an-arms-race-acquisition-retention-and-monetization-in-mobile-gaming">funnel</a> in a better way.</p>
<p dir="ltr">However, the Triangle suggests to monetize with at most two of the methods, which is sound advice. Given that 10000000 isn’t a place to “enjoy watching an aquarium” such as DragonVale or Hay Day, the clever thing would be to stick with unlocks and boosts.</p>
<p dir="ltr">So that would be it, if we were only considering <strong>monetization</strong> aspects of Free to play games. As of now, we have discussed monetization venues for in-app purchases (which many paid games include), but free to play games <strong>must</strong> include social aspects within their designs. In a nutshell, <a href="http://gamasutra.com/blogs/PhilipDriver/20130326/189315/Player_Valuation_For_Marketing_in_Free_to_Play_Games.php">non-paying players can be your best sources of new players</a> (for another more general discussion, see <a href="http://platformed.info/the-network-effect-playbook-social-products-win-with-utility-not-invites/">here</a>).</p>
<p dir="ltr">What social features can we include in this game? Endless runner games usually allow players to share their scores as a text on social networks such as Twitter or Facebook, but that’s rather limited given the unique aesthetic of the game, and specially its music. The guys at Nimblebit know this very well with their feature of <a href="http://towers.nimblebit.com/1027355270">sharing towers</a> in Tiny Tower, planes on Pocket Planes and now video on their latest game: <a href="https://everyplay.com/nimble-quest">Nimble Quest</a>, through the <a href="https://everyplay.com/">Everyplay</a> service. See it at work <a href="https://everyplay.com/player?id=24004">here</a>.</p>
<p>10000000 is an excellent game to share video replays to feel closer to the excitement of the game itself and sharing amazing feats that can be achieved in it. One additional content tweak would be increasing the animations and “pyrotechnic effects” of achieving chain reactions with the tiles in the running zone. When you’re playing and doing amazing feats, you feel great but you’re focused on the tiles, and when someone else is viewing, it would be nice to have something for other people to watch that is spectacular.</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/04/SonicDashTrick.png"><img class="aligncenter size-medium wp-image-29282" alt="SonicDashTrick" src="http://www.altdevblogaday.com/wp-content/uploads/2013/04/SonicDashTrick-168x300.png" width="168" height="300" /></a></p>
<p dir="ltr">For example in Sonic Dash, they control the pacing of races and allow the player to do some “quick time swipes” for Sonic to breakdance in the air. This looks awesome and also wins some rings if done right.</p>
<p dir="ltr">If we want to go nuts, we can even discuss a room dedicated to store these glorious gameplay images and/or videos so the player herself can revisit them in the game or have it for her friends to see, but that’s a lot of additional work, development-wise.</p>
<p dir="ltr"><em><strong>Execution tradeoffs</strong></em></p>
<p>We have discussed monetization and social aspects for the game to be considered a Free to play game, is that it? Well, not so much. Free to play games start when the game launches, and operate as <a href="http://www.gamasutra.com/blogs/SethSivak/20130305/187766/">a service</a>, not a product. This cannot be stressed enough as it is easy to overlook in practical decisions and prioritizations how to approach the execution of these designs and handling the expectations associated to them.</p>
<p>So what does all this mean? In addition to the elements mentioned above they need to pass a check for game balance from a <a href="http://lloydmelnick.com/2013/03/20/why-would-anyone-buy-a-virtual-good/">qualitative</a> <a href="http://www.gamasutra.com/blogs/LarsDoucet/20121115/181659/Free_2_Play_and_the_Four_Currencies.php">perspective</a> and a quantitative one, hopefully <a href="http://www.theverge.com/2012/11/14/3647410/punch-quest-goes-paid-after-free-to-play-failure%20http://ufert.se/user-acquisition/mobile-game-analytics/analytics-is-not-a-cost-center/">informed through analytics</a> -especially when the game is already live. Additional checks must be passed regarding UI, accessibility, and timing of the monetization elements. There’s a huge amount of games that hide away the options to pay more under too many screens, unclear menus or the wrong timing for monetization, making it annoying instead of convenient.<b id="internal-source-marker_0.7604140245821327"><br />
</b></p>
<p dir="ltr">Adjusting the expectations is another important issue. It is fairly easy to <a href="http://www.theverge.com/2012/11/14/3647410/punch-quest-goes-paid-after-free-to-play-failure">fail at Free to play</a> with a great game, even <a href="http://penny-arcade.com/report/article/going-broke-with-success-how-an-app-with-200000-downloads-led-to-devel">spectacularly</a>. Many times this is because developers fail to see the service aspects and just throw in some IAP without too much thought about them, only to claim foul when they don’t get disgustingly rich overnight.</p>
<p dir="ltr">Then all the work needed with art, programming, balancing and testing needs to be estimated and considered to be split in several iterations that have different tradeoffs on different platforms when they go live. For example, monetization re-designs would allow the game to be set free and include more revenue venues but it would not achieve all of its strength without the social features. On the other hand, working the social features first would put the game in the eyes of more potential players that still would be stopped at a paywall if they’re not willing to pay anyway. However, the social features discussed here can be integrated in the game without making it Free to play at all and it could potentially be a good thing anyway.</p>
<p dir="ltr">In my particular opinion, I would thoroughly design all the aforementioned elements up to a point of actual estimation of the development work needed and consider the tradeoffs with the actual resources available and any other strategic considerations for the game. 10000000 is already present on several platforms and the best course of action would be to set up a <a href="http://www.altdevblogaday.com/2013/02/04/brewing-your-own-game-analytics-service/">minimal analytics service</a> on all platforms to monitor the game’s performance and then decide how to go from there, possibly making it free to play on Android first (and possibly an <a href="http://ufert.se/user-acquisition/mobile-game-monetization/mobile-gaming-revenues-are-shifting-to-tabletsand-to-asia/">Asian localization</a>). Then moving these changes to all platforms including the social features, that can be developed for the game to scale once you have data and revenue to support such scaling.</p>
<p dir="ltr"><em><strong>Where do we go from here?</strong></em></p>
<p dir="ltr">This was a general discussion to a deeper level of how to take an already great game to millions of players through the Free to play model, considering several aspects of the decisions involved.</p>
<p>For more detailed discussions on monetization and Free to play, I recommend to check:</p>
<ul>
<li>
<p dir="ltr"><a href="http://www.gamasutra.com/view/feature/188359/the_language_of_monetization_design.php">The Language of Monetization Design</a></p>
</li>
<li>
<p dir="ltr"><a href="http://deconstructoroffun.blogspot.fi/2013/02/monetizing-infinite-runner.html">Monetizing an Infinite Runner</a></p>
</li>
<li>
<p dir="ltr"><a href="http://www.gamasutra.com/view/feature/6592/the_design_of_freetoplay_games_.php">The Design of Free-to-Play Games, Part 2</a> (<a href="http://www.gamasutra.com/view/feature/183307/Designing_Freemium_Titles_for_Hardcore_Gamers.php">Part 1</a>)</p>
</li>
<li>
<p dir="ltr"><a href="http://www.gamesbrief.com/2012/12/managing-a-free-to-play-product-a-publishers-perspective/">Managing a Free-to-Play Product: a Publisher’s Perspective</a></p>
</li>
</ul>
<p dir="ltr">To understand all the nuances involved in the design of a Free to play “casual” successful title, Candy Crush Saga:</p>
<ul>
<li>
<p dir="ltr"><a href="https://medium.com/mobile-games/f89203a90c13">Why Candy Crush Saga is taking over the world</a></p>
</li>
<li>
<p dir="ltr"><a href="http://www.gamasutra.com/view/news/188962/Video__Candy_Crush_Saga_uses_luck_in_the_right_places.php">Video: Candy Crush Saga uses luck in the right places</a> (GDC 2013)</p>
</li>
</ul>
<p dir="ltr">The controversial decision made by Candy Crush developers of not to use a virtual currency in their game and going with direct purchase of boosts draws special attention. This was a risky and bold decision (albeit a good one given the game&#8217;s performance).</p>
<p dir="ltr">For expectation handling and pitfall avoidance: <a href="http://www.gamasutra.com/view/feature/181419/7_ways_to_fail_at_freetoplay.php">7 Ways to Fail at Free-to-Play</a>. On social aspects, a previous post of mine: <a href="http://www.altdevblogaday.com/2011/05/17/some-social-game-design-principles-before-launch/">Some social game design principles before launch</a>. More resources in general, my previous post: <a href="http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/">Almost everything you need to know to enter mobile game development on 2013</a>.</p>
<p dir="ltr">In summary, 10000000 is a great game, that includes within itself many options to make it <strong>a game that allow players themselves to put a better price on the value of the whole experience -a fun, convenient and social experience</strong>. When we analyze the tweaks and additions we can make to the game, we must take into consideration the costs and benefits of each improvement and how they can add value to the whole game incrementally. This will change from a finished, bounded product to an ongoing live service dedicated to its community of fans.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/04/05/designing-10000000-as-a-free-to-play-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is gimbal lock and why do we still have to worry about it?</title>
		<link>http://www.altdevblogaday.com/2013/03/15/what-is-gimbal-lock-and-why-do-we-still-have-to-worry-about-it/</link>
		<comments>http://www.altdevblogaday.com/2013/03/15/what-is-gimbal-lock-and-why-do-we-still-have-to-worry-about-it/#comments</comments>
		<pubDate>Fri, 15 Mar 2013 14:17:48 +0000</pubDate>
		<dc:creator>Niklas Frykholm</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[euler angles]]></category>
		<category><![CDATA[gimbal lock]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29247</guid>
		<description><![CDATA[<p>If you have ever worked with rotations and Euler angles you are probably at least somewhat familiar with the phrase <em>&#8220;gimbal lock&#8221;</em>. But like many things concerning rotations, angles and spaces it can be tricky to visualize and get a good grasp of.</p>
<p><a href="http://www.altdevblogaday.com/2013/03/15/what-is-gimbal-lock-and-why-do-we-still-have-to-worry-about-it/" class="more-link">Read more on What is gimbal lock and why do we still have to worry about it?&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>If you have ever worked with rotations and Euler angles you are probably at least somewhat familiar with the phrase <em>&#8220;gimbal lock&#8221;</em>. But like many things concerning rotations, angles and spaces it can be tricky to visualize and get a good grasp of.</p>
<p>Sometimes it feels like every time I need to think about gimbal lock I have forgotten everything about it and have to go back the beginning and ask myself: OK, but what is it <em>really</em> that is happening?</p>
<p>Hopefully, this article will take care of that problem.</p>
<p>The <a class="link" href="http://en.wikipedia.org/wiki/Gimbal_lock">Wikipedia page</a> shows how gimbal lock can happen in a mechanical system. But it isn&#8217;t necessarily self-evident how this translates to the computer game world. In the computer there are no mechanical limitations, we can rotate an object however we like. How can anything be &#8220;locked&#8221;?</p>
<h2>Euler angles</h2>
<p>When we are using <a class="link" href="http://en.wikipedia.org/wiki/Euler_angles">Euler angles</a>, we represent an object&#8217;s orientation as three consecutive rotations around the object&#8217;s axes. We can choose the axes and the order in which we apply the rotations arbitrarily, and depending on what we choose we get different Euler representations. So XYZ is the Euler representation where the first angle rotates the object around its X-axis, the second around its (new) Y-axis and the third around its (new) Z-axis. YZX gives us a different representation. We can even have representations with repeated axes, such as XZX.</p>
<p>So if we want to talk about the &#8220;Euler angles&#8221; of an object, we really must also talk about what axes we are rotating around and in what order. Otherwise we have no idea at all what we are talking about. Unfortunately, many articles about Euler angles are pretty sloppy with this and throw around terms like <em>yaw</em>, <em>pitch</em> and <em>roll</em> as if they had completely well-defined and unambiguous meanings. I prefer to use more wordy, but descriptive names, such as <em>euler_xyz[0]</em> that unambiguously state the axis rotation order and the index of the angle we are talking about.</p>
<p>An object has three rotational degrees of freedom and it is quite easy to see that the three Euler angles for a particular axis order (XYZ) are enough to define any possible orientation of an object. Note though that the representation is not unique. There are many possible Euler angles that represent the same orientation. For example, adding 360 degrees to any of the three angles will give us a different representation that results in the same object orientation.</p>
<p>So &#8220;gimbal lock&#8221; doesn&#8217;t mean that there are rotations that can&#8217;t be expressed as Euler angles. We can express any rotation in Euler angle form. Given an object, we can convert its orientation to Euler angles, and from that orientation we can rotate the object however we like and convert the new orientation to other Euler angles.</p>
<p>So what exactly is it that is &#8220;locked&#8221;? It seems we can do whatever we like.</p>
<h2>The &#8220;lock&#8221; in gimbal lock</h2>
<p>The term &#8220;gimbal lock&#8221; comes from the mechanical world. If the problem had originated in the world of computers, it would probably have been called something less confusing, such as &#8220;Euler angle flip&#8221; or &#8220;coordinate singularity&#8221;.</p>
<p>Because, in the computer world, there is really nothing that gets &#8220;locked&#8221;. Instead, the problem is this: when the Euler angles have particular values, there are orientations that are very similar to the current orientation which can&#8217;t be achieved by just making small changes to the Euler angles. In particular, this happens when one of the angles is at 90 degrees, so that two rotation axes coincide.</p>
<p>So even though the orientations are &#8220;close&#8221; in the real world, they are not close in the Euler representation. In fact, at least one of the Euler angles will have to flip 180 degrees in order for us to represent the new orientation.</p>
<p>So one of the angles have to flip? What is the big deal? Can&#8217;t we just flip it and get on with our stuff?</p>
<p>We can, as long as the angles only represent instantaneous &#8220;snapshots&#8221; of the object&#8217;s orientation. However, if the angles represent key frames in an animation and we want to interpolate between those key frames we run into trouble. If one of the angles flips 180 degrees between two key frames and we interpolate between those values, we will see the the object animating through all those 180 degrees. In the viewport, we will see the object doing a &#8220;flip&#8221; or &#8220;roll&#8221; that shouldn&#8217;t be there.</p>
<p>Note that it is only the interpolation that creates this unwanted behavior. If we just displayed the actual key frames and didn&#8217;t interpolate between them &#8212; everything would look right. We could work in Euler angles as much as we liked and be as close to the gimbal lock position as we wanted and no-one would ever know.</p>
<p>So the only thing we need to fix to get rid of gimbal lock is the interpolation. If you have done any work with 3D graphics you probably already know the answer &#8212; to use quaternions instead of Euler angles to represent angles. Quaternions don&#8217;t have the weird singularity points that Euler angles have and we can interpolate between any keyframes by just lerping the quaternions.</p>
<p>It doesn&#8217;t matter if the animation package is using Euler angles internally, as long as we convert everything to quaternions before we do the interpolation. Note that interpolation in quaternion space is not the same as interpolation in Euler space though, so to get as close as possible to what the animator intended, we probably want to sample the animation at our target frame rate and generate our quaternion key frames from those samples, rather than directly converting the animator&#8217;s key frames (which may be further apart).</p>
<p>Well, there is one caveat actually. If we have more than 180 degrees of rotation in a single frame we can&#8217;t represent that nicely with quaternions. Quaternions always lerp the shortest path between two orientations and you can&#8217;t represent several &#8220;laps&#8221; of rotation with quaternions as you can do with Euler angles (by setting one of the angles to 9000 degrees, for example). But you can fix that by sampling at a higher frame rate if you need to represent really fast rotations with quaternions.</p>
<p>So with that we can say good bye and good riddance to Euler angles and never have to worry about their sorry gimbal locking asses ever again.</p>
<p>Or so you may think&#8230;</p>
<h2>The return of gimbal lock</h2>
<p>I certainly thought so, until I started working on the new cutscene animation system for our level editor.</p>
<p>You see, animators really like to work with <em>curves</em>. They like to see a visual representation of what the animation will do to an object over time with key points that can be moved and handles that can be adjusted to change the slope of the curve.</p>
<div id="attachment_29248" class="wp-caption aligncenter" style="width: 970px"><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/03/curves.png"><img src="http://www.altdevblogaday.com/wp-content/uploads/2013/03/curves.png" alt="Curves! Animators love them!" width="960" height="587" class="size-full wp-image-29248" /></a><p class="wp-caption-text">Curves! Animators love them!</p></div>
<p>Quaternions are great for interpolation, but they are no good for curve editing.</p>
<p>Sure, you could probably draw some curves that represented a quaternion (the laziest thing would be to just draw the x, y and z components of the quaternion), but those curves wouldn&#8217;t <em>mean</em> anything to an animator, the way the Euler angle curves do. They wouldn&#8217;t be able to <em>do</em> anything with them.</p>
<p>So, animators want curves with keyframe interpolation. Curves need Euler angles. But what happens when we mix Euler angles with keyframe interpolation? Presto! Our old friend the gimbal lock is back again! Haven&#8217;t we missed him.</p>
<p>That&#8217;s it. We&#8217;re stuck. Gimbal lock is here to stay and the animators will just have to work around it.</p>
<p>And we have to add support for all the usual tricks and workarounds that animators use to get around gimbal lock, such as changing the axis order (from XYZ, to XYZ, XZX or another of the twelve possible permutations), converting to quaternion and back again, applying an &#8220;Euler filter&#8221;, etc.</p>
<p>But who said this game engine gig should be easy?</p>
<p>This has also been posted to <a class="link" href="http://bitsquid.blogspot.com">The Bitsquid blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/03/15/what-is-gimbal-lock-and-why-do-we-still-have-to-worry-about-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Launch Day 2.0</title>
		<link>http://www.altdevblogaday.com/2013/03/12/launch-day-2-0/</link>
		<comments>http://www.altdevblogaday.com/2013/03/12/launch-day-2-0/#comments</comments>
		<pubDate>Tue, 12 Mar 2013 22:48:40 +0000</pubDate>
		<dc:creator>Kyle-Kulyk</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[General Interest]]></category>
		<category><![CDATA[indie]]></category>
		<category><![CDATA[launch]]></category>
		<category><![CDATA[vex blocks]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29243</guid>
		<description><![CDATA[<p><a href="http://itzyinteractive.com/wp-content/uploads/2013/03/Rocket-Launch.png"><img class=" wp-image-693 alignleft" style="margin: 5px" alt="Rocket Launch" src="http://itzyinteractive.com/wp-content/uploads/2013/03/Rocket-Launch.png" width="280" height="208" /></a>I didn&#8217;t sleep well the night before our Sunday launch of <a title="Vex Blocks" href="http://itzyinteractive.com/vexblocks/">Vex Blocks</a>. Despite the weeks we’ve had the game in the hands of testers, a new bug had come to light late Saturday evening. While not game breaking it still needed to be addressed. I stayed up working on the problem until solved. Chat messages, frantic on my part, went back and forth between myself and my partner until between the two of us we were able smooth things out. I then prepped the build for the next morning’s launch and finally after a long day allowed myself to push back away from my desk just after 1am. I tried and failed to sleep after that.</p>
<p><a href="http://www.altdevblogaday.com/2013/03/12/launch-day-2-0/" class="more-link">Read more on Launch Day 2.0&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p><a href="http://itzyinteractive.com/wp-content/uploads/2013/03/Rocket-Launch.png"><img class=" wp-image-693 alignleft" style="margin: 5px" alt="Rocket Launch" src="http://itzyinteractive.com/wp-content/uploads/2013/03/Rocket-Launch.png" width="280" height="208" /></a>I didn&#8217;t sleep well the night before our Sunday launch of <a title="Vex Blocks" href="http://itzyinteractive.com/vexblocks/">Vex Blocks</a>. Despite the weeks we’ve had the game in the hands of testers, a new bug had come to light late Saturday evening. While not game breaking it still needed to be addressed. I stayed up working on the problem until solved. Chat messages, frantic on my part, went back and forth between myself and my partner until between the two of us we were able smooth things out. I then prepped the build for the next morning’s launch and finally after a long day allowed myself to push back away from my desk just after 1am. I tried and failed to sleep after that.</p>
<p>The late night adrenalin rush of fixing a bug on the eve of our self-imposed deadline had fired up my brain and my thoughts erratically leap from point to point like popcorn popping while anxiety knotted up in my stomach and settled in for a winter’s nap. I stared at my bedside table for an undetermined length of time before I eventually drifted off into a fitful sleep.</p>
<p>At some point during the night my wife woke up to comfort our baby girl, Hanna and had fallen asleep in her room. My day started when my wife came back to bed and informed me that our 3-year-old, Jake, was awake and calling for Daddy. I squinted, noticed the sun was up so there was no chance at another hour of sleep and rolled out of bed just as Jake hit the living room and started honking the horn of an obnoxiously noisy pink riding car meant for his sister. I settled him down with a cup of a fruit/veggie juice I have yet the had the courage to taste and turned on “The Cat in the Hat knows a lot about that” before heading to my office to launch our second title.</p>
<p>Launch day this time was different. With our <a title="Itzy3d" href="http://itzyinteractive.com/itzy3d/">first title</a>, our core group hunkered down in my home office in a marathon of testing the ultimately cumulated with “Well. That’s it. Let’s launch.” Someone suggested we should have a drink so we did toasting each other and then that was it. Game launched. The next day I sat, staring at my computer screen knowing I needed to “market” somehow but not having a clue even where to start. This time out there was no empty void of “What the hell do I do now” waiting for me after launch. There’s no one else in the room. No one to raise a toast to. The artwork was finished months ago by very talented student artists. The testers I haven’t actually seen face to face in who knows how long. People complete their assigned tasks and then scatter leaving only us, the two founders of our indie studio, each waking up with their respective families on a cold, Canadian Sunday morning. There was still a long list of of objectives that needed to be completed to launch <a title="Vex Blocks" href="http://itzyinteractive.com/vexblocks/">Vex</a> on other platforms, in other app stores. There’s another team working on our third title that needs checking in on. There’s communications that have been piling up, unanswered while we pushed to complete. The gaping maw of uncertainty that greeted me after the first game released didn&#8217;t exist this time out. I know what needs to be done and we can’t afford to slow down.</p>
<p>So while the Cat in the Hat explains to my 3 year old the benefits to singing underwater with a whale I sat down to release our new game. The sun tries to poke through the clouds outside my office window but it just can’t decide whether it wants to clear up or add to the snow on my back deck. I noticed the time and remembered that Daylight Savings had struck again. I could almost feel that hour suddenly sucked away from me like a voodoo spell setting in as I lamented the time shift. I shook the sudden tiredness off and a quick check of my emails included a brief message from our other developer, my brother-in-law Will. No doubt he had a late night as well. If he wasn’t awake due to work, I&#8217;m sure his sleep would have been interrupted by their first child only weeks old, waking and bellowing his displeasure. I took the few cosmetic changes to <a title="Vex Blocks" href="http://itzyinteractive.com/vexblocks/">Vex Blocks</a> that Will had pushed up to our server, installed the new build and then uploaded the apk file to Google Play. Then I hit “Publish”.</p>
<p>That was it. I leaned back in my chair and despite being told by an online message that it could take hours to populate to Google’s servers, I punched in the url just to see if it was visible. It wasn’t. I went through my email and then checked a few links to press releases that were scheduled to go live that morning to herald the <a title="Vex Blocks" href="http://itzyinteractive.com/vexblocks/">Vex Blocks</a> release. I clicked refresh on the Google Play site again. Still nothing. I flipped back and forth between press releases, finding the announcements somehow comforting and real, like the launch of the game after ten months wasn’t just a dream. I’d then refresh the Google Play link. I don’t know how many times I did this before the baby monitor in the living room announced that Hanna was awake. I fired off a message to Will for whenever his sleep deprived old bones made his way into his office that morning, informing him that the deed was done.</p>
<p>The links to the game on our Facebook and web pages were live. The press releases were out. The game was published. I went to rescue my daughter from the confines of her crib. She smiled her huge, baby smile when I entered her room, just like she always does and I took her into the living room where she proceeded to make short work of some Cheerios I placed out on the coffee table for her to keep her occupied. My son jumped up on the couch beside me and we talked and watched TV, letting my wife sleep in a bit. Little Einsteins was on now. The rocket ship apparently runs off leg pats, so we patted our laps faster and faster to rev up Rocket as we were instructed, raised our hands as high as we could and announced together “Blast off!” Hanna turned from where she was standing, leaning against our ottoman, swaying a bit on her unsteady little legs. She giggled at us.</p>
<p>It was a good day.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/03/12/launch-day-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>30 Weeks of Game Development</title>
		<link>http://www.altdevblogaday.com/2013/03/08/30-weeks-of-development/</link>
		<comments>http://www.altdevblogaday.com/2013/03/08/30-weeks-of-development/#comments</comments>
		<pubDate>Fri, 08 Mar 2013 12:00:24 +0000</pubDate>
		<dc:creator>Forrest Smith</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29219</guid>
		<description><![CDATA[<p>Outland Games is an iOS game I’ve been working on at Uber Entertainment since late last summer. We just released the game to the app store this week (<a href="https://itunes.apple.com/app/id591262172">iTunes &#8211; $0.99</a>). This post is the first in a short series on it’s development.</p>
<p><a href="http://www.altdevblogaday.com/2013/03/08/30-weeks-of-development/" class="more-link">Read more on 30 Weeks of Game Development&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Outland Games is an iOS game I’ve been working on at Uber Entertainment since late last summer. We just released the game to the app store this week (<a href="https://itunes.apple.com/app/id591262172">iTunes &#8211; $0.99</a>). This post is the first in a short series on it’s development.</p>
<h2>Evolution</h2>
<p>On every project I’ve ever shipped I wished I could have chronicled the game’s production from start to finish. It’s a really interesting process that the public never gets to see.</p>
<p>The scale and starting point of Outland Games enabled us to record progress in a way that I’ve never been able to do before. We used fraps to capture a video at the end of almost every week of development [1]. Eka took those videos and edited them into the following video.</p>
<p><span style="text-align:center; display: block;"><a href="http://www.altdevblogaday.com/2013/03/08/30-weeks-of-development/"><img src="http://img.youtube.com/vi/XHNTwIhr5ns/2.jpg" alt="" /></a></span></p>
<p>We also took that video and compressed it to a single image.</p>
<p style="text-align: center"><a href="https://outland-live.s3-us-west-2.amazonaws.com/media/downloads/30weeksOfOutland.jpg"><img class="aligncenter" alt="history_thumb" src="http://www.altdevblogaday.com/wp-content/uploads/2013/03/history_thumb.jpg" width="100" height="416" /></a></p>
<p style="text-align: left">That’s what game development looks like &#8211; warts and all. I’m not sure I’ve ever seen a video put together like this one. Certainly nothing so raw.</p>
<h2>Scope</h2>
<p>The team behind Outland Games was small and consisted of just five primary team members.</p>
<p><a href="https://twitter.com/forrestthewoods">Forrest Smith</a> &#8211; coding/design &#8211; 7 months<br />
<a href="https://twitter.com/ekanaut">Chandana Ekanayake</a> &#8211; art/ui/design/trailer &#8211; 4 months<br />
<a href="https://twitter.com/AZOstuff">Aung Zaw Oo</a> &#8211; animation/modeling &#8211; 3 months<br />
<a href="https://twitter.com/bgolus/">Ben Golus</a> &#8211; effects/misc awesome &#8211; 3 months<br />
<a href="https://twitter.com/howardmostrom">Howard Mostrom</a> &#8211; audio &#8211; 2 months</p>
<p>Unity3d is all the rage these days but this game was made using a custom engine. It’s actually the same codebase as <a title="Planetary Annihilation" href="http://www.uberent.com/pa">Planetary Annihilation</a>. I’ll cover that in more detail in another post.</p>
<p>The game never had any official milestones. I think it can be broken down into the following stages.</p>
<h2>Prototype (weeks 1-6)</h2>
<p>When we started the goal was to create an endless runner using internal tech and the Monday Night Combat IP. What that meant precisely we didn’t know.</p>
<p>After implementing and playing with various jump mechanics we settled into the double jump you see in the final version. The remarkably basic grey and red block based gameplay from the very first week was actually pretty fun!</p>
<p>We also tested various art creation strategies. Our initial plan for character animation was hand drawn sprite flipbooks. This idea was quickly scrapped in favor of a 3dsmax skeleton with attached sprites. (Which would later become full 3d meshes.)</p>
<p>Much experimentation was done in regards to physics, dash mechanics, level design, and art style. Howard wanted audio hook ups from week 1 and insisted it wasn’t a “real game” until it had sound. Unfortunately sound kept getting pushed back and didn’t get configured until the end of the prototype phase. Sorry Howard!</p>
<h2>Europe (weeks 7-8)</h2>
<p>During September I went to Germany and Amsterdam on a two week trip. At this point I was still the only full time member on Outland Games so development was temporarily stalled. Beer consumption levels however reached an all-time high.</p>
<p style="text-align: center"><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/03/Beerfest-in-Munchen-Germany_Beer-festival_5603.jpg"><img class="aligncenter size-medium wp-image-29224" alt="Beerfest in Munchen, Germany-Beer festival tourism destinations" src="http://www.altdevblogaday.com/wp-content/uploads/2013/03/Beerfest-in-Munchen-Germany_Beer-festival_5603-300x167.jpg" width="300" height="167" /></a></p>
<h2>Tech (weeks 9-13)</h2>
<p>Because we used early stage internal tech there were a lot of feature gaps to fill. Adding build tool support for iOS. Fleshing out the bare bones UI system. Defining and/or implementing export/import processes for compressed textures, meshes, and animations. Plus various game specific systems.</p>
<p>Much of this work didn’t actually show up on screen. It’s easy to work for weeks on systems that are invisible to the eye. This can be super frustrating at times. Particularly when attempting to record weekly videos.</p>
<h2>Content (weeks 14-25)</h2>
<p>The basic components of functionality were finally in place at the start of week 14 despite the game looking quite meager. If you exclude the non-productive Thanksgiving week and out town Christmas week the content phase was ten weeks.</p>
<p>By week 25 the game had two environments, animated enemies, coins, pickups, profile save/load, upgrade progression, full UI including store, layered music, voice overs, and the whole shebang. Although not quite ready for primetime the game was functional and, more importantly, fun.</p>
<h2>Ship (weeks 26-30)</h2>
<p>The final push was focused on one clear objective &#8211; shipping.</p>
<p>I was tempted to call this phase polish but that’s not quite right. A lot of polish did go in. Final animations. Carefully tuned audio. Continuously tweaked level design. But too many features weren’t finished to call it just polish. GameCenter leaderboards and app store IAP weren’t even started until the very end. Even the in-game intro cinematic was a last weekend addition.</p>
<p>After three submissions the game was finally approved. We gave a great sigh of relief and consumed much scotch.</p>
<p style="text-align: center"><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/03/photo-3.jpg"><img class="aligncenter size-medium wp-image-29225" alt="photo 3" src="http://www.altdevblogaday.com/wp-content/uploads/2013/03/photo-3-300x225.jpg" width="300" height="225" /></a></p>
<h2>History Keeping</h2>
<p>The hardest part of capturing footage is having the willpower to record every week. It’s easy to push back the capture because a major feature is <em>almost done</em>. Game dev is often an emotional rollercoaster and when you’re in a low it’s hard to muster the motivation to click record.</p>
<p>I actually stopped making the videos around week 16. Every week felt like too little progress was being made to justify a video. After going gold and watching the early videos I was hit with a wave of inspiration so I synced perforce week by week to re-build and capture [2].</p>
<p>In hindsight progress was much more visible than I realized! It’s easy to feel perpetually “one month away” which it turn feels like no progress is being made. The truth is that you are getting a lot done even if it’s taking longer than initially planned [3].</p>
<p>All I can say is to stick with it. Capture every single week. Even if you are <em>almost done</em> with some cool new thing. When the project is shipped and you look back you may be surprised at how much was getting done.</p>
<h2>Conclusion</h2>
<p>That’s a brief review of the development of Outland Games. We&#8217;re super happy with the final product and thrilled to finally release an evolution video. It’s a unique insight to the dev process that I hope folks find informative and entertaining.</p>
<h2>Footnotes</h2>
<p>[1] Despite being an iOS game 95% of development was done on PC.<br />
[2] synced? sync’d? sunk? sank? These all feel wrong.<br />
[3] Game dev always takes longer than initially planned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/03/08/30-weeks-of-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Bug in Object Replication and Message Reordering</title>
		<link>http://www.altdevblogaday.com/2013/03/01/a-bug-in-object-replication-and-message-reordering/</link>
		<comments>http://www.altdevblogaday.com/2013/03/01/a-bug-in-object-replication-and-message-reordering/#comments</comments>
		<pubDate>Fri, 01 Mar 2013 16:13:59 +0000</pubDate>
		<dc:creator>Niklas Frykholm</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[peer to peer]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29212</guid>
		<description><![CDATA[<p>The Bitsquid network system supports a peer-to-peer model with <em>migration</em> of network objects &#8212; i.e., changing the owner of a network object from one peer to another. This recently lead to an rare race condition.</p>
<p><a href="http://www.altdevblogaday.com/2013/03/01/a-bug-in-object-replication-and-message-reordering/" class="more-link">Read more on A Bug in Object Replication and Message Reordering&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>The Bitsquid network system supports a peer-to-peer model with <em>migration</em> of network objects &#8212; i.e., changing the owner of a network object from one peer to another. This recently lead to an rare race condition.</p>
<p>To understand this bug you must first understand a little bit about how our network system works.</p>
<h2>Background</h2>
<p>The entire network model is based on an packet delivery system (on top of UDP) that provides ACKs for unreliable packets as well as a reliable (and ordered) packet stream between any two network endpoints. At the next layer we have implemented a remote-procedure-call service for Lua as well as an object replication system.</p>
<p>Games can use these services however they like, but our recommendation is to do as much as possible with the object replication system and as little as possible with RPC calls, since using explicit RPC messages tends to require more bandwidth and be more error prone.</p>
<p>The network be run in both client-server and peer-to-peer mode. The only difference is that in client-server mode, the server relays all messages (clients never talk directly to each other) and owns most of the network objects. (Clients <em>can</em> own objects in client-server mode, in that case the changes to the objects are relayed by the server.)</p>
<p>Objects are replicated with a message stream that looks something like this:</p>
<pre>A: CREATE [wait for ack] UPDATE_1 UPDATE_2 ... UPDATE_n DESTROY</pre>
<p>Here, <em>A</em> (the owner of the object) first sends a reliable message that creates the object. When it has received an <em>ACK</em> for that message, it starts sending updates, informing the other players about changes to the object. (By monitoring ACKs, it knows which changes the other players have received, so it only sends updates when necessary and it will resend updates if the messages are lost.) Finally, at some future point, the object is destroyed, through another reliable message.</p>
<p>The <em>UPDATE</em> messages are sent on the unreliable stream (for maximum performance), so they can potentially arrive before <em>CREATE</em> or after <em>DELETE</em>. But this is not a problem, because we simply ignore <em>UPDATE</em> messages that arrive out of order.</p>
<p>This approach ensures that everybody that participates in the game session will see the same set of objects with the same properties (at least eventually, keeping in mind that messages can be delayed).</p>
<h2>Migration</h2>
<p>Migration complicates this picture somewhat.</p>
<p>Migrating a network object means changing the owner of the object from one peer to another. There are a number of reasons why you might want to do that. First, if a player drops out of the game, the objects owned by that player may need to be taken over by somebody else. Second, in a peer-to-peer game we may want to load balance, so that each peer is managing about the same amount of objects. Finally, sometimes a particular player is interacting directly with a particular object (picking up a rock, etc). It can then be beneficial to make that player owner of the object, so that the interaction is not affected by network latency.</p>
<p>In our network, migration is implemented with a reliable <em>MIGRATION</em> message that tells everybody in the session about the object&#8217;s new owner. The migration message is always sent by a special peer, the <em>HOST</em> of the game session. (To ensure that peers do not compete for the ownership of an object.)</p>
<p>So if we look at a message stream with migration involved, it looks something like this:</p>
<pre>   A:  C Ua Ua Ua Ua Ua
HOST:                    M_ab
   B:                          Ub Ub Ub Ub Ub Ub Ub Ub D</pre>
<p>If you are an experienced network programmer you should start to smell trouble at this point.</p>
<p>The problem is that while the message system provides an ordered stream of messages between any two endpoints, there is no ordering of messages between <em>different</em> endpoints.</p>
<p>Consider an additional network peer <em>X</em>. There is an ordered stream of messages <em>A → X</em>. There is also an ordered stream of messages <em>B → X</em>. But there is no guaranteed ordering between the messages sent from <em>A</em> and the messages sent from <em>B</em> and <em>HOST</em>. So, suppose the messages from <em>A → X</em> are delayed. Then <em>X</em> could see the following message stream:</p>
<pre>M_ab Ub Ub Ub D C Ua Ua Ua</pre>
<p>So <em>X</em> gets a request to migrate the object before it has been created. And the creation message arrives after <em>DELETE</em>. In other words, a complete mess.</p>
<p>To be sure, this only happens if the object gets migrated <em>really</em> close to being created or deleted and if there are asymmetric network delays on top of that. But of course, it always happens to <em>someone</em>.</p>
<h2>The Fix</h2>
<p>There are many possible ways of fixing this. Here are some:</p>
<ul>
<li>
<p><em>We could impose a global message ordering.</em> We could make sure that the reliable message streams are globally ordered to prevent &#8220;paradoxes&#8221; of this kind. I.e., if <em>HOST</em> sends <em>M_ab</em> after receiving <em>C</em>, no peer should receive <em>M_ab</em> before <em>C</em>. Unfortunately, this is not as easy as it sounds. For example, what if <em>A</em> dies before it has sent <em>C</em> to <em>X?</em> In that case, that failed delivery will also block the channels <em>HOST → X</em> and <em>B → X</em>, since they are not allowed to deliver any messages before <em>X</em> has received <em>C</em>.</p>
</li>
<li>
<p><em>We could use a migration handshake.</em> We could do some kind of handshake procedure to make sure that everybody has received <em>M_ab</em>, before <em>B</em> takes over ownership. But this would require a lot of extra messages and temporarily put the object in limbo.</p>
</li>
<li>
<p><em>We could fix the ACKs.</em> We could make it so that <em>X</em> doesn&#8217;t <em>ACK</em> <em>M_ab</em> until <em>C</em> has arrived, thus forcing <em>HOST</em> to keep resending it, until we are ready to receive it. This would work, but would require us to implement ACKing of individual messages. Currently, we just ACK an entire UDP packet (containing many messages) on reception, which is simpler and more performant.</p>
</li>
<li>
<p><em>We could create an internal message queue.</em> We could queue up migration, create and delete messages in some sort of internal queue if they arrive out of order and try to fix things up later. This is a truly horrible &#8220;solution&#8221; that increases code complexity and is likely to cause lots of confusing bugs in the future.</p>
</li>
</ul>
<p>All these solutions are probably workable, but they all have the drawback of increasing complexity. And I <em>really</em> don&#8217;t like to increase the complexity of network code. Reasoning about network code is hard enough as it is, we should always strive for the simplest solution possible.</p>
<p>So, instead, the first thing I did was to simplify the problem by eliminating the host from the equation. I simply let the new owner send out the migration message instead of the host:</p>
<pre>   A:  C Ua Ua Ua Ua Ua
   B:                    M_ab Ub Ub Ub Ub Ub Ub Ub Ub D</pre>
<p>This is already a lot better. Now we only have two parties to worry about (apart from <em>X)</em>, instead of three.</p>
<p>We still want the host to be <em>in charge</em> of migration. Otherwise we run into tricky problems of what should happen if several peers try to assume ownership of an object at the same time. So we let the host initiate the migration by sending a message to the new owner (<em>B)</em>. Then, <em>B</em> is responsible for notifying everybody else about this.</p>
<p>With this approach, we can use the same &#8220;wait for ack&#8221; trick that we used during creation to make sure that <em>B</em> doesn&#8217;t send any updates to peers that haven&#8217;t acked the migration:</p>
<pre>   A:  C [wait] Ua Ua Ua Ua Ua
   B:                            M_ab [wait] Ub Ub Ub Ub Ub Ub Ub Ub D</pre>
<p>We still haven&#8217;t completely solved the problem, <em>X</em> can still see weird message orderings such as:</p>
<pre>M_ab   C   D
M_ab   D   C</pre>
<p>But this won&#8217;t be a problem as long as we do two things:</p>
<ul>
<li>
<p>We let <em>MIGRATE</em> act as a <em>CREATE</em> message, if we get <em>MIGRATE</em> for an object that doesn&#8217;t exist.</p>
</li>
<li>
<p>We ignore &#8220;old&#8221; <em>CREATE</em> messages. (The <em>C</em> that arrives after <em>M.)</em></p>
</li>
</ul>
<p>To be able to distinguish old messages I introduced a <em>migration counter</em>. This is just a number that starts at zero when the object is created and is increased (by <em>HOST)</em> every time the object is migrated.</p>
<p>We tag all <em>CREATE</em>, <em>DESTROY</em> and <em>MIGRATE</em> messages with the migration counter and simply ignore &#8220;old&#8221; messages. With this approach, the message streams will look like this:</p>
<pre>   A:  C_0 [wait] Ua Ua Ua Ua Ua
   B:                             M_ab_1 [wait] Ub Ub Ub Ub Ub Ub Ub Ub D_1</pre>
<p>We can now verify that all possible message orderings that <em>X</em> can see work correctly:</p>
<pre>C_0      M_ab_1  D_1  -- ok, the expected order
M_ab_1   C_0     D_1  -- ok, M_ab_1 creates the object with migration counter 1 and C_0 is ignored
M_ab_1   D_1     C_0  -- ok, M_ab_1 creates the object with migration counter 1 and C_0 is ignored</pre>
<p>The system works equally well if there are multiple migration steps:</p>
<pre>   A:  C_0 [wait] Ua Ua 
   B:                   M_ab_1 [wait] Ub Ub Ub
   C:                                            M_bc_2 [wait] Uc Uc Uc D_2</pre>
<p>No matter in which order the messages arrive we will end up in the correct state.</p>
<p>This has also been posted to <a class="link" href="http://bitsquid.blogspot.com">The Bitsquid blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/03/01/a-bug-in-object-replication-and-message-reordering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Latency Mitigation Strategies</title>
		<link>http://www.altdevblogaday.com/2013/02/22/latency-mitigation-strategies/</link>
		<comments>http://www.altdevblogaday.com/2013/02/22/latency-mitigation-strategies/#comments</comments>
		<pubDate>Fri, 22 Feb 2013 17:25:46 +0000</pubDate>
		<dc:creator>John-Carmack</dc:creator>
				<category><![CDATA[Computer Graphics]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29198</guid>
		<description><![CDATA[<p>&#160;</p>
<p><b>Abstract</b></p>
<p>Virtual reality (VR) is one of the most demanding human-in-the-loop applications from a latency standpoint.  The latency between the physical movement of a user’s head and updated photons from a head mounted display reaching their eyes is one of the most critical factors in providing a high quality experience.</p>
<p><a href="http://www.altdevblogaday.com/2013/02/22/latency-mitigation-strategies/" class="more-link">Read more on Latency Mitigation Strategies&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p><b>Abstract</b></p>
<p>Virtual reality (VR) is one of the most demanding human-in-the-loop applications from a latency standpoint.  The latency between the physical movement of a user’s head and updated photons from a head mounted display reaching their eyes is one of the most critical factors in providing a high quality experience.</p>
<p>Human sensory systems can detect very small relative delays in parts of the visual or, especially, audio fields, but when absolute delays are below approximately 20 milliseconds they are generally imperceptible.  Interactive 3D systems today typically have latencies that are several times that figure, but alternate configurations of the same hardware components can allow that target to be reached.</p>
<p>A discussion of the sources of latency throughout a system follows, along with techniques for reducing the latency in the processing done on the host system.</p>
<p><b>Introduction</b></p>
<p>Updating the imagery in a head mounted display (HMD) based on a head tracking sensor is a subtly different challenge than most human / computer interactions.  With a conventional mouse or game controller, the user is consciously manipulating an interface to complete a task, while the goal of virtual reality is to have the experience accepted at an unconscious level.</p>
<p>Users can adapt to control systems with a significant amount of latency and still perform challenging tasks or enjoy a game; many thousands of people enjoyed playing early network games, even with 400+ milliseconds of latency between pressing a key and seeing a response on screen.</p>
<p>If large amounts of latency are present in the VR system, users may still be able to perform tasks, but it will be by the much less rewarding means of using their head as a controller, rather than accepting that their head is naturally moving around in a stable virtual world.  Perceiving latency in the response to head motion is also one of the primary causes of simulator sickness.  Other technical factors that affect the quality of a VR experience, like head tracking accuracy and precision, may interact with the perception of latency, or, like display resolution and color depth, be largely orthogonal to it.</p>
<p>A total system latency of 50 milliseconds will feel responsive, but still subtly lagging.  One of the easiest ways to see the effects of latency in a head mounted display is to roll your head side to side along the view vector while looking at a clear vertical edge.  Latency will show up as an apparent tilting of the vertical line with the head motion; the view feels “dragged along” with the head motion.  When the latency is low enough, the virtual world convincingly feels like you are simply rotating your view of a stable world.</p>
<p>Extrapolation of sensor data can be used to mitigate some system latency, but even with a sophisticated model of the motion of the human head, there will be artifacts as movements are initiated and changed.  It is always better to not have a problem than to mitigate it, so true latency reduction should be aggressively pursued, leaving extrapolation to smooth out sensor jitter issues and perform only a small amount of prediction.</p>
<p><b>Data collection</b></p>
<p>It is not usually possible to introspectively measure the complete system latency of a VR system, because the sensors and display devices external to the host processor make significant contributions to the total latency.  An effective technique is to record high speed video that simultaneously captures the initiating physical motion and the eventual display update.  The system latency can then be determined by single stepping the video and counting the number of video frames between the two events.</p>
<p>In most cases there will be a significant jitter in the resulting timings due to aliasing between sensor rates, display rates, and camera rates, but conventional applications tend to display total latencies in the dozens of 240 fps video frames.</p>
<p>On an unloaded Windows 7 system with the compositing Aero desktop interface disabled, a gaming mouse dragging a window displayed on a 180 hz CRT monitor can show a response on screen in the same 240 fps video frame that the mouse was seen to first move, demonstrating an end to end latency below four milliseconds.  Many systems need to cooperate for this to happen: The mouse updates 500 times a second, with no filtering or buffering.  The operating system immediately processes the update, and immediately performs GPU accelerated rendering directly to the framebuffer without any page flipping or buffering.  The display accepts the video signal with no buffering or processing, and the screen phosphors begin emitting new photons within microseconds.</p>
<p>In a typical VR system, many things go far less optimally, sometimes resulting in end to end latencies of over 100 milliseconds.</p>
<p><b>Sensors</b></p>
<p>Detecting a physical action can be as simple as a watching a circuit close for a button press, or as complex as analyzing a live video feed to infer position and orientation.</p>
<p>In the old days, executing an IO port input instruction could directly trigger an analog to digital conversion on an ISA bus adapter card, giving a latency on the order of a microsecond and no sampling jitter issues.  Today, sensors are systems unto themselves, and may have internal pipelines and queues that need to be traversed before the information is even put on the USB serial bus to be transmitted to the host.</p>
<p>Analog sensors have an inherent tension between random noise and sensor bandwidth, and some combination of analog and digital filtering is usually done on a signal before returning it.  Sometimes this filtering is excessive, which can contribute significant latency and remove subtle motions completely.</p>
<p>Communication bandwidth delay on older serial ports or wireless links can be significant in some cases.  If the sensor messages occupy the full bandwidth of a communication channel, latency equal to the repeat time of the sensor is added simply for transferring the message.  Video data streams can stress even modern wired links, which may encourage the use of data compression, which usually adds another full frame of latency if not explicitly implemented in a pipelined manner.</p>
<p>Filtering and communication are constant delays, but the discretely packetized nature of most sensor updates introduces a variable latency, or “jitter” as the sensor data is used for a video frame rate that differs from the sensor frame rate.  This latency ranges from close to zero if the sensor packet arrived just before it was queried, up to the repeat time for sensor messages.  Most USB HID devices update at 125 samples per second, giving a jitter of up to 8 milliseconds, but it is possible to receive 1000 updates a second from some USB hardware.  The operating system may impose an additional random delay of up to a couple milliseconds between the arrival of a message and a user mode application getting the chance to process it, even on an unloaded system.</p>
<p><b>Displays</b></p>
<p>On old CRT displays, the voltage coming out of the video card directly modulated the voltage of the electron gun, which caused the screen phosphors to begin emitting photons a few microseconds after a pixel was read from the frame buffer memory.</p>
<p>Early LCDs were notorious for “ghosting” during scrolling or animation, still showing traces of old images many tens of milliseconds after the image was changed, but significant progress has been made in the last two decades.  The transition times for LCD pixels vary based on the start and end values being transitioned between, but a good panel today will have a switching time around ten milliseconds, and optimized displays for active 3D and gaming can have switching times less than half that.</p>
<p>Modern displays are also expected to perform a wide variety of processing on the incoming signal before they change the actual display elements.  A typical Full HD display today will accept 720p or interlaced composite signals and convert them to the 1920&#215;1080 physical pixels.  24 fps movie footage will be converted to 60 fps refresh rates.  Stereoscopic input may be converted from side-by-side, top-down, or other formats to frame sequential for active displays, or interlaced for passive displays.  Content protection may be applied.  Many consumer oriented displays have started applying motion interpolation and other sophisticated algorithms that require multiple frames of buffering.</p>
<p>Some of these processing tasks could be handled by only buffering a single scan line, but some of them fundamentally need one or more full frames of buffering, and display vendors have tended to implement the general case without optimizing for the cases that could be done with low or no delay.  Some consumer displays wind up buffering three or more frames internally, resulting in 50 milliseconds of latency even when the input data could have been fed directly into the display matrix.</p>
<p>Some less common display technologies have speed advantages over LCD panels; OLED pixels can have switching times well under a millisecond, and laser displays are as instantaneous as CRTs.</p>
<p>A subtle latency point is that most displays present an image incrementally as it is scanned out from the computer, which has the effect that the bottom of the screen changes 16 milliseconds later than the top of the screen on a 60 fps display.  This is rarely a problem on a static display, but on a head mounted display it can cause the world to appear to shear left and right, or “waggle” as the head is rotated, because the source image was generated for an instant in time, but different parts are presented at different times.  This effect is usually masked by switching times on LCD HMDs, but it is obvious with fast OLED HMDs.</p>
<p><b>Host processing</b></p>
<p>The classic processing model for a game or VR application is:</p>
<p>Read user input -&gt; run simulation -&gt; issue rendering commands -&gt; graphics drawing -&gt; wait for vsync -&gt; scanout</p>
<p>I = Input sampling and dependent calculation<br />
S = simulation / game execution<br />
R = rendering engine<br />
G = GPU drawing time<br />
V = video scanout time</p>
<p>All latencies are based on a frame time of roughly 16 milliseconds, a progressively scanned display, and zero sensor and pixel latency.</p>
<p>If the performance demands of the application are well below what the system can provide, a straightforward implementation with no parallel overlap will usually provide fairly good latency values.  However, if running synchronized to the video refresh, the minimum latency will still be 16 ms even if the system is infinitely fast.   This rate feels good for most eye-hand tasks, but it is still a perceptible lag that can be felt in a head mounted display, or in the responsiveness of a mouse cursor.</p>
<pre>Ample performance, vsync:
ISRG------------|VVVVVVVVVVVVVVVV|
.................. latency 16 – 32 milliseconds</pre>
<p>Running without vsync on a very fast system will deliver better latency, but only over a fraction of the screen, and with visible tear lines.  The impact of the tear lines are related to the disparity between the two frames that are being torn between, and the amount of time that the tear lines are visible.  Tear lines look worse on a continuously illuminated LCD than on a CRT or laser projector, and worse on a 60 fps display than a 120 fps display.  Somewhat counteracting that, slow switching LCD panels blur the impact of the tear line relative to the faster displays.</p>
<p>If enough frames were rendered such that each scan line had a unique image, the effect would be of a “rolling shutter”, rather than visible tear lines, and the image would feel continuous.  Unfortunately, even rendering 1000 frames a second, giving approximately 15 bands on screen separated by tear lines, is still quite objectionable on fast switching displays, and few scenes are capable of being rendered at that rate, let alone 60x higher for a true rolling shutter on a 1080P display.</p>
<pre>Ample performance, unsynchronized:
ISRG
VVVVV
..... latency 5 – 8 milliseconds at ~200 frames per second</pre>
<p>In most cases, performance is a constant point of concern, and a parallel pipelined architecture is adopted to allow multiple processors to work in parallel instead of sequentially.  Large command buffers on GPUs can buffer an entire frame of drawing commands, which allows them to overlap the work on the CPU, which generally gives a significant frame rate boost at the expense of added latency.</p>
<pre>CPU:ISSSSSRRRRRR----|
GPU:                |GGGGGGGGGGG----|
VID:                |               |VVVVVVVVVVVVVVVV|
    .................................. latency 32 – 48 milliseconds</pre>
<p>When the CPU load for the simulation and rendering no longer fit in a single frame, multiple CPU cores can be used in parallel to produce more frames.  It is possible to reduce frame execution time without increasing latency in some cases, but the natural split of simulation and rendering has often been used to allow effective pipeline parallel operation.  Work queue approaches buffered for maximum overlap can cause an additional frame of latency if they are on the critical user responsiveness path.</p>
<pre>CPU1:ISSSSSSSS-------|
CPU2:                |RRRRRRRRR-------|
GPU :                |                |GGGGGGGGGG------|
VID :                |                |                |VVVVVVVVVVVVVVVV|
     .................................................... latency 48 – 64 milliseconds</pre>
<p>Even if an application is running at a perfectly smooth 60 fps, it can still have host latencies of over 50 milliseconds, and an application targeting 30 fps could have twice that.   Sensor and display latencies can add significant additional amounts on top of that, so the goal of 20 milliseconds motion-to-photons latency is challenging to achieve.</p>
<p><b>Latency Reduction Strategies</b></p>
<p><b>Prevent GPU buffering</b></p>
<p>The drive to win frame rate benchmark wars has led driver writers to aggressively buffer drawing commands, and there have even been cases where drivers ignored explicit calls to glFinish() in the name of improved “performance”.  Today’s fence primitives do appear to be reliably observed for drawing primitives, but the semantics of buffer swaps are still worryingly imprecise.  A recommended sequence of commands to synchronize with the vertical retrace and idle the GPU is:</p>
<p>SwapBuffers();<br />
DrawTinyPrimitive();<br />
InsertGPUFence();<br />
BlockUntilFenceIsReached();</p>
<p>While this should always prevent excessive command buffering on any conformant driver, it could conceivably fail to provide an accurate vertical sync timing point if the driver was transparently implementing triple buffering.</p>
<p>To minimize the performance impact of synchronizing with the GPU, it is important to have sufficient work ready to send to the GPU immediately after the synchronization is performed.  The details of exactly when the GPU can begin executing commands are platform specific, but execution can be explicitly kicked off with glFlush() or equivalent calls.  If the code issuing drawing commands does not proceed fast enough, the GPU may complete all the work and go idle with a “pipeline bubble”.  Because the CPU time to issue a drawing command may have little relation to the GPU time required to draw it, these pipeline bubbles may cause the GPU to take noticeably longer to draw the frame than if it were completely buffered.  Ordering the drawing so that larger and slower operations happen first will provide a cushion, as will pushing as much preparatory work as possible before the synchronization point.</p>
<pre>Run GPU with minimal buffering:
CPU1:ISSSSSSSS-------|
CPU2:                |RRRRRRRRR-------|
GPU :                |-GGGGGGGGGG-----|
VID :                |                |VVVVVVVVVVVVVVVV|
     ................................... latency 32 – 48 milliseconds</pre>
<p>Tile based renderers, as are found in most mobile devices, inherently require a full scene of command buffering before they can generate their first tile of pixels, so synchronizing before issuing any commands will destroy far more overlap.  In a modern rendering engine there may be multiple scene renders for each frame to handle shadows, reflections, and other effects, but increased latency is still a fundamental drawback of the technology.</p>
<p>High end, multiple GPU systems today are usually configured for AFR, or Alternate Frame Rendering, where each GPU is allowed to take twice as long to render a single frame, but the overall frame rate is maintained because there are two GPUs producing frames</p>
<pre>Alternate Frame Rendering dual GPU:
CPU1:IOSSSSSSS-------|IOSSSSSSS-------|
CPU2:                |RRRRRRRRR-------|RRRRRRRRR-------|
GPU1:                | GGGGGGGGGGGGGGGGGGGGGGGG--------|
GPU2:                |                | GGGGGGGGGGGGGGGGGGGGGGG---------|
VID :                |                |                |VVVVVVVVVVVVVVVV|
     .................................................... latency 48 – 64 milliseconds</pre>
<p>Similarly to the case with CPU workloads, it is possible to have two or more GPUs cooperate on a single frame in a way that delivers more work in a constant amount of time, but it increases complexity and generally delivers a lower total speedup.</p>
<p>An attractive direction for stereoscopic rendering is to have each GPU on a dual GPU system render one eye, which would deliver maximum performance and minimum latency, at the expense of requiring the application to maintain buffers across two independent rendering contexts.</p>
<p>The downside to preventing GPU buffering is that throughput performance may drop, resulting in more dropped frames under heavily loaded conditions.</p>
<p><b>Late frame scheduling</b></p>
<p>Much of the work in the simulation task does not depend directly on the user input, or would be insensitive to a frame of latency in it.  If the user processing is done last, and the input is sampled just before it is needed, rather than stored off at the beginning of the frame, the total latency can be reduced.</p>
<p>It is very difficult to predict the time required for the general simulation work on the entire world, but the work just for the player’s view response to the sensor input can be made essentially deterministic.  If this is split off from the main simulation task and delayed until shortly before the end of the frame, it can remove nearly a full frame of latency.</p>
<pre>Late frame scheduling:
CPU1:SSSSSSSSS------I|
CPU2:                |RRRRRRRRR-------|
GPU :                |-GGGGGGGGGG-----|
VID :                |                |VVVVVVVVVVVVVVVV|
                    .................... latency 18 – 34 milliseconds</pre>
<p>Adjusting the view is the most latency sensitive task; actions resulting from other user commands, like animating a weapon or interacting with other objects in the world, are generally insensitive to an additional frame of latency, and can be handled in the general simulation task the following frame.</p>
<p>The drawback to late frame scheduling is that it introduces a tight scheduling requirement that usually requires busy waiting to meet, wasting power.  If your frame rate is determined by the video retrace rather than an arbitrary time slice, assistance from the graphics driver in accurately determining the current scanout position is helpful.</p>
<p><b>View bypass</b></p>
<p>An alternate way of accomplishing a similar, or slightly greater latency reduction Is to allow the rendering code to modify the parameters delivered to it by the game code, based on a newer sampling of user input.</p>
<p>At the simplest level, the user input can be used to calculate a delta from the previous sampling to the current one, which can be used to modify the view matrix that the game submitted to the rendering code.</p>
<p>Delta processing in this way is minimally intrusive, but there will often be situations where the user input should not affect the rendering, such as cinematic cut scenes or when the player has died.  It can be argued that a game designed from scratch for virtual reality should avoid those situations, because a non-responsive view in a HMD is disorienting and unpleasant, but conventional game design has many such cases.</p>
<p>A binary flag could be provided to disable the bypass calculation, but it is useful to generalize such that the game provides an object or function with embedded state that produces rendering parameters from sensor input data instead of having the game provide the view parameters themselves.  In addition to handling the trivial case of ignoring sensor input, the generator function can incorporate additional information such as a head/neck positioning model that modified position based on orientation, or lists of other models to be positioned relative to the updated view.</p>
<p>If the game and rendering code are running in parallel, it is important that the parameter generation function does not reference any game state to avoid race conditions.</p>
<pre>View bypass:
CPU1:ISSSSSSSSS------|
CPU2:                |IRRRRRRRRR------|
GPU :                |--GGGGGGGGGG----|
VID :                |                |VVVVVVVVVVVVVVVV|
                      .................. latency 16 – 32 milliseconds</pre>
<p>The input is only sampled once per frame, but it is simultaneously used by both the simulation task and the rendering task.  Some input processing work is now duplicated by the simulation task and the render task, but it is generally minimal.</p>
<p>The latency for parameters produced by the generator function is now reduced, but other interactions with the world, like muzzle flashes and physics responses, remain at the same latency as the standard model.</p>
<p>A modified form of view bypass could allow tile based GPUs to achieve similar view latencies to non-tiled GPUs, or allow non-tiled GPUs to achieve 100% utilization without pipeline bubbles by the following steps:</p>
<p>Inhibit the execution of GPU commands, forcing them to be buffered.  OpenGL has only the deprecated display list functionality to approximate this, but a control extension could be formulated.</p>
<p>All calculations that depend on the view matrix must reference it independently from a buffer object, rather than from inline parameters or as a composite model-view-projection (MVP) matrix.</p>
<p>After all commands have been issued and the next frame has started, sample the user input, run it through the parameter generator, and put the resulting view matrix into the buffer object for referencing by the draw commands.</p>
<p>Kick off the draw command execution.</p>
<pre>Tiler optimized view bypass:
CPU1:ISSSSSSSSS------|
CPU2:                |IRRRRRRRRRR-----|I
GPU :                |                |-GGGGGGGGGG-----|
VID :                |                |                |VVVVVVVVVVVVVVVV|
                                       .................. latency 16 – 32 milliseconds</pre>
<p>Any view frustum culling that was performed to avoid drawing some models may be invalid if the new view matrix has changed substantially enough from what was used during the rendering task.  This can be mitigated at some performance cost by using a larger frustum field of view for culling, and hardware clip planes based on the culling frustum limits can be used to guarantee a clean edge if necessary.  Occlusion errors from culling, where a bright object is seen that should have been occluded by an object that was incorrectly culled, are very distracting, but a temporary clean encroaching of black at a screen edge during rapid rotation is almost unnoticeable.</p>
<p><b>Time warping</b></p>
<p>If you had perfect knowledge of how long the rendering of a frame would take, some additional amount of latency could be saved by late frame scheduling the entire rendering task, but this is not practical due to the wide variability in frame rendering times.</p>
<pre>Late frame input sampled view bypass:
CPU1:ISSSSSSSSS------|
CPU2:                |----IRRRRRRRRR--|
GPU :                |------GGGGGGGGGG|
VID :                |                |VVVVVVVVVVVVVVVV|
                          .............. latency 12 – 28 milliseconds</pre>
<p>However, a post processing task on the rendered image can be counted on to complete in a fairly predictable amount of time, and can be late scheduled more easily.  Any pixel on the screen, along with the associated depth buffer value, can be converted back to a world space position, which can be re-transformed to a different screen space pixel location for a modified set of view parameters.</p>
<p>After drawing a frame with the best information at your disposal, possibly with bypassed view parameters, instead of displaying it directly, fetch the latest user input, generate updated view parameters, and calculate a transformation that warps the rendered image into a position that approximates where it would be with the updated parameters.  Using that transform, warp the rendered image into an updated form on screen that reflects the new input.  If there are two dimensional overlays present on the screen that need to remain fixed, they must be drawn or composited in after the warp operation, to prevent them from incorrectly moving as the view parameters change.</p>
<pre>Late frame scheduled time warp:
CPU1:ISSSSSSSSS------|
CPU2:                |RRRRRRRRRR----IR|
GPU :                |-GGGGGGGGGG----G|
VID :                |                |VVVVVVVVVVVVVVVV|
                                    .... latency 2 – 18 milliseconds</pre>
<p>If the difference between the view parameters at the time of the scene rendering and the time of the final warp is only a change in direction, the warped image can be almost exactly correct within the limits of the image filtering.  Effects that are calculated relative to the screen, like depth based fog (versus distance based fog) and billboard sprites will be slightly different, but not in a manner that is objectionable.</p>
<p>If the warp involves translation as well as direction changes, geometric silhouette edges begin to introduce artifacts where internal parallax would have revealed surfaces not visible in the original rendering.  A scene with no silhouette edges, like the inside of a box, can be warped significant amounts and display only changes in texture density, but translation warping realistic scenes will result in smears or gaps along edges.  In many cases these are difficult to notice, and they always disappear when motion stops, but first person view hands and weapons are a prominent case.  This can be mitigated by limiting the amount of translation warp, compressing or making constant the depth range of the scene being warped to limit the dynamic separation, or rendering the disconnected near field objects as a separate plane, to be composited in after the warp.</p>
<p>If an image is being warped to a destination with the same field of view, most warps will leave some corners or edges of the new image undefined, because none of the source pixels are warped to their locations.  This can be mitigated by rendering a larger field of view than the destination requires; but simply leaving unrendered pixels black is surprisingly unobtrusive, especially in a wide field of view HMD.</p>
<p>A forward warp, where source pixels are deposited in their new positions, offers the best accuracy for arbitrary transformations.  At the limit, the frame buffer and depth buffer could be treated as a height field, but millions of half pixel sized triangles would have a severe performance cost.  Using a grid of triangles at some fraction of the depth buffer resolution can bring the cost down to a very low level, and the trivial case of treating the rendered image as a single quad avoids all silhouette artifacts at the expense of incorrect pixel positions under translation.</p>
<p>Reverse warping, where the pixel in the source rendering is estimated based on the position in the warped image, can be more convenient because it is implemented completely in a fragment shader.  It can produce identical results for simple direction changes, but additional artifacts near geometric boundaries are introduced if per-pixel depth information is considered, unless considerable effort is expended to search a neighborhood for the best source pixel.</p>
<p>If desired, it is straightforward to incorporate motion blur in a reverse mapping by taking several samples along the line from the pixel being warped to the transformed position in the source image.</p>
<p>Reverse mapping also allows the possibility of modifying the warp through the video scanout.  The view parameters can be predicted ahead in time to when the scanout will read the bottom row of pixels, which can be used to generate a second warp matrix.  The warp to be applied can be interpolated between the two of them based on the pixel row being processed.  This can correct for the “waggle” effect on a progressively scanned head mounted display, where the 16 millisecond difference in time between the display showing the top line and bottom line results in a perceived shearing of the world under rapid rotation on fast switching displays.</p>
<p><b>Continuously updated time warping</b></p>
<p>If the necessary feedback and scheduling mechanisms are available, instead of predicting what the warp transformation should be at the bottom of the frame and warping the entire screen at once, the warp to screen can be done incrementally while continuously updating the warp matrix as new input arrives.</p>
<pre>Continuous time warp:
CPU1:ISSSSSSSSS------|
CPU2:                |RRRRRRRRRRR-----|
GPU :                |-GGGGGGGGGGGG---|
WARP:                |               W| W W W W W W W W|
VID :                |                |VVVVVVVVVVVVVVVV|
                                     ... latency 2 – 3 milliseconds for 500hz sensor updates</pre>
<p>The ideal interface for doing this would be some form of “scanout shader” that would be called “just in time” for the video display.  Several video game systems like the Atari 2600, Jaguar, and Nintendo DS have had buffers ranging from half a scan line to several scan lines that were filled up in this manner.</p>
<p>Without new hardware support, it is still possible to incrementally perform the warping directly to the front buffer being scanned for video, and not perform a swap buffers operation at all.</p>
<p>A CPU core could be dedicated to the task of warping scan lines at roughly the speed they are consumed by the video output, updating the time warp matrix each scan line to blend in the most recently arrived sensor information.</p>
<p>GPUs can perform the time warping operation much more efficiently than a conventional CPU can, but the GPU will be busy drawing the next frame during video scanout, and GPU drawing operations cannot currently be scheduled with high precision due to the difficulty of task switching the deep pipelines and extensive context state.  However, modern GPUs are beginning to allow compute tasks to run in parallel with graphics operations, which may allow a fraction of a GPU to be dedicated to performing the warp operations as a shared parameter buffer is updated by the CPU.</p>
<p><b>Discussion</b></p>
<p>View bypass and time warping are complementary techniques that can be applied independently or together.  Time warping can warp from a source image at an arbitrary view time / location to any other one, but artifacts from internal parallax and screen edge clamping are reduced by using the most recent source image possible, which view bypass rendering helps provide.</p>
<p>Actions that require simulation state changes, like flipping a switch or firing a weapon, still need to go through the full pipeline for 32 – 48 milliseconds of latency based on what scan line the result winds up displaying on the screen, and translational information may not be completely faithfully represented below the 16 – 32 milliseconds of the view bypass rendering, but the critical head orientation feedback can be provided in 2 – 18 milliseconds on a 60 hz display.  In conjunction with low latency sensors and displays, this will generally be perceived as immediate.  Continuous time warping opens up the possibility of latencies below 3 milliseconds, which may cross largely unexplored thresholds in human / computer interactivity.</p>
<p>Conventional computer interfaces are generally not as latency demanding as virtual reality, but sensitive users can tell the difference in mouse response down to the same 20 milliseconds or so, making it worthwhile to apply these techniques even in applications without a VR focus.</p>
<p>A particularly interesting application is in “cloud gaming”, where a simple client appliance or application forwards control information to a remote server, which streams back real time video of the game.  This offers significant convenience benefits for users, but the inherent network and compression latencies makes it a lower quality experience for action oriented titles.  View bypass and time warping can both be performed on the server, regaining a substantial fraction of the latency imposed by the network.  If the cloud gaming client was made more sophisticated, time warping could be performed locally, which could theoretically reduce the latency to the same levels as local applications, but it would probably be prudent to restrict the total amount of time warping to perhaps 30 or 40 milliseconds to limit the distance from the source images.</p>
<p><b>Acknowledgements</b></p>
<p>Zenimax for allowing me to publish this openly.</p>
<p>Hillcrest Labs for inertial sensors and experimental firmware.</p>
<p>Emagin for access to OLED displays.</p>
<p>Oculus for a prototype Rift HMD.</p>
<p>Nvidia for an experimental driver with access to the current scan line number.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/02/22/latency-mitigation-strategies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why Lua?</title>
		<link>http://www.altdevblogaday.com/2013/02/19/why-lua/</link>
		<comments>http://www.altdevblogaday.com/2013/02/19/why-lua/#comments</comments>
		<pubDate>Tue, 19 Feb 2013 08:23:00 +0000</pubDate>
		<dc:creator>Niklas Frykholm</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[lua]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29194</guid>
		<description><![CDATA[<p>A question that I get asked regularly is why we have chosen <a class="link" href="http://www.lua.org/">Lua</a> as our engine scripting language. I guess as opposed to more well-known languages, such as JavaScript or C#. The short answer is that Lua is lighter and more elegant than both those languages. It is also faster than JavaScript and more dynamic than C#.</p>
<p><a href="http://www.altdevblogaday.com/2013/02/19/why-lua/" class="more-link">Read more on Why Lua?&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>A question that I get asked regularly is why we have chosen <a class="link" href="http://www.lua.org/">Lua</a> as our engine scripting language. I guess as opposed to more well-known languages, such as JavaScript or C#. The short answer is that Lua is lighter and more elegant than both those languages. It is also faster than JavaScript and more dynamic than C#.</p>
<p>When we started Bitsquid, we set out four key design principles for the engine:</p>
<ul>
<li>
<p><strong>Simplicity</strong>. (A small, manageable codebase with a minimalistic, modular design.)</p>
</li>
<li>
<p><strong>Flexibility</strong>. (A completely data-driven engine that is not tied to any particular game type.)</p>
</li>
<li>
<p><strong>Dynamism</strong>. (Fast iteration times, with hot reload of everything on real target platforms.)</p>
</li>
<li>
<p><strong>Speed</strong>. (Excellent multicore performance and cache-friendly data-oriented layouts.)</p>
</li>
</ul>
<p>Whenever we design new systems for the engine, we always keep these four goals in mind. As we shall see below, Lua does very well on all four counts, which makes it a good fit for our engine.</p>
<h2>Simplicity in Lua</h2>
<p>As I grow older (and hopefully more experienced) I find myself appreciating simplicity more and more. My favorite scripting language has gone from &#8220;Swiss army chainsaw&#8221; <a class="link" href="http://www.perl.org/">Perl</a> (I claim youthful ignorance!) to &#8220;kitchen-drawer-esque&#8221; <a class="link" href="http://www.ruby-lang.org/en/">Ruby</a>, to minimalistic <a class="link" href="http://www.lua.org/">Lua</a>.</p>
<p>Lua is <em>really small</em> for a programming language. The entire Lua syntax fits on a single page. In fact, here it is:</p>
<pre>chunk ::= {stat [`;´]} [laststat [`;´]]
block ::= chunk
stat ::=  varlist `=´ explist | 
     functioncall | 
     do block end | 
     while exp do block end | 
     repeat block until exp | 
     if exp then block {elseif exp then block} [else block] end | 
     for Name `=´ exp `,´ exp [`,´ exp] do block end | 
     for namelist in explist do block end | 
     function funcname funcbody | 
     local function Name funcbody | 
     local namelist [`=´ explist] 
laststat ::= return [explist] | break
funcname ::= Name {`.´ Name} [`:´ Name]
varlist ::= var {`,´ var}
var ::=  Name | prefixexp `[´ exp `]´ | prefixexp `.´ Name 
namelist ::= Name {`,´ Name}
explist ::= {exp `,´} exp
exp ::=  nil | false | true | Number | String | `...´ | function | 
     prefixexp | tableconstructor | exp binop exp | unop exp 
prefixexp ::= var | functioncall | `(´ exp `)´
functioncall ::=  prefixexp args | prefixexp `:´ Name args 
args ::=  `(´ [explist] `)´ | tableconstructor | String 
function ::= function funcbody
funcbody ::= `(´ [parlist] `)´ block end
parlist ::= namelist [`,´ `...´] | `...´
tableconstructor ::= `{´ [fieldlist] `}´
fieldlist ::= field {fieldsep field} [fieldsep]
field ::= `[´ exp `]´ `=´ exp | Name `=´ exp | exp
fieldsep ::= `,´ | `;´
binop ::= `+´ | `-´ | `*´ | `/´ | `^´ | `%´ | `..´ | 
     `&lt;´ | `&lt;=´ | `&gt;´ | `&gt;=´ | `==´ | `~=´ | 
     and | or
unop ::= `-´ | not | `#´</pre>
<p>The same minimalistic philosophy is applied across the entire language. From the standard libraries to the C interface to the actual language implementation. You can understand all of Lua by just understanding a few key concepts.</p>
<p>Lua&#8217;s simplicity and size does not mean that it lacks features. Rather it is just <em>really well</em> designed. It comes with a small set of orthogonal features that can be combined in lots of interesting ways. This gives the language a feeling of elegance, which is quite rare in the programming world. It is not a perfect language (perfect languages don&#8217;t exist), but it is a little gem that fits very well into its particular niche. In that way, Lua is similar to C (the original, not the C++ monstrosity) &#8212; it has a nice small set of features that fit very well together. (I suspect that Smalltalk and LISP also have this feeling of minimalistic elegance, but I haven&#8217;t done enough real-world programming in those languages to really be able to tell.)</p>
<p>As an example of how powerful Lua&#8217;s minimalism can be, consider this: Lua does not have a class or object system, but that doesn&#8217;t matter, because you can implement a class system in about 20 lines or so of Lua code. In fact, here is one:</p>
<pre>function class(klass, super)
    if not klass then
        klass = {}
        
        local meta = {}
        meta.__call = function(self, ...)
            local object = {}
            setmetatable(object, klass)
            if object.init then object:init(...) end
            return object
        end
        setmetatable(klass, meta)
    end
    
    if super then
        for k,v in pairs(super) do
            klass[k] = v
        end
    end
    klass.__index = klass
    
    return klass
end</pre>
<p>If you prefer prototype based languages &#8212; no problem &#8212; you can make a prototype object system in Lua too. </p>
<p>Smallness and simplicity makes everything easier. It makes Lua easier to learn, read, understand, port, master and optimize. A project such as LuaJIT &#8212; created by a single developer &#8212; would not have been possible in a more complicated language.</p>
<h2>Flexibility in Lua</h2>
<p>Lua is a fully featured language, and in the Bitsquid engine, Lua is not just used as an extension language, rather it has direct control over the gameplay loop. This means that you have complete control over the engine from Lua. You can create completely different games by just changing the Lua code. (Examples: First person medieval combat <a class="link" href="http://www.waroftherosesthegame.com/">War of the Roses</a>, top-down RTS <a class="link" href="http://www.kratergame.com/">Krater</a>, beat-em-up platformer <a class="link" href="http://www.theshowdowneffect.com/">Showdown</a> and hand-held puzzler <a class="link" href="http://www.tegrazone.com/games/hamiltons">Hamilton</a>.)</p>
<h2>Dynamism in Lua</h2>
<p>Unlike C#, which only has limited support for <em>Edit and Continue</em>, Lua makes it possible to reload <em>everything</em> &#8212; the entire program &#8212; on all target platforms, including consoles, mobiles and tablets.</p>
<p>This means that gameplay programmers can work on the code, tweak constants, fix bugs and add features without having to restart the game. And they can do this while running on the real target hardware, so that they know exactly what performance they get, how the controls feel and how much memory they are using. This enables fast iterations which is the key to increasing productivity and improving quality in game development.</p>
<h2>Speed of Lua</h2>
<p>Measuring the performance of a language is always tricky, but by most accounts, <a class="link" href="http://luajit.org/">LuaJIT 2</a> is one of the fastest dynamic language implementations in the world. It outperforms other dynamic languages on many benchmarks, often by a substantial margin.</p>
<p>On the platforms where JITting isn&#8217;t allowed, LuaJIT can be run in interpreter mode. The interpreter mode of LuaJIT is very competitive with other non-JITed language implementations.</p>
<p>Furthermore, Lua has a very simple C interoperability interface (simplified further by LuaJIT FFI). This means that in performance critical parts of the code it is really easy to drop into C and get maximum performance.</p>
<h2>Lua&#8217;s weak points</h2>
<p>As I said above, no language is perfect. The things I miss most when programming in Lua don&#8217;t have that much to do with the actual language, but rather with the ecosystem around it. C# has spoiled me with things like an integrated debugger, Intellisense, a very active <a class="link" href="http://stackoverflow.com/">StackOverflow</a> community and the wonderfully helpful <a class="link" href="http://www.jetbrains.com/resharper/">ReSharper</a>. Lua has no &#8220;official&#8221; debugger, and not much in the way of autocompletion or refactoring tools.</p>
<p>Some people would argue that this shouldn&#8217;t be counted as an argument against Lua, since it doesn&#8217;t really concern the <em>language</em> Lua. I disagree. A language is not a singular, isolated thing. It is part of a bigger programming experience. When we judge a language we must take that entire experience into account: Can you find help in online forums? Are there any good free-to-use development tools? Is the user base fragmented? Can you easily create GUIs with native look-and-feel? Etc.</p>
<p>The lack of an official debugger is not a huge issue. Lua has an excellent debugging API that can be used to communicate with external debuggers. Using that API you can quite easily write your own debugger (we have) or integrate a debugger into your favorite text editor. Also, quite recently, the <a class="link" href="http://unknownworlds.com/blog/lua-ide-decoda-open-source/">Decoda IDE</a> was open sourced, which means there is now a good open source debugger available.</p>
<p>Getting autocompletion and refactoring to work well with Lua is trickier. Since Lua is dynamically typed the IDE doesn&#8217;t know the type of variables, parameters or return values. So it doesn&#8217;t know what methods to suggest. And when doing refactoring operations, it can&#8217;t distinguish between methods that have the same name, but operate on different types.</p>
<p>But I don&#8217;t think it necessarily <em>has</em> to be this way. An IDE could do type inference and try to guess the type of variables. For example, if a programmer started to write something like this:</p>
<pre>local car = Car()
car:</pre>
<p>the IDE could infer that the variable <em>car</em> was of type <em>Car</em>. It could then display suitable autocompletion information for the <em>Car</em> class.</p>
<p>Lua&#8217;s dynamic nature makes it tricky to write type inference code that is guaranteed to be 100 % correct. For example, a piece of Lua code could dynamically access the global <em>_G</em> table and change the <em>math.sin()</em> function so that returned a string instead of a number. But such examples are probably not <em>that</em> common in regular Lua code. Also, autocompletion backed by type inference could still be very useful to the end user even if it wasn&#8217;t always 100 % correct.</p>
<p>Type inference could be combined with explicit type hinting to cover the cases where the IDE was not able to make a correct guess (such as for functions exposed through the C API). Hinting could be implemented with a specially formatted comment that specified the type of a variable or a function:</p>
<pre>-- @type Car -&gt; number
function top_speed(car)
    ...
end</pre>
<p>In the example above, the comment would indicate that <em>top_speed</em> is a function that takes a <em>Car</em> argument and returns a <em>number</em>.</p>
<p>Type hinting and type inference could also be used to detect &#8220;type errors&#8221; in Lua code. For example, if the IDE saw something like this:</p>
<pre>local bike = Bicycle()
local s = top_speed(bike)</pre>
<p>it could conclude that since <em>bike</em> is probably a <em>Bicycle</em> object and since <em>top_speed</em> expects a <em>Car</em> object, this call will probably result in a runtime error. It could indicate this with a squiggly red line in the source code.</p>
<p>I don&#8217;t know of any Lua IDE that really explores this possibility. I might try it for my next hack day.</p>
<p>This has also been posted to <a class="link" href="http://bitsquid.blogspot.com">The Bitsquid blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/02/19/why-lua/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vexing puzzle design</title>
		<link>http://www.altdevblogaday.com/2013/02/10/vexing-puzzle-design/</link>
		<comments>http://www.altdevblogaday.com/2013/02/10/vexing-puzzle-design/#comments</comments>
		<pubDate>Sun, 10 Feb 2013 09:32:26 +0000</pubDate>
		<dc:creator>Kyle-Kulyk</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29180</guid>
		<description><![CDATA[<p><a href="http://www.altdevblogaday.com/2013/02/10/vexing-puzzle-design/"><img class="wp-image-621 alignright" style="margin: 5px" alt="Puzzle" src="http://itzyinteractive.com/wp-content/uploads/2013/02/Puzzle.jpg" width="306" height="219" /></a>I enjoy a good puzzle.  At my core, I look for patterns in pretty much everything around me and I think we all do to some extent.  Looking for order in chaos is just something that we all do from the time we’re toddlers.  That’s when toddlers aren’t creating chaos, as I’m sure other new parents can attest to.  It’s no surprise that puzzle games are among the most popular games available for mobile devices.  A good puzzle game will keep us captivated for as long as we find it challenging.  I thought I’d take a moment and share my design process as a new game designer working on the puzzle mode for our imminent title, <a title="Vex Blocks" href="http://itzyinteractive.com/vexblocks/" target="_blank">Vex Blocks</a>.</p>
<p><a href="http://www.altdevblogaday.com/2013/02/10/vexing-puzzle-design/" class="more-link">Read more on Vexing puzzle design&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.altdevblogaday.com/2013/02/10/vexing-puzzle-design/"><img class="wp-image-621 alignright" style="margin: 5px" alt="Puzzle" src="http://itzyinteractive.com/wp-content/uploads/2013/02/Puzzle.jpg" width="306" height="219" /></a>I enjoy a good puzzle.  At my core, I look for patterns in pretty much everything around me and I think we all do to some extent.  Looking for order in chaos is just something that we all do from the time we’re toddlers.  That’s when toddlers aren’t creating chaos, as I’m sure other new parents can attest to.  It’s no surprise that puzzle games are among the most popular games available for mobile devices.  A good puzzle game will keep us captivated for as long as we find it challenging.  I thought I’d take a moment and share my design process as a new game designer working on the puzzle mode for our imminent title, <a title="Vex Blocks" href="http://itzyinteractive.com/vexblocks/" target="_blank">Vex Blocks</a>.</p>
<p>When we started development of Vex Blocks, we set out to create a falling block style arcade game in the vein of Tetris that utilised a device’s rotation.  The job of the player was to chain together blocks on the screen by matching colors, symbols or both and tracing out patterns with their fingers to connect the blocks.  Random blocks would fall into the play area and the job was to clear as many as possible, rotating the device as necessary so blocks would fall into different arrangements.  Once we had created the basic gameplay mechanics, we set about trying to think of how we could change the rules of the game to create different gameplay modes and a “nice to have feature if we have the time” was puzzle mode.</p>
<p>So, as development moved along I ultimately found myself faced with the job of creating various puzzles for our puzzle mode.  I had never set out to create a puzzle before, but how hard could it be?  Start simple, right?</p>
<p><a href="http://itzyinteractive.com/wp-content/uploads/2013/02/PuzzleWorking1.jpg"><img class=" wp-image-622 alignright" style="margin: 5px" alt="PuzzleWorking1" src="http://itzyinteractive.com/wp-content/uploads/2013/02/PuzzleWorking1.jpg" width="401" height="247" /></a>I started by recreating my playing area in Photoshop and went about duplicating the various game pieces so I could simply drag and drop to create the puzzles before coding them into our game.  My next step was to create something aesthetically pleasing before I even thought of how the puzzle would play.  I’d drop in blocks to create geometric shapes and patterns, often drawing inspiration from simple icons as I only had a 5&#215;8 grid to work with.  Once I had a pattern on the screen that I was relatively happy with, I’d start thinking about how it would play.</p>
<p>Here’s where it really started to get fun.  The point of the puzzle mode was to solve the puzzle, clearing all playing blocks from the screen in as few chains as possible, with an upper limit on the amount of chains you could use before the puzzle would reset.  I’d have a look at the blocks in front of me and start tracing out the various options for chains.  If it was too straightforward, then I’d start to throw in obstacles by swapping out blocks that couldn’t be readily chained together, or could only be part of a chain coming from one particular direction.  Or, I’d start with a puzzle and then mimic a few phone rotations to see what I’d end up with.  It was a bit like messing up a Rubik’s cube.  As challenging as a Rubik’s cube is to solve, there’s a certain amount of satisfaction in taking a solved cube and mixing it up for another to solve.  For a few puzzles, that’s exactly what it was like.  Starting with a solved puzzle that was easy to chain together, then scrambling it.  Mmmm&#8230;satisfying.</p>
<p><a href="http://itzyinteractive.com/wp-content/uploads/2013/02/PuzzleWorking2.jpg"><img class=" wp-image-623 alignleft" style="margin: 5px" alt="PuzzleWorking2" src="http://itzyinteractive.com/wp-content/uploads/2013/02/PuzzleWorking2.jpg" width="184" height="277" /></a>From a design perspective, starting simple was really the only way for this project to evolve.  As I started to become comfortable designing simple puzzles, I’d gradually add in new game mechanics.  What if I add a block that can’t be chained and has to be surrounded?  What if I introduce blocks that stay fixed in one spot despite device orientation?  What if we throw in blocks that explode if you don’t clear them quickly enough?  What about using specific power-ups?  Adding one new gameplay mechanic at a time and exploring that mechanic fully before moving onto the next, then adding them together provided a nice progression in terms of variety and difficulty.  As I became more familiar with process, design started to shift away from the look of the puzzle and instead started with a particular challenge, and then I moulded the look around the puzzle.</p>
<p><a href="http://itzyinteractive.com/wp-content/uploads/2013/02/Puzzle7.jpg"><img class=" wp-image-624 alignright" style="margin: 5px" alt="Puzzle7" src="http://itzyinteractive.com/wp-content/uploads/2013/02/Puzzle7.jpg" width="213" height="319" /></a>Next up I assembled the puzzles in-game and turned them loose on our testers.  I quickly discovered that what seems easy to me after working on the game full-time for nine months isn’t necessarily as easy for gamers who haven’t spent that type of time with the product.  Test, test test.  Who knew?  There’s a fine line between challenging and “Nuts to this” with gamers.  Thankfully, I’ve received some excellent feedback and what was originally a “nice to have feature if we have the time” has become a challenging addition to the title that extends the gameplay options while offering us the opportunity to release additional content if gamers like what they see.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/02/10/vexing-puzzle-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Brewing Your Own Game Analytics Service</title>
		<link>http://www.altdevblogaday.com/2013/02/04/brewing-your-own-game-analytics-service/</link>
		<comments>http://www.altdevblogaday.com/2013/02/04/brewing-your-own-game-analytics-service/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 15:29:51 +0000</pubDate>
		<dc:creator>Colt McAnlis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29157</guid>
		<description><![CDATA[<p style="text-align: left">In this post, I describe how to implement a game analytics system to collect and store game data.  At the end of the post you’ll find links to the source code for my sample implementation.</p>
<p><a href="http://www.altdevblogaday.com/2013/02/04/brewing-your-own-game-analytics-service/" class="more-link">Read more on Brewing Your Own Game Analytics Service&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p style="text-align: left">In this post, I describe how to implement a game analytics system to collect and store game data.  At the end of the post you’ll find links to the source code for my sample implementation.</p>
<p style="text-align: left"><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/02/0.jpg"><img class="aligncenter size-medium wp-image-29168" alt="cloud_anlytics" src="http://www.altdevblogaday.com/wp-content/uploads/2013/02/0-300x225.jpg" width="300" height="225" /></a></p>
<p>&nbsp;</p>
<p><span style="font-size: 1.5em">Introduction</span></p>
<p>As a game developer, you <a href="http://www.articlesbase.com/outsourcing-articles/data-collection-is-important-part-for-any-business-808520.html">must</a> gather data about your game’s users, mine that data, and respond to it. The cloud being what it is today, there are multiple costs associated with collecting and using game data, including costs for transactions and storage.</p>
<p>There are of course tons and tons of services out there that do pretty much the same thing in terms of data collection. This is especially true in the mobile space, where it seems that a new games analytics VC-funded company pops up every day. However, these services often come with lots of questions regarding data ownership, costs, reporting structures, and so forth. At bottom, these services may or may not fit your needs.</p>
<p>As such, if you’re simply looking to understand more about a game analytics system, need more functionality, or just want to roll your own, let’s take a look at how to build your very own low-cost game analytics service from scratch.</p>
<h2>The setup</h2>
<p>To begin, we make the following assumptions:</p>
<ul>
<li>The user will play your client, and you’ll submit events to a server for cataloging.</li>
<li>You have some client code that can make HTTP requests (we’ll use HTML5 in this article).</li>
<li>You have some semi-resident server-side compute resource with direct access to a data store. We’ll use <a href="https://developers.google.com/appengine/">Google App Engine</a> (GAE) in this article.</li>
</ul>
<p>In a naive implementation, we assume that the client does the bulk of the work, and pushes data up to the cloud in a regular fashion. For example, we can push an event every time a rat is killed. This setup results in a simple dataflow between our components:</p>
<p>&nbsp;</p>
<div id="attachment_29162" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/02/anal0.png"><img class="size-medium wp-image-29162" alt="anal0" src="http://www.altdevblogaday.com/wp-content/uploads/2013/02/anal0-300x50.png" width="300" height="50" /></a><p class="wp-caption-text">As shown above, the client submits some packet of data to a server, which then pushes it to the GAE Datastore directly.</p></div>
<p style="text-align: left">Let’s hypothetically say that our game has around 15,000 players a day, and each player kills about 2,000 rats – that’s a shocking 30 million events that we’ll be tracking. At this point, we need to take a hard look at what our cost structure is for storing and computing all that data. For instance, the latest pricing on Google App Engine charges about <a href="https://cloud.google.com/pricing/">$0.10 per 100k writes to the Datastore</a>, meaning you’d pay about $30 a day for 30 million writes.  That’s a lot of money to throw around just to store in-game events for data-mining. I mean, if you have a dedicated data miner to track that information then the cost might be justified; otherwise, you’re going to need to find a more cost-effective solution.</p>
<p>In addition, your client may be sending huge amounts of data to the server (for instance if you’re tracking each mouse click in an RTS game).  That’s lots of traffic and compute time that you’re churning just to collect some floating point numbers.</p>
<h2>Client-side batching</h2>
<p style="text-align: left">In the naive implementation above, the dominating cost factor is the sheer number of writes into the Datastore.  To lower the cost, we have to reduce the number of writes.</p>
<p>The first thing we should do is determine the importance of the data that we’re collecting and how often we need to use that data.  For instance, mouse clicks in an RTS game may be semi-important, but not so important that we need that data instantly.  As such, we could batch those mouse clicks and submit them at the end of the game.  This deferred batch-submit strategy is great for reducing the amount of transfers from client to server (since we only get the data at the end of the game), but doesn’t really help us reduce the number of writes into the Datastore (assuming that we’d write each entry in the batch to the Datastore after receipt).</p>
<p>To reduce the number of writes, we turn to another offering in App Engine.  The <a href="https://developers.google.com/appengine/docs/python/blobstore/">Blobstore</a> API allows our application to create data objects (called blobs) that are much larger than objects allowed in the Datastore service. The original Blobstore API only allowed clients to submit blobs via HTTP request, but the new <a href="https://developers.google.com/appengine/docs/python/blobstore/overview#Writing_Files_to_the_Blobstore">experimental Blobstore API</a> allows writing directly to the storage system from server-side code.</p>
<p>Using Blobstore allows us to batch our events on the client side, and submit them in a single  blob.<br />
<a href="http://www.altdevblogaday.com/wp-content/uploads/2013/02/anal1.png"><img class="aligncenter" alt="anal1" src="http://www.altdevblogaday.com/wp-content/uploads/2013/02/anal1-300x96.png" width="300" height="96" /></a></p>
<p>&nbsp;</p>
<p>With this setup, we only submit a batch of events at the end of the game and then store them into the Blobstore, which drops our overall cost per day significantly.</p>
<p>There are, however, two issues with this setup.  The first issue is client connectivity.  Say a user plays 20 minutes and is then disconnected, dropping needed data that we may really want. This issue is even more apparent on mobile platforms, where users are on unreliable network connections and where you should expect random data loss during transmission.</p>
<p>Luckily clients can take advantage of persistent storage, which allows them to store batched data and attempt to resubmit the data at a later time. Having reliable network connections means submissions are more likely to succeed the first time, but any client-side batching system needs to have, at its core, the concept of cache-resubmit for any gathered data.</p>
<p>The second issue is that storing data in Blobstore limits our ability to do analysis on the data directly. Before we can mess with the data, we must read it from the Blobstore into a computational structure for usage.  In other words, the query “give me all the users who’ve killed a rat today” requires us to read out the data from Blobstore into Datastore (or a similar container) before doing processing.</p>
<h2>Server-side batching</h2>
<p style="text-align: left">In an ideal world we’d allow clients to message-spam our server as much as they want, so that we wouldn’t have to worry about clients dropping out randomly and taking their precious data with them. We can accommodate such spammy submissions by batching events at the server.</p>
<p>For those of you that are new to cloud computing systems like Google App Engine, it’s worth emphasizing that GAE modules aren’t always running – rather, they are instances that are spun up depending on request volume.  More importantly, they can get spun down as well, depending on query volume and infrastructure service scheduling.  That means there’s really no way to keep a resident in-memory copy of data.</p>
<p>This is where <a href="https://developers.google.com/appengine/docs/python/backends/">App Engine Backends</a> come in.  Backends are pseudo persistent, heavier-weight process that can hang around for longer durations. With backends, we can allow clients/GAE instances to communicate as normal, and cache/batch the requests into a backend before submitting to the Blobstore</p>
<p><a href="https://developers.google.com/appengine/docs/billing">The cost</a> for this setup would be about $0.08/hour for the GAE backend, in addition to the size of the data that’s being stored in the Blobstore, as well as any additional front-end / back-end compute times.<br />
<a href="http://www.altdevblogaday.com/wp-content/uploads/2013/02/anal2.png"><img class="aligncenter" alt="anal2" src="http://www.altdevblogaday.com/wp-content/uploads/2013/02/anal2-300x110.png" width="300" height="110" /></a></p>
<p>With this setup, clients can be very spammy and intermittent, and the GAE instance effectively acts as a pass-through, simply handing data off to the backend.</p>
<p>You can also make the backend public-facing, allowing clients to submit data to it directly rather than going through the GAE instance.  But be warned that this may create a vulnerability point, as spammy/rogue clients may have the ability to engage in <a href="http://en.wikipedia.org/wiki/Denial-of-service_attack">Denial Of Service</a> attacks against the backend. Combining the scalability of the GAE instance frontend with the longer-running backend is a good way to eliminate this vulnerability and still allow per-client scaling/throttling.</p>
<p>As the number of writes in our system increases, we’ll eventually hit an upper limit on the number of requests a backend can process.  More specifically, depending on the size of our event structure, our 30 million events may exceed the capacity of the back end&#8217;s available RAM.</p>
<p>One way to address this issue is to add an upper storage limit and start flushing data.  For example, once the backend caches say 10MB of data, it can flush that data to the Blobstore for storage. This technique is particularly helpful given that GAE backends are not truly persistent – they are processes that can be rescheduled on different physical machines, which can die or become unavailable for various reasons. As such, we run into similar connectivity issues as we do with clients, although at much lower frequency. Adding regular flushes can ensure regular storage pulses to safeguard our system from losing data. A downside to these regular flushes is that they can take a chunk of time, and generally, we’ll need to flush during an event submission (if the cache gets full, we’ll need to flush before adding the new event). As such, the GAE instance can easily timeout waiting for the backend to flush its data.</p>
<p>A more scalable method of dealing with the limited number of requests a backend can process is to simply increase the number of backends to a desired capacity, and use a hashing function in the GAE instance to evenly distribute events to the backends. Or rather, once our traffic increases to the point where it exceeds what one backend can handle, we can add additional backends (which obviously increases the cost).</p>
<h2>Creating a balanced approach</h2>
<p>One important point to note is that there are actually different types of data that you will want to collect for your game.  Every game is different – there is no one best set of data for all games.  Your game will have a range of statistics that you should collect and store with some variability. For instance:</p>
<ul>
<li>There may be some statistics that are fine to gather locally and push up at periodic intervals; others, you’ll want to store immediately because they are so critical.</li>
<li>You may not need guaranteed delivery of every single event from every single game for every single player. You may just need “most” data or a representative amount of data. For example, you can log only data from a statistically relevant percentage of clients and then extrapolate results.</li>
<li>Not all events can/should come from clients. For MMO games, most of the event calculation and game state reckoning takes place on a game server instance, and as such, that instance should have access to submit events as well.</li>
</ul>
<p style="text-align: left">You should also adjust your data collection based on input loads.  Tune your storage/flushing options based on where the bulk of your data is coming from. For any flushing point (client to server, or server to Blobstore) you should adjust when to flush based on duration and how much data is stored. Always remember that you&#8217;re trading RAM for IO operations – keep data in RAM longer and you’ll need more RAM; flush data more often and you&#8217;ll do more IO.  Tweak the numbers constantly to find a good balance.</p>
<p>One final issue to consider is the cost associated with the size of your data in Blobstore. Since you’re charged per byte, it might be worth reducing the size of the stored data. Thankfully App Engine also has a solution for that through its ZIP API.</p>
<p>Our final implementation, shown in the figure below, includes data segmentation, multiple levels of batching, and data compression.</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/02/anal3.png"><img class="aligncenter" alt="anal3" src="http://www.altdevblogaday.com/wp-content/uploads/2013/02/anal3-300x225.png" width="300" height="225" /></a></p>
<h2></h2>
<h2>Additional considerations</h2>
<h3>True cost gut-check</h3>
<p>There are of course many additional costs involved with cloud processing. For example, there’s the computational cost (= instance hours) of processing/handling every individual HTTP request from clients, as well as the bandwidth cost associated with the per-HTTP-request overhead.  To estimate your true cost, the best thing to do is to build a mock system and run some valid traffic through it to ballpark your numbers.</p>
<h3>Reducing long-term data costs</h3>
<p>When you implement your game analytics system, you should plan for success and consider what you want to do in the long haul. For example, imagine that on a good day, you’ll be storing some 50 million in-game events. That adds up to a significant amount of data to keep around long-term. After a year of production, the likelihood that a single day’s worth of data will be useful drops significantly, so keeping it in the cloud is going to cost you money for data that’s not used. In that case, you should consider moving the data into a form that reduces your cost over time.</p>
<p>One solution that may make sense is to move data regularly from the cloud to a local box, where you can access the data for a longer period of time at a lower cost. Before archiving, you should cache important data elements so that future analysis can reference the results of the data without having to pull it all back out from deep freeze.</p>
<h2>The source</h2>
<p>You can find <a href="https://github.com/mainroach/sandbox/tree/master/stat_tracker">source code</a> for each of the 3 tracking methods we’ve discussed here on my <a href="https://github.com/mainroach">github </a>page. With the <a href="https://developers.google.com/appengine/downloads?hl=nl#Google_App_Engine_SDK_for_Python">App Engine SDK for Python</a>, you can quickly upload and run the instances.  Use the given HTML pages to test the system and see how things work.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/02/04/brewing-your-own-game-analytics-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Garbage Collection and Memory Allocation Sizes</title>
		<link>http://www.altdevblogaday.com/2013/01/31/garbage-collection-and-memory-allocation-sizes/</link>
		<comments>http://www.altdevblogaday.com/2013/01/31/garbage-collection-and-memory-allocation-sizes/#comments</comments>
		<pubDate>Thu, 31 Jan 2013 15:21:52 +0000</pubDate>
		<dc:creator>Niklas Frykholm</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[garbage collection]]></category>
		<category><![CDATA[lua]]></category>
		<category><![CDATA[memory management]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29153</guid>
		<description><![CDATA[<p>As a performance conscious programmer in a soft-realtime environment I&#8217;ve never been too fond of garbage collection.</p>
<p>Incremental garbage collectors (like the one in Lua) make it tolerable (you get rid of the horrible garbage collection stalls), but there is still something unsettling about it. I keep looking at the garbage collection time in the profiler, and I can&#8217;t shake the feeling that all that time is wasted, because <em>it doesn&#8217;t really do anything</em>.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/31/garbage-collection-and-memory-allocation-sizes/" class="more-link">Read more on Garbage Collection and Memory Allocation Sizes&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>As a performance conscious programmer in a soft-realtime environment I&#8217;ve never been too fond of garbage collection.</p>
<p>Incremental garbage collectors (like the one in Lua) make it tolerable (you get rid of the horrible garbage collection stalls), but there is still something unsettling about it. I keep looking at the garbage collection time in the profiler, and I can&#8217;t shake the feeling that all that time is wasted, because <em>it doesn&#8217;t really do anything</em>.</p>
<p>Of course that isn&#8217;t true. Garbage collection frees the programmers from a lot of busywork. And the time they gain can go into optimizing other systems, which leads to a net performance win.</p>
<p>It also simplifies some of the hairy ownership questions that arise when data is transferred between systems. Without garbage collection, those questions must be solved in some other way. Either by reference counting (error-prone) or by making local copies of the data to assume ownership (ugly and costly).</p>
<p>But still, there is that annoying performance hit. </p>
<p>I was pretty surprised to see that the developers <a class="link" href="http://golang.org/">Go</a>, a language that looks well-designed and targets low-level programmers, decided to go with garbage collection rather than manual memory management. It seemed like a strange choice.</p>
<p>But recently I&#8217;ve started to see things differently.</p>
<p>One thing I&#8217;ve noticed as I delve deeper and deeper into data-oriented design is that I tend to allocate memory in much larger chunks than before. It&#8217;s a natural consequence of trying to keep things continuous in memory, treating resources as large memory blobs and managing arrays of similar objects together.</p>
<p>This has interesting consequences for garbage collection, because when the garbage collector only has to keep track of a small number of large chunks, rather than a large number of small chunks, it can perform a lot better.</p>
<p>Let&#8217;s look at a simple example in Lua. Say we want to write a class for managing bullets. In the non-data-oriented solution, we allocate each bullet as a separate object:</p>
<pre>function Bullet:update(dt)
    self.position = self.position + self.velocity * dt
end

function Bullets:update(dt)
    for i,bullet in ipairs(self.bullets) do
        bullet:update(dt)
    end
end</pre>
<p>In the data-oriented solution, we instead use two big arrays to store the position and velocity of <em>all</em> the bullets:</p>
<pre>function Bullets:update(dt)
    for i=1,#self.pos do
        self.pos[i] = self.pos[i] + dt * self.vel[i]
    end
end</pre>
<p>I tested these two solutions with a large number of bullets and got two interesting results:</p>
<ul>
<li>
<p>The data-oriented solution runs <strong>50 times</strong> faster.</p>
</li>
<li>
<p>The data-oriented solution only needs <strong>half</strong> as much time for garbage collection.</p>
</li>
</ul>
<p>That the data-oriented solution runs so much faster shows what cache coherence can do for you. It is also a testament to how awesome LuaJIT is when you give it tight inner loops to work with.</p>
<p>Note that in this test, the <em>Bullet</em> code itself did not create any garbage. The speed-up comes from being faster at collecting the garbage created by <em>other systems</em>. And the reason for this is simply that with fewer, larger memory allocations, there is less stuff that the garbage collector has to trawl through. If we add in the benefit that the data-oriented solution will create fewer objects and generate less garbage, the benefits will be even greater.</p>
<p>So maybe the real culprit in isn&#8217;t garbage collection, but rather having many small memory allocations. And having many small memory allocations does not just hurt the garbage collector, it is bad for other reasons as well. It leads to bad cache usage, high overhead in the memory allocator, fragmentation and bad allocator performance. It also makes all kinds of memory problems harder to deal with: memory leaks, dangling pointers, tracking how much memory is used by each system, etc.</p>
<p>So it is not just garbage-collected languages like Lua that would benefit from allocating memory in larger chunks, but manually managed languages like C++ as well.</p>
<p>Recently, I&#8217;ve come to think that the best solution to memory management issues in C++ is to avoid the kitchen-sink global memory allocator as much as possible and instead let each subsystem take a much more hands-on approach to managing its own memory.</p>
<p>What I mean by this is that instead of having the sound system (for example) send lots of memory requests to the kitchen-sink memory manager, it would only request a few large memory blocks. Then, it would be the responsibility of the system to divide that up into smaller, more manageable pieces that it can make practical use of.</p>
<p>This approach has a number of advantages:</p>
<ul>
<li>
<p>Since the system knows the usage patterns for its data, it can arrange the memory efficiently. A global memory allocator has no such knowledge.</p>
</li>
<li>
<p>It becomes much easier to track memory use by system. There will be a relatively small number of global memory allocations, each tagged by system. It becomes obvious how much memory each system is consuming.</p>
</li>
<li>
<p>Memory <em>inside</em> a system can be easily tracked, since the system knows what the memory <em>means</em> and can thus give useful information about it (such as the name of the object that owns it).</p>
</li>
<li>
<p>When a system shuts down it can quickly and efficiently free all of its memory.</p>
</li>
<li>
<p>Fragmentation problems are reduced.</p>
</li>
<li>
<p>It actively encourages good memory behavior. It makes it easier to do good things (achieve cache locality, etc) and harder to do bad things (lots of small memory allocations).</p>
</li>
<li>
<p>Buffer overflows will tend to overwrite data within the same system or cause page faults, which will make them easier to find.</p>
</li>
<li>
<p>Dangling pointer access will tend to cause page faults, which will make them easier to find.</p>
</li>
</ul>
<p>I&#8217;m tempted to go so far as to <em>only</em> allow <em>whole page allocations</em> on the global level. I.e., a system would only be allowed to request memory from the global manager in chunks of whole system pages. Then it would be up to the system to divide that up into smaller pieces. For example, if we did the bullet example in C++, we might use one such chunk to hold our array of <em>Bullet</em> structs.</p>
<p>This has the advantage of completely eliminating external fragmentation. (Since everything is allocated in chunks of whole pages and they can be remapped by the memory manager.) We can still get address space fragmentation, but using a 64-bit address space should take care of that. And with this approach using 64-bit pointers is less expensive, because we have fewer individually allocated memory blocks and thus fewer pointers.</p>
<p>Instead we get internal fragmentation. If we allocate the bullet array as a multiple of the page size (say 4 K), we will on average have 2 K of wasted space at the end of the array (assuming the number of bullets is random).</p>
<p>But internal fragmentation is a <em>much nicer</em> problem to deal with than external fragmentation. When we have internal fragmentation, it is one particular system that is having trouble. We can go into that system and do all kinds of things to optimize how its handling memory and solve the problem. With external fragmentation, the problem is <em>global</em>. There is no particular system that owns it and no clear way to fix it other than to try lots of things that we hope might &#8220;improve&#8221; the fragmentation situation.</p>
<p>The same goes for out-of-memory problems. With this approach, it is very clear which system is using too much memory and easy to fix that by reducing the content or doing optimizations to that system.</p>
<p>Dealing with bugs and optimizations on a system-by-system simplifies things enormously. It is quite easy to get a good grasp of everything that happens in a particular system. Grasping everything happens in the entire engine is a superhuman task.</p>
<p>Another nice thing about this approach is that it is quite easy to introduce it on a system-by-system basis. All we have to do is to change one system at a time so that it allocates its memory using the page allocator, rather than the kitchen-sink allocator. </p>
<p>And if we have some messy systems left that are too hard to convert to this approach we can just let them keep using the kitchen-sink allocator. Or, even better, we can give them their own private heaps in memory that they allocate from the page allocator. Then they can make whatever mess they want there, without disturbing the other systems.</p>
<p>This has also been posted to <a class="link" href="http://bitsquid.blogspot.com">The Bitsquid blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/31/garbage-collection-and-memory-allocation-sizes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing Voxel Cone Tracing</title>
		<link>http://www.altdevblogaday.com/2013/01/31/implementing-voxel-cone-tracing/</link>
		<comments>http://www.altdevblogaday.com/2013/01/31/implementing-voxel-cone-tracing/#comments</comments>
		<pubDate>Thu, 31 Jan 2013 14:22:12 +0000</pubDate>
		<dc:creator>Simon Yeung</dc:creator>
				<category><![CDATA[Computer Graphics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[global illumination]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sparse voxel octree]]></category>
		<category><![CDATA[voxel cone tracing]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29117</guid>
		<description><![CDATA[<p>[<b>Updated on 25-2-2013</b>: added a paragraph about lowering the voxel update frequency for faster dynamic update. The <a href="https://docs.google.com/file/d/0B_CrrCOiha-VdWp4cXNZcllWRmM/edit">demo</a> also added a combo box for choosing the update frequency]</p>
<p><b><span class="Apple-style-span" style="font-size: large">Introduction</span></b></p>
<p>In last year SIGGRAPH, Epic games presented their <a href="http://www.unrealengine.com/files/misc/The_Technology_Behind_the_Elemental_Demo_16x9_(2).pdf">real time GI solution</a> which based on <a href="http://maverick.inria.fr/Publications/2011/CNSGE11b/GIVoxels-pg2011-authors.pdf">voxel cone tracing</a>. They showed some nice results which attract me to implement the technique and my implementation runs at around 22~30fps (updated every frame) at 1024&#215;768 screen resolution using a 256x256x256 voxel volume on my GTX460 graphic card. The demo program can be downloaded <a href="https://docs.google.com/file/d/0B_CrrCOiha-VdWp4cXNZcllWRmM/edit">here</a> which requires a DX11 GPU to run.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/31/implementing-voxel-cone-tracing/" class="more-link">Read more on Implementing Voxel Cone Tracing&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>[<b>Updated on 25-2-2013</b>: added a paragraph about lowering the voxel update frequency for faster dynamic update. The <a href="https://docs.google.com/file/d/0B_CrrCOiha-VdWp4cXNZcllWRmM/edit">demo</a> also added a combo box for choosing the update frequency]</p>
<p><b><span class="Apple-style-span" style="font-size: large">Introduction</span></b></p>
<p>In last year SIGGRAPH, Epic games presented their <a href="http://www.unrealengine.com/files/misc/The_Technology_Behind_the_Elemental_Demo_16x9_(2).pdf">real time GI solution</a> which based on <a href="http://maverick.inria.fr/Publications/2011/CNSGE11b/GIVoxels-pg2011-authors.pdf">voxel cone tracing</a>. They showed some nice results which attract me to implement the technique and my implementation runs at around 22~30fps (updated every frame) at 1024&#215;768 screen resolution using a 256x256x256 voxel volume on my GTX460 graphic card. The demo program can be downloaded <a href="https://docs.google.com/file/d/0B_CrrCOiha-VdWp4cXNZcllWRmM/edit">here</a> which requires a DX11 GPU to run.</p>
<table>
<tbody>
<tr>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://3.bp.blogspot.com/-XaUDldta9LI/UQVHxULKiOI/AAAAAAAAAhQ/-4Sb64oMMRU/s1600/gi0.png"><img alt="" src="http://3.bp.blogspot.com/-XaUDldta9LI/UQVHxULKiOI/AAAAAAAAAhQ/-4Sb64oMMRU/s1600/gi0.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">With GI</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://1.bp.blogspot.com/-tjaW2p5zK5o/UQVH2qHmiSI/AAAAAAAAAhY/C84ROUJDIzk/s1600/gi1.png"><img alt="" src="http://1.bp.blogspot.com/-tjaW2p5zK5o/UQVH2qHmiSI/AAAAAAAAAhY/C84ROUJDIzk/s1600/gi1.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Without GI</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><b><span class="Apple-style-span" style="font-size: large">Overview</span></b></p>
<p>There are 5 major steps in voxel cone tracing:</p>
<blockquote><p>0. Given a scene with directly lighting only<br />
1. Voxelize the triangle meshes<br />
2. Construct sparse voxel octree<br />
3. Inject direct lighting into the octree<br />
4. Filter the direct lighting to generate mip-map<br />
5. Sample the mip-mapped values by cone tracing</p></blockquote>
<table>
<tbody>
<tr>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://2.bp.blogspot.com/-MO4f_YWl9wY/UQVH9eQDFkI/AAAAAAAAAhg/5_DCCzljCrE/s1600/ov0.png"><img alt="" src="http://2.bp.blogspot.com/-MO4f_YWl9wY/UQVH9eQDFkI/AAAAAAAAAhg/5_DCCzljCrE/s1600/ov0.png" width="200" height="155" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Step 0</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://4.bp.blogspot.com/-P2BVPwilQsE/UQVIEgGhRoI/AAAAAAAAAho/XdXtwZ_EMmw/s1600/ov1.png"><img alt="" src="http://4.bp.blogspot.com/-P2BVPwilQsE/UQVIEgGhRoI/AAAAAAAAAho/XdXtwZ_EMmw/s1600/ov1.png" width="200" height="155" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Step 1</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://1.bp.blogspot.com/-IOAxp7niW_s/UQVII8ur4OI/AAAAAAAAAhw/OJdMZ6trHjk/s1600/ov2.png"><img alt="" src="http://1.bp.blogspot.com/-IOAxp7niW_s/UQVII8ur4OI/AAAAAAAAAhw/OJdMZ6trHjk/s1600/ov2.png" width="200" height="155" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Step 2</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://1.bp.blogspot.com/-_Y2TWCOlTxs/UQVINT1T_iI/AAAAAAAAAh4/4NGeItw8SIs/s1600/ov3.png"><img alt="" src="http://1.bp.blogspot.com/-_Y2TWCOlTxs/UQVINT1T_iI/AAAAAAAAAh4/4NGeItw8SIs/s1600/ov3.png" width="200" height="155" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Step 3</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://2.bp.blogspot.com/-f-2JVZ5PLiU/UQVIRhWUIpI/AAAAAAAAAiA/2njRLi2e19c/s1600/ov4.png"><img alt="" src="http://2.bp.blogspot.com/-f-2JVZ5PLiU/UQVIRhWUIpI/AAAAAAAAAiA/2njRLi2e19c/s1600/ov4.png" width="200" height="155" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Step 4</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://4.bp.blogspot.com/-6oxrpji5wd4/UQVIW5WFmQI/AAAAAAAAAiI/QiA2Zv9viZc/s1600/ov5.png"><img alt="" src="http://4.bp.blogspot.com/-6oxrpji5wd4/UQVIW5WFmQI/AAAAAAAAAiI/QiA2Zv9viZc/s1600/ov5.png" width="200" height="155" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Step 5</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>The step 1 and 2 can be done only once for static geometry while step 3 to 5 need to be done every frame. The following sections will briefly describe the above steps, you may want to take a look at the <a href="http://maverick.inria.fr/Publications/2011/CNSGE11b/GIVoxels-pg2011-authors.pdf">original paper</a> first as some of the details will not be repeated in the following sections.</p>
<div>
<p><b><span class="Apple-style-span" style="font-size: large">Voxelization pass</span></b></p>
<p>The first step is to voxelize the scene. I first output all the voxels from triangle meshes into a big voxel fragment queue buffer. Each voxel fragment use 16 bytes:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://4.bp.blogspot.com/-bilhjuv67FA/UQVKbBjDjiI/AAAAAAAAAis/Oq_3yEp_C4g/s1600/voxelDataFragmentLayout.png"><img alt="" src="http://4.bp.blogspot.com/-bilhjuv67FA/UQVKbBjDjiI/AAAAAAAAAis/Oq_3yEp_C4g/s1600/voxelDataFragmentLayout.png" width="197" height="200" border="0" /></a></div>
<p>The first 4 bytes store the position of that voxel inside the voxel volume which is at most 512, so 4 bytes is enough to store the XYZ coordinates.</p>
<p>Voxel fragments are created using the conservative rasterization described in this <a href="http://www.seas.upenn.edu/%7Epcozzi/OpenGLInsights/OpenGLInsights-SparseVoxelization.pdf">OpenGL Insights</a> charter which requires only 1 geometry pass by enlarging the triangle a bit using the geometry shader. So I modify my <a href="http://simonstechblog.blogspot.hk/2012/08/shader-generator.html">shader generator</a> to generate the shaders for creating voxel fragments based on the material.</p>
<table>
<tbody>
<tr>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://1.bp.blogspot.com/-NRyrOzHslBw/UQVKjsrh-QI/AAAAAAAAAi0/cn2y1bzi8u8/s1600/vp0.png"><img alt="" src="http://1.bp.blogspot.com/-NRyrOzHslBw/UQVKjsrh-QI/AAAAAAAAAi0/cn2y1bzi8u8/s1600/vp0.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Scene before voxelize</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://4.bp.blogspot.com/-LihpATI6lKk/UQVKn_Kr5mI/AAAAAAAAAi8/CwrITUtsKUs/s1600/vp1.png"><img alt="" src="http://4.bp.blogspot.com/-LihpATI6lKk/UQVKn_Kr5mI/AAAAAAAAAi8/CwrITUtsKUs/s1600/vp1.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Scene after voxelize</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><b><span class="Apple-style-span" style="font-size: large">Octree building pass</span></b></p>
<p>I use a similar data structure that described in the <a href="http://maverick.inria.fr/Publications/2011/CNSGE11b/GIVoxels-pg2011-authors.pdf">voxel cone tracing paper</a> and <a href="http://maverick.inria.fr/Publications/2011/Cra11/">giga voxel paper</a> with a large octree node buffer storing the octree/voxel node data (with 8 node grouped into 1 tile which described in the paper) and a 3D texture storing the reflected radiance and alpha from the direct lighting at that voxel (I assume all the surface reflect light diffusely so only 1 3D texture is used which is different from the paper storing incoming radiance).</p>
<p>Each octree node is 28 bytes with the first 4 bytes storing the child tile index with another 24 bytes storing the neighbor node byte offset from the start of the octree node buffer:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://3.bp.blogspot.com/-s_YGclOlD4M/UQVLH2S0e8I/AAAAAAAAAjE/kLbz3nVoffQ/s1600/octreeNodeDataLayout.png"><img alt="" src="http://3.bp.blogspot.com/-s_YGclOlD4M/UQVLH2S0e8I/AAAAAAAAAjE/kLbz3nVoffQ/s1600/octreeNodeDataLayout.png" width="187" height="320" border="0" /></a></div>
<p>The child node tile index is also used to index the 3D texture brick(more details can be found in <a href="http://maverick.inria.fr/Publications/2011/CNSGE11b/GIVoxels-pg2011-authors.pdf">voxel cone tracing paper</a> about the texture brick) which store the reflected radiance of that octree node tile. And since I use 5 bits for store different bit flags for dynamic update, so my voxel volume can only be at most 512x512x512 large.</p>
<p>In the octree leaf node, it stores the voxel data directly which only use 16 bytes:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://4.bp.blogspot.com/-23Op1U3D4sQ/UQVLPPlwgmI/AAAAAAAAAjM/eg7h4EHjbpk/s1600/octreeLeafNodeDataLayout.png"><img alt="" src="http://4.bp.blogspot.com/-23Op1U3D4sQ/UQVLPPlwgmI/AAAAAAAAAjM/eg7h4EHjbpk/s1600/octreeLeafNodeDataLayout.png" width="199" height="320" border="0" /></a></div>
<p>the first 4 bytes store the bit flag to indicate whether that voxel is created from static mesh so that it will not be overwrite by dynamic geometry. Also the 1 byte counter stored along with the voxel normal is used to perform averaging when different voxel fragments fall into the same voxel. The steps to perform atomic average can be found in the <a href="http://www.seas.upenn.edu/%7Epcozzi/OpenGLInsights/OpenGLInsights-SparseVoxelization.pdf">OpenGL Insight Chapter</a>.</p>
<p>So given the voxel fragment queue output from the previous steps, we can build the octree using the steps described in  <a href="http://www.seas.upenn.edu/%7Epcozzi/OpenGLInsights/OpenGLInsights-SparseVoxelization.pdf">OpenGL Insights Chapter</a> and average the octree leaf node values when different voxels fall into the same node.</p>
<div>
<table>
<tbody>
<tr>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://2.bp.blogspot.com/-x5iweSNn5AE/UQVLpqY6fPI/AAAAAAAAAjU/yROoR5S8Jjw/s1600/op0.png"><img alt="" src="http://2.bp.blogspot.com/-x5iweSNn5AE/UQVLpqY6fPI/AAAAAAAAAjU/yROoR5S8Jjw/s1600/op0.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">showing highest octree level</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://1.bp.blogspot.com/-gaewbHxL1YA/UQVLuId7ykI/AAAAAAAAAjc/C4CXQRKQe0o/s1600/op1.png"><img alt="" src="http://1.bp.blogspot.com/-gaewbHxL1YA/UQVLuId7ykI/AAAAAAAAAjc/C4CXQRKQe0o/s1600/op1.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">showing the octree with the voxels</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><b><span class="Apple-style-span" style="font-size: large">Inject direct lighting pass</span></b></p>
<p>After building the voxelized scene, we need to add the lighting data into the data structure to calculate global illumination. First, we render the shadow map from the light&#8217;s point of view. Then for each pixel of the shadow map, we can re-construct the world position of the shadow map texel and then traverse down the octree data structure to calculate the reflected radiance(assume reflected diffusely) and write it to the 3D texture bricks.</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://2.bp.blogspot.com/-vbpJe1TgxS4/UQVMStDZM2I/AAAAAAAAAjk/BTCl1_Kjcdo/s1600/ip0.png"><img alt="" src="http://2.bp.blogspot.com/-vbpJe1TgxS4/UQVMStDZM2I/AAAAAAAAAjk/BTCl1_Kjcdo/s1600/ip0.png" width="320" height="248" border="0" /></a></div>
<p>In my engine, I use cascade shadow map with 4 cascades, the last cascade is used to perform the light injection, with the slope scale depth bias disabled, otherwise, the re-constructed world position may not located exactly inside the voxel. Also, it is better to stablize the shadow map (in the demo, the position of the directional light is computed from view camera)  in order to avoid flicking during cone tracing step when the camera moves. But after stablizing the shadow map, not all the voxels are filled with lighting data at 512x512x512 voxel resolution as the shadow map is not fully utilized&#8230;</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://1.bp.blogspot.com/-Yh_KS8-tplc/UQVMYUaxPeI/AAAAAAAAAjs/t2Gkjd8OqK4/s1600/ip1.png"><img alt="" src="http://1.bp.blogspot.com/-Yh_KS8-tplc/UQVMYUaxPeI/AAAAAAAAAjs/t2Gkjd8OqK4/s1600/ip1.png" width="320" height="248" border="0" /></a></div>
<div class="separator" style="clear: both;text-align: center"></div>
<p>This artifact will also occur when the shadow map resolution is low. Consider the the figure below, we have a directional light injecting lighting to the scene (which have a wall and floor).</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://4.bp.blogspot.com/-SKgY0-mICw8/UQaSfPcnP6I/AAAAAAAAAoM/8GJL_MwD6yw/s1600/smLowRes.png"><img alt="" src="http://4.bp.blogspot.com/-SKgY0-mICw8/UQaSfPcnP6I/AAAAAAAAAoM/8GJL_MwD6yw/s1600/smLowRes.png" width="157" height="200" border="0" /></a></div>
<p>As we launch one thread for each shadow map texel to determine which voxel get light injected, we can only inject light to 3 voxels(the white square in the figure) in the above case. While if the shadow map resolution is high enough, those 5 vertical voxels should all be injected with light.</p>
<p><b><span class="Apple-style-span" style="font-size: large">Filtering pass</span></b></p>
<p>In order to perform cone tracing step, we need to filter the lighting data at the leaf node of the octree. The voxel lighting data is filtered anisotropically along the positive and negative XYZ directions. For example, in a 2D case(which is easier to explain and very similar to the 3D case), for each node tile, we will have 5&#215;5 voxels which will be filtered to 3&#215;3 voxels in the upper mip level like this:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://2.bp.blogspot.com/-aBit6SzNDeM/UQVMeL4G6eI/AAAAAAAAAj0/IdCtwuWiRV0/s1600/filterVoxel25to9.png"><img alt="" src="http://2.bp.blogspot.com/-aBit6SzNDeM/UQVMeL4G6eI/AAAAAAAAAj0/IdCtwuWiRV0/s1600/filterVoxel25to9.png" width="320" height="150" border="0" /></a></div>
<p>To filter the center voxel(texel E in the figure) in the node tile in upper mip level along the +X direction, we need to consider the 9 texels (texel g, h, i, l, m, n, q, r, s in the figure) in the lower level, The texels are divided into 4 groups as the figure below:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://2.bp.blogspot.com/-EjBColCh7AI/UQVMlIEbo3I/AAAAAAAAAj8/aegaQqszbuY/s1600/divide3x3into4gp.png"><img alt="" src="http://2.bp.blogspot.com/-EjBColCh7AI/UQVMlIEbo3I/AAAAAAAAAj8/aegaQqszbuY/s1600/divide3x3into4gp.png" width="320" height="159" border="0" /></a></div>
<p>in each group, we filter along the +X direction, for example in the upper left group, we first alpha blend the value in the +X direction and then average them to get the value for that group.</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://3.bp.blogspot.com/-tTuW5WNU9vM/UQVMsbmYOAI/AAAAAAAAAkE/9XljOpicSc0/s1600/filterBlending.png"><img alt="" src="http://3.bp.blogspot.com/-tTuW5WNU9vM/UQVMsbmYOAI/AAAAAAAAAkE/9XljOpicSc0/s1600/filterBlending.png" width="200" height="175" border="0" /></a></div>
<p>After calculate the values for all the 4 groups, we can compute the filtered center voxel value by repeating the above steps for the 4 group values.</p>
<p>But for the corner values(e.g. texel a, b, f, g) in a node tile we cannot access all the 9 texels to compute a filtered value as those values are in the neighbor node tile. So the group value are partially computed and store in the 3D texture first, then we rely on the transfer step described in the <a href="http://maverick.inria.fr/Publications/2011/CNSGE11b/GIVoxels-pg2011-authors.pdf">cone tracing paper</a> to complete the calculation. In other words, during the transfer steps, some of the filtered value is computed by first alpha blending the neighbor group values followed by averaging them, and other filtered value will be computed by averaging first followed by alpha blending. Although this calculation is not commutative, but this can reduce the number of dispatch passes to compute the filtered value with a similar result.</p>
<p>So we have 6 directional values for a filtered voxels. To get a sample from it for a particularly direction, we can sample it using the method like <a href="http://www.valvesoftware.com/publications/2006/SIGGRAPH06_Course_ShadingInValvesSourceEngine.pdf">ambient cube</a> with 3 texture read (the following code is simplified):</p>
<ol>
<li>float3 sampleAnisotropic(float3 direction)</li>
<li>{</li>
<li>    float3 nSquared = direction * direction;</li>
<li>    uint3 isNegative = ( direction &lt; 0.0 );</li>
<li>    float3 filteredColor=</li>
<li>        nSquared.x * anisotropicFilteredBrickValue[isNegative.x] +</li>
<li>        nSquared.y * anisotropicFilteredBrickValue[isNegative.y+2] +</li>
<li>        nSquared.z * anisotropicFilteredBrickValue[isNegative.z+4];</li>
<li>    return filteredColor;</li>
<li>}</li>
</ol>
<p><b><span class="Apple-style-span" style="font-size: large">Voxel Cone Tracing pass</span></b></p>
</div>
<div>
<p>After doing the above steps, we finally can compute our global illumination. We first consider the simple case for ambient occlusion, which need to compute the AO integral. We approximate it by partitioning the integral with several cones:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://1.bp.blogspot.com/-IRkYoeGcs_M/UQVQGSuEMrI/AAAAAAAAAko/0K2iOTp5O5s/s1600/integral_ao.png"><img alt="" src="http://1.bp.blogspot.com/-IRkYoeGcs_M/UQVQGSuEMrI/AAAAAAAAAko/0K2iOTp5O5s/s1600/integral_ao.png" width="320" height="149" border="0" /></a></div>
<p>Where each partition need to multiply with a weight W. In my implementation, 6 cones are traced with 60 degree over the hemi-sphere in the following direction (Y-axis as the up vector):</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://1.bp.blogspot.com/-FWGnacfrQ2o/UQVQNYhEj9I/AAAAAAAAAkw/99C0J8G-1Rk/s1600/coneTraceDir.png"><img alt="" src="http://1.bp.blogspot.com/-FWGnacfrQ2o/UQVQNYhEj9I/AAAAAAAAAkw/99C0J8G-1Rk/s1600/coneTraceDir.png" width="200" height="101" border="0" /></a></div>
<p>each with a weight W:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://3.bp.blogspot.com/-L5C8sxl5rYE/UQVQUCzd2KI/AAAAAAAAAk4/cXLoT4UvvGM/s1600/coneTraceWeight.png"><img alt="" src="http://3.bp.blogspot.com/-L5C8sxl5rYE/UQVQUCzd2KI/AAAAAAAAAk4/cXLoT4UvvGM/s1600/coneTraceWeight.png" width="58" height="200" border="0" /></a></div>
<p>Then to calculate the visibility inside one cone, we take multiple samples from the filtered 3D texture bricks along the cone direction:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://3.bp.blogspot.com/-HhHImwIQbcU/UQVQt62qCFI/AAAAAAAAAlA/ezXJXNgsJB4/s1600/coneTraceSampleLoc.png"><img alt="" src="http://3.bp.blogspot.com/-HhHImwIQbcU/UQVQt62qCFI/AAAAAAAAAlA/ezXJXNgsJB4/s1600/coneTraceSampleLoc.png" width="200" height="155" border="0" /></a></div>
<p>But, the remaining problem is to determine the sampling position. Since we manually filter the 3D texture bricks, the hardware quadrilinear interpolation will not work.  So to avoid performing the quadrilinear interpolation manually, It is better to make sampling position located at each mip level, having voxel size equals to the cone width at that position. This position is calculated by assuming the shape of voxel is sphere rather than cube(which is easier to calculate) as follows:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://4.bp.blogspot.com/-4Ch8UtZb0WE/UQVQz-ftlaI/AAAAAAAAAlI/NY9GZw5Ik7I/s1600/coneTraceSampleSphereLoc.png"><img alt="" src="http://4.bp.blogspot.com/-4Ch8UtZb0WE/UQVQz-ftlaI/AAAAAAAAAlI/NY9GZw5Ik7I/s1600/coneTraceSampleSphereLoc.png" width="200" height="155" border="0" /></a></div>
<p>Then the sampling location can be calculated given the cone origin, cone angle, trace direction and voxel radius with some simple geometry. And here is the voxel AO result:</p>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://3.bp.blogspot.com/-M0QCsel-EYk/UQVQ5N27v7I/AAAAAAAAAlQ/FandFHx7I2k/s1600/vctp_ao.png"><img alt="" src="http://3.bp.blogspot.com/-M0QCsel-EYk/UQVQ5N27v7I/AAAAAAAAAlQ/FandFHx7I2k/s1600/vctp_ao.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">AO result using 512x512x512 voxel volume</td>
</tr>
</tbody>
</table>
<p>Next, for diffuse indirect illumination, the calculation is very similar to AO:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://1.bp.blogspot.com/-I1Nt67FQwlE/UQVREmeYB6I/AAAAAAAAAlY/TwNxb0k3Pss/s1600/integral_diffuse.png"><img alt="" src="http://1.bp.blogspot.com/-I1Nt67FQwlE/UQVREmeYB6I/AAAAAAAAAlY/TwNxb0k3Pss/s1600/integral_diffuse.png" width="400" height="180" border="0" /></a></div>
<p>The indirect diffuse calculation is done using the same cones as the AO so that both the indirect diffuse and AO can be calculated at the same time:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://2.bp.blogspot.com/-a-W0YCegQlE/UQVRKrvszeI/AAAAAAAAAlg/N794saJ2IEY/s1600/vctp_diffuse.png"><img alt="" src="http://2.bp.blogspot.com/-a-W0YCegQlE/UQVRKrvszeI/AAAAAAAAAlg/N794saJ2IEY/s1600/vctp_diffuse.png" width="320" height="248" border="0" /></a></div>
<p>Finally, we calculate the indirect specular, where cone is traced in the reflected view direction along the surface normal. The cone angle is depends on the glossiness, <i><b>g</b></i>, of the material, currently I use the following equation to calculate the angle:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://4.bp.blogspot.com/-wTO1GBD_KoA/UQVRSqalOnI/AAAAAAAAAlo/GMIiPBUjA0o/s1600/specConeAngle.png"><img alt="" src="http://4.bp.blogspot.com/-wTO1GBD_KoA/UQVRSqalOnI/AAAAAAAAAlo/GMIiPBUjA0o/s1600/specConeAngle.png" width="320" height="54" border="0" /></a></div>
<p>The glossiness is limited to a range so that the cone angle will not be too narrow to avoid stepping through thin walls. Here is the result of indirect specular:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://1.bp.blogspot.com/-5QDIN_rV0b4/UQVRieAprQI/AAAAAAAAAlw/mpQVJe6-0jA/s1600/vctp_specular.png"><img alt="" src="http://1.bp.blogspot.com/-5QDIN_rV0b4/UQVRieAprQI/AAAAAAAAAlw/mpQVJe6-0jA/s1600/vctp_specular.png" width="320" height="248" border="0" /></a></div>
<p>In my engine, I use a light pre-pass renderer, so for the opaque objects, I calculate the indirect lighting by rendering a full screen quad after the lighting pass which is then blend on top of the direct lighting buffer using the following blend state:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://2.bp.blogspot.com/-IFxVbID7h9Q/UQVRo3fvcbI/AAAAAAAAAl4/Ml0nc3U5RfA/s1600/blendStateSameAO.png"><img alt="" src="http://2.bp.blogspot.com/-IFxVbID7h9Q/UQVRo3fvcbI/AAAAAAAAAl4/Ml0nc3U5RfA/s1600/blendStateSameAO.png" width="200" height="32" border="0" /></a></div>
<p>With the value of AO store in alpha channel. this can apply AO to both the direct and indirect lighting. Sometimes different AO intensity is need for the direct and indirect light, this blend state can be used instead:</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://2.bp.blogspot.com/-R4tJaQQAy9k/UQVRtaYZ12I/AAAAAAAAAmA/5_E46w_rfIM/s1600/blendStateDifferentAO.png"><img alt="" src="http://2.bp.blogspot.com/-R4tJaQQAy9k/UQVRtaYZ12I/AAAAAAAAAmA/5_E46w_rfIM/s1600/blendStateDifferentAO.png" width="200" height="30" border="0" /></a></div>
<p>which apply the alpha blending to only the direct lighting and the indirect AO is applied inside the shader.</p>
<p>When filtering mip map directionally from the leaf node, normal direction is not taken into account, which results in more light leaking for thin objects as below. And this artifact can be hidded slightly with the AO value calculated in cone tracing:</p>
<table>
<tbody>
<tr>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://1.bp.blogspot.com/-opltKhwHevA/UQVRzj3jn-I/AAAAAAAAAmI/skfb8vZDpD4/s1600/lightLeak0.png"><img alt="" src="http://1.bp.blogspot.com/-opltKhwHevA/UQVRzj3jn-I/AAAAAAAAAmI/skfb8vZDpD4/s1600/lightLeak0.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">light leak through thin geometry</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://3.bp.blogspot.com/-bVruWs-TAzg/UQVR4cUArWI/AAAAAAAAAmQ/2AmuZwzDhQU/s1600/lightLeak1.png"><img alt="" src="http://3.bp.blogspot.com/-bVruWs-TAzg/UQVR4cUArWI/AAAAAAAAAmQ/2AmuZwzDhQU/s1600/lightLeak1.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">apply the AO can only hide the leaking a bit</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p><b><span class="Apple-style-span" style="font-size: large">Dynamic update</span></b></p>
<p>To make the indirect illumination calculation faster, 5 ways are used to speed up the calculation a bit.</p>
<p>First, when the scene is initialized, the first 4 steps that described in the overview section are performed for all the static geometry. Then in every frame, we re-calculate all the 5 steps for voxels that affected by dynamic objects. So, only dynamic objects will be voxelized every frame (while static voxels are already stored in the octree and we don&#8217;t overwrite those data which can be identified by bit flag stored in the node). Those dynamic voxel fragments are appended to the end of the octree node buffer which can be cleared easily. Also, we need to reset the static octree node neighbor offset which points to dynamic nodes, and those static nodes that affected by dynamic voxels in previous and current frame need to re-filter again. Those nodes are found by dispatching threads for all the nodes and queue those node index into another buffer. So only those with changed value will be re-calculated.</p>
<p>Second, for voxelizing the dynamic geometry, the InterlockedMax() function is used to compute both the diffuse and normal for the octree voxel which is faster than performing an atomic average. Note that using InterlockedMax() function for the normal will decrease the lighting quality if the voxel volume is at a small size(e.g. 256x256x256). You can see the artifact in the below figure:</p>
<table>
<tbody>
<tr>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://4.bp.blogspot.com/-MsDVhrYUW24/UQVSfesq4MI/AAAAAAAAAmY/tAxrLB6uhGc/s1600/duMax0.png"><img alt="" src="http://4.bp.blogspot.com/-MsDVhrYUW24/UQVSfesq4MI/AAAAAAAAAmY/tAxrLB6uhGc/s1600/duMax0.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Reflect light using an average voxel normal</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://1.bp.blogspot.com/-pdyte6aypYk/UQVSjiC57dI/AAAAAAAAAmg/iRv5cvNOav8/s1600/duMax1.png"><img alt="" src="http://1.bp.blogspot.com/-pdyte6aypYk/UQVSjiC57dI/AAAAAAAAAmg/iRv5cvNOav8/s1600/duMax1.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">Reflect light using InterlockedMax() voxel normal.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>So I only use InterlockedMax() function for normal in the dynamic geometry and keeping the static geometry computing an average normal. That is why you can see the octree voxel data structure(in octree building pass section) store a 1 byte counter along with the normal but not other attributes.</p>
<p>Third, I perform a view-frustum culling when injecting the direct lighting into the octree because there is no point to filter the light that is far from the camera where we never sample it from the current point of view. An extended frustum is calculated from the current camera (refer to the figure below) for culling.</p>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://4.bp.blogspot.com/-EpQcL8m2LUE/UQVTPk2wMoI/AAAAAAAAAmo/ZB5I02PpSTc/s1600/frustumCulling.png"><img alt="" src="http://4.bp.blogspot.com/-EpQcL8m2LUE/UQVTPk2wMoI/AAAAAAAAAmo/ZB5I02PpSTc/s1600/frustumCulling.png" width="196" height="200" border="0" /></a></div>
<p>This frustum is simply moving the camera backward a bit with increased far plane using the same field of view. The extended distance is calculated by the maximum cone tracing distance (I limited the cone tracing distance in the demo, which lost the ability to sample from far objects like the sky) and the filtered voxel size.</p>
<p>Fourthly, I perform the cone tracing pass at half resolution of the screen resolution. However, this result in visible artifact when up-scaling to full resolution especially at the edge of the geometry (the strength of the indirect lighting in the following screen shots are increased to show the artifact more clearly).</p>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://2.bp.blogspot.com/-Uxm44Xox4sc/UQVTrCqnbjI/AAAAAAAAAmw/tcdlFaA9QUg/s1600/duUpScaleHalfResNone.png"><img alt="" src="http://2.bp.blogspot.com/-Uxm44Xox4sc/UQVTrCqnbjI/AAAAAAAAAmw/tcdlFaA9QUg/s1600/duUpScaleHalfResNone.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">up-sample with only bilinear filtering</td>
</tr>
</tbody>
</table>
<p>So, I first decided to just fix those pixels by finding them with an edge detection filter using depth buffer.</p>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://4.bp.blogspot.com/-9gFKRv9kzvw/UQVTzJNxcSI/AAAAAAAAAm4/g6aPih3XPg4/s1600/duUpScaleHalfResEdgeDetection.png"><img alt="" src="http://4.bp.blogspot.com/-9gFKRv9kzvw/UQVTzJNxcSI/AAAAAAAAAm4/g6aPih3XPg4/s1600/duUpScaleHalfResEdgeDetection.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">perform an edge detection pas</td>
</tr>
</tbody>
</table>
<p>And then perform cone tracing at those pixel again at full resolution:</p>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://4.bp.blogspot.com/-UWt20sb14Vs/UQVT73f6jRI/AAAAAAAAAnA/6v6v2B6Y0Vw/s1600/duUpScaleHalfResReTrace.png"><img alt="" src="http://4.bp.blogspot.com/-UWt20sb14Vs/UQVT73f6jRI/AAAAAAAAAnA/6v6v2B6Y0Vw/s1600/duUpScaleHalfResReTrace.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">perform the cone-tracing again in the edge pixel at full resolution</td>
</tr>
</tbody>
</table>
<p>Some of the artifacts are gone, but the frame rate drops a lot again&#8230;</p>
<p>So, my second attempt is to just simply blur those pixels (averaging with the neighbor pixel). The quality of blurring is not as good as re-compute the cone tracing, but it is much faster.</p>
<table>
<tbody>
<tr>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://4.bp.blogspot.com/-xLV_g8cuF44/UQVUJyJ6h5I/AAAAAAAAAnI/cKMmzn5IU7g/s1600/duUpScaleHalfResBlur.png"><img alt="" src="http://4.bp.blogspot.com/-xLV_g8cuF44/UQVUJyJ6h5I/AAAAAAAAAnI/cKMmzn5IU7g/s1600/duUpScaleHalfResBlur.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">up sample with blurring at edge</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://4.bp.blogspot.com/-9gLIX8e_wes/UQVUPYxPPFI/AAAAAAAAAnQ/cQlHN2JRNUk/s1600/duUpScaleFullRes.png"><img alt="" src="http://4.bp.blogspot.com/-9gLIX8e_wes/UQVUPYxPPFI/AAAAAAAAAnQ/cQlHN2JRNUk/s1600/duUpScaleFullRes.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">cone tracing at full resolution for reference</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<div></div>
<div>Lastly, The voxel world can be updated at a different frequency than the render frame rate. By assuming the  light source/dynamic models are not moving very fast, we can take advantage of the temporary coherency and perform the voxelization at a lower frequency, say update at every 5 frames. We can trade the accuracy of the voxels for update speed, but this may result in the artifact shown below:</div>
<table class="tr-caption-container" style="margin-left: auto;margin-right: auto;text-align: center" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td style="text-align: center"><a style="margin-left: auto;margin-right: auto" href="http://1.bp.blogspot.com/-gmnKqXtcuw4/USuEm-2gxLI/AAAAAAAAApU/Bf9je4_cogk/s1600/duInterval.png"><img alt="" src="http://1.bp.blogspot.com/-gmnKqXtcuw4/USuEm-2gxLI/AAAAAAAAApU/Bf9je4_cogk/s1600/duInterval.png" width="320" height="248" border="0" /></a></td>
</tr>
<tr>
<td class="tr-caption" style="text-align: center">The voxel model is lag behind the triangle<br />
mesh due to the lower update frequency</td>
</tr>
</tbody>
</table>
<p><b><span class="Apple-style-span" style="font-size: large">Conclusion</span></b></p>
<p>The advantage of voxel cone tracing is to compute the GI in real-time with both the dynamic lighting and geometry. Also the specular indirect lighting gives a very nice glossy effect. However, it uses lots of the processing power/memory and quality of lighting is not as good as the baked solution. In my implementation, I can only use 1 directional light to compute single bounce indirect lighting. And there are still room to improve in my implementation as fewer cones can be used for tracing, using the depth buffer for view frustum culling, better up-sampling when performing cone tracing and divide the voxels into several regions to handle a larger scene like Unreal Engine does. But there is never enough time to implement all that stuff&#8230; So I decided to release the <a href="https://docs.google.com/file/d/0B_CrrCOiha-VdWp4cXNZcllWRmM/edit">demo</a> at this stage first. In the demo, I have added some simple interface (for changing stuffs like the light direction, indirect lighting strength) for you to play around with. Hope you all enjoy the <a href="https://docs.google.com/file/d/0B_CrrCOiha-VdWp4cXNZcllWRmM/edit">demo</a>.</p>
<p>Finally, I would like to thanks Kevin Gadd and Luke Hutchinson for reviewing this article.</p>
<table>
<tbody>
<tr>
<td>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://1.bp.blogspot.com/-3XIunxXIcFI/UQVU6EscbcI/AAAAAAAAAnY/MppCCKxFpec/s1600/demo0.png"><img alt="" src="http://1.bp.blogspot.com/-3XIunxXIcFI/UQVU6EscbcI/AAAAAAAAAnY/MppCCKxFpec/s1600/demo0.png" width="320" height="248" border="0" /></a></div>
</td>
<td>
<div class="separator" style="clear: both;text-align: center"><a style="margin-left: 1em;margin-right: 1em" href="http://1.bp.blogspot.com/-slFJ6rttJco/UQVU-PxzkbI/AAAAAAAAAng/mAelRkhNNfA/s1600/demo1.png"><img alt="" src="http://1.bp.blogspot.com/-slFJ6rttJco/UQVU-PxzkbI/AAAAAAAAAng/mAelRkhNNfA/s1600/demo1.png" width="320" height="248" border="0" /></a></div>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
</div>
<div><b>References</b></div>
<div><span class="Apple-style-span" style="font-size: x-small">[1] The Technology Behind the “Unreal Engine 4 Elemental demo” <a href="http://www.unrealengine.com/files/misc/The_Technology_Behind_the_Elemental_Demo_16x9_(2).pdf">http://www.unrealengine.com/files/misc/The_Technology_Behind_the_Elemental_Demo_16x9_(2).pdf</a></span></div>
<div><span class="Apple-style-span" style="font-size: x-small">[2] Interactive Indirect Illumination Using Voxel Cone Tracing <a href="http://maverick.inria.fr/Publications/2011/CNSGE11b/GIVoxels-pg2011-authors.pdf">http://maverick.inria.fr/Publications/2011/CNSGE11b/GIVoxels-pg2011-authors.pdf</a></span></div>
<div><span class="Apple-style-span" style="font-size: x-small">[3] Octree-Based Sparse Voxelization Using the GPU Hardware Rasterizer <a href="http://www.seas.upenn.edu/%7Epcozzi/OpenGLInsights/OpenGLInsights-SparseVoxelization.pdf">http://www.seas.upenn.edu/%7Epcozzi/OpenGLInsights/OpenGLInsights-SparseVoxelization.pdf</a></span></div>
<div><span class="Apple-style-span" style="font-size: x-small">[4] GigaVoxels: A Voxel-Based Rendering Pipeline For Efficient Exploration Of Large And Detailed Scenes</span><br />
<a href="http://maverick.inria.fr/Publications/2011/Cra11/"><span class="Apple-style-span" style="font-size: x-small">http://maverick.inria.fr/Publications/2011/Cra11/</span></a></div>
<div><span class="Apple-style-span" style="font-size: x-small">[5] GPU Gems 2: Conservative Rasterization <a href="http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter42.html">http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter42.html</a></span><br />
<span class="Apple-style-span" style="font-size: x-small">[6] Shading in Valve’s Source Engine <a href="http://www.valvesoftware.com/publications/2006/SIGGRAPH06_Course_ShadingInValvesSourceEngine.pdf">http://www.valvesoftware.com/publications/2006/SIGGRAPH06_Course_ShadingInValvesSourceEngine.pdf</a></span><br />
<span class="Apple-style-span" style="font-size: x-small">[7] Perpendicular Possibilities <a href="http://blog.selfshadow.com/2011/10/17/perp-vectors/">http://blog.selfshadow.com/2011/10/17/perp-vectors/</a></span></div>
<div><span class="Apple-style-span" style="font-size: x-small">[8] A couple of notes about Z <a href="http://www.humus.name/index.php?ID=255">http://www.humus.name/index.php?ID=255</a></span></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/31/implementing-voxel-cone-tracing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An update to Single Joystick</title>
		<link>http://www.altdevblogaday.com/2013/01/29/an-update-to-single-joystick/</link>
		<comments>http://www.altdevblogaday.com/2013/01/29/an-update-to-single-joystick/#comments</comments>
		<pubDate>Tue, 29 Jan 2013 09:23:34 +0000</pubDate>
		<dc:creator>Alex Moore</dc:creator>
				<category><![CDATA[Game design]]></category>
		<category><![CDATA[UI and UX]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29143</guid>
		<description><![CDATA[<p>Two weeks ago I posted an article showing progress on a <a href="http://www.altdevblogaday.com/2013/01/15/a-new-type-of-touch-screen-joystick/">new type of touch screen joystick</a>, that allows you to move and rotate using a single touch. The response to that was really positive, and so I&#8217;ve continued working on it in the background. This is a short post updating on progress.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/29/an-update-to-single-joystick/" class="more-link">Read more on An update to Single Joystick&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Two weeks ago I posted an article showing progress on a <a href="http://www.altdevblogaday.com/2013/01/15/a-new-type-of-touch-screen-joystick/">new type of touch screen joystick</a>, that allows you to move and rotate using a single touch. The response to that was really positive, and so I&#8217;ve continued working on it in the background. This is a short post updating on progress.</p>
<p>Most of the update is covered in this video, which I&#8217;ve recorded on a camera so that I could narrate:</p>
<span style="text-align:center; display: block;"><a href="http://www.altdevblogaday.com/2013/01/29/an-update-to-single-joystick/"><img src="http://img.youtube.com/vi/gu8wM7jsSOc/2.jpg" alt="" /></a></span>
<p>To cover the main points done on the road to improving the system:</p>
<ul>
<li>To alleviate the issue of not being able to see where your thumb is on the stick, I&#8217;ve added a mirror joystick in the centre of the screen that appears when you&#8217;re touching the main one.</li>
<li>I&#8217;ve added a nice orange dot to show you the direction you&#8217;re walking in. This was first done by Eric Raue on his own implementation of the original article (Eric also added <a href="http://ericraue.com/f/external/unity/Joystick/">a web player build of his version here</a>).</li>
<li>Rotation arrows now appear when you touch the rotate gizmo. This seems to have been the turning point for ease of use: without these arrows people struggled to understand why they were rotating, with them they get it much easier.</li>
<li>The faster you rotate the slower you walk. This makes it possible to perform much tighter turns, which seems important as a lot of people don&#8217;t turn until they&#8217;re at the point they want to (unlike myself, who tends to use it more akin to driving a car).</li>
</ul>
<p>This version has been focus tested quite a bit now, and is showing a lot of promise. Most people get it within a minute, a few take a bit longer. Eased into the mechanic though I think this is very good, especially when compared to the learning curve of dual sticks.</p>
<p>I&#8217;m going to keep working on this when I can, but it might be a little while before there&#8217;s another update. Which may well be about starting a kickstarter :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/29/an-update-to-single-joystick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Put On Your Game Face (revisited)</title>
		<link>http://www.altdevblogaday.com/2013/01/29/put-on-your-game-face-revisited/</link>
		<comments>http://www.altdevblogaday.com/2013/01/29/put-on-your-game-face-revisited/#comments</comments>
		<pubDate>Tue, 29 Jan 2013 04:25:58 +0000</pubDate>
		<dc:creator>David Czarnecki</dc:creator>
				<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29137</guid>
		<description><![CDATA[<p><span style="text-decoration: underline">TL;DR</span></p>
<p>About a year ago, <a href="http://www.altdevblogaday.com/2012/03/28/put-on-your-game-face/">I wrote a blog post</a> here about a weekly blog series on our company blog called <a href="http://blog.agoragames.com/blog/category/game-face/">&#8220;Game Face&#8221;</a>. A blog post revisiting a blog post about blog posts? It&#8217;s blog posts all the way down. As a refresher, &#8220;Game Face&#8221; is “our weekly round-up of our internal and external open source work at Agora Games. Internal open source refers to our public projects that you can find over at our <a href="https://github.com/agoragames/">Agora Games GitHub</a> account. External open source work refers to projects that we contribute to in off-hours and may or may not have anything to do with video games because we’re swell folks like that.” How&#8217;d we do in our open source efforts over the last year? Read on&#8230;</p>
<p><a href="http://www.altdevblogaday.com/2013/01/29/put-on-your-game-face-revisited/" class="more-link">Read more on Put On Your Game Face (revisited)&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p><span style="text-decoration: underline">TL;DR</span></p>
<p>About a year ago, <a href="http://www.altdevblogaday.com/2012/03/28/put-on-your-game-face/">I wrote a blog post</a> here about a weekly blog series on our company blog called <a href="http://blog.agoragames.com/blog/category/game-face/">&#8220;Game Face&#8221;</a>. A blog post revisiting a blog post about blog posts? It&#8217;s blog posts all the way down. As a refresher, &#8220;Game Face&#8221; is “our weekly round-up of our internal and external open source work at Agora Games. Internal open source refers to our public projects that you can find over at our <a href="https://github.com/agoragames/">Agora Games GitHub</a> account. External open source work refers to projects that we contribute to in off-hours and may or may not have anything to do with video games because we’re swell folks like that.” How&#8217;d we do in our open source efforts over the last year? Read on&#8230;</p>
<p><span style="text-decoration: underline">THE BRASS TACKS</span></p>
<p>In 2011, <a href="http://blog.agoragames.com/blog/2012/01/09/2011-open-source-projects/">we open sourced 22 projects</a>. In 2012, <a href="http://blog.agoragames.com/blog/2012/12/14/game-face-41/">we open sourced 33 projects</a>. Obviously not all of these projects are going to &#8220;stick&#8221;, but one man&#8217;s trash is another man&#8217;s treasure right? The projects aren&#8217;t trash, BTW. A few projects came out of internal company-wide Hack-A-Thon sessions that we run every 2 months, but a fair number of them are taken from production applications. In looking at the 2012 project breakdown, by language, we have Ruby (22), Python (3), CoffeeScript (3), JavaScript (2), C++ (2), PHP (1). 7 of our engineers and 21 external people contributed to the various projects that we open sourced in 2012. Contributions range from clarifications in documentation to major new features that are developed, documented and tested.</p>
<p>It is very easy for us to track contributions to all of our open source projects. All of the projects are setup with a service hook to notify our company&#8217;s &#8220;Open Source&#8221; chat room when events happen like code is committed or a pull request is opened or an issue is filed. Every week I create a new &#8220;shell&#8221; for the &#8220;Game Face&#8221; blog post after the last one is published. I set it to be published automatically at 9 AM on the following Friday. As contributions come in to our open source projects, next week&#8217;s blog post is updated.</p>
<p>I&#8217;m not sure if we&#8217;ll open source more projects than we did in 2012. 33 is a fair number of projects to have open sourced. We obviously want quality over quantity. I&#8217;m always pushing to see if there&#8217;s anything we can open source. One of the ideas being tossed around as a way to expand our open source efforts would be to hold a weekly &#8220;Office Hours&#8221; session where a few engineers hop onto IRC or a Google &#8220;hangout&#8221; for an hour or so and field questions on our projects.</p>
<p><span style="text-decoration: underline">FIN</span></p>
<p>We are happy to contribute back in any way we can to open source software, whether it be our own projects or the projects we use on a daily basis. Again, if your company does anything with open source, I’d love to know about it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/29/put-on-your-game-face-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Crowdfunding Experience</title>
		<link>http://www.altdevblogaday.com/2013/01/27/the-crowdfunding-experience/</link>
		<comments>http://www.altdevblogaday.com/2013/01/27/the-crowdfunding-experience/#comments</comments>
		<pubDate>Sun, 27 Jan 2013 04:25:07 +0000</pubDate>
		<dc:creator>Alex Norton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29112</guid>
		<description><![CDATA[<p>So, just recently, I was asked to give a 90 min lecture in my home city regarding crowdfunding after managing to run a successful campaign myself in mid 2012. The lecture is pretty long, but I&#8217;ll <a title="Original crowdfunding lecture" href="http://www.youtube.com/watch?v=x3XKry6HSLc" target="_blank">include the video</a> at the end in case anyone&#8217;s interested in sitting through the whole thing. If not, I was also asked to write a shortened version of it for people to read, so I thought I&#8217;d share it here.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/27/the-crowdfunding-experience/" class="more-link">Read more on The Crowdfunding Experience&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>So, just recently, I was asked to give a 90 min lecture in my home city regarding crowdfunding after managing to run a successful campaign myself in mid 2012. The lecture is pretty long, but I&#8217;ll <a title="Original crowdfunding lecture" href="http://www.youtube.com/watch?v=x3XKry6HSLc" target="_blank">include the video</a> at the end in case anyone&#8217;s interested in sitting through the whole thing. If not, I was also asked to write a shortened version of it for people to read, so I thought I&#8217;d share it here.</p>
<p>Keep in mind this whole lecture purely relates to my own experience with crowdfunding and not to that of others, but I hope that any prospective crowdfunding applicants can get something useful out of it!</p>
<p>&#8212;</p>
<p>Hi, my name is Alex Norton, and in mid 2012 I ran a successful crowd-funding campaign for my procedural RPG, Malevolence: The Sword of Ahkranox, earning over 500% of my requested total. How did I do it? Well, I&#8217;ll tell you &#8211; but it&#8217;s not an exact science. The best I can do is to give you what advice I can.<br />
First of all, why did I even look into crowd-funding? Many campaigns you see on places such as Kickstarter are looking to fund an entire project &#8211; sometimes asking for hundreds of thousands of dollars to do this. To me, that seems a bit much, particularly given that all that is offered up on these campaigns are some design drawings and an empassioned speech by a director of some sort. My tact was different. I already had a product, but a rough one. It worked, but wasn&#8217;t as pretty as it could be. To make your project pretty is often the part that takes up most of your money, so that&#8217;s what I looked to crowd-funding for. Polish is often what makes or breaks a product. No matter how impressive something is technically, without the right shine it just becomes hard to &#8220;sell&#8221; to an audience.<br />
In addition to polish, crowd-funding my game gave me an insight into its market viability. Would it sell? Is the idea sound? How will the public  react to it? All of these questions and more were answered purely based on the social response that my project got on the network, and on blog sites that talked about it. So that&#8217;s another angle for you to look at.<br />
The first time I attempted crowd-funding, however, didn&#8217;t go so well. I made up a video for my product, slapped together a few screen- shots and gameplay videos and left it there for a month on IndieGoGo, expecting to find the account full of money at the end of it.<br />
Needless to say, the excersise was fruitless. Not only did it get to barely an eighth of what I needed financially, it copped a fair amount of negative publicity, which put me to thinking.<br />
Now please, don&#8217;t get me wrong, the fault for this lay with me entirely. IndieGoGo is a fantastic site (and available for use by people in Australia) but my strategy for running my campaign was entirely wrong. So I took the lessons I learned from it and made the move to Kickstarter via one of the American members of my team.<br />
After doing significant research on other, more successful, crowd-funded projects, I came to the following conclusions:</p>
<p>- Communication is key! Talk to your pledgers and potential customers. Answer their questions when they have them and keep them engaged.</p>
<p>- It all comes down to how you sell your product, and how you sell yourself and your team as people.</p>
<p>- Be aware of your target audience and gear every little thing you do towards them and only them.</p>
<p>- Market your campaign. Send links to blogs, reviewers, journals, magazines and spread it across social networks. Get traffic to it.</p>
<p>- Be willing to put in the hours that it takes to make regular updates, answer all questions and keep the customer engaged at all times.</p>
<p>On top of this, I decided to change my tactics to include the following:</p>
<p>- Show the customer that the project is being made by people. Good quality, friendly, nice people. If they like you, they&#8217;ll be more<br />
inclined to like what you&#8217;re selling.</p>
<p>- Don&#8217;t just show them why your product is special. Show them why it&#8217;s special to YOU, and why it should be special to THEM.</p>
<p>- When you&#8217;re selling your product, you should also be selling the people making it. It makes the customer feel a part of something,<br />
rather than a simple &#8216;browse and buy&#8217; scenario.</p>
<p>- Write lots of updates. At LEAST 3 per week. Show them you&#8217;re working at it. Show them how dedicated you are. Try and use video where<br />
possible. People respond to video. Get your best speaker onto it.</p>
<p>- Talk to the pledgers, not just as someone who answers questions, but really engage them in conversation. Show them you&#8217;re real.</p>
<p>So after doing all that, I had an interesting campaign. It took work, to do all that, I won&#8217;t lie, and that&#8217;s something you have to be prepared to do. It&#8217;ll be more work than you think it will be, too. So, for the month that your campaign is running, prepare to turn away friends and family, to decline invitations and to tell everyone to leave you alone. If this project really means that much to you, then you need to be willing to dedicate your life to it for a month.<br />
I did this myself, and the response was massive. My project was fully funded within the first week, and after that it just kept climbing and climbing. I had to move on to add stretch goals quite quickly, which was something I&#8217;ll admit I had not planned for, but when it comes to crowd-funding, you never know what might happen, so you have to be prepared for not only the worst, but the best, too!<br />
Once it was all over and done with, I had the aftermath to deal with, which was another thing I wasn&#8217;t expecting. It&#8217;s not as simple as all that. To suddenly go from being a penniless developer to having all that cash sitting there&#8230; It&#8217;s a hard thing to be responsible and look after it properly, but you must. Don&#8217;t go nuts with it as some people have done in the past. Be responsible, be well-managed and you&#8217;ll reap the benefits of it.<br />
Another thing you&#8217;ll have to deal with is the public hatred. Yes, it&#8217;s strange, but some people don&#8217;t like to see other people succeed, and if you happen to have a particularly successful campaign, some people will hate you for it. They will make you feel terrible, but trust me when I say that it&#8217;s best to just ignore them. If you&#8217;ve handled your campaign as I stated above then you&#8217;ll have a vast and loyal following behind not only your product, but you as well, and they&#8217;ll always make you feel welcome!</p>
<p>Not all campaigns work though, and it&#8217;s not always your own fault, or because your product is a bad one. Sometimes the planets just don&#8217;t want to align for you, and that&#8217;s alright, too. If that happens, it is definitely worth your time to analyze the wreckage and find out what could have been done better, so that you don&#8217;t make repeat mistakes next time. That information is PRICELESS, I cannot stress enough. A failure is only a failure if you fail to learn from it. Remember that. You can always try again.</p>
<p>So, what would some last-minute advice be to a potential crowd-funder? The following is the best I can offer:</p>
<p>- Just because you CAN crowd-fund, doesn&#8217;t necessarily mean you SHOULD. Make sure your product has GOTTEN somewhere first, otherwise jumping<br />
into a crowd-funding situation can bring some pretty nasty PR down on your project.</p>
<p>- Don&#8217;t do it unless you&#8217;re prepared to deal with it. I cannot stress to you just how much work it is if you do it right, and that is<br />
something that you really have to be ready for. PROPERLY ready for.</p>
<p>- Be sure to market your campaign EVERYWHERE. Don&#8217;t rely on people to just happen across it one day. Spread the word EVERYWHERE. Don&#8217;t be<br />
shy about it!</p>
<p>So that&#8217;s all for now! This is a cut-down version of this topic, but for the full version, feel free to watch the video at the link below. I wish you all the best in your campaign and your projects! Good luck!</p>
<p>&nbsp;</p>
<p><a href="http://www.youtube.com/watch?v=x3XKry6HSLc">(In case the embedded video doesn&#8217;t show up, click here for the link to YouTube)</a></p>

<object width="425" height="344">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/http://www.youtube.com/watch?v=x3XKry6HSLc&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/http://www.youtube.com/watch?v=x3XKry6HSLc&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="425" height="344">
</embed>
</object>


]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/27/the-crowdfunding-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Surviving a Game Jam</title>
		<link>http://www.altdevblogaday.com/2013/01/24/surviving-a-game-jam/</link>
		<comments>http://www.altdevblogaday.com/2013/01/24/surviving-a-game-jam/#comments</comments>
		<pubDate>Thu, 24 Jan 2013 23:12:00 +0000</pubDate>
		<dc:creator>Andrew Meade</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Production]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Game Jam]]></category>
		<category><![CDATA[GGJ]]></category>
		<category><![CDATA[Red Bull]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29107</guid>
		<description><![CDATA[<p>So this being AltDevBlogADay, I’m sure that a lot of people reading this have done at least one game jam. I’m sure that a good deal of people also haven’t had the pleasure yet, so this little write up is for them. This isn’t really a full article, just a jot-down of some musings that are kind of rushed because I’m most busy when an article on it is most timely.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/24/surviving-a-game-jam/" class="more-link">Read more on Surviving a Game Jam&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>So this being AltDevBlogADay, I’m sure that a lot of people reading this have done at least one game jam. I’m sure that a good deal of people also haven’t had the pleasure yet, so this little write up is for them. This isn’t really a full article, just a jot-down of some musings that are kind of rushed because I’m most busy when an article on it is most timely.</p>
<p>In a  few days, thousands of people around the globe will gather at pre-registered locations, and attempt to make a game with a specific theme within 48 hours at the 2013 Global Game Jam. Game Jams are an amazing place to have fun, make new connections, and learn new skills. And of course, there’s the ever-valuable fact that you walk into a place, and 48 hours later you (hopefully) have a functioning game with YOUR name on the credits. Boom. 48 Hours. Game. Done.</p>
<p>So what can you expect from a one of these events? Well every locale is different, but typically you all meet at the prescribed location at the prescribed time, watch a video, and then get pseudo-randomly assigned to teams (unless you come with your own team). Once the 48 hours is up, an expo is held where everyone shares their games and talks about the process. Once that’s over, some people will continue to punish their bodies by the intense imbibing of spirits. That least bit I can’t recommend, but I do it anyway.</p>
<p>Anyways, the goal is to have fun. The goal is also to make a game, and it sucks when a team just can’t get it together in time. Unfortunately this will happen to some teams, so I’m here to kind of help keep that from happening. So without further ado, here is a small list of thoughts and hard-learned lessons to help you out on your maiden voyage.</p>
<p>&nbsp;</p>
<p><strong>Nourishment</strong></p>
<p>I’m not huge on caffeine, but here’s where you’re going to see cases of red bull and pots of coffee all over the place. I personally like to stay hydrated with tons of water, naked juice to boost my energy, and snacks high in fiber and vitamins. I’ll also go through about 6-7 red bulls. That’s just me. You can also get by fine on Bawls, tasty cakes, and bugles, but don’t blame me if you’re feeling gross and your body starts producing neon waste after the 24 hour mark. I also advise that the team at least once physically remove themselves from their chairs, and go for a walk to a nearby eatery. First off, breaking bread together is just great teaming. Second, everyone gets a much needed break and some decent hot food. If you aren’t jamming next to a place to eat, consider ordering delivery and eating in a location where you aren&#8217;t working. I go to the Game Jam in Orlando, so we have the luxury of comfortably being outside without bundling up. I know some of you may not be that lucky.</p>
<p>&nbsp;</p>
<p><strong>Hygiene</strong></p>
<p>Shower before you go! You probably won’t for two days. Nobody wants you to stink.</p>
<p>&nbsp;</p>
<p><strong>Rest</strong></p>
<p>Try to get some rest. Some people can power through for 48 hours and do fine. If you’re one of those people, then good for you. I can be, depending on my mood. I recommend getting some sleep around the 30 hour mark. Maybe 4 or 5 hours. I knew a guy that refused to sleep and around hour 40 started wandering around aimlessly before falling asleep in the cupboard. Fun times. If you don’t sleep, take a break. When I do a Game jam, I get up and go outside for ten minutes every hour. Keeps my mind sharp, keeps my limbs moving, and keeps my energy up.</p>
<p>&nbsp;</p>
<p><strong>What should I bring?</strong></p>
<p>-          Your rig, obviously, with any spare stuff you can afford to lug. People are always forgetting cables, headphones, mouse pads – stupid little stuff.</p>
<p>-          Drinks and snacks for you, plus room for it to get mooched on. Don’t be the guy that brings nothing, but don’t be the guy that’s a tightwad with the snacks when the less prepared run out. You’re all in this together, after all.</p>
<p>-          Pillow, blanket, bedroll. You’ll likely be sleeping on the floor, so do what you can to make that a better experience for you.</p>
<p>-          Change of unmentionables, fresh t-shirt, overshirt, and maybe a sweatshirt or hoodie if you want.</p>
<p>-          Toothbrush, toothpaste, deodorant, meds, etc.</p>
<p>-          Your talent!</p>
<p>&nbsp;</p>
<p><strong>Jobs</strong></p>
<p>Well programmer, artist, and audio engineer seem pretty self explanatory, but the designer is a little harder to define. As much as it pains me to say, a designer’s talents aren&#8217;t optimal for a game jam, but they can still be super useful. As a designer, I do design work, but I also step into a producer role, a runner role,  and an “oh my god we need three more artists and we have ten hours go find them” roll.</p>
<p>I wouldn&#8217;t advise for a team to take on more than one designer, unless you’re working in an engine like UDK or Unity, and all the programming is already done. Just remember designers, it’s not that we’re not useful, it’s that a Game jam isn’t a nurturing environment for us to really get going. Don’t believe me? That’s fine. Just do the game jam before you get on the comments section and call me an idiot.</p>
<p>&nbsp;</p>
<p><strong>Making the Game</strong></p>
<p>You&#8217;ve got your team. You&#8217;ve got your red bull. The coordinator has announced the theme. Here’s some advice. Pick a simple game idea, with one simple mechanic, and get it working. Then figure out how to get your theme to work with that. At one GGJ we went through a list of simple games like pong, asteroids, and connect four. We ended up going with an on-rails platformer where the sole mechanic was jumping. To be fair, it was for the kinect, so you could maybe get a little more complex than that if you’re not putting together a kinect game in 48 hours.</p>
<p>Ideally you should have your game functional and running within a few hours, then spend the rest of the time making it your own and iterating. This is advice I was given for my first game jam by a very smart person. It is really a winning way to ensure you get a game done.</p>
<p>&nbsp;</p>
<p>Well that’s it! If anyone out there has any more advice, add it in the comments! Good luck and happy jamming!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/24/surviving-a-game-jam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aesop’s Games</title>
		<link>http://www.altdevblogaday.com/2013/01/18/aesops-games/</link>
		<comments>http://www.altdevblogaday.com/2013/01/18/aesops-games/#comments</comments>
		<pubDate>Fri, 18 Jan 2013 09:00:00 +0000</pubDate>
		<dc:creator>Rich Skorski</dc:creator>
				<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28997</guid>
		<description><![CDATA[<p>My wife and I just had our first child. While our daughter was baking in my wife’s belly, we would talk about what kinds of video games she would like to play when she grew up or if she would wind up liking them at all. I thought long and hard about what games I would want her to play. Which games in my library would I leave on the table for her to discover, and at what ages? What I’ve been looking for are games that teach morals and lessons, particularly ones that do so in a way that cannot be done in other media. A game puts the audience in control, which brings a high level of teaching possibilities to the table.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/18/aesops-games/" class="more-link">Read more on Aesop’s Games&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>My wife and I just had our first child. While our daughter was baking in my wife’s belly, we would talk about what kinds of video games she would like to play when she grew up or if she would wind up liking them at all. I thought long and hard about what games I would want her to play. Which games in my library would I leave on the table for her to discover, and at what ages? What I’ve been looking for are games that teach morals and lessons, particularly ones that do so in a way that cannot be done in other media. A game puts the audience in control, which brings a high level of teaching possibilities to the table.</p>
<p>Aesop was a person who may or may not have existed, but Aesop’s fables are well known. Even if you’ve never heard of them, you most certainly know one of the tales. The story of <em>The Tortoise and the Hare</em> and <em>The Boy Who Cried Wolf</em> are Aesop&#8217;s fables. They’re fun stories, and are great for children because they have good lessons behind them. The story is crucial because it drives the point home. You can tell a child “slow and steady wins the race” and they’ll think you’re a loony. Silly daddy, you’re supposed to go fast to win races! If you go on about the over confident hare and the determined tortoise, then you have planted the seed of knowledge and enlightened that youngster.</p>
<p>You can take a story with a good lesson, and smack that narrative into a game.  There’s nothing wrong with that, but that’s not what I’m looking for. Instead, a game can teach through its mechanics and the choices presented to the player. This is like a lesson on steroids because the player needs to consciously make the correct decisions on their own in order to succeed (let’s pretend gamefaqs.com doesn’t exist for a moment). There is no better teaching tool than that! Think of the saying, “you can lead a horse to water but you can’t make him drink.” A horse must drink to complete a game, and if you design a game well then they will learn to drink on their own.  I’m sure there’s a market for horse drinking games. Part of our art is in making that learning experience better. It’s no easy task, but this is what separates games from other art forms. This power cannot be found elsewhere.</p>
<p>But, with great power there must also come great responsibility!<br />
<a href="http://www.altdevblogaday.com/wp-content/uploads/2013/01/Voltaire.png"><img alt="" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/Voltaire.png" /></a></p>
<p>Teaching the player how to think rather than what to think is the goal. Otherwise, you’re brainwashing, and that’s no good. There are many studies that try to prove games are great for psychological and social development, while others try to convince us that they desensitize us and encourage excessive aggression. It seems like Gamasutra.com has an article about new research every week or so. Studies that try to definitively mark games as good or bad are ridiculous, because it’s impossible to pin either side as the absolute conclusion. The power is in our hands to design a game that is healthy or harmful.</p>
<p>Labeling even a single game as one extreme or the other isn&#8217;t easy, either. There are few games I’ve played that have no health benefits.  Those I’ve seen that are trash are found on Facebook.  I don&#8217;t mean to knock Facebook games, and I have seen a number that are enjoyable and worth playing. The problem is that most of these games try to make everybody overly happy so that they play the game, and to do that they instill a false sense of accomplishment and never inflict penalties on the player. Even if they sit back and do next to nothing (they’ll probably have to hit a button), players will advance in the game. There’s nothing gained from that except wasted time.  My wife calls these gerbil games because players bring their nose to the tube to get a drop of achievement water.  Water is healthy, but a game is meant to have value in the way the water is obtained.<br />
<a href="http://www.altdevblogaday.com/wp-content/uploads/2013/01/gerbil-video-game.jpg"><img alt="" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/gerbil-video-game.jpg" width="400" height="300" /></a></p>
<p>Some folks may mark violent or vulgar games as unhealthy, but I will not denounce these games.  The target audience needs to acknowledges the same way medicine&#8217;s instructions and dosage are.  Such games are not healthy for a young child, but nor is 1000mg of Tylenol<strong>*</strong>.  They can be useful to adults as stress relief, or perhaps work as a sort of reverse physcology.  As I&#8217;ve grown older, I have found myself thinking &#8220;I&#8217;m sure glad I don&#8217;t have to do this for reals&#8221; while playing war centric games.  That would be an interesting research topic: can a violent games be designed to encourage people to be less violent?  Regardless,  I will let my little girl sticks with IRL games of cops and robbers and cute games of boyfriend+girlfriend+puppy for a good long while before letting her play adult games.</p>
<p>It&#8217;s not inherently bad to allow the player to make &#8220;evil&#8221; choices in a game, either.  Most RPGs I’ve played recently had a good/evil meter or presented me with choices that were fairly black and white. Letting the player be a bad guy is ok. In fact, it’s the sign of a healthy game because it lets the player decide which path to take. If these games were to make it more advantageous to be a bad guy then it might be unhealthy, but the games I’ve been playing are pretty well balanced and sit in the grey area until the player starts to make decisions. That’s a good spot for games with moral meters to aim for, the neutral bull’s eye.   If instead they were to lead the player to one side or the other, then they would be telling the player what to think. Having the world react reasonably to their decisions gives them the ability to decide how to proceed on their own. That makes a beautiful game.</p>
<p>But back to my task…I need to find a few games now that I want to store away so my daughter can play later. Here’s a few of the games I’ve picked out for my daughter, along with the lesson I think it teaches. Mind you that it’s going to be a few years before I let her play most of these.</p>
<h1>Demon’s Souls – always keep your guard up</h1>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/01/Demons-Souls.jpg"><img class="alignright" alt="" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/Demons-Souls.jpg" /></a><br />
There were a few points early on in that game where I was reamed and killed with one or two shots from a sneaky demon because I was strolling around observing my surroundings with my shield and sword by my side. I learned quick. Any player who treads new territory without holding R1 is a fool. The lessons I learned in this game stayed with me while I played the sequel, Dark Souls, and I was better for it. This is generally good advice for somebody who is about to embark on their own adventures in the world: stay on your toes and don’t leave yourself vulnerable.</p>
<h1>Pixel Junk Monsters – Time not dancing is time wasted</h1>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/01/PixeljunkMonster-Dancing.png"><img class="alignright" alt="" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/PixeljunkMonster-Dancing.png" /></a><br />
In this game, you build towers to kill dudes who are coming to eat your babies. If you stand in an area occupied by a tower, you dance to give that tower experience so it can be upgraded. If you’re sitting in the middle of nowhere, you’re wasting valuable dancing time that can be strengthening your towers (unless you’re dealing with the hive tower, but you shouldn’t be standing away from a tower for long). And who doesn’t love dancing? It’s fun, good exercise, and you don’t even have to be good at it for those two features to hold. If you are not enjoying what you’re doing, you’re wasting your time.</p>
<h1>Resident Evil – Choose your battles</h1>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/01/ResidentEvil-Hunter.jpg"><img class="alignright" alt="" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/ResidentEvil-Hunter.jpg" /></a><br />
You have two shotgun shells, five 9mm bullets, and no green herbs. You walk up a set of stairs, see a zombie staring at a wall in a far corner of the room. There’s two other zombies doing the same in a hallway you need to travel, and you know that the door on the other end of that hallway is a door that leads outside.  There are probably hunters outside, and they are mean sons of guns. That first zombie can stand there all the doo dah day. He’s not going to bother you. The other two zombies are slow, and you can weave through them no problem. Ignore them, because those two shells will likely be just enough to keep the hunter at bay while you dart through the garden. It’s just not worth taking on every challenge full force, and sometimes you just have to ignore them. Save your energy for the bigger challenges that really matter.</p>
<h1>Mega Man – Practice makes perfect</h1>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/01/MegaMan-Spikes.jpg"><img class="alignright" alt="" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/MegaMan-Spikes.jpg" /></a><br />
I dare say that in every Mega Man level, something will kill you without warning on your first time through. The game is designed that way. There are some surprises that are meant to knock you down, and you just have to learn where they are and be ready for them next time. Each time you die, you try again and aim to get just a little bit further. Eventually, you build the muscle memory to get through the levels and you can almost perform them without thinking about it or maybe even without looking at the screen. Repeat something enough times, and you will become an expert.</p>
<h1>Once Upon a Monster &#8211; ???</h1>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/01/OnceUponAMonster.jpg"><img class="alignright" alt="" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/OnceUponAMonster.jpg" /></a><br />
I don’t know if there’s a main lesson in this game, I haven’t played it yet. But I will get this game because it requires two players, a parent and a child, and puts them together in an ultra co-op mode. In many cooperative games, you can get through with another player without ever really interacting with them. You can just play alongside them (excluding the harder difficulty modes). But Once Upon A Monster naturally has you play together. It’s beautiful really. I can’t believe this game would fail to impress me, because Tim Schafer is dreamy and everything that comes from Double Fine is great.</p>
<h1>Braid &#8211; ???</h1>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2013/01/Braid-TimRunningFromRabbits.jpg"><img class="alignright" alt="" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/Braid-TimRunningFromRabbits.jpg" /></a><br />
I have a tough time pinning a lesson on this one. I’m fascinated by this game because it tells the story through the game mechanics, and that’s just awesome. But, it’s also very abstract and that means its moral can change depending on how you interpret the game. I myself thought Tim was a young man trying to make his mark in the world, and the princess was a metaphor for The Big City. Others thought it was a nuclear bomb. Whatever it is, this game is a shining example of the power game designers wield, and how to use it for great justice. If my daughter is a gamer, she will play this game.</p>
<pre></pre>
<p>This is only the top of my list, there are many more. I hope these help show how both core game mechanics and tiny details can be used to teach a lesson.</p>
<pre></pre>
<p><em>* I am not a doctor. If a doctor tells you that your child needs this dosage of Tylenol, do not cite me as an argument against it.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/18/aesops-games/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A new type of touch screen joystick</title>
		<link>http://www.altdevblogaday.com/2013/01/15/a-new-type-of-touch-screen-joystick/</link>
		<comments>http://www.altdevblogaday.com/2013/01/15/a-new-type-of-touch-screen-joystick/#comments</comments>
		<pubDate>Tue, 15 Jan 2013 22:30:50 +0000</pubDate>
		<dc:creator>Alex Moore</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[UI and UX]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29076</guid>
		<description><![CDATA[<p>This post is going to be a little different to my usual posts, as it&#8217;s going to be more akin to how I write a document for a mechanic. The mechanic in question is a challenge I set myself: try and design a touch based joystick that, in a single stick, provides the functionality that usually requires two. I&#8217;ve decided to call this task &#8220;Single Joystick&#8221;.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/15/a-new-type-of-touch-screen-joystick/" class="more-link">Read more on A new type of touch screen joystick&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>This post is going to be a little different to my usual posts, as it&#8217;s going to be more akin to how I write a document for a mechanic. The mechanic in question is a challenge I set myself: try and design a touch based joystick that, in a single stick, provides the functionality that usually requires two. I&#8217;ve decided to call this task &#8220;Single Joystick&#8221;.</p>
<p>Read on to see how I went about finding out if such a this is possible&#8230;</p>
<h2>High Concept</h2>
<p>For lots of types of games, touch screens are a fantastic input device. They currently don&#8217;t offer any sense of tactile response, though I&#8217;m sure that&#8217;s coming in time. Today, the games which are most successful on our phones and tablets are ones that use touch screens to their advantage. There is demand, however, to put games that have been very successful on PC and console straight onto our phones and tablets; by which I refer to first person and third person action games.</p>
<p>To date, this has often been done by drawing two virtual joysticks on the screen, one in each corner. These react in a similar fashion to how the physical joysticks do on a traditional console controller, with the left stick controlling XY movement and the right stick controlling rotation and looking up and down.</p>
<p>This approach has two main flaws:</p>
<ol>
<li>The amount of screen space required for the joysticks</li>
<li>To hold the device so you can use both thumbs, you effectively remove the ability to use any other fingers at the same time.</li>
</ol>
<p>In addition, such approaches:</p>
<ul>
<li>Assumes that the user is familiar with twin joystick controls from console games, which requires a significant amount of skill and dexterity.</li>
<li>Often does not offer support for left handed players</li>
<li>Does not offer support for gamers with reduced mobility</li>
</ul>
<p>I think these are all fairly well known, but it&#8217;s still an accepted approach because there doesn&#8217;t seem to be a better alternative.</p>
<p>Or is there?</p>
<h2>Initial Concept</h2>
<p>The initial concept is to combine moving and rotating into a single joystick. This is something that is only possible on a touch-based device, as the user can be very precise about exactly where they are touching the screen.</p>
<p>The joystick is made up of 3 core elements:</p>
<ol>
<li>The move gizmo</li>
<li>The rotate gizmo</li>
<li>The nub graphic</li>
</ol>
<p>Arranged as such:</p>
<p style="text-align: center"><img class="aligncenter  wp-image-29079" alt="singlejoystick_base" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/singlejoystick_base.png" width="272" height="178" /></p>
<h3>The Move Gizmo</h3>
<p>The move gizmo works the same as in an ordinary two-stick system:</p>
<ul>
<li>The centre of the graphic is stored as (x,y).</li>
<li>The radius of the gizmo is known (stored as a variable, <b>InnerRadius</b>, to allow for tweaking)</li>
<li>When the user touches the screen, a check is done to ensure they are inside the move graphic.</li>
<li>If they are, then the touch location is stored as (x1, y1):</li>
</ul>
<p style="text-align: center"><img alt="singlejoystick_movement" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/singlejoystick_movement.png" width="226" height="178" /></p>
<ul>
<li>The amount to move the player by is simply calculated by:
<ul>
<li>Position.x = (x1 – x) / InnerRadius</li>
<li>Position.y = (y1 – y) / InnerRadius</li>
</ul>
</li>
<li>This returns a value between 0 – 1, which gets applied directly to the player movement code per frame, where a multiplier is added as a scalar to allow for faster movement if required.</li>
<li>Because of the size of the stick, there is unlikely to be any need to apply an acceleration curve to this movement. There may be a need to implement a dead zone, to be decided in testing.</li>
</ul>
<h3>The Rotate Gizmo</h3>
<p>The rotate gizmo fully encompasses the move gizmo, and has an internal size stored as the variable <b>OuterRadius</b>. The rotate gizmo is only active when the user’s touch position is between InnerRadius and OuterRadius.</p>
<p>To calculate the rotation amount, the gizmo works off angles rather than absolute location of the touch. <b>This is very different to how rotate joysticks usually work.</b></p>
<ul>
<li>At the point where the user’s touch enters the rotate gizmo, the position is stored and a vector is calculated from that position back to the centre of the joystick (x, y):</li>
</ul>
<p style="text-align: center"><img class="aligncenter  wp-image-29081" alt="singlejoystick_rotate" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/singlejoystick_rotate.png" width="219" height="185" /></p>
<ul>
<li>The user is now required to keep their touch within the rotation gizmo, and the position they move to creates an additional vector, <strong>current vector</strong>. The angle, θ, between this new vector and the original determines how much the user rotates per frame:</li>
</ul>
<p style="text-align: center"><img class="aligncenter  wp-image-29082" alt="singlejoystick_rotateAngle" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/singlejoystick_rotateAngle.png" width="313" height="203" /></p>
<ul>
<li>If the user rotates clockwise past the initial vector then they turn clockwise, and likewise turning anti-clockwise past the initial vector turns them that way.</li>
<li>There may need to be a maximum rotation speed, to be determined with testing.</li>
<li>If the user&#8217;s touch moves outside of the OuterRadius then the joystick deactivates and resets.</li>
<li>If they move their touch back inside the move gizmo, the rotation stops and movement resumes from where the updated touch resides.</li>
<li>Releasing the touch or moving outside of OuterRadius stops all movement and rotation, and resets the joystick to its initial phase.</li>
<li>If the user&#8217;s initial touch is within the rotate gizmo then the user can look around on the spot.</li>
</ul>
<h3><b>The key to Single Joystick is this:</b></h3>
<p>If the user starts touching inside the move gizmo and then moves into the rotation gizmo, (x1,y1) remains at the point that they ‘pierced’ the rotation gizmo. This allows for circle strafing on a single touch.</p>
<h3>Nub Graphic</h3>
<p>This is just a simple graphic that moves to reflect the current touch position, assuming the user is inside the OuterRadius.</p>
<h2>Vertical Look</h2>
<p>The one downside of the Single Joystick is that it doesn’t have any support for controlling vertical look. There are several possible solutions to this by using additional touches or lock-ons, but for initial prototyping a simple height check slightly in front of the player camera (2m) is performed. If the check is lower than the player height then make the camera look up, and likewise look down if it is higher:</p>
<p><img class="aligncenter size-large wp-image-29078" alt="FPS_VLook" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/FPS_VLook-1024x217.png" width="1024" height="217" /></p>
<h2>Testing the theory</h2>
<p>Writing a game mechanic requires a leap of imagination and, for me, often involves a great degree of holding the input device, closing my eyes and moving my fingers trying to imagine myself playing the game.</p>
<p>This is great, and helps iron out any major flaws with a specification. But nothing beats actually playing it.</p>
<p>As I&#8217;m currently freelance, access to programmers is limited. However, access to game engines isn&#8217;t: especially with Unity available for free. I already had a licence for iOS deployment, and once registered as an Apple developer I could very quickly build projects and get them running on my iPad. Note: this is not to say the mechanic is only devised for Apple devices, but purely to say that&#8217;s what I had to hand and thus it made sense to use it.</p>
<p>So, here&#8217;s a prototype of this mechanic running. The stuttering is due to my capture method off my iPad, rather than framerate &#8211; as you&#8217;d hope / expect, it runs at a solid 60fps currently.</p>
<span style="text-align:center; display: block;"><a href="http://www.altdevblogaday.com/2013/01/15/a-new-type-of-touch-screen-joystick/"><img src="http://img.youtube.com/vi/Oy99mJD8qq4/2.jpg" alt="" /></a></span>
<p>As you can probably see, the concept works to a decent degree but isn&#8217;t yet completely robust. I&#8217;ve been playing with this for about a week now, tweaking bits here and there. If you&#8217;ve read everything above, you&#8217;ll notice no mention of the icon that lights up when the touch is inside the rotate gizmo: that came about simply because you can&#8217;t see the nub (or, in fact, half of the background) when you&#8217;re actually touching it.</p>
<h2>What next?</h2>
<p>There&#8217;s quite a few more improvements to make, but I thought that this project had hit a point where I should write about it and see if anyone else has any feedback. I&#8217;ve tested it on a few people, with varying degrees of success &#8211; everyone needs to be told how it works, so at the &#8216;intuitive&#8217; point from the brief it&#8217;s not quite there yet.</p>
<p>I&#8217;ll hopefully do a follow up post in a few weeks with improvements I&#8217;ve made. For now though, hopefully I&#8217;ve started to set designers everywhere a challenge: find a way to make touch screen joysticks better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/15/a-new-type-of-touch-screen-joystick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Happens Next? (2013)</title>
		<link>http://www.altdevblogaday.com/2013/01/09/what-happens-next-2013/</link>
		<comments>http://www.altdevblogaday.com/2013/01/09/what-happens-next-2013/#comments</comments>
		<pubDate>Wed, 09 Jan 2013 14:08:59 +0000</pubDate>
		<dc:creator>Alex Moore</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29010</guid>
		<description><![CDATA[<p>In June 2011 I wrote an article called <a title="What happens next?" href="http://www.altdevblogaday.com/2011/06/23/what-happens-next/">What Happens Next?</a>, where I had a quick go at peering into a crystal ball and predicting the future of video games. Recently I did a talk for <a href="http://socialmediacafeliverpool.wordpress.com/">Social Media Cafe</a>, discussing similar thoughts with 18 months worth of additional future taken into account. Parts of what I discussed in the original article still hold true, and I elaborated upon them in my talk. This article is an amalgamation of the original article, the talk, and a few more bits that I realised I could have discussed at the time.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/09/what-happens-next-2013/" class="more-link">Read more on What Happens Next? (2013)&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>In June 2011 I wrote an article called <a title="What happens next?" href="http://www.altdevblogaday.com/2011/06/23/what-happens-next/">What Happens Next?</a>, where I had a quick go at peering into a crystal ball and predicting the future of video games. Recently I did a talk for <a href="http://socialmediacafeliverpool.wordpress.com/">Social Media Cafe</a>, discussing similar thoughts with 18 months worth of additional future taken into account. Parts of what I discussed in the original article still hold true, and I elaborated upon them in my talk. This article is an amalgamation of the original article, the talk, and a few more bits that I realised I could have discussed at the time.</p>
<p>Before reading on, please understand that my definition of the AAA gaming model is thus:</p>
<blockquote><p>A game that you go to your favourite store to buy for £45 / $60, take home and play on a console or PC in the comfort of your own home. You expect that there&#8217;s a single player component that will last you at least 8 hours, if not quite a bit more, and a multiplayer component that will be polished and fun.</p></blockquote>
<p>With that in mind:</p>
<h2>Is AAA is dead?</h2>
<p>Eighteen months or so ago, this wouldn&#8217;t have really even been considered. There were signs that the model was struggling, but sales were still plenty high enough on the big hits of the year and there were plenty of rumours that Sony and Microsoft were working away on the next consoles &#8211; a sure fire way to inject new life into the fire.</p>
<p>Today though, it seems to <a href="http://www.huffingtonpost.co.uk/patrick-garratt/2012s-video-games-industry_b_2423361.html" target="_blank">quite a few people&#8217;s minds</a>. Sony and Microsoft haven&#8217;t unveiled any new hardware yet, and it&#8217;s costing more than ever to produce a current generation AAA game, which is against what has happened in the past. I&#8217;ve previously mentioned that <a title="Making AAA games is hard" href="http://alexmoore.me.uk/articles/making-games-is-hard/">making AAA games is hard</a>, and nowhere is this more evident but in a simple table:</p>
<p style="text-align: center"><img class="wp-image-983 aligncenter" alt="devtimes" src="http://alexmoore.me.uk/blog/wp-content/uploads/2012/12/devtimes.png" width="404" height="197" /></p>
<p>These are averages &#8211; naturally there are games that go against the grain, both up and down. If we take the middle-of-the-road for all of these, it took <strong>19 man years</strong> to make a PlayStation 1 game, back in 1995. Fast forward to 2001 and it took <strong>124 years</strong> to make a PlayStation 2 game. Today, it takes <strong>420 man years</strong>. That&#8217;s 22 times longer than it took in 1995, yet games still cost £45 / $60 at retail. Thanks to mobile gaming, people are starting to become unwilling to pay £45, even though <a href="http://www.thisismoney.co.uk/money/bills/article-1633409/Historic-inflation-calculator-value-money-changed-1900.html" target="_blank">in real terms they&#8217;re cheaper than ever</a>. In fact, people don&#8217;t even want to pay 69p &#8211; a lot of people expect entertainment for free. Currently, no one expects Assassin&#8217;s Creed III on their mobile phone for 69p, but, as the speed of mobile phones increases, so do customer expectations.</p>
<p>The number of copies you&#8217;d need to sell at 69p to make a profit on a game that&#8217;s taken 420 man years to make is astronomical, and highly unlikely to happen. Something has to change.</p>
<h2>Technology will save us</h2>
<p>The two most time consuming elements of making a AAA game are making the game engine and then creating the content to go in. A modern day game engine has a lot of boxes to tick:</p>
<ul>
<li>Deferred Rendering</li>
<li>Texture and Geometry Streaming</li>
<li>
<div>Online Multiplayer Support</div>
</li>
<li>
<div>Parallax Mapping</div>
</li>
<li>
<div>Blended Animation System</div>
</li>
<li>
<div>Rigid Body Physics and IK Solutions</div>
</li>
<li>
<div>Motion Blur</div>
</li>
<li>
<div>Full Body Rig</div>
</li>
<li>
<div>SSAO (Screen Space Ambient Occlusion)</div>
</li>
<li>
<div>And on..</div>
</li>
</ul>
<p>Not all of these boxes have to be ticked to make a game, but to get anywhere near the visual quality expected by the audience and gaming press your engine is going to have to do a lot. Technical accomplishments will only get you so far of course &#8211; your game needs solid art direction and high quality assets, so you&#8217;ll also have to spend a lot of money on high calibre artists, animators and sound designers. When so much money is being spent, it&#8217;s rare for a team to be afforded the ability to experiment too much with game mechanics: instead it&#8217;s safer to tread the well worn path that successful games have already laid.</p>
<p>As a games designer, this feels wrong to me. Thankfully, it feels that the tide is turning.</p>
<p>A lot of this comes down to the sheer power of hardware becoming available. Right now a <a href="http://osxdaily.com/2012/09/16/iphone-5-benchmarks-1gb-ram-cpu/" target="_blank">mobile phone has more processing power than a top of the range desktop from 6 years ago</a>. That is, officially, bonkers. And it&#8217;s only going to get even more so &#8211; in another couple of cycles mobiles phones will easily be as fast as current generation consoles, and they&#8217;ll continue to get faster.</p>
<h3>Speeding up engine development</h3>
<p>This power starts to give game makers a little bit of breathing space, because it begins to reduce the requirement to squeeze every last ounce of processing power out of the hardware to get the same results. That, in turn, gives you the ability to make more use of pre-written <a href="http://en.wikipedia.org/wiki/Library_(computing)" target="_blank">software libraries</a>. In the past, these might have been avoided or rewritten to be tailored specifically to your exact needs and any additional code removed. As well as software libraries, CPUs and GPUs continue to advance and provide specific processing units for performing some of the heavy work on the chips themselves, such as physics, and this frees up valuable coding time down the line.</p>
<p>In addition to on-chip improvements, <a href="http://en.wikipedia.org/wiki/Application_programming_interface" target="_blank">APIs</a>, software libraries and even off-the-shelf game engines continue to advance at a good rate, as do <a href="http://en.wikipedia.org/wiki/Protocol_(computing)" target="_blank">protocols</a> to bring about a level of standardisation between devices. In fact, these are the two areas that I think can bring about the biggest change in how game engines are made. This year looks like it&#8217;s going to be all about new hardware, with <a href="http://www.ouya.tv" target="_blank">Ouya</a>, a <a href="http://www.vg247.com/2013/01/08/valve-backed-living-room-pc-system-debuts-today/" target="_blank">Steambox</a>, an <a href="http://www.bbc.co.uk/news/technology-20931265" target="_blank">nVidia console</a>, <a href="http://www.engadget.com/2013/01/02/gamestick-brings-a-new-android-game-console-to-your-tv/" target="_blank">GameStick</a> and a handful of others, and that&#8217;s before even considering that the Wii U is only just out and Microsoft and Sony might have something new this year too. That&#8217;s a lot of potential fragmentation, and I&#8217;ve not even mentioned mobile phones or tablets&#8230;</p>
<p>How about, instead of buying a specific device to play games on, you just run the platform of your choice on whatever you have to hand. Think of something like DirectX, but imagine it as a whole console layer. Imagine if you just wrote your game for Steam, and let the APIs, libraries and protocols do everything else to make sure that it runs on the device in your hand, from providing the input layer to rendering the graphics. This is a few years ahead, but I think it will happen. For instance, it wouldn&#8217;t matter how many buttons a device has, as long as it adheres to the interface protocol. That layer may be physical buttons, a touch screen, a motion sensor or something else entirely. The device would deal with how the user interacts with it, and push that information to the game as a series of standard inputs.</p>
<p>This might sound slightly ridiculous, but this is already how browsing the internet works. The websites you visit don&#8217;t know if you&#8217;re using a mouse, a touch screen or a TV remote. They don&#8217;t need to: the browser on your device deals with the input layer, and also does all the rendering of the data that gets sent back. Could this be a future for game engines too?</p>
<h3>Asset Creation</h3>
<p>Shorter term, asset creation is going to benefit greatly from more computing power. As with the engine, the requirement to optimise a model to within an inch of its life is reduced if there&#8217;s more processing power and memory available. Equally, as engines continue to become more sophisticated, they can offer perfectly acceptable optimisation of models on the fly. The requirement to create multiple <a href="http://en.wikipedia.org/wiki/Level_of_detail" target="_blank">LODs</a> reduces and, soon, should disappear. This will save a lot of time.</p>
<p>In addition to this, the tools that create the content will continue to improve. It makes full financial sense: if you put resources into better tools, you need fewer people using them. If, for instance, six coders working on tools could reduce your art team by twenty, surely that&#8217;s the best thing to do?</p>
<p>The ability to scan objects in real time and generate models is becoming a reality. <a href="http://www.daz3d.com/faceshop-for-photoshop" target="_blank">Faceshop for Photoshop</a> can take a 2D image and create a 3D head from it. The results aren&#8217;t professional quality yet, but in time tools like this will get better and better.</p>
<p>Finally, the way we interact with computers is constantly evolving. There are a <a href="http://www.hongkiat.com/blog/next-gen-user-interface/" target="_blank">lot of UI developments just round the corner</a>, some of which could help massively with content creation. Imagine sculpting a 3D model using a <a href="https://leapmotion.com" target="_blank">LEAP</a> controller, or sketching out a 2D layout on <a href="http://www.youtube.com/watch?v=81iiGWdsJgg&amp;feature=player_embedded" target="_blank">PaperTab</a> and having a tool turn that into 3D for you.</p>
<p>With all these developments, and many more, combined:</p>
<h3>Gameplay becomes king</h3>
<p>If development teams aren&#8217;t focused on ticking engine feature boxes, and art teams can produce high quality art in a fraction of the time currently required, then the focus will hopefully shift more onto just making great games. This has already been kickstarted by the mobile and independent scene, and it&#8217;s where AAA development is heading. But wait a minute&#8230; didn&#8217;t we say that AAA might be dead?</p>
<p>Well, yes and no. There will always be a market for high budget entertainment, and there will be developers that will cater for that. They may have to seek a different funding model, possibly a combination of a kickstarter campaign, a traditional publisher deal and in-app purchases. With development cycles being shorter and it being sold as purely a digital download, it should be possible to sell a game for less and still make a profit. See the Steam model.</p>
<p>Will technology have an impact on the type of gameplay? Motion controllers and Kinect opened the door to different types of gameplay interaction, and it&#8217;s hard not to assume that new interfaces will bring new gameplay experiences. New controllers are great, but inherently create fragmentation. If you look at mobile games, the ones that are successful aren&#8217;t necessarily breaking new gameplay ground. In fact, if anything, they&#8217;re relying quite heavily on paradigms that made games successful in the 1980s and 1990s. They are very highly polished, and very well defined &#8211; distilled almost down to a few core mechanics. Interestingly, too, is that mobile and independent games often offer a greater challenge than AAA games. Getting 3 stars on every level in Angry Birds is not easy at all, yet people who can&#8217;t finish the first mission in Halo will happily sit there for hours until they get them. I still haven&#8217;t managed to complete a game of <a href="http://www.ftlgame.com" target="_blank">Faster Than Light</a>, but I&#8217;m having a lot of fun trying. I could list 50 such examples, but this article is already far longer than I originally intended.</p>
<p>The point I&#8217;m trying to make here is that there will be a meeting point of polished gameplay experience that looks as good as the top budget games of today: but for a fraction of the development cost. At the point that it doesn&#8217;t cost tens of millions to make Call of Duty, people will have room to take bigger risks with the gameplay.</p>
<h2>Wrapping it up</h2>
<p>Quite a bit has been made of <a href="http://www.ingress.com" target="_blank">Ingress</a>, a location based game on Android. You go to a real location &#8211; predefined as an &#8216;energy source&#8217; &#8211; and hack in. You&#8217;ve already decided side you&#8217;re on. Currently, I&#8217;ve heard (I haven&#8217;t tried it myself), it&#8217;s not very engaging. It&#8217;s currently in beta and an interesting experiment, and a sign of potential directions that some games will take. Coupled with <a href="http://en.wikipedia.org/wiki/Project_Glass" target="_blank">Project Glass</a> (aka, Google Glasses), it&#8217;s not hard to imagine that you could be playing games all the time, as you walk down the street or go shopping.</p>
<p>The technology to synchronise data automatically between devices is already with us, as is the ability to connect your mobile phone up to your TV &#8211; effectively turning it into a Wii U controller (iPhones achieve this via Apple TV, whereas other manufactures are looking to incorporate <a href="http://www.engadget.com/tag/widi/" target="_blank">Intel&#8217;s WiDi protocols)</a>.</p>
<p>All of this means that we&#8217;ll be able to play games wherever we are, whenever we want. Whether or not that&#8217;s a good thing&#8230; I&#8217;m not sure because it doesn&#8217;t take into account why we play games. Partly we play them for a distraction, a way of turning the mundane into something more. But one of the biggest pleasures of any leisure activity is <strong>making time for it</strong>. You may be meant to be doing something else, but you&#8217;ve decided that for the next few hours you&#8217;re going to play a game. This is important, and isn&#8217;t going to go away.</p>
<p>The great thing is, there&#8217;ll be a huge amount of great games for you to play on whatever you&#8217;ve got to hand.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/09/what-happens-next-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Networking Tips and Tricks Part 1</title>
		<link>http://www.altdevblogaday.com/2013/01/09/networking-tips-and-tricks-part-1/</link>
		<comments>http://www.altdevblogaday.com/2013/01/09/networking-tips-and-tricks-part-1/#comments</comments>
		<pubDate>Wed, 09 Jan 2013 01:26:20 +0000</pubDate>
		<dc:creator>Andrew Meade</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[General Interest]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[GDC]]></category>
		<category><![CDATA[Klout]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[Online Presence]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Social Media]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=29007</guid>
		<description><![CDATA[<p>Wow, it’s been a long time since I&#8217;ve posted to AltDevBlogADay! Life has been massively crazy for the past six months or so, and I’m nearing the end of my time in school. In almost 30 days, I will be a college graduate! In the midst of our final project sprint, I was asked by a friend of mine if I ever thought about doing a blog post about networking.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/09/networking-tips-and-tricks-part-1/" class="more-link">Read more on Networking Tips and Tricks Part 1&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Wow, it’s been a long time since I&#8217;ve posted to AltDevBlogADay! Life has been massively crazy for the past six months or so, and I’m nearing the end of my time in school. In almost 30 days, I will be a college graduate! In the midst of our final project sprint, I was asked by a friend of mine if I ever thought about doing a blog post about networking.</p>
<p>Now, some of you may be wondering who I am to tell you about networking, to whit I like to reference Hitchhikers Guide to the Galaxy by saying “I’m just this guy, you know?”.</p>
<p>In my three years as a student, designer, contractor, and employee, I have picked up a few tips and tricks that may or may not appear to be common sense to you. Yet I consistently get people coming to me saying how outgoing I am, or how it’s insane how much I network, and I’m here to tell you a dirty secret. Networking, to me, is one of the hardest things I have ever done.</p>
<p>I’m actually a pretty huge introvert when left to my own devices, so the physical and mental act of getting out there and meeting people is just daunting. I share this with you because maybe you’re the same way, and feel like I’m being too casual with my advice, but the plain and simple fact is, Network and you will make friends and reap dividends. I have no advice for the introvert short of “get over it and do it”, because that’s how I pull it off. But enough about me, let’s go over some networking tips. This first part will be about your online presence, and some best practices for both online and in person, and then the next part will be about in person and online follow-ups!</p>
<p><b> </b></p>
<p><b>Rule #1: Think Before You Post </b></p>
<p>So we all know that our online presence is a huge deal nowadays. Make one off-color comment that has the potential to be misconstrued, and you’re hosed. An actual example I saw a few months ago comes to mind.</p>
<p><i>Designer A shares a picture he thinks is funny on social media. Designer B thinks it’s tacky and wrong. Designer B loses respect for Designer A. Designer B will remember that if he is ever in a position to hire Designer A. </i></p>
<p>Over a simple laugh, Designer A is potentially out a contact, a positive relationship with an acquaintance, and a gig. Awful, yeah? Well it happens all the time.</p>
<p>It may be common knowledge, but I must say it. Think before you post.</p>
<p>&nbsp;</p>
<p><b>Rule #2: Get Your Own Dot Com (And Maintain It!)</b></p>
<p>This is probably the hardest piece of advice I can give, because maintaining your site can be a pain in the butt. I could go on about your site for an entire post so for brevity I’ll try and boil it down into a few bullet points.</p>
<ul>
<li>Make the URL easy to type and relevant. Your name is always a good bet, provided it isn’t far out in how it’s spelled.</li>
<li>Don’t put up your Works in progress. A recruiter may only look at your resume for 30 seconds. Do you want them to see polished content, or half finished content? Worse, do you want them to see half finished content that they don’t read as WIP, and assume that it’s your polished content? **shudder**</li>
<li>Put your contact info on every page. EVERY. PAGE. That’s name, number, email address. I know that some people like to break up their address as “my name at domain dot com” to thwart spammers, but come on. Again, people looking at your site have a lot of stuff to look at. Let them click on your email address, and have it come up in outlook. The less energy they exert to contact you, the better your chances.</li>
<li>Have a tab for your resume. In that tab put your resume down online in plain text, and then provide download links for your resume in both Word and PDF. Give them a choice in how they can view it.</li>
<li>Update it. All the time. Think your site is good enough? It isn&#8217;t. Tweak it. Tweak it again. Never stop being great.</li>
</ul>
<p>Finally, there is an<a href="http://jacobminkoff.com/educational-work/"> amazing keynote from GDC</a> by Jacob Minkoff from Naughty Dog. It is hands down the best 50 minutes you will ever spend on your portfolio. Watch it, learn from it, and follow it.</p>
<p>&nbsp;</p>
<p><b>Rule #3: Social Media is a Tool Chest.</b></p>
<p>A lot of people use social media in a blanket way. Maybe Programmer A uses every account they have to share lolcats. Maybe Programmer B uses every account to be political. In my opinion, that’s paying a disservice to the strengths and weaknesses of each type of social media. Below is a small list of my social accounts, and how I handle them.</p>
<p>&nbsp;</p>
<p><i>Twitter</i></p>
<p>Twitter is how I make new friends. I try to be interesting, share relevant and fun “geek” links, and get into thoughtful and informative discussions. I can approach anyone I want on Twitter, and be seen. When I post to Twitter, I am posting to an audience of devs I don’t know, recruiters, colleagues, and friends. I am still myself. I still curse a bit. I am still opinionated, but I mold it for a certain audience.  Everyone I meet at a convention also gets followed on Twitter, provided it’s on their business card.</p>
<p>&nbsp;</p>
<p><i>Facebook</i></p>
<p>Facebook is my next tier of friends. In Facebook you get a glimpse into more of my private life, my photos, my politics, and my overall thoughts. In here lurk family, longtime friends since childhood, and colleagues. If I add you on Facebook it means that we have had numerous conversations, and we both seem to agree that we are rather friendly. Sometimes I will make an exception and add someone on Facebook cold, if they don’t have Twitter and I think they are an especially cool cat.</p>
<p>&nbsp;</p>
<p><i>LinkedIn</i></p>
<p>Here I keep every single thing I&#8217;ve ever done professionally. I keep it current, and tweak it bi-weekly. I connect with anyone that has similar interest to me, and I likewise get the same connection requests from others. I am constantly expanding my network and meeting folks. I also hook my Twitter feed up to LinkedIn.</p>
<p>LinkedIn has a highly underused tool for making connections. I use it all the time. If I see someone I want to be connected with that’s out of my network, I’ll find a friend that is connected, and ask for a recommendation. Here’s the thing, LinkedIn is for one thing and one thing only. Networking. Don’t feel like you’re being ruthless by pointedly networking. The only caveat I can really add is make sure you don’t try and jump too far out of your area when asking for connections. For instance, I wouldn&#8217;t ask my buddies at Ubisoft for a connection with a CEO or something, because for one it’s not relevant, and for another it’s level-jumping, and I would be putting my friends in the awkward position of saying no, or feeling uncomfortable and doing it anyway. You never ever want to make anyone feel uncomfortable. Ever. With that in mind, I&#8217;ve gotten tons of great contacts just by asking for an introduction. Likewise, I am constantly recommending contacts (but more on that in a bit).</p>
<p>&nbsp;</p>
<p><i>Klout</i></p>
<p>Klout is a great site that hooks up to your various social media and tells you, in a numerical way, how influential you are within your circle on a number of topics. It’s a great site to check out if you’re interested in seeing what sort of footprint you’re leaving on the internet. If your biggest sphere of influence is Vintage French Nude Lithographs, then maybe you need to reassess. Or not. That’s actually kind of awesome.</p>
<p>So that’s social media. You don’t have to follow my template, but remember that each site is a tool that can and must be used differently to be effective. Finally let’s look at a rule that bridges the gap of online and real life networking.</p>
<p>&nbsp;</p>
<p><b>Rule #4: Don’t Be Selfish. </b></p>
<p>I mentioned earlier in the LinkedIn section about recommending contacts, and it’s so important that I thought I’d give it its own section. This is good for both online and in real life, so take heed.</p>
<p>If you are to become a crazy whirling dervish of networking, you&#8217;ve gotta spread the love. You have to share. If you don’t pay it forward, then it stops with you and doesn&#8217;t go any further. That’s no good for anyone, and is just plain selfish. When you see two people with common interests, introduce them! There is a classic method of introduction which is a bit formal, but I absolutely love. It goes like this:</p>
<p>&nbsp;</p>
<p><i>*Talking with Artist A, when Artist B walks up*</i></p>
<p><i>Me: Oh, hey Artist B! Have you met Artist A? </i></p>
<p><i>Artist B: No I haven’t. </i></p>
<p><i>Me: Really? Well let me introduce you. This is Artist A. Artist A is an Environmental Artist at Treyarch. Artist A, this is Artist B. Artist B is a Concept Artist at Epic. Now, Artist A and I were just talking about (Blank), what do you think, Artist B? </i></p>
<p>&nbsp;</p>
<p>Boom! Introduction! What you have done is repeated names at least twice, given relevant information, aligned interests, and included everyone in the conversation. Now gently steer the convo until you feel you are no longer needed, then excuse yourself. You have just connected two professionals, and potentially started a long and healthy acquaintanceship.</p>
<p>The thing is, you should want to get your friends gigs. Your friends should want to get you gigs. If you hear about something that isn’t up your alley, pass it on to a buddy. Furthermore, don’t be a mercenary cock. There’s an awesome studio that a few of my friends have been INTENSELY courting for the longest time. I would love to work there, but why would I try to? First off, I don’t have the relationship these guys have built. It would be a waste of my energy with so many places out there. Second, it’s just a dick move. Let them get the gig unobstructed. Getting a gig is hard enough without your friends pulling a fast one. Besides, once your friend gets in, he can try and help you out. Win/Win. Now, if that same studio comes to YOU and says they want to interview you, for the love of god don’t turn it down. All bets are off at that point.</p>
<p>Come back later for my next part, where I talk about networking in person, and how it folds back to the interwebs!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/09/networking-tips-and-tricks-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C/C++ Low Level Curriculum Part 10: User Defined Types</title>
		<link>http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/</link>
		<comments>http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/#comments</comments>
		<pubDate>Sat, 05 Jan 2013 15:25:05 +0000</pubDate>
		<dc:creator>Alex Darby</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[education]]></category>
		<category><![CDATA[low level]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28818</guid>
		<description><![CDATA[<p>Hello again peoples of the interweb. It has been <em>quite</em> a while since the last one (probably even longer than the gap between part 8 and part 9) so I thought I ought to pull my finger out and get the next post in the C/C++ Low Level Curriculum done.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/" class="more-link">Read more on C/C++ Low Level Curriculum Part 10: User Defined Types&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Hello again peoples of the interweb. It has been <em>quite</em> a while since the last one (probably even longer than the gap between part 8 and part 9) so I thought I ought to pull my finger out and get the next post in the C/C++ Low Level Curriculum done.</p>
<p>In the previous posts we&#8217;ve covered the structural aspects of the language: flow control, functions, and so forth; and so now we move on to looking in detail at user defined types in C/C++ (i.e. struct, class, and associated keywords) which I naively expected to comprise the bulk of this potentially never ending series when I started it. D&#8217;oh!</p>
<p><span id="more-28818"></span>Before we start, dear reader, I&#8217;m going to assume that you&#8217;re the kind of person / recently self aware google web trawling AI entity who likes to understand your jargon terms and so I will be including appropriate links (probably mostly wikipedia or other ADBAD articles) where appropriate.</p>
<p>You may also want to read the previous posts in this series (though I don&#8217;t think this one will particularly rely on older posts) so, in case you missed them, here are the back-links for preceding articles in the series (warning: reading these might take a while&#8230;) :</p>
<ol>
<li><a href="http://www.altdevblogaday.com/2011/11/09/a-low-level-curriculum-for-c-and-c/" rel="nofollow">http://altdevblogaday.com/2011/11/09/a-low-level-curriculum-for-c-and-c/</a></li>
<li><a href="http://www.altdevblogaday.com/2011/11/24/c-c-low-level-curriculum-part-2-data-types/" rel="nofollow">http://altdevblogaday.com/2011/11/24/c-c-low-level-curriculum-part-2-data-types/</a></li>
<li><a href="http://www.altdevblogaday.com/2011/12/14/c-c-low-level-curriculum-part-3-the-stack/">http://altdevblogaday.com/2011/12/14/c-c-low-level-curriculum-part-3-the-stack/</a></li>
<li><a href="http://www.altdevblogaday.com/2011/12/24/c-c-low-level-curriculum-part-4-more-stack/">http://altdevblogaday.com/2011/12/24/c-c-low-level-curriculum-part-4-more-stack/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/02/07/c-c-low-level-curriculum-part-5-even-more-stack/">http://altdevblogaday.com/2012/02/07/c-c-low-level-curriculum-part-5-even-more-stack/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/03/07/c-c-low-level-curriculum-part-6-conditionals/">http://altdevblogaday.com/2012/03/07/c-c-low-level-curriculum-part-6-conditionals/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/04/10/cc-low-level-curriculum-part-7-more-conditionals/">http://www.altdevblogaday.com/2012/04/10/cc-low-level-curriculum-part-7-more-conditionals/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/05/07/cc-low-level-curriculum-part-8-looking-at-optimised-assembly/">http://www.altdevblogaday.com/2012/05/07/cc-low-level-curriculum-part-8-looking-at-optimised-assembly/</a></li>
<li><a href="http://www.altdevblogaday.com/2012/09/04/cc-low-level-curriculum-part-9-loops/">http://www.altdevblogaday.com/2012/09/04/cc-low-level-curriculum-part-9-loops/</a></li>
</ol>
<p>&nbsp;</p>
<h2>Data Types and Enums</h2>
<p>We covered <a href="http://www.altdevblogaday.com/2011/11/24/c-c-low-level-curriculum-part-2-data-types/">fundamental and intrinsic types in the second post</a> in the series, which also touched on the <em><strong>enum</strong> </em>keyword. I deliberately didn&#8217;t cover the use of the keywords <em><strong>struct</strong></em> or <em><strong>class </strong></em>in this post, but we did cover some facts about the behaviour of values defined using the <em><strong>enum</strong> </em>keyword (i.e. that it was up to the compiler to decide what intrinsic type to use to represent each <em><strong>enum</strong></em>erated type you declare, based on the range required by its values).</p>
<p>Helpfully, the <a href="http://en.wikipedia.org/wiki/C%2B%2B11#Strongly_typed_enumerations">C++11 standard made some sweeping changes to the behaviour of enums</a>; amongst which was the ability to specify the the fundamental type used to represent the values of each <em><strong>enum</strong></em>. Tasty.</p>
<p>Mentioning this welcome change is the extent of our discussion of <em><strong>enum</strong></em>, so let&#8217;s get on with starting to look at <strong style="font-style: italic;">struct</strong>, <em><strong>class, </strong></em>and<em><strong>union</strong></em>.</p>
<p>&nbsp;</p>
<h2>Thankyou Visual Studio Devteam</h2>
<p>If you have been <em>really</em> paying attention to the older posts, you might remember that I mentioned some undocumented (and unsupported!) command line options for Microsoft&#8217;s Visual Studio C++ compiler which can be used to print out the memory layout of data types defined using the <em><strong>struct</strong>, </em><em><strong>class, </strong></em>or<em><strong>union</strong></em> keywords.</p>
<p>These secret compiler options are <strong>/d1reportAllClassLayout</strong> which reports the layout of all classes in the current project, and its more user friendly sibling <strong>/d1reportSingleClassLayout</strong><em><strong>xxx</strong> </em>(where <em><strong>xxx</strong> </em> is a string used to do a substring match against classes that you wish to have reported).</p>
<p>I will be leaning pretty heavily on this compiler for the next few posts, so we may as well cover how to use it. It definitely works in VS2010 and VS2012; it even works with the Express versions. Woo!</p>
<p>Here&#8217;s where you type in the command line option in the property pages (n.b. this is the &#8216;single&#8217; version and matches any class or struct with the string &#8216;Test&#8217; in its name):</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/CCPPLLC_010_MagicCompilerOptions.png"><img class="alignnone  wp-image-28825" alt="" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/CCPPLLC_010_MagicCompilerOptions.png" width="664" height="469" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>Output from /d1reportSingleClassLayout</h2>
<p>So far so froody.</p>
<p>Now, it&#8217;s about time we looked at a code snippet defining a simple <a href="http://en.wikipedia.org/wiki/Plain_old_data_structure">POD</a> <em><strong>struct</strong> </em>(POD types being the simplest cases of aggregate data types) and the output produced by <strong>/d1reportSingleClassLayout</strong> when we build it&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;stdafx.h&quot;</span>
&nbsp;
<span style="color: #993333;">struct</span> STest
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> iA<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> iB<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When we compile this with the fancy secret compiler switch, as expected we find an extra bit of information in amongst the usual Visual Studio compiler&#8217;s output:</p>
<pre>1&gt; class STest size(8):
1&gt;   +---
1&gt; 0 | iA
1&gt; 4 | iB
1&gt;   +---</pre>
<p>Hopefully this should appear pretty much self explanatory to you, but in case it doesn&#8217;t &#8211; rest assured we&#8217;re about to look at it in a little more detail.</p>
<p>The first line contains the name of the class and its size in bytes &#8211; <em><strong>STest</strong></em> is a <em><strong>struct</strong></em>, but it is reported as a <em><strong>class</strong></em> &#8211; don&#8217;t worry about this for now.</p>
<p>The <em><strong>struct</strong></em>&#8216;s name contains the string &#8216;Test&#8217; which is the substring we specified to match against in the compiler option in order to get class layout information.</p>
<p>The rest of the information details the member-by-member memory layout of the struct organised by the name of the data members &#8211; the number at the start of the line is the memory offset in bytes of that member relative to the start of the struct.</p>
<p>The first thing to note is that the member variables are laid out in memory in the order specified in the class declaration.</p>
<p>A guarantee is given in both the C and C++ language specifications that memory address of each member will be higher than that of the one declared before it (see this post on <a href="http://stackoverflow.com/questions/281045/do-class-struct-members-always-get-created-in-memory-in-the-order-they-were-decl">Stack Overflow</a> for more detail of the wording).</p>
<p>In the case of <em><strong>STest</strong></em> the first member <strong>iA</strong> is at an offset of 0 bytes from the start of the struct; and the second member <em><strong>iB</strong> </em>is at an offset of 4 bytes from the start of the struct.</p>
<p>Importantly (by doing a little maths with the offsets and the size of the struct) this also tells us that the size taken up by <em><strong>iA</strong></em> is 4 bytes, and the size taken up by <em><strong>iB</strong></em> is 4 bytes &#8211; since <em><strong>sizeof(int) == 4</strong></em> this matches up with what we would expect.</p>
<h2>Accessing the members of a struct in assembly</h2>
<p>We all knew this was coming, right?</p>
<p>Woo! I know you all live for hexadecimal numbers and assembler mnemonics.</p>
<p>As always, the main thing I want you to take away from this is not so much the understanding of the specific assembly code itself (though clearly it has its benefits&#8230;), but more of a generalised appreciation for the combinations of assembly instructions that &#8216;smell like&#8217; the compiler accessing the members of a struct or class.</p>
<p>Getting used to the assembly level &#8216;smells&#8217; of the various high level constructs in compiler generated assembly code will enable you to find your bearings much more quickly in code you see in the disassembly window, and &#8211; most importantly (assuming that you are lucky enough to have a valid callstack &#8211; and, like a sensible person, you have symbols for your release build) &#8211; you should quickly develop the ability to work out which bit of the high level code corresponds to the assembly you&#8217;re currently looking at. Win.</p>
<p>Here&#8217;s a code snippet that accesses the data members of the struct we just defined:</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="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;stdafx.h&quot;</span>
&nbsp;
<span style="color: #993333;">struct</span> STest
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> iA<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> iB<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    STest sOnStack<span style="color: #339933;">;</span>
    sOnStack.<span style="color: #202020;">iA</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    sOnStack.<span style="color: #202020;">iB</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
&nbsp;
    STest<span style="color: #339933;">*</span> psOnHeap <span style="color: #339933;">=</span> new STest<span style="color: #339933;">;</span>
    psOnHeap<span style="color: #339933;">-&gt;</span>iA <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span>
    psOnHeap<span style="color: #339933;">-&gt;</span>iB <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span>
    delete psOnHeap<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Before we look at the disassembly we should explain a little about the snippet.</p>
<p>Two instances of <em><strong>STest</strong></em> are created:</p>
<ul>
<li><em><strong>sOnStack</strong> </em>on the Stack &#8211; i.e. automatically allocated by the compiler as a local variable</li>
<li><em><strong>psOnHeap</strong></em> on the Heap &#8211; i.e. dynamically allocated.</li>
</ul>
<p>The reasons for doing this will become clear once we&#8217;ve inspected the assembly.</p>
<p style="padding-left: 30px;"><em><strong>Aside</strong>: technically the area of dynamic memory managed by <strong>new</strong> and <strong>delete</strong> in C++ is called the Free Store, but almost everyone calls it the Heap. I&#8217;m pretty sure this is because the dynamic memory in C managed by <a href="http://en.wikipedia.org/wiki/C_dynamic_memory_allocation">malloc and free</a> has colloquially and historically been known as &#8220;the Heap&#8221;, and a lot of C++ implementations define new and delete using malloc and free (and most if not all used to).</em></p>
<p>So here&#8217;s the disassembly generated by the VS2010 debug compiler:</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
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;">    <span style="color: #ff0000;">14</span><span style="color: #339933;">:</span> STest sOnStack<span style="color: #666666; font-style: italic;">;</span>
    <span style="color: #ff0000;">15</span><span style="color: #339933;">:</span> sOnStack<span style="color: #339933;">.</span>iA = <span style="color: #ff0000;">1</span><span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">00A01269</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">8</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">1</span> 
    <span style="color: #ff0000;">16</span><span style="color: #339933;">:</span> sOnStack<span style="color: #339933;">.</span>iB = <span style="color: #ff0000;">2</span><span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">00A01270</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">2</span> 
    <span style="color: #ff0000;">17</span><span style="color: #339933;">:</span> 
    <span style="color: #ff0000;">18</span><span style="color: #339933;">:</span> STest<span style="color: #339933;">*</span> psOnHeap = new STest<span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">00A01277</span> <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #ff0000;">8</span> 
<span style="color: #adadad; font-style: italic;">00A01279</span> <span style="color: #00007f; font-weight: bold;">call</span> 00A010F5 
<span style="color: #adadad; font-style: italic;">00A0127E</span> <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #46aa03; font-weight: bold;">esp</span><span style="color: #339933;">,</span><span style="color: #ff0000;">4</span> 
<span style="color: #adadad; font-style: italic;">00A01281</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">54h</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #46aa03; font-weight: bold;">eax</span> 
<span style="color: #adadad; font-style: italic;">00A01284</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">54h</span><span style="color: #009900; font-weight: bold;">&#93;</span> 
<span style="color: #adadad; font-style: italic;">00A01287</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">0Ch</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #46aa03; font-weight: bold;">eax</span> 
    <span style="color: #ff0000;">19</span><span style="color: #339933;">:</span> psOnHeap<span style="color: #339933;">-</span>&gt;iA = <span style="color: #ff0000;">3</span><span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">00A0128A</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">0Ch</span><span style="color: #009900; font-weight: bold;">&#93;</span> 
<span style="color: #adadad; font-style: italic;">00A0128D</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">3</span> 
    <span style="color: #ff0000;">20</span><span style="color: #339933;">:</span> psOnHeap<span style="color: #339933;">-</span>&gt;iB = <span style="color: #ff0000;">4</span><span style="color: #666666; font-style: italic;">; </span>
<span style="color: #adadad; font-style: italic;">00A01293</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">0Ch</span><span style="color: #009900; font-weight: bold;">&#93;</span> 
<span style="color: #adadad; font-style: italic;">00A01296</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">+</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">4</span></pre></td></tr></table></div>

<p>Looking at lines 3 and 6 (and remembering what we learned in <a href="http://www.altdevblogaday.com/2011/11/09/a-low-level-curriculum-for-c-and-c/">post 2</a> about how variables in memory are accessed in assembly); we can see that both <em><strong>sOnStack.iA</strong></em> and <em><strong>sOnStack.iB</strong></em> are being directly accessed by their memory addresses as offsets from <em><strong>ebp </strong></em>(<em><strong>[ebp-8]</strong></em> and <em><strong>[ebp-4]</strong></em> respectively).</p>
<p>Looking at<em> lines 15-16</em> and <em>lines 18-19</em>, we can see that <em><strong>psOnHeap.iA</strong></em> and<em><strong> psOnHeap.iB</strong></em> are being accessed differently.</p>
<p>Since this is different to what we have seen before, let&#8217;s break it down a little:</p>
<ul>
<li>For each of these assignments, first the pointer <em><strong>psOnHeap</strong> </em>(i.e. memory address of the instance of <em><strong>STest</strong></em> created at line 7) is loaded into <em><strong>eax</strong> </em>(<em>line 15 and line 18</em>), and&#8230;</li>
<li>&#8230; then the member is accessed via the memory address stored in <em><strong>eax</strong></em><strong> </strong>(<em>line 16</em> and <em>line 19</em> &#8211; via <em><strong>[eax]</strong></em> and <em><strong>[eax+4]</strong></em> respectively).</li>
</ul>
<p>In particular, note that when <em><strong>STest::iB</strong></em> is accessed (at address <em><strong>[eax+4]</strong> </em>- <em>line 19</em>) an 4 byte offset is added, which is exactly the offset that the output from <strong>/d1reportSingleClassLayout</strong><strong> </strong>gave us.</p>
<p>Hopefully it should now be pretty obvious why the instances of <em><strong>STest</strong> </em>are accessed differently like this &#8211; and by extension why I showed code accessing an instance on the Stack and on the Heap (via a pointer):</p>
<ul>
<li>When an instance of a user defined type is on the Stack, the compiler is in charge of where the instance is stored (relative to the stack frame); and so it can access its members by their direct offsets within the stack frame.</li>
<li>When an instance is stored in a memory location that is not known at compile time (e.g. accessed via a pointer) the compiler can&#8217;t do this and has to access it via offsets from the instance&#8217;s base address (i.e. the memory address the instance starts at).</li>
</ul>
<p><em><strong>NOTE</strong></em>: this is debug disassembly code, please do not attempt to infer anything about the relative efficiency of Stack vs. Heap memory from this! As far as I am aware, on every machine I&#8217;ve ever used Stack and Heap are both stored in the same memory and accessed via the same physical systems so in terms of theoretical minimum access speeds Stack == Heap.</p>
<p>&nbsp;</p>
<h2>What about class?</h2>
<p>The short answer to this question is that there<em><strong> is</strong></em> no difference whatsoever between <em><strong>class</strong></em>es and <em><strong>struct</strong></em>s at the implementational level of C++.</p>
<p>The long answer is that, in the C++ language, <em><strong>struct</strong> </em>is actually a special case of <em><strong>class</strong></em> with one specific difference &#8211; for <em><strong>class</strong></em>es any unsupplied access specifier (i.e. <em><strong>public</strong></em>, <em><strong>protected</strong></em>, or <em><strong>private </strong></em>anywhere in the type declaration) will default to <em><strong>private</strong></em>, but for <em><strong>struct</strong></em>s it will default to <em><strong>public</strong></em>.</p>
<p>That&#8217;s it.  The only difference.  Honest.</p>
<p>Access specifiers are ultimately just language level syntactic sugar to allow us to control the way our classes are used; under the hood struct and class are implemented the same way &#8211; even with regards to stuff like inheritance and virtual functions.</p>
<p>If you do a search and replace of <em><strong>struct</strong></em> for <em><strong>class</strong></em> in the snippet and add a <em><strong>public:</strong></em> to the top of each class declaration (so it compiles) you will get the exact same output from the class layout information and the same disassembly.</p>
<p>&nbsp;</p>
<h2>Union</h2>
<p>As well as <em><strong>class</strong> </em>and <em><strong>struct,</strong></em> there is another keyword that can define a type &#8211; the keyword <em><strong>union</strong></em>.</p>
<p>It&#8217;s not a frequently seen or used language feature, and so it&#8217;s all the more worthwhile discussing here because it can be very useful and its low frequency of use means that a lot of people don&#8217;t really know what it&#8217;s for, let alone how it works.</p>
<p>Let&#8217;s look at this with another example code snippet. This has had two new types added to it:</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
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;stdafx.h&quot;</span>
&nbsp;
<span style="color: #993333;">struct</span> STest
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> iA<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> iB<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">struct</span> STestTwo
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> iC<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> iD<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> iE<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">union</span> UTestUnion
<span style="color: #009900;">&#123;</span>
    STest sTest<span style="color: #339933;">;</span>
    STestTwo sTestTwo<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    UTestUnion<span style="color: #339933;">*</span> psOnHeap <span style="color: #339933;">=</span> new UTestUnion<span style="color: #339933;">;</span>
&nbsp;
    psOnHeap<span style="color: #339933;">-&gt;</span>sTest.<span style="color: #202020;">iA</span>    <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    psOnHeap<span style="color: #339933;">-&gt;</span>sTestTwo.<span style="color: #202020;">iC</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
&nbsp;
    psOnHeap<span style="color: #339933;">-&gt;</span>sTest.<span style="color: #202020;">iB</span>    <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span> 
    psOnHeap<span style="color: #339933;">-&gt;</span>sTestTwo.<span style="color: #202020;">iD</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span>
&nbsp;
    psOnHeap<span style="color: #339933;">-&gt;</span>sTestTwo.<span style="color: #202020;">iE</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span>
&nbsp;
    delete psOnHeap<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Compiling this with <strong>/d1reportSingleClassLayout</strong> we get the following output for the layouts:</p>
<pre>1&gt; class STest	size(8):
1&gt;  	+---
1&gt;   0	| iA
1&gt;   4	| iB
1&gt;  	+---
1&gt;  
1&gt; class STestTwo	size(12):
1&gt;  	+---
1&gt;   0	| iC
1&gt;   4	| iD
1&gt;   8	| iE
1&gt;  	+---
1&gt;
1&gt; class UTestUnion	size(12):
1&gt;     +---
1&gt;   0 | STest sTest
1&gt;   0 | STestTwo sTestTwo
1&gt;     +---</pre>
<p>The first thing to note is that <em><strong>UTestUnion</strong></em> is the same size as <em><strong>STestTwo</strong></em>. This is exactly as one would expect.</p>
<p>The second thing to note is that both <em><strong>UTestUnion::sTest</strong></em> and <em><strong>UTestUnion::sTestTwo</strong></em> have an offset of 0 bytes within <em><strong>UTestUnion</strong></em>. Again, exactly as one would expect.</p>
<p>So, why is this the case?</p>
<p>The keyword <em><strong>union</strong></em> allows you specify multiple layouts for a chunk of memory. When we declare the union of <em><strong>STest</strong></em> and <em><strong>STestTwo </strong></em>within <em><strong>UTestUnion</strong></em>, we declare our intent to be able to treat the memory of type <em><strong>UTestUnion</strong></em> as either an instance of <em><strong>STest</strong></em> or an instance of <em><strong>STestTwo</strong></em> at our discretion.</p>
<p>This means that, within the type <em><strong>UTestUnion</strong></em>, an instance of <em><strong>STest</strong></em> and an instance of <em><strong>STestTwo</strong></em> exist overlaid on each other. Since the union can be treated as either type, this means that it must necessarily have the same size as the larger of the two types.</p>
<p>Let&#8217;s back this up by looking at the disassembly:</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
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;">    <span style="color: #ff0000;">29</span><span style="color: #339933;">:</span> psOnHeap<span style="color: #339933;">-</span>&gt;sTest<span style="color: #339933;">.</span>iA = <span style="color: #ff0000;">1</span><span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">0122127C</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span> 
<span style="color: #adadad; font-style: italic;">0122127F</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">1</span> 
    <span style="color: #ff0000;">30</span><span style="color: #339933;">:</span> psOnHeap<span style="color: #339933;">-</span>&gt;sTestTwo<span style="color: #339933;">.</span>iC = <span style="color: #ff0000;">2</span><span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">01221285</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span> 
<span style="color: #adadad; font-style: italic;">01221288</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">2</span> 
    <span style="color: #ff0000;">31</span><span style="color: #339933;">:</span> 
    <span style="color: #ff0000;">32</span><span style="color: #339933;">:</span> psOnHeap<span style="color: #339933;">-</span>&gt;sTest<span style="color: #339933;">.</span>iB = <span style="color: #ff0000;">3</span><span style="color: #666666; font-style: italic;">; </span>
<span style="color: #adadad; font-style: italic;">0122128E</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span> 
<span style="color: #adadad; font-style: italic;">01221291</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">+</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">3</span> 
    <span style="color: #ff0000;">33</span><span style="color: #339933;">:</span> psOnHeap<span style="color: #339933;">-</span>&gt;sTestTwo<span style="color: #339933;">.</span>iD = <span style="color: #ff0000;">4</span><span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">01221298</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span> 
<span style="color: #adadad; font-style: italic;">0122129B</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">+</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">4</span> 
    <span style="color: #ff0000;">34</span><span style="color: #339933;">:</span> 
    <span style="color: #ff0000;">35</span><span style="color: #339933;">:</span> psOnHeap<span style="color: #339933;">-</span>&gt;sTestTwo<span style="color: #339933;">.</span>iE = <span style="color: #ff0000;">5</span><span style="color: #666666; font-style: italic;">;</span>
<span style="color: #adadad; font-style: italic;">012212A2</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">ebp</span><span style="color: #339933;">-</span><span style="color: #ff0000;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span> 
<span style="color: #adadad; font-style: italic;">012212A5</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #0000ff; font-weight: bold;">dword</span> ptr <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #46aa03; font-weight: bold;">eax</span><span style="color: #339933;">+</span><span style="color: #ff0000;">8</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">5</span></pre></td></tr></table></div>

<p>There it is, clear as day :)</p>
<p>In case you&#8217;re not seeing it, here&#8217;s a quick breakdown:</p>
<ul>
<li>we can see that <em><strong>psOnHeap</strong></em> is stored at <em><strong>[ebp-4].</strong></em></li>
<li>(<em>line 2</em>)<strong><em> UTestUnion::sTest::iA</em></strong> and (<em>line 5</em>) <strong><em>UTestUnion::sTestTwo::iC</em></strong> are both being accessed directly via the value loaded into <strong>eax</strong> from <em><strong>[ebp-4]</strong> - </em>i.e. at an offset of 0 bytes; the same as their offset within their respective types as shown in the class layout information.<strong><br />
</strong></li>
<li>(<em>line 9</em>)<em> <strong>UTestUnion::sTest::iB</strong></em> and (<em>line 12</em>) <em><strong>UTestUnion::sTestTwo::iD</strong></em> are both being accessed via <em><strong>[eax+4]</strong></em> at an offset of 4 bytes from the value loaded into <em><strong>eax</strong></em> from <em><strong>[ebp-4]</strong></em>. Again, the same as their offsets within their respective types as shown in the class layout information.</li>
<li>(<em>line 16</em>) <strong><em>UTestUnion::sTestTwo::iE</em></strong> is accessed via <em><strong>[eax+8]</strong></em> &#8211; an offset of 8 bytes as specified in the class layout information.</li>
</ul>
<p>A more &#8216;real world&#8217; example of the use of <em><strong>union</strong></em> might be a data structure used in a vector maths library similar to the one below:</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
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">class CTestVec4
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">union</span> 
    <span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">struct</span> 
        <span style="color: #009900;">&#123;</span>
            <span style="color: #993333;">float</span> x<span style="color: #339933;">;</span>
            <span style="color: #993333;">float</span> y<span style="color: #339933;">;</span>
            <span style="color: #993333;">float</span> z<span style="color: #339933;">;</span>
            <span style="color: #993333;">float</span> w<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">struct</span>  
        <span style="color: #009900;">&#123;</span>
            <span style="color: #993333;">float</span> vec<span style="color: #009900;">&#91;</span> <span style="color: #0000dd;">4</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The above code declares a vector structure whose data can be accessed either via its components or like an array &#8211; e.g. <em><strong>CTestVec4::z</strong></em> occupies the same memory as <em><strong>CTestVec4::vec[ 2 ]</strong></em>.</p>
<p>The code looks like it should be illegal but it isn&#8217;t &#8211; leaving all the names out is entirely deliberate, this defines an &#8220;anonymous union&#8221; which makes the syntax for accessing the union &#8216;less cumbersome&#8217; (i.e. basically just less typing).</p>
<p>If you weren&#8217;t sure how <em><strong>union</strong></em> worked, or indeed what it was for, now you know :)</p>
<p>&nbsp;</p>
<h2>Surely we&#8217;re due a spanner in the works about now?</h2>
<p>We most certainly are! Well spotted.</p>
<p>There is an incredibly important low level aspect of the way memory is laid out within <em><strong>class</strong></em>es and <em><strong>struct</strong></em>s that I have deliberately skimmed over until now.</p>
<p>Consider the following snippet containing an innocent looking <em><strong>struct</strong> </em>declaration:</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
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;stdafx.h&quot;</span>
&nbsp;
<span style="color: #993333;">struct</span> STestSpanner
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span>     iOne<span style="color: #339933;">;</span>
    <span style="color: #993333;">double</span>  fdTwo<span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span>    chThree<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span>     iFour<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When we compile this we get the following output from the class layout information:</p>
<pre>1&gt;  class STestSpanner    size(24):
1&gt;  	+---
1&gt;   0	| iOne
1&gt;    	| &lt;alignment member&gt; (size=4)
1&gt;   8	| fdTwo
1&gt;  16	| chThree
1&gt;    	| &lt;alignment member&gt; (size=3)
1&gt;  20	| iFour
1&gt;  	+---</pre>
<p>What witchcraft is this!?!</p>
<p>We&#8217;ve added a <em><strong>char</strong> </em>and a <em><strong>double</strong></em> to our <em><strong>struct </strong></em>- requiring a total of an extra <em><strong>9</strong></em> bytes (on win32 <em><strong>sizeof(char) == 1</strong></em> and <em><strong>sizeof(double) == 8</strong></em>).</p>
<p>However, the total size of the struct has increased by <em><strong>16</strong> </em>bytes &#8211; in addition to the <strong>9</strong> bytes we know we asked for, we have also added an additional <strong>7</strong> bytes of invisible &#8216;<em>alignment member</em>&#8216; fields.</p>
<p>What is going on? Padding &#8211; that&#8217;s what.</p>
<p>&nbsp;</p>
<h2>Padding!?!</h2>
<p>As long as the layout of the data members of a type meet the ordering requirement of the language standard (as covered earlier) they do not have to be immediately adjacent in memory.</p>
<p>The compiler is free, encouraged even, to insert additional padding into your <em><strong>struct</strong></em>s / <em><strong>class</strong></em>es at its discretion.</p>
<p>Why might the compiler wish to adjust the layout like this?</p>
<p>The short answer is: to optimise for speed of memory access for the intrinsic types stored in that structure.</p>
<p>The longer answer goes something like this&#8230;</p>
<p>On each platform, the various intrinsic types have different sizes and typically also different memory alignment requirements.</p>
<p>In the best case, accessing an intrinsic type with an alignment requirement from an incorrectly aligned memory address will cause the memory access time to be slower than usual (on x86 the cost is typically relatively small, but can be an order of magnitude slower on other platforms); and in the worst case can actually cause the CPU to crash (yes, really &#8211; on some platforms unaligned access makes the CPU freak out).</p>
<p>There are three separate factors at play in determining the size of <em><strong>STestSpanner:</strong></em></p>
<ol>
<li>The logical number of bytes required by its constituent types &#8211; this is the minimum possible size of the type.</li>
<li>The ordering of the constituent types within the class declaration.</li>
<li>The individual alignment requirements of those constituent types.</li>
</ol>
<p>The compiler honours both the ordering of the constituent types and their individual alignment requirements, and this interaction determines the amount of padding bytes that get added.</p>
<p>Since they affect each other and are closely related, the distinction between alignment, packing, and padding often causes confusion:</p>
<ul>
<li>Alignment is a constraint on the start address of instances of a type in memory</li>
<li>Packing is a constraint on the alignment of adjacent members within the memory of a struct or class</li>
<li>Padding is the bytes added within a <em><strong>class</strong> </em>or <em><strong>struct</strong> </em>to maintain its packing constraints</li>
</ul>
<p>This <a href="http://stackoverflow.com/questions/548164/mis-aligned-pointers-on-x86">Stack Overflow question</a> has a good a discussion of the implications of unaligned access on x86 for those of you who are interested.</p>
<p>&nbsp;</p>
<h2>Sorry, why the padding?</h2>
<p>As we have covered before, compiler writers are wily.</p>
<p>You must be able to declare an array of any type that you define, and so the memory layout of a struct or class you define must not only maintain the alignment constraints of its constituent intrinsic types within an instance, but also across an array of instances laid out contiguously in memory.</p>
<p>The simplest way to ensure this is to make the internal structure of the type adhere to the largest alignment constraint of its constituent types &#8211; and this means that the size and internal packing of any structure you declare will usually end up being determined by the largest alignment requirement of its constituent types.</p>
<p>In the case of our struct this would be double which has a default alignment of 8 bytes (at least under the Visual Studio x86 complier, it varies with other compilers), and consequently so does the structure STest &#8211; hence the 7 extra bytes of padding  to take the struct from the 17 bytes ( 2 ints (8bytes) + 1 double (8 bytes) + 1 char (1 byte) ) of data we asked it to contain up to 24 bytes &#8211; i.e. the next size that maintains the alignment of double.</p>
<p>You should find that,  no matter how you shuffle the  members of <em><strong>STestSpanner</strong> </em>around, you still end up with a 24 byte structure that includes 7 bytes of padding.</p>
<p>On the plus side, if we needed to add 3 extra <em><strong>char</strong> </em>and an extra <em><strong>int</strong> </em>into <em><strong>STestSpanner</strong> </em>we would get that storage space for free as long as we put them in the correct positions in the type declaration :)</p>
<p>&nbsp;</p>
<h2>But what about all the wasted bytes?</h2>
<p>The compiler knows what it is doing, and 99% of the time you should not worry about the wasted space.</p>
<p>Get a cup of tea and a biscuit and make peace with it &#8211; it&#8217;s not wasted space, it&#8217;s space invested in making your memory access more efficient.</p>
<p>However, you should worry about it a little &#8211; because it is entirely possible to cause the compiler to introduce padding into a type that is <em>actually</em> a total waste of memory.</p>
<p>Consider this struct:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> STestSpannerTwo
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span>     iOne<span style="color: #339933;">;</span>
    <span style="color: #993333;">double</span>  fdTwo<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span>     iThree<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>which produces this class layout:</p>
<pre>1&gt;  class STestSpanner	size(24):
1&gt;     +---
1&gt;   0 | iOne
1&gt;     | &lt;alignment member&gt; (size=4)
1&gt;   8 | fdTwo
1&gt;  16 | iThree
1&gt;     | &lt;alignment member&gt; (size=4)
1&gt;     +---</pre>
<p>A quick look at the class layout above informs us that there is 4 bytes of padding between <em><strong>STestSpannerTwo::iOne</strong></em> and <em><strong>STestSpannerTwo::fdTwo; </strong></em>and another 4 bytes of padding after <em><strong>STestSpannerTwo::iThree.</strong></em></p>
<p>The x86 intrinsic 64 bit float format used to represent double is 8 bytes long and clearly has default alignment of 8-bytes under Visual Studio&#8217;s compiler.</p>
<p>The constraints of our type declaration combined with the 8 byte alignment constraint for <em><strong>double</strong></em> have resulted in:</p>
<ul>
<li>4 padding bytes after <em><strong>STestSpannerTwo::iOne</strong></em> and before <em><strong>STestSpannerTwo::fdTwo </strong></em>to maintain the alignment within the memory of a single instance of <em><strong>STestSpannerTwo&#8230;</strong></em></li>
<li>&#8230;and 4 padding bytes after <em><strong>STestSpannerTwo::iThree </strong></em>to maintain the 8 byte alignment across instances of <em><strong>STestSpannerTwo</strong></em><strong> </strong> that are contiguous in memory (i.e. an array of <em><strong>STestSpannerTwo</strong></em>).</li>
</ul>
<p>However, we can also see that  <em><strong>STestSpannerTwo::iThree</strong></em> is a 4 byte <em><strong>int</strong></em> and so it will fit into the first block of padding; eliminating the need for the 8 padding bytes.</p>
<p>Re-ordering the members by hand like this will save 8 bytes off the total size of the struct, and so we can see that &#8211; in this case &#8211; we can save 33% of the memory used by the struct basically for free &#8211; don&#8217;t take my word for it, try it!</p>
<p>whilst this isn&#8217;t something you should lose sleep over, you should now be able to see the benefit in always taking a second to consider the most appropriate place to insert a new data member into an existing type ;)</p>
<p>&nbsp;</p>
<h2>&#8230;but what if I <em><strong>really</strong></em> need those padding bytes?</h2>
<p>Unsurprisingly, this being C/C++, it is entirely possible to ask the compiler to change its default alignment and packing behaviour.</p>
<p>This is usually accomplished by use of command line compiler options and/or compiler specific commands that are inserted inline in your code.</p>
<p>In Visual Studio, for example, there is the <em><strong>/Zp</strong></em> compiler option, and another 2 ways to affect the alignment of data structures and the packing of their members with compiler commands in the code itself <a href="http://msdn.microsoft.com/en-us/library/83ythb65(v=vs.110).aspx"><em><strong>__declspec( align( x ) )</strong></em></a> and <a href="http://msdn.microsoft.com/en-us/library/2e70t5y1(v=vs.110).aspx"><em><strong>#pragma pack (x)</strong></em></a>). There may also be others I&#8217;ve never seen or used, but a quick search on t&#8217;interwebs didn&#8217;t find them.</p>
<p>For example, using <em><strong>#pragma pack</strong></em> to tell the compiler to pack <em><strong>STestSpanner </strong></em>to a 1 byte boundary like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#pragma pack(1) </span>
<span style="color: #993333;">struct</span> STestSpanner
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span>     iOne<span style="color: #339933;">;</span>
    <span style="color: #993333;">double</span>  fdTwo<span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span>    chThree<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span>     iFour<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Gives this class layout output:</p>
<pre>1&gt;  class STestSpanner	size(17):
1&gt;  	+---
1&gt;   0	| iOne
1&gt;   4	| fdTwo
1&gt;  12	| chThree
1&gt;  13	| iFour
1&gt;  	+---</pre>
<p><em><strong>Be warned!</strong></em></p>
<p>Adjusting the packing of a type can (and probably will) break the alignment constraints of its constituent types &#8211; in the example above there are no &#8216;wasted&#8217; bytes; but <em><strong>STestSpanner </strong></em>no longer honours the alignment requirements of  its constituent types and so will presumably take significantly longer to access than it would do had we not fiddled about with it.</p>
<p>This means that when you ask the compiler to change the packing of a type you need to be <em><strong>very</strong></em> careful.</p>
<p>My advice is that &#8211; in general &#8211; you shouldn&#8217;t mess with alignment or padding unless you have a <em>very</em> good reason to; altering padding and alignment can get you into a whole world of pain, especially with bigger projects and when using code libraries &#8211; here&#8217;s a link to <a href="http://blogs.msdn.com/b/vcblog/archive/2007/05/17/diagnosing-hidden-odr-violations-in-visual-c-and-fixing-lnk2022.aspx">a post on the Visual C++ Team Blog</a> that goes into it in some detail.</p>
<p>The decisions to change alignment or padding will typically come down to essentially platform specific trade offs based on data derived from run time profiling &#8211; balancing issues like data sizes vs. memory resource constraints, worst case access times of individual parts of the data, and issues relating to system cache sizes and alignments.</p>
<p>&nbsp;</p>
<h2>Summary</h2>
<p>In summary here are the main points I&#8217;d like you to take away from this post:</p>
<ul>
<li>The undocumented compiler options  <strong>/d1reportSingleClassLayout </strong>and  <strong><strong>/d1reportAllClassLayout </strong></strong>are awesome, and can help you to understand the memory use implications of code you write, as well as being very useful debugging tools</li>
<li>We now know that, when an instance of a structure is accessed via pointer,  its members are accessed via an offset from the instance&#8217;s base address in the assembly, and &#8230;</li>
<li>&#8230; that, logically, we can use this in the disassembly view to work out which member is being accessed</li>
<li>The difference between <em><strong>struct</strong></em> and <em><strong>class. </strong></em>i.e. that there is no low level representational difference.</li>
<li>What the keyword <em><strong>union</strong></em> does and how it works</li>
<li>What padding and alignment are and some of their implications</li>
</ul>
<p>Next time we will look at how (simple) inheritance affects this picture&#8230;</p>
<p>&nbsp;</p>
<h2>Epilogue: Debugger Trick 17a</h2>
<p>Here&#8217;s an alternative way to find out the offset of a member within a user defined data type, a way that you can happily use in the debugger rather than having to compile the code.</p>
<p>This method works with the vast majority of debuggers I&#8217;ve used in the last 5 years or so on both PC and console; and it relies on the fact that the standard C style cast syntax works in watch windows (try it! It&#8217;s awesome).</p>
<p>One upshot of this is that you can use casting to calculate the byte offset of any member of any user defined type (this is also valid, and very useful, C/C++ code):</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/CLLC_10UserDefinedTypes_DebuggerTrick7a.png"><img alt="CLLC_10UserDefinedTypes_DebuggerTrick7a" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/CLLC_10UserDefinedTypes_DebuggerTrick7a.png" width="545" height="107" /></a></p>
<p>That code looks horrible, not to mention dangerous, but what it&#8217;s doing is actually very simple and totally safe.</p>
<p>We have seen that, when using a pointer to an instance of a type, the compiler accesses members of that user defined type by adding an offset to the memory address the instance is stored at (its &#8216;base address&#8217;).</p>
<p>Note that the values we&#8217;re seeing in the watch window are identical to those seen in the output from <strong>/d1reportSingleClassLayout</strong>.</p>
<p>Here&#8217;s how this works:</p>
<ul>
<li><em><strong>(STest*) 0</strong></em> - tells the debugger to treat 0 as the value of a pointer to an instance STest. If you&#8217;re thinking &#8220;but 0 is NULL!&#8221; &#8211; remember that 0 is <em>only &#8216;NULL&#8217; by convention</em> (in fact, on some consoles, 0 is a valid memory address and can be accessed&#8230;). In any case, this code isn&#8217;t accessing the memory &#8211; it&#8217;s just asking the compiler to treat 0 as the value of a pointer.</li>
<li><em><strong>&amp;(((STest*)0)-&gt;iB)</strong></em> - tells the debugger to calculate the address of <em><strong>STest::iB</strong></em>. Again, since this is just calculating an address and not attempting to access it it is fine.</li>
</ul>
<p>This is possibly my favourite thing I have ever found out about debuggers, and has come in incredibly useful over the years :)</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/05/cc-low-level-curriculum-part-10-user-defined-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Video Game Industry Predictions 2013</title>
		<link>http://www.altdevblogaday.com/2013/01/02/video-game-industry-predictions-2013/</link>
		<comments>http://www.altdevblogaday.com/2013/01/02/video-game-industry-predictions-2013/#comments</comments>
		<pubDate>Wed, 02 Jan 2013 01:20:34 +0000</pubDate>
		<dc:creator>Alistair Doulin</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[General Interest]]></category>
		<category><![CDATA[2013]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[prediction]]></category>
		<category><![CDATA[tablet]]></category>
		<category><![CDATA[virtual reality]]></category>
		<category><![CDATA[VR]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28977</guid>
		<description><![CDATA[<p>Well, the world didn&#8217;t end (of course) so it&#8217;s time to look to the next twelve months and predict what we might see in 2013. Below are my predictions for the video game industry in 2013.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/02/video-game-industry-predictions-2013/" class="more-link">Read more on Video Game Industry Predictions 2013&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Well, the world didn&#8217;t end (of course) so it&#8217;s time to look to the next twelve months and predict what we might see in 2013. Below are my predictions for the video game industry in 2013.</p>
<h2>Virtual Reality</h2>
<p><a href="http://www.doolwind.com/blog/video-game-industry-predictions-2013/oculusrift/" rel="attachment wp-att-593"><img class="alignright size-medium wp-image-593" alt="Oculus Rift" src="http://www.doolwind.com/blog/wp-content/uploads/2013/01/oculusrift-300x161.jpg" width="300" height="161" /></a></p>
<p>I&#8217;ve long been a fan of VR and have been disappointed with the consumer level hardware up to this point. That all changed in 2012 with the announcement of the <a href="http://www.oculusvr.com/">Oculus Rift</a>. With the backing of John Carmack, it was hard for the industry to ignore this new product. It looks like VR has finally turned a corner and (thanks to the booming smart phone market) the technology is available allowing a cheap (almost) consumer grade VR headset to be mass produced. Developers will have most of 2013 to prepare for the consumer grade headset and I see a lot of time and research going into these preparations. Rather than gamers peering through a small (24-70&#8243;) window into our worlds, they can now be completely immersed in them. The current&nbsp;fascination&nbsp;with (stereoscopic only)&nbsp;3D &nbsp;is one thing, but true immersive head-tracked 3D will take our games to the next level. While there are only a handful of games that support the Oculus Rift at this stage, by the end of 2013 I predict this to be in the hundreds.</p>
<h2>Mobile/Tablet</h2>
<p>I predict a large number of people (particularly&nbsp;indie&#8217;s) will make it big on mobile in 2013. This is still the direction I plan to head in 2013. While some people have moved toward social/Facebook gaming in 2011-2012 I see some of them returning to mobile/tablet gaming in 2013. With Microsoft entering the <a href="http://www.microsoft.com/Surface">tablet market</a> (and with a better mobile offering) I see this market growing substantially in 2013. The &#8220;get rich quick&#8221; attitude many had towards Facebook games has died off a little and I&#8217;m seeing a number of indie developers I know pivoting back to mobile rather than pure Facebook/social. I see the mobile/tablet market maturing in 2013 as many developers learn from their mistakes in the past and embrace the benefits of the platform (touch interface, always connected, etc).</p>
<h2>Real Social Games</h2>
<p><a href="http://www.doolwind.com/blog/video-game-industry-predictions-2013/zynga/" rel="attachment wp-att-594"><img class="size-full wp-image-594 alignleft" alt="zynga" src="http://www.doolwind.com/blog/wp-content/uploads/2013/01/zynga.png" width="75" height="65" /></a>With Zynga <a href="http://techcrunch.com/2012/12/30/zynga-shuts-down-petville-fishville-mafia-wars-2/">shutting down</a> a bunch of their games, I see the need for truly social games. Facebook and other social networks give game developers amazing opportunity for connecting gamers to their friends and others around the world. Rather than abusing these connections I see a switch to meaningful engagement. Games like LetterPress show the simplicity of Facebook to connect users rather than allowing users to bug their friends into getting them in-game items for free. True social games will take this simple connection and use it to enrich their game design. Many older gamers grew up playing together in arcades or lugging their giant computers to each others houses for a chance to play together. I&#8217;d like to see this same experience enabled by social games rather than the cheap &#8220;social&#8221; behavior we see currently. Like it or not, many developers go where the money is and the fact Zynga and the like are now falling on hard times shows the need for more than a superficial social connection if these types of games are to succeed.</p>
<h2>No New Apple Product</h2>
<p><a href="http://www.doolwind.com/blog/video-game-industry-predictions-2013/applelogo/" rel="attachment wp-att-595"><img class="alignright  wp-image-595" alt="applelogo" src="http://www.doolwind.com/blog/wp-content/uploads/2013/01/applelogo.png" width="84" height="101" /></a>I don&#8217;t see Apple releasing any significantly new products in 2013. They will continue to evolve their existing products, however I see the pace of of their evolution picking up. The iPhone 5 was a&nbsp;disappointment&nbsp;to many of the die-hard Apple fans I know. 2013 will be a real turning point for Apple as they forge new territory without Jobs at the helm. I&#8217;m sure much of 2012 had already been planned out but decisions like the iPad Mini show a new course is being set. I&#8217;d love to see a new product as innovative as the iPad, but I don&#8217;t see that&nbsp;occurring&nbsp;in 2013. Perhaps in a year or two we might see Apple move into the VR market, but I think they will wait and see the response to the Oculus Rift before making a large move like that.</p>
<h2>Last Generation of Consoles</h2>
<p><a href="http://www.doolwind.com/blog/video-game-industry-predictions-2013/xbox720/" rel="attachment wp-att-596"><img class=" wp-image-596 alignleft" alt="xbox720" src="http://www.doolwind.com/blog/wp-content/uploads/2013/01/xbox720-300x177.jpg" width="180" height="106" /></a>It&#8217;s looking like the next XBox and Playstation will be released in late 2013. I predict this will be the final &#8220;pure console&#8221; generation we see. As mobile, tablet and PC converge I think it&#8217;s logical that the concept of the console will disappear. With the current console cycle being closer to 10 years than 5, we can expect the next generation to be at least as long. With the current speed of innovation in the tablet/mobile sector, it will only be a matter of years before a portable device is as powerful as the next generation of consoles. The only difference then is the input/output mechanisms. Microsoft has already shown their Surface is compatible with a XBox360 controller and I see this trend continuing.</p>
<p>In the mid-term future, I forsee one, or maybe a couple, of devices powering most of our personal computing. This device will connect to the output device of our choosing to power our experience. On the road we will use the device itself (which will be around the size of a phone and/or tablet, depending on your preference). At work the computing device wirelessly connects to your mouse,&nbsp;keyboard&nbsp;and&nbsp;monitor(s). Playing games and watching movies it will wirelessly connect to a large TV or projector.</p>
<h2>Summary</h2>
<p>What are your predictions for 2013? Do you agree or disagree with any of my points? What would you love to see in 2013?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/02/video-game-industry-predictions-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Almost everything you need to know to enter mobile game development on 2013</title>
		<link>http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/</link>
		<comments>http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/#comments</comments>
		<pubDate>Wed, 02 Jan 2013 00:20:10 +0000</pubDate>
		<dc:creator>Raul Aliaga Diaz</dc:creator>
				<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28963</guid>
		<description><![CDATA[<p>This is a list of useful resources to help you refine, define, execute and possibly reconsider your decision to enter mobile game development this year. The resources are a little more inclined to the business and game design parts of game development, except for a couple of ones linking other lists.</p>
<p><a href="http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/" class="more-link">Read more on Almost everything you need to know to enter mobile game development on 2013&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>This is a list of useful resources to help you refine, define, execute and possibly reconsider your decision to enter mobile game development this year. The resources are a little more inclined to the business and game design parts of game development, except for a couple of ones linking other lists.</p>
<p>The executive summary version: It is a very attractive and fast growing market, but the odds are stacked against small, new and indie game developers. Successful games are usually paid, greatly innovative and highly polished casual titles -specially when working with a good publisher or a known brand- or free to play titles that operate as a service, seeing little revenue for a span of at least six months after launch, adding new content and/or further polishing, balancing and optimizing for retention and monetization. The former approach can be a logical step for studios that already have game development expertise, a team already in place and experience working with publishers. The latter is the approach that might yield the greater rewards, but requires a mid to long term vision, and also a tight and strong combination of resources and execution speed to actually pull it off.</p>
<p>What is mobile game development? We’ll consider it as any game focused development for smartphones or tablets running Android or iOS. What does this market look like? Let’s look at some numbers and insights:</p>
<ul>
<li><a href="http://www.gamesindustryblog.com/2012/11/mobile-gaming-market-projected-to-grow-at-an-annual-rate-of-12-3/">Mobile Gaming Market Projected to Grow at an Annual Rate of 12.3%</a></li>
<li><a href="http://venturebeat.com/2012/11/29/apples-app-store-makes-4x-google-play-but-google-play-is-growing-100x-faster/">Apple’s app store revenue is 4X Google Play’s … but Google Play is growing 24X faster</a></li>
<li><a href="http://blog.appannie.com/app-annie-index-november-2012/">Google Play revenue grew 17%, iOS revenue contracted 0.7% in Nov 2012</a> but <a href="http://venturebeat.com/2012/11/29/apple-disputes-app-annie-report-the-app-store-did-not-grow-just-13-this-year-it-grew-by-over-200/">Apple disputes App Annie report: the app store did NOT grow just 13% this year — it grew over 200%</a></li>
<li><a href="http://techcrunch.com/2012/08/15/natural-motion/">A $12-Million-A-Month iOS Game? NaturalMotion Has It With CSR Racing</a></li>
</ul>
<p><a href="http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/usracetomobile/" rel="attachment wp-att-28964"><img class="aligncenter size-full wp-image-28964" alt="USRaceToMobile" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/USRaceToMobile.gif" width="324" height="430" /></a></p>
<p>&nbsp;</p>
<p style="text-align: left">[Source: <a href="http://www.emarketer.com/Article.aspx?R=1009543">eMarketer</a>]</p>
<p style="text-align: left">Looks promising, but it’s not all good:<b><b><br />
</b></b></p>
<ul>
<li><a href="http://www.philterdesign.com/?p=582">Some Numbers on the Top Grossing Games in the App Store</a></li>
<li><a href="http://venturebeat.com/2012/12/03/investors-weigh-in-on-falling-game-startup-valuations/">Investors weigh in on falling game-startup valuations</a></li>
<li><a href="http://techcrunch.com/2012/12/04/analyst-just-25-developers-grabbed-50-of-app-revenues-on-u-s-app-store-google-play-last-month-earning-60m-between-them/">Analyst: Just 25 Developers Grabbed 50% Of App Revenues On U.S. App Store, Google Play Last Month; Earning $60M Between Them</a>. (also on <a href="http://venturebeat.com/2012/12/05/half-of-revenue-generated-by-ios-and-android-apps-goes-to-just-25-developers/">Venturebeat</a>).</li>
<li><a href="http://www.serkantoto.com/2012/12/19/sales-profit-market-caps-gree-zynga-dena/">Sales, Profit And Market Caps: GREE vs. Zynga vs. DeNA (Overview)</a></li>
<li><a href="http://venturebeat.com/2012/12/28/report-user-acquisition-costs-for-ios-shot-up-30-last-month/">Report: User acquisition costs for iOS shot up 30% last month</a></li>
</ul>
<p style="text-align: left">So, how to make sense of the opportunity? Is it reasonable? Affordable? Worth pursuing? Let’s start with a list of general projections for gaming on 2013 and summaries for 2012:<b><b><br />
</b></b></p>
<ul>
<li><a href="http://www.slideshare.net/GMOCloud/japanese-gaming-market-2012">Japanese Gaming Market 2012</a></li>
<li><a href="http://blog.appsfire.com/2012-a-year-in-app-store-infographic/">2012: A Year in App Store (Infographic)</a></li>
<li><a href="http://blog.nielsen.com/nielsenwire/social/2012/">Social Media Report 2012</a></li>
<li><a href="http://www.gamasutra.com/view/feature/183892/Gamasutras_Best_of_2012.php">Gamasutra&#8217;s Best of 2012</a></li>
<li><a href="http://ufert.se/user-acquisition/game-companies/mobile-gaming-industry-2013/">2013 Predictions for Mobile Gaming</a></li>
<li><a href="http://techcrunch.com/2012/12/22/whats-next-for-social-mobile-games/">What’s Next For Social Mobile Games?</a></li>
<li><a href="http://www.forbes.com/sites/ciocentral/2012/12/24/7-predictions-for-the-mobile-gaming-market-for-2013/">7 Predictions For The Mobile Gaming Market For 2013</a></li>
<li><a href="http://venturebeat.com/2012/12/28/the-deanbeat-game-industry-predictions-for-2013/">The DeanBeat: Game industry predictions for 2013</a></li>
</ul>
<p style="text-align: left">This is a list of studies, articles and slides worth studying bit by bit to get a clearer picture:<b><b><br />
</b></b></p>
<ul>
<li><a href="http://www.slideshare.net/kleinerperkins/kpcb-internet-trends-2012">Internet Trends by KPCB</a> and <a href="http://www.slideshare.net/kleinerperkins/2012-kpcb-internet-trends-yearend-update">2012 KPCB Internet Trends Year-End Update</a></li>
<li><a href="http://andrewchen.co/2009/01/19/how-to-create-a-profitable-freemium-startup-spreadsheet-model-included/">How to create a profitable Freemium startup (spreadsheet model included!)</a></li>
<li><a href="http://www.slideshare.net/superdata/casual-games-sector-report-mobile-gaming">Casual Games Sector Report: Mobile Gaming</a></li>
<li><a href="http://virtual-economy.org/2012/04/25/acquisition-retention-monetization-final-report/">Acquisition, Retention, Monetization: Final Report</a></li>
<li><a href="http://www.lostgarden.com/2011/03/gdc-2011-game-of-platform-power.html">The Game of Platform Power</a></li>
</ul>
<p><a href="http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/platforms/" rel="attachment wp-att-28966"><img class="aligncenter size-full wp-image-28966" alt="Platforms" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/platforms.png" width="652" height="491" /></a></p>
<p>&nbsp;</p>
<p dir="ltr" style="text-align: left">[Source: <a href="http://www.lostgarden.com/2011/03/gdc-2011-game-of-platform-power.html">Lostgarden</a>]</p>
<p dir="ltr">Next, a collection of thoughts from established players in the industry:</p>
<ul>
<li><a href="http://www.gamesindustry.biz/articles/2012-11-28-chillingo-ruthless-mobile-has-no-room-for-anything-except-perfection">Chillingo: Ruthless mobile platform has &#8220;no room for anything except perfection&#8221;</a></li>
<li><a href="http://www.gamasutra.com/view/news/182289/The_future_of_mobile_games_according_to_Gree.php#.UOFFAYnjmEC">The future of mobile games, according to Gree</a></li>
<li><a href="http://www.gamesindustry.biz/articles/2012-12-12-monetizing-games-crucial-advice-from-key-players">Gamers rule: Only 10% of the industry&#8217;s $50 billion comes from casuals</a></li>
<li><a href="http://www.pocketgamer.biz/r/PG.Biz/ngmoco+news/news.asp?c=47416">2012 in review: Doug Scott, ngmoco</a></li>
</ul>
<p dir="ltr">Assuming you have a clearer picture now, and you are eager to learn more, what would be good resources to learn about all this?</p>
<p><span style="text-decoration: underline">Business links</span></p>
<ul>
<li><a href="http://blog.flurry.com/bid/72755/Mobile-Freemium-Games-Women-Thrifty-Men-Binge">Mobile Freemium Games: Women Thrifty, Men Binge</a></li>
<li><a href="http://www.altdevblogaday.com/2012/06/07/three-steps-from-paid-to-freemium/">Three Steps from Paid to Freemium</a></li>
<li><a href="http://www.gamasutra.com/view/feature/6700/">Virtual Goods &#8211; An Excerpt from Social Game Design: Monetization Methods and Mechanics</a></li>
<li><a href="http://www.develop-online.net/blog/413/More-money-from-your-mobile-game-for-0-part-1">More money from your mobile game for $0, part 1</a> and <a href="http://www.develop-online.net/blog/418/More-money-from-your-mobile-game-for-0-part-2">part 2</a></li>
<li><a href="http://www.businessinsider.com/bii-report-the-mobile-advertising-ecosystem-explained-2012-12">BII REPORT: The Mobile Advertising Ecosystem Explained</a></li>
<li><a href="http://www.whatgamesare.com/2011/04/you-need-100000-game-development.html">You Need $100,000 [Game Development]</a></li>
<li><a href="http://www.gamasutra.com/view/feature/182962/What_Do_Investors_Look_for_in_a_Game_Developer.php">What Do Investors Look for in a Game Developer?</a></li>
<li><a href="http://steveblank.com/tools-and-blogs-for-entrepreneurs/">Steve Blank’s List of Tools for Entrepreneurs</a>. (includes technical tools and software)</li>
</ul>
<p style="text-align: center"><a href="http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/ma/" rel="attachment wp-att-28967"><img class="aligncenter  wp-image-28967" alt="ma" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/ma.png" width="605" height="353" /></a></p>
<p dir="ltr" style="text-align: left">[Source: <a href="http://www.businessinsider.com/bii-report-the-mobile-advertising-ecosystem-explained-2012-12">Business Insider</a>]</p>
<p><span style="text-decoration: underline">Game Development links<b><b><br />
</b></b></span></p>
<ul>
<li>How does Rage of Bahamut monetizes? <a href="http://iteratingfun.com/post/30438564732/top-grossing-rage-of-bahamut-analysis">Analysing a Top Grossing Game: Rage of Bahamut</a> and <a href="http://deconstructoroffun.blogspot.fi/2012/11/how-rage-of-bahamut-monetizes.html">How Rage of Bahamut Monetizes</a>.</li>
<li><a href="http://deconstructoroffun.blogspot.fi/2012/09/clash-of-clans-winning-formula.html">Clash of Clans &#8211; the Winning Formula</a></li>
<li><a href="http://www.gamasutra.com/blogs/LarsDoucet/20121115/181659/Free_2_Play_and_the_Four_Currencies.php">Free 2 Play and the Four Currencies</a></li>
<li><a href="http://www.gamasutra.com/view/feature/181419/7_ways_to_fail_at_freetoplay.php">7 Ways to Fail at Free-to-Play</a></li>
<li><a href="http://www.whatgamesare.com/2012/10/the-free-to-play-triangle-game-economics.html">The Free-To-Play Triangle [Game Economics]</a></li>
<li><a href="http://www.altdevblogaday.com/2012/02/09/the-principles-of-game-monetization/">The Principles of Game Monetization</a></li>
<li><a href="http://www.gamasutra.com/view/feature/6592/the_design_of_freetoplay_games_.php">The Design of Free-to-Play Games, Part 2</a> (<a href="http://www.gamasutra.com/view/feature/183307/Designing_Freemium_Titles_for_Hardcore_Gamers.php">Part 1</a>)</li>
<li><a href="http://www.gamasutra.com/view/news/182853/5_tips_for_boosting_your_virtual_economy.php#.UOFE_4njmEC">5 tips for boosting your virtual economy</a></li>
<li><a href="http://techcrunch.com/2012/12/14/engagement-mobile-games/">Which Types Of Mobile Games Are In The Engagement Sweet Spot?</a></li>
<li><a href="http://www.mangatutorials.com/forum/showthread.php?742-The-Ultimate-Indie-Game-Developer-Resource-List&amp;s=c464f498b3a5ace9cea0664c5f823df6">The Ultimate Indie Game Developer Resource List</a> (includes technical tools and software)</li>
<li><a href="http://www.pixelprospector.com/the-big-list-of-game-making-tools/">The Big List of Game Making Tools</a> (includes technical tools and software)</li>
</ul>
<p><a href="http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/triangle-2/" rel="attachment wp-att-28968"><img class="aligncenter size-full wp-image-28968" alt="Triangle" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/Triangle.png" width="330" height="310" /></a></p>
<p style="text-align: left">[Source: <a href="http://www.whatgamesare.com/2012/10/the-free-to-play-triangle-game-economics.html">What Games Are</a>]</p>
<p style="text-align: left"><span style="text-decoration: underline">Going live links</span><b><b><br />
</b></b></p>
<ul>
<li>Analytics: <a href="http://www.flurry.com/">Flurry</a>, <a href="http://www.kontagent.com/">Kontagent</a> and <a href="http://www.appannie.com/">AppAnnie</a>.</li>
<li><a href="http://kadank.com/blog/?p=270">The long post : metrics and business model.</a></li>
<li><a href="http://globaldecision.com/blog/online-gaming-analytics/arpu-arppu-arpmu-ltv-cac-cpa/">ARPU vs ARPPU / ARPMU … but really LTV and CAC / CPA</a></li>
<li><a href="http://cristinajcordova.com/post/36553000358/the-biggest-problem-in-mobile-retention">The Biggest Problem in Mobile: Retention</a></li>
<li><a href="http://www.gamesbrief.com/2012/06/refining-my-first-monetisation-strategy/">Refining my first monetisation strategy</a> and <a href="http://www.majaka.net/so-how-did-ski-champion-do-part-deux/">part 2</a>.</li>
<li><a href="http://www.gamesbrief.com/2012/12/managing-a-free-to-play-product-a-publishers-perspective/">Managing a Free To Play Product: A Publisher’s Perspective</a></li>
<li><a href="http://venturebeat.com/2012/11/26/why-your-free-to-play-users-arent-coming-backing-back/">Why your free-to-play users aren’t coming back</a></li>
<li><a href="http://blog.count.ly/post/37489471018/6-tips-for-a-better-mobile-analytics-experience">6 tips for a better mobile analytics experience</a></li>
<li><a href="http://venturebeat.com/2012/12/27/how-canada-has-become-americas-mobile-app-guinea-pig/">How Canada has become America’s mobile app guinea pig</a></li>
<li><a href="http://www.pixelprospector.com/the-big-list-of-indie-game-marketing/">The Big List of Indie Game Marketing</a></li>
</ul>
<p style="text-align: center"><a href="http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/dau-conversion-arppu1/" rel="attachment wp-att-28969"><img class="aligncenter  wp-image-28969" alt="dau-conversion-arppu1" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/dau-conversion-arppu1.png" width="655" height="334" /></a></p>
<p style="text-align: left">[Source: <a href="http://www.gamesbrief.com/2012/06/refining-my-first-monetisation-strategy/">GamesBrief</a>]</p>
<p style="text-align: left">Last but not least, Blogs, People and Websites worth following.<br />
<b><b><br />
</b></b><span style="text-decoration: underline">Blogs<b><b><br />
</b></b></span></p>
<ul>
<li><a href="http://deconstructoroffun.blogspot.fi/">Deconstructor of Fun</a>: Monetization in Social Games, written by “the evil monetization guy @ Rovio”.</li>
<li><a href="http://penny-arcade.com/patv/show/extra-credits">Extra Creditz</a>: Not exactly a blog, but lots of fun and thought provoking videos about gaming, game design and game development in general.</li>
<li><a href="http://www.serkantoto.com/">Dr. Serkan Toto</a>: Japan Mobile And Social Games Consulting.</li>
<li><a href="http://andrewchen.co/">Andrew Chen’s blog</a>: Great insights about startups in general.</li>
<li><a href="http://www.whatgamesare.com/">What Games Are</a>: Great for game design and production.</li>
<li><a href="http://www.gamesbrief.com/">Games Brief</a>: Special focus on monetization.</li>
<li><a href="http://www.sirlin.net/">Dave Sirlin’s blog</a>: Great game design blog.</li>
<li><a href="http://www.gameconfs.com/">Gameconfs</a>: a directory of game industry events.</li>
<li><a href="http://indiebits.com/">Indiebits</a>: Great tips for Indie Game Developers.</li>
<li><a href="http://gamedesignconcepts.wordpress.com/">Game Design Concepts</a> and <a href="http://gamebalanceconcepts.wordpress.com/">Game Balance Concepts</a>.</li>
<li><a href="http://www.raphkoster.com/">Raph Koster’s blog</a>: The author of Theory of Fun.</li>
</ul>
<p style="text-align: left"><b><b><br />
</b></b><span style="text-decoration: underline">People on Twitter</span>: All of them usually share good insights and links about mobile game development</p>
<ul>
<li>Devs: <a href="https://twitter.com/aquito">Aki Järvinen</a>, <a href="https://twitter.com/tiedtiger">Tadhg Kelly, </a><a href="https://twitter.com/PwnLaw">Shawn Foust</a>, <a href="https://twitter.com/will_luton">Will Luton</a>, <a href="https://twitter.com/m_katkoff">Michail Katkoff</a>, <a href="https://twitter.com/amyjokim">Amy Jo Kim</a>, <a href="https://twitter.com/danctheduck">Daniel Cook</a>, <a href="https://twitter.com/mike_acton">Mike Acton</a>, <a href="https://twitter.com/jesseschell">Jesse Schell</a>, <a href="https://twitter.com/cuppy">Tami Baribeau</a>, <a href="https://twitter.com/raphkoster">Raph Koster</a>.</li>
<li>Executives: <a href="https://twitter.com/sbergel">Shanti Bergel</a>, <a href="https://twitter.com/jussil">Jussi Laakkonen</a>, <a href="https://twitter.com/LloydMelnick">Lloyd Melnick</a>, <a href="https://twitter.com/TheKevinDent">Kevin Dent</a>, <a href="https://twitter.com/BenjaminCousins">Ben Cousins</a>, <a href="https://twitter.com/chudson">Charles Hudson</a>, <a href="https://twitter.com/nabeel">Nabeel Hyatt</a>, <a href="https://twitter.com/giordanobc">Giordano Contestabile</a>,  <a href="https://twitter.com/Gamebiz">Scott Dodson</a></li>
<li>Press and thought leaders: <a href="https://twitter.com/ferricide">Christian Nutt</a>, <a href="https://twitter.com/stephentotilo">Stephen Totilo</a>, <a href="https://twitter.com/leighalexander">Leigh Alexander</a>, <a href="https://twitter.com/adriancrook">Adrian Crook</a>, <a href="https://twitter.com/serkantoto">Dr. Serkan Toto</a>, <a href="https://twitter.com/nicholaslovell">Nicholas Lovell</a>, <a href="https://twitter.com/EponaSchweer">Epona Schweer</a>, <a href="https://twitter.com/AllenVarney">Allen Varney</a>, <a href="https://twitter.com/NicoleLazzaro">Nicole Lazzaro</a>.</li>
</ul>
<p><a href="http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/tweet-2/" rel="attachment wp-att-28970"><img class="aligncenter size-full wp-image-28970" alt="tweet" src="http://www.altdevblogaday.com/wp-content/uploads/2013/01/tweet.png" width="533" height="502" /></a></p>
<p>&nbsp;</p>
<p style="text-align: left">[Source: <a href="https://twitter.com/BenjaminCousins/status/282933942749917184">@BenjaminCousins</a>]</p>
<p><span style="text-decoration: underline">Sites</span>: Good for keeping up with trends, news, good games and stuff<b><b><br />
</b></b></p>
<ul>
<li><a href="http://www.altdevblogaday.com/">http://www.altdevblogaday.com/</a></li>
<li><a href="http://www.gamasutra.com/">http://www.gamasutra.com/</a></li>
<li><a href="http://www.pocketgamer.biz/">http://www.pocketgamer.biz/</a></li>
<li><a href="http://venturebeat.com/">http://venturebeat.com/</a></li>
<li><a href="http://techcrunch.com/">http://techcrunch.com/</a></li>
<li><a href="http://news.ycombinator.com/">http://news.ycombinator.com/</a></li>
<li><a href="http://toucharcade.com/">http://toucharcade.com/</a></li>
<li><a href="http://www.appspy.com/">http://www.appspy.com/</a></li>
<li><a href="http://www.insidesocialgames.com/">http://www.insidesocialgames.com/</a></li>
<li><a href="http://www.insidemobileapps.com/">http://www.insidemobileapps.com/</a></li>
</ul>
<p>I hope all this serves you as a starting point to learn more about your upcoming adventure on mobile gaming this year. Enjoy!</p>
<p><span style="text-decoration: underline">Bonus Tracks</span><b><b><br />
</b></b></p>
<ul>
<li><a href="http://techcrunch.com/2012/12/05/flurry-mobile-apps-television/">Time Spent In Mobile Apps Is Starting To Challenge Television, Flurry Says</a></li>
<li><a href="http://allthingsd.com/20121217/all-i-want-for-xmas-is-my-apple-tv/">All I Want for Christmas Is My Apple TV</a></li>
<li><a href="http://www.afterdawn.com/news/article.cfm/2012/12/09/valve_will_release_pc_console_next_year">Valve will release PC/console next year</a></li>
<li><a href="http://techcrunch.com/2012/12/13/ios-continues-to-reign-over-developer-interest-but-cross-platform-apps-are-now-on-everyones-mind/">iPhone And iPad Continue To Reign Over Developer Interest, But Cross-Platform Apps Are Now On Everyone’s Mind</a></li>
<li><a href="http://www.plinan.com/stop-trying-to-make-an-angry-birds-build-a-rovio/">Stop Trying to Make an Angry Birds. Build a Rovio.</a> Or <a href="http://pandodaily.com/2012/11/27/supercell-is-accels-fastest-growing-company-ever-and-it-has-a-ball-pit/">Supercell</a>. Or move to <a href="http://www.gamasutra.com/view/feature/183064/supercells_secret_sauce.php">Finland</a>.</li>
<li><a href="http://www.avc.com/a_vc/2012/12/rethinking-mobile-first.html">Rethinking Mobile First.</a></li>
<li><a href="http://www.theequitykicker.com/2012/12/18/2012-has-been-the-year-of-mobile-but-the-big-mobile-ad-acquisitions-were-made-three-years-ago/">2012 has been ‘the year of mobile’ but the big mobile ad acquisitions were made three years ago</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2013/01/02/almost-everything-you-need-to-know-to-enter-mobile-game-development-on-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lessons from Europe</title>
		<link>http://www.altdevblogaday.com/2012/12/26/lessons-from-europe/</link>
		<comments>http://www.altdevblogaday.com/2012/12/26/lessons-from-europe/#comments</comments>
		<pubDate>Wed, 26 Dec 2012 12:40:31 +0000</pubDate>
		<dc:creator>Claire Blackshaw</dc:creator>
				<category><![CDATA[General Interest]]></category>
		<category><![CDATA[lessons]]></category>
		<category><![CDATA[motivation]]></category>
		<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28922</guid>
		<description><![CDATA[<p>Often posts from a personal perspective are a contrite, self-promotion exercise of polishing the trumpets. They can also be an honest expression sometimes lost in the NDA red tape culture.</p>
<p>It is important to know why you do things, what drives and motivates you, bringing happiness and a sense of satisfaction. Though most importantly to admit when you made a gigantic cock-up and own up to being an idiot.</p>
<p><a href="http://www.altdevblogaday.com/2012/12/26/lessons-from-europe/" class="more-link">Read more on Lessons from Europe&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Often posts from a personal perspective are a contrite, self-promotion exercise of polishing the trumpets. They can also be an honest expression sometimes lost in the NDA red tape culture.</p>
<p>It is important to know why you do things, what drives and motivates you, bringing happiness and a sense of satisfaction. Though most importantly to admit when you made a gigantic cock-up and own up to being an idiot.</p>
<p>In my last post I requested contribution to a survey on why we create. The results were watered down when, by casual. non-formal inquiry of two large studios, I realised the results are not representative. In the inquiry I reminded myself that most people do not read industry press or actively participate in what I will term the &#8220;creators community&#8221;. Instead the bulk of our co-workers are content in their enjoyable job, which they still see as a job. They are happy, good on them, and many are talented and motivated individuals. Individuals I enjoy working with and who make awesome games. Though for completeness the results of the online survey are presented below.</p>
<p style="text-align: center">
<a href="http://www.altdevblogaday.com/2012/12/26/lessons-from-europe/image00-2/" rel="attachment wp-att-28923"><img class="size-medium wp-image-28923" alt="image00" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/image00-300x185.png" width="300" height="185" /></a><a href="http://www.altdevblogaday.com/2012/12/26/lessons-from-europe/image01/" rel="attachment wp-att-28924"><img class="size-medium wp-image-28924 aligncenter" alt="image01" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/image01-300x185.png" width="300" height="185" /></a><a href="http://www.altdevblogaday.com/2012/12/26/lessons-from-europe/image02/" rel="attachment wp-att-28925"><img class="size-medium wp-image-28925" alt="image02" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/image02-300x185.png" width="300" height="185" /></a></p>
<p>The reason for the lateness of this post and the original self examination which triggered this exploration was an honest peeling away of my own fate and career. Since leaving Mere-Mortals I have not published work of which I am proud, that is not to say I haven&#8217;t worked on amazing things but they just will not see the light of day for a range of reasons, or when they finally do surface I shall not be credited.</p>
<p>Prompted by this situation a good friend whose creative ability and integrity I trust offered me an chance at a large publisher studio which sounded exciting. Much more exciting to me was a chance to turn my currently long distance relationship of almost 3 years into a no-distance relationship. So I packed my bags and moved to Europe with a healthy relocation package in the offering.</p>
<p>When I arrived the situation on the ground was very different. On day one I found out the project had changed from a traditional boxed console product to a free-to-play title. No-one&#8217;s fault, things change.</p>
<p>Now the &#8220;sensible&#8221; thing to do would have been hold out in Europe in a well paid job, cash in the relocation package and enjoy my relationship. This while creating a style of game I have morale issue with and not being able to express myself in the hopes of a relocation or change of circumstance. This is what I like to call &#8220;existing while waiting to live&#8221;, I have made a similar mistake in the past and refused to repeat it and possible watch my relationship and happiness fall to pieces over it.</p>
<p>So I swallowed what looks to be over £2000 in loss, cancelled my contract 3 days in on moral grounds and returned to the UK. There my previous employer welcomed me back in the most awesome way, way to go Climax. The only part of which I regret being the fact that my relationship is once again long distance.</p>
<p>On my first weekend back in the UK I found myself in my old flat living out of a suitcase, sleeping on the floor next to my heater cuddled in a blanket making a game in 48 hours on my chromebook with my phone providing internet. I was happy. It really doesn&#8217;t take much to create and make games and that&#8217;s what I enjoy doing.</p>
<p>My experience in Europe has taught me many things. Firstly that free-to-play, while a nuanced topic, will not resolve nicely if we stand on the sidelines. As opponents to it we need to actively offer alternatives to help shape it and lobby for a future without exploitation. Non-participation will not work when companies make the kinds of profits they are currently making.</p>
<p>The industry is secondary to the products it creates. It is a process and machine which aids the creation of games, but games can be created without it. To serve the industry as an end rather than a means to an end is raising the process above the product. Do not glorify the industry for its own sake.</p>
<p>Finally on a personal note I am an entertainer and a creator. I will make games, plays, art, things, watchmacallits and thingymajigs because I enjoy it. I want to enhance the world in some small way through entertainment or education. Yes I have bills to pay, making money is not bad, free-to-play is not evil but the games come first and should be a positive force, not a commercial parasite to maximise profit. To this end I’ve committed to the One Game a Month project for 2013 and to advance the conversation around Free-to-Play with my personal voice I will be launching a project in the new year.</p>
<p>My name is Claire, I make things to feel better about the world and improve it. This is my goal and purpose.</p>
<p>Happy New Years</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/12/26/lessons-from-europe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Four meditations on bad design decisions</title>
		<link>http://www.altdevblogaday.com/2012/12/11/four-meditations-on-bad-design-decisions/</link>
		<comments>http://www.altdevblogaday.com/2012/12/11/four-meditations-on-bad-design-decisions/#comments</comments>
		<pubDate>Tue, 11 Dec 2012 15:25:12 +0000</pubDate>
		<dc:creator>Niklas Frykholm</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28847</guid>
		<description><![CDATA[<p>I&#8217;ve recently been doing a major rewrite of one of our core engine systems, the graph that we use for our visual scripting language <em>Flow</em>. Taking it from something that looks like this:</p>
<p><a href="http://www.altdevblogaday.com/2012/12/11/four-meditations-on-bad-design-decisions/" class="more-link">Read more on Four meditations on bad design decisions&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve recently been doing a major rewrite of one of our core engine systems, the graph that we use for our visual scripting language <em>Flow</em>. Taking it from something that looks like this:</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-old-flow.png"><img src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-old-flow-300x164.png" alt="" width="300" height="164" class="aligncenter size-medium wp-image-28852" /></a></p>
<p>To something that looks like this:</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-new-flow.png"><img src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-new-flow-300x154.png" alt="" width="300" height="154" class="aligncenter size-medium wp-image-28851" /></a></p>
<p>A major rewrite like this is always a humbling experience. When you have to rewrite your own code, every bad decision you made comes back to haunt you. And you don&#8217;t have anybody else to blame them on.</p>
<p>As if facing your own inadequacy wasn&#8217;t enough &#8212; rewriting an existing system is always harder than writing one from scratch. When you write a new system you start with a blank slate and can do whatever you want. When you rewrite, you are constrained by what the old system did &#8212; at least if you want to maintain any kind of backwards compatibility.</p>
<p>In addition, a new system can be written iteratively. You can start with a very small, simple system, release early and get feedback. Based on that feedback you can tweak the system. You don&#8217;t have to think about adding features until you have a good stable base.</p>
<p>When you are doing a rewrite you can&#8217;t release the new system until it is <em>at least as good</em> as the old one. Otherwise, your users will question why you have spent all that time working on a system that is <em>worse</em> than what you had before. And they will be right.</p>
<p>So a rewrite forces you away from the comfortable land of early releases and quick iterations and into the ugly old waterfall model.</p>
<p>With the power of hindsight, I&#8217;d like to reflect a bit on four design mistakes I made when I wrote the first version of the system that made this rewrite a lot harder than it could have been.</p>
<h2>Don&#8217;t use strings for non-text things</h2>
<p>Strings have one really good use &#8212; to hold pieces of text that either gets displayed to or inputted by the user. All other use of strings should be regarded as suspicious.</p>
<p>Strings are scary because they are both ambiguous and powerful. Does &#8220;a/b.txt&#8221; and &#8220;A//b.txt&#8221; represent the same path? Hard to tell. But maybe you can use case conversion, search and replace and some regular expression monstrosity to figure that out.</p>
<p>If you are doing that kind of string manipulation in any part of the code that is not directly related to user input or output, it is a clear warning sign that your code might be too &#8220;stringified&#8221;.</p>
<p>The most obvious example stringified code is the use of &#8220;stringly typed&#8221; data, for example, storing a date as the string &#8220;2012-12-09&#8243;. But the problem with strings can also manifest more subtle ways.</p>
<p>The original version of Flow used strings to identify connectors, both internally (as a representation of the connection) and visually (to show the name of the connector):</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-connector-name.png"><img src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-connector-name-300x260.png" alt="" width="300" height="260" class="aligncenter size-medium wp-image-28849" /></a></p>
<p>As a consequence, a Flow node couldn&#8217;t have two connectors with the same name, and a connector couldn&#8217;t be renamed (even visually) without breaking all existing connections.</p>
<p>In retrospect, rather than having a single <em>Name</em> property, it would be much better to have separate <em>Id</em> and <em>DisplayName</em> properties. The <em>Id</em> would be a <em>GUID</em> that uniquely identified the property, and the <em>DisplayName</em> would be a (localizable) name, suitable for displaying to the end user.</p>
<p>Using names/strings as identifiers has bitten me in other ways as well. In one system I knew that the names had to be unique (because that is how the script would refer to the objects) so I thought it would be safe to use them as identifiers. What I didn&#8217;t consider was that there could be situations when there <em>temporarily</em> were two objects that had the same name. For example, if the user had created a <em>rock</em> object, and wanted to create a <em>rock_small</em> object &#8212; as she was half-way through typing that name, there would suddenly be two objects named <em>rock</em>. This created problems for the system.</p>
<p>Lesson learned, I now avoid using strings as identifiers.</p>
<h2>When in doubt, you should opt-out</h2>
<p>Every system acquires features over time. That is good of course. Those features make the system more powerful and easier to work with.</p>
<p>But among the good features there are usually a few that don&#8217;t feel quite right. That don&#8217;t really fit into the design of the system. You can <em>do</em> them of course. You can do anything.</p>
<p>But usually it is best not to. Most of the time when I have added a feature that didn&#8217;t quite feel right, I have regretted it later. In retrospect it would have been better to try to find a different way of doing what the users wanted that was more natural to the ideas behind the system.</p>
<p>An example: Users of Flow wanted some way to specify the order in which events were triggered, when multiple connections are connected to the same <em>Out</em> connector.  This is needed in some situations, for example you may want to make sure that a unit is spawned before it is used.</p>
<p>In the old version of Flow, this was implemented with a context menu on the connection where you could select if it should be a &#8220;Do First&#8221;, &#8220;Do Last&#8221; or &#8220;Do Normal&#8221; connection.</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-do-first.png"><img src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-do-first-300x230.png" alt="" width="300" height="230" class="aligncenter size-medium wp-image-28850" /></a></p>
<p>This solution never felt 100 % right to me. It was hard to find a good intuitive way to visually represent the &#8220;Do First&#8221; and &#8220;Do Last&#8221; connections, and as a result the Flow graphs became harder to understand. </p>
<p>In retrospect, it would have been much better to avoid this feature and wait until I had come up with the more elegant alternative: a sequence node that triggers each of its outputs sequentially:</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-sequence.png"><img src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-sequence-300x241.png" alt="" width="300" height="241" class="aligncenter size-medium wp-image-28853" /></a></p>
<h2>Be explicit or you&#8217;ll miss it</h2>
<p>Writing code where a lot of things happen implicitly feels great &#8212; to begin with. It is amazing how much you are able to do with just a few lines of code.</p>
<p>But in my experience, implicit code almost always ends up more costly in the long run. It is harder to understand, harder to debug and harder to change. It tends to lock you down in a &#8220;local minimum&#8221; that can be tricky to come out of.</p>
<p>In Flow, a lot of things are done implicitly. The definition of a Flow node is just a simple C# class:</p>
<pre>[Category("Animation")]
public class AnimationEvent : Node
{
    public InVariableUnit Unit;
    public StringVariable Event;
    public InEvent In;
    public OutEvent Out;
}</pre>
<p>Through reflection, Flow finds out the members in the class and their types and automatically generates Flow nodes for them. This process involves some ugly string processing (bad decision #1), such as stripping <em>In</em> and <em>Variable</em> from the type name to find the underlying type of members. Reflection is also used to serialize the graphs.</p>
<p>While it is nice to be able to express a node so concisely, there are also a lot of problematic consequences. For example, since the class names get serialized, we can&#8217;t change the names of classes or properties without breaking the ability to load old files. Also, we have to use some <em>really</em> ugly C# hacks to make sure that the reflection system always returns the members of a class in the order they are declared in the file (so that we can control the order of the connectors).</p>
<p>In retrospect, it would been much better to avoid all this clever reflection stuff and instead just define the node types in configuration files.</p>
<h2>Avoid the road of complex code</h2>
<p>There is some code that needs to be complex, because it is dealing with fundamentally tricky stuff (like computational geometry) or because it needs to run <em>really</em>, <em>really</em> fast. But in all other cases, complexity is just a cost.</p>
<p>If your code starts to feel complex and hard to keep track of, it is a sign that you are probably doing something wrong. And if you are not careful, you may lock yourself in, so that when you write the next version of the system, you have to recreate all that complex behavior in your new, simpler system. You have to deliberately make your code uglier.</p>
<p>The old version of Flow had a way of &#8220;folding&#8221; nodes. You could select a number of nodes, group them, and then &#8220;fold&#8221; the group, collapse it to a single node.</p>
<p>The system had a lot of really hairy code for dealing with this. The code takes a bunch of nodes and creates a new node from them, with connectors matching only the external connectors of the collapsed nodes. it also keeps track of the internal nodes and their connections so they can be recreated if the node is later &#8220;expanded&#8221;.</p>
<p>As you might imagine, this was complicated further by the need for connector names to be unique (see bad decision #1), which meant that some of the external connectors in the new node had to be renamed (since they could come from different internal nodes that had connectors with the same name). So a mapping table was needed to keep track of these renames. Obviously a bad idea, but once you have started down the path of wrongness, it can be hard to turn around.</p>
<p>The new version handles this a lot better. Collapse and expansion is just a visual feature. There are no new nodes created and no other strange things happening to the data, the visualizer just chooses to draw the data in a different way when it is collapsed. In retrospect, that is a much better choice.</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-collapsed.png"><img src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/meditations-collapsed-300x104.png" alt="" width="300" height="104" class="aligncenter size-medium wp-image-28848" /></a></p>
<pre>That is all, four simple lessons
to guide your future coding sessions
now let your code be light and merry
until its time for Charon's ferry</pre>
<p>This has also been posted to <a class="link" href="http://bitsquid.blogspot.com">The Bitsquid blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/12/11/four-meditations-on-bad-design-decisions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Internet for free-samples gaming</title>
		<link>http://www.altdevblogaday.com/2012/12/10/using-the-internet-for-free-samples-gaming/</link>
		<comments>http://www.altdevblogaday.com/2012/12/10/using-the-internet-for-free-samples-gaming/#comments</comments>
		<pubDate>Mon, 10 Dec 2012 15:52:46 +0000</pubDate>
		<dc:creator>Colt McAnlis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28829</guid>
		<description><![CDATA[<p>&#160;</p>
<p style="text-align: center"><strong></strong><strong><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/free-samples.jpg"><img class="aligncenter size-medium wp-image-28831" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/free-samples-300x201.jpg" alt="" width="300" height="201" /></a><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/free-samples.jpg"><br />
</a></strong></p>
<p><strong></strong><strong><br />
</strong></p>
<h1>Why Free Samples Work</h1>
<p>Every week or so, I walk into my local <a href="http://www.costco.com/">Costco</a> and talk to Meredith, who politely offers me a taste of whatever food she’s providing free samples of that day. Luckily for me, last week was chicken nugget week, and Meredith’s food cart was conveniently standing in front of a huge display of chicken nugget bags. Within 4 feet, I could try the free sample, and if I liked it, grab the bag to purchase.</p>
<p><a href="http://www.altdevblogaday.com/2012/12/10/using-the-internet-for-free-samples-gaming/" class="more-link">Read more on Using the Internet for free-samples gaming&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p style="text-align: center"><strong><strong><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/free-samples.jpg"><img class="aligncenter size-medium wp-image-28831" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/free-samples-300x201.jpg" alt="" width="300" height="201" /></a><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/free-samples.jpg"><br />
</a></strong></strong></p>
<p><strong><strong><br />
</strong></strong></p>
<h1>Why Free Samples Work</h1>
<p>Every week or so, I walk into my local <a href="http://www.costco.com/">Costco</a> and talk to Meredith, who politely offers me a taste of whatever food she’s providing free samples of that day. Luckily for me, last week was chicken nugget week, and Meredith’s food cart was conveniently standing in front of a huge display of chicken nugget bags. Within 4 feet, I could try the free sample, and if I liked it, grab the bag to purchase.</p>
<p>Costco has used the free sample approach for as long as I can remember, because they understand the need to entice shoppers to new products. Shoppers generally walk into a store with a shopping list, and they are numb to discovery of new products that are not on their list. This lack of interest makes sense from a consumer standpoint: Why should someone invest money in a new product that they know nothing about, especially when their old chicken nuggets taste just fine? <a href="http://www.sethgodin.com/sg/">Seth Godin</a>, a fellow <a href="http://www.thedailyshow.com/watch/thu-august-16-2012/rob-corddry">bald guy</a>, describes this principle in his TED talk about <a href="http://www.youtube.com/watch?v=V82OwyF_vBg">purple cows</a>:</p>
<blockquote>
<p dir="ltr"><em>Consumers don’t care about you at all, they just don’t care. Part of the reason is that they have way more choices than they are used to, and way less time; and in a world where we have too many choices and too little time, the obvious thing to do is ignore stuff.</em></p>
</blockquote>
<p><strong><strong><br />
</strong></strong>Game development today is dominantly focused on mobile, and with a <a href="http://venturebeat.com/2012/10/30/android-ios-number-of-apps/">total app footprint topping 1.4 million</a>, it’s safe to say that most users have too many choices and too little time. This is why mobile app stores are so fervently fought over: They tell users what to pay attention to, and without that prompting, apps can easily languish.</p>
<p>The question for you as a game developer, then, is how to get noticed in these ecosystems and make your app rise above the noise. In this context, many developers have come to the realization that cost is an added barrier to entry. This realization has led to the development of <a href="http://en.wikipedia.org/wiki/Freemium">freemium</a> applications, which are now a <a href="http://www.gamasutra.com/blogs/TylerYork/20120920/178048/Why_Freemium_is_Dominating_Mobile.php">dominant revenue stream</a>. Even developers of premium applications produce free-trial equivalents in app stores, offering a familiar nod back to our <a href="http://www.doomworld.com/pageofdoom/shareware.html">shareware roots</a>. The proof is there: Users are more willing to try something if it’s free.</p>
<p>As a game developer, then, you should be providing free samples of your game, not just in app stores, but to every human on the planet. For years, game developers have focused on making their apps available on as many platforms as possible. Digital distribution services do offer an opportunity to provide a free version of your content, but silo barriers still filter out many of the potential users that would otherwise seek to discover your content. Supporting multiple platforms also comes with an implicit resource cost, which at some point raises the issue of <a href="http://en.wikipedia.org/wiki/Diminishing_returns">diminishing returns</a> and <a href="http://en.wikipedia.org/wiki/Region_of_interest">Region of Interest</a>.</p>
<p>&nbsp;</p>
<h1>The Ultimate Free-Candy Platform: The Internet</h1>
<p>As a platform, the web provides an unbounded opportunity for game developers to reach out and engage with potential users. The viral nature of the Internet hasn’t diminished with time; in fact it has accelerated. Consider as an example the launch of the game <a href="http://penny-arcade.com/report/editorial-article/a-pregnancy-an-enthusiastic-editor-and-the-worst-name-ever-the-unlikely-suc">10000000</a>. Eli Hodapp, the editor-in-chief of TouchArcade, quickly found and fell in love with the game. As was reported:</p>
<p>&nbsp;</p>
<blockquote>
<p dir="ltr"><em>The speed of all this is remarkable: It only took a few hours for the community to begin talking about the game, which alerted Hodapp to its existence, and he gave it a shot and played through the day. His review went live that evening, less than 12 hours after the game had been released, and before anyone else in the industry was aware of it.</em></p>
</blockquote>
<p><strong><strong><br />
</strong></strong>Hodapp then went on to quickly tell his friends about the app, even buying some a copy so they could try it.</p>
<p style="text-align: left">That type of quick uptake and social championing confirms the results of a large <a href="http://www.gamasutra.com/view/news/178516/Research_How_mobile_players_find_new_games_to_play.php#.UIqe9Uq-iHM">research study</a> that analyzed how mobile users discover new content. Not surprisingly, the two dominant sources through which users found out about new content were social channels and friends groups; on-mobile stores were in 3rd place in the study.</p>
<p style="text-align: center"><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/12/howfind.jpg"><img class="aligncenter size-medium wp-image-28832" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/howfind-300x140.jpg" alt="" width="300" height="140" /></a></p>
<p>This trend has been confirmed by other studies as well. Google’s own <a href="http://www.thinkwithgoogle.com/insights/">Research Division</a> produced a great <a href="http://www.thinkwithgoogle.com/insights/library/studies/understanding-the-modern-gamer/">case study</a> showing that game players are more attached to the web for their discovery/purchasing options. They also retain the connection to the web post-purchase, looking to extend their experience through multiple channels.</p>
<p>As an industry, we’ve seen web-based success stories play out frequently. Minecraft started as a <a href="https://minecraft.net/play">Java application played in a browser</a>. That web presence let players experience and share the content quickly, and enabled the developer to raise over <a href="http://www.escapistmagazine.com/news/view/103385-PayPal-Freezes-750K-in-MineCraft-Devs-Account">$700k in user-contributed funds</a> to help finish the game (a task done way before Kickstarter was around).</p>
<p>The HTML5 game <a href="http://chrome.bouncymousegame.com/">Bouncy Mouse</a> illustrates another great example of how to use the free-candy web. Their <a href="http://www.html5rocks.com/en/tutorials/casestudies/munkadoo_bouncymouse/#toc-monetization">case study</a> shows that the web version of their game not only generates revenue, but also gives them the ability to leverage the reach and ease-of-discovery aspects of the web to help drive users to the mobile versions of the game.</p>
<p>Other games, like <a href="https://chrome.google.com/webstore/detail/airmech/hdahlabpinmfcemhcbcfoijcpoalfgdn?utm_source=chrome-ntp-icon">Air-Mech</a> and <a href="https://chrome.google.com/webstore/detail/dont-starve/hiledapehlkhdehbhppgmekfalnlfajc?utm_source=chrome-ntp-icon">Don’t Starve</a>, have taken advantage of the web’s reach and ease-of-access to offer early beta builds of the games to a large user base, iterating and making improvements before doing bigger launches in other digital distribution locations.</p>
<p>And on a personal note, I quickly backed funding support for <a href="http://www.desktopdungeons.net/">Desktop Dungeons</a> after I found  the game and played a <a href="http://www.desktopdungeons.net/HTML5/">lightweight version of it in HTML5</a>. Which I highly suggest you do too.</p>
<p>&nbsp;</p>
<h1>How to Make Free Candy</h1>
<p>Creating a web version of your game is <a href="http://martinfowler.com/bliki/TwoHardThings.html">not an easy engineering task</a>, but it’s far from impossible. Modern web technologies are easily capable of running high quality games in a browser. With a little effort you can put those technologies to work for you.</p>
<p><strong><strong><br />
</strong></strong></p>
<h2>Overcome the Language Hurdle</h2>
<p>Converting C++ to HTML5 is one avenue that simple 2D games like <a href="https://chrome.google.com/webstore/detail/angry-birds/aknpkdffaafgjchaibgeefbgmgeghloj?utm_source=chrome-ntp-icon">Angry Birds</a>, <a href="https://chrome.google.com/webstore/detail/fishing-joy/mlonhgnjdlnjgalpdigmbpfpielpadmc?utm_source=chrome-ntp-icon">Fishing Joy</a>, <a href="https://chrome.google.com/webstore/detail/cut-the-rope/gkddaofiamhgfjmaccfcfpfolpgbeomj?utm_source=chrome-ntp-icon">Cut The Rope</a>, and <a href="https://chrome.google.com/webstore/detail/bouncy-mouse/cgdllcbmneiklcmbeclfegccdjholomb?utm_source=chrome-ntp-icon">Bouncy Mouse</a> have followed. A straight port may be cumbersome, but you can fill in the gaps with a technologies like <a href="https://github.com/kripken/emscripten">emscripten</a>, which help maintain a game’s look-and-feel while providing decent performance.</p>
<p>For more complex games, you can use new technologies like <a href="http://www.gonacl.com/">Native Client</a> that let you run your existing C++ code in a web page. <a href="http://beta.coreonline.com/lara-croft-guardian-of-light/">Lara Croft and the Guardian of Light</a> is one example of a full console game that runs right in Chrome—Native Client let the developer leverage their existing code and content in their migration to the web.</p>
<p><a href="http://unity3d.com/">Unity</a> developers have the option to export a web version of their game that users can play with a browser plugin. As a bonus, in the <a href="http://google.com/chrome">Chrome</a> browser, <a href="http://www.gonacl.com/">Native Client</a> eliminates the need for users to install anything.</p>
<p>New languages like <a href="http://haxe.org/">Haxe</a> provide an interesting middle ground. Haxe is a language that you can use to generate language-specific code for your desired platform, including <a href="http://haxe.org/doc#targets">C++, Objective-C, JavaScript, and Flash</a>. With Haxe, you can write your entire game in one meta-language, and generate platform-specific builds as you see fit, each one optimized for performance and features post-Haxe-conversion.</p>
<p>&nbsp;</p>
<h2>Optimize for the Web</h2>
<p>Once you’ve addressed the initial issues in creating a web build, you must make sure that your game translates over to a web experience properly. Specifically, make sure that you:</p>
<ul>
<li>Use <a href="http://www.youtube.com/watch?v=huXucPChX3g">best practices for developing web games</a>.</li>
<li>Take into account <a href="http://www.altdevblogaday.com/2012/10/22/cover-your-assets-the-cost-of-distributing-your-games-digital-content/">how to transfer digital assets</a>.</li>
<li>Collect <a href="http://mainroach.blogspot.com/2012/03/reporting-errors-from-your-web-app.html">error feedback from users in the wild</a>.</li>
</ul>
<p><strong><strong><br />
</strong></strong>Once your game is live on the web, make sure that you allow users everywhere to experience it, and give them easy and incentivised means to <a href="http://mainroach.blogspot.com/2012/05/post-game-achievements-to-your-g-stream.html">share the game with their friends</a>.</p>
<p>Most importantly, make sure that you take full advantage of your web presence by adding <a href="http://www.coolinfographics.com/blog/2009/1/12/halo-3-heatmaps.html">deep user-metric tracking</a> to understand your users better, and implementing <a href="http://www.smashingmagazine.com/2010/06/24/the-ultimate-guide-to-a-b-testing/">A/B testing</a> to <a href="http://www.wired.co.uk/magazine/archive/2012/01/features/test-test-test?page=all">collect information</a> about how users play your game. With that type of information, you can gain enough statistical data to determine which design elements in your game work, which ones don’t work, and which ones do the best job at funneling users from free-candy samples to premium  purchases.</p>
<p>&nbsp;</p>
<h1>Start Making Candy!</h1>
<p>The Internet is all about free content, social channels, and going viral. By using a few key pieces of technology, you can quickly generate a web-based build of your game to help drive user adoption and provide a base platform for marketing and viral social media. Give users some free candy, and they will happily buy the <a href="http://www.steak-enthusiast.com/2010/06/8-of-the-most-expensive-cuts-of-beef-you-never-knew-you-had-to-have/">Kobe steak</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/12/10/using-the-internet-for-free-samples-gaming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Marketing Outside the Box</title>
		<link>http://www.altdevblogaday.com/2012/12/05/marketing-outside-the-box/</link>
		<comments>http://www.altdevblogaday.com/2012/12/05/marketing-outside-the-box/#comments</comments>
		<pubDate>Wed, 05 Dec 2012 02:07:13 +0000</pubDate>
		<dc:creator>Alex Norton</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28808</guid>
		<description><![CDATA[<p>So, as an indie developer new to the scene, the thought of marketing <a href="http://www.malevolencegame.com/" target="_blank">my game</a> has proven to be a daunting one. There are many avenues for marketing available through third parties, but indies rarely have the money for that sort of thing.<br />
<a href="http://joostdevblog.blogspot.nl/2012/11/the-indie-marketing-plan.html" target="_blank">Many</a> <a href="http://blog.wolfire.com/2009/03/5-indie-pr-tips-from-wolfire/" target="_blank">excellent</a> <a href="http://gillen.cream.org/wordpress_html/assorted-essays/how-to-use-and-abuse-the-games-press-and-how-the-games-press-wants-to-use-and-abuse-you/" target="_blank">blog</a> <a href="http://christophermpark.blogspot.com.au/2010/07/wearing-multiple-hats-is-tough-and-pr.html" target="_blank">posts</a> before have gone into the various ways in which an indie can get their product out there on the cheap, but I want to talk about going a little bit deeper, and tell how you can use gamer psychology to your advantage to do a lot of your marketing for you.</p>
<p><a href="http://www.altdevblogaday.com/2012/12/05/marketing-outside-the-box/" class="more-link">Read more on Marketing Outside the Box&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>So, as an indie developer new to the scene, the thought of marketing <a href="http://www.malevolencegame.com/" target="_blank">my game</a> has proven to be a daunting one. There are many avenues for marketing available through third parties, but indies rarely have the money for that sort of thing.<br />
<a href="http://joostdevblog.blogspot.nl/2012/11/the-indie-marketing-plan.html" target="_blank">Many</a> <a href="http://blog.wolfire.com/2009/03/5-indie-pr-tips-from-wolfire/" target="_blank">excellent</a> <a href="http://gillen.cream.org/wordpress_html/assorted-essays/how-to-use-and-abuse-the-games-press-and-how-the-games-press-wants-to-use-and-abuse-you/" target="_blank">blog</a> <a href="http://christophermpark.blogspot.com.au/2010/07/wearing-multiple-hats-is-tough-and-pr.html" target="_blank">posts</a> before have gone into the various ways in which an indie can get their product out there on the cheap, but I want to talk about going a little bit deeper, and tell how you can use gamer psychology to your advantage to do a lot of your marketing for you.</p>
<p>But before we go into that, the first thing that an indie developer really needs to do is to have their product displayed in as many places as possible. When starting work on <a href="http://www.malevolencegame.com/" target="_blank">Malevolence</a> I started out with just a simple <a href="http://swordofahkranox.blogspot.com.au/" target="_blank">BlogSpot account</a> and did all of my updates on there. Guess how many people cared? None. And why should they? How could they even FIND the blog unless they were told about it?</p>
<p>Take a search engine like Google. It has a &#8220;crawler&#8221; that goes around the web, finding pages, and finding all of the links on those pages. It analyzes where the links link to, and finds which pages have lots of links heading to them. If a page has hundreds of other pages linking to it, and lots of visitors, then it must be important, right? Well, to make your game more visible, you need to have lots of people visiting your page &#8211; a bit of a catch 22 &#8211; but you can help it by having a presence in many different places. Oh, and good news everyone&#8230; The Internet has many, many viable, justifiable places where you can put your game on show.</p>
<p>For Malevolence, the first big step after BlogSpot was to create a profile on <a href="http://www.indiedb.com/games/malevolence-the-sword-of-ahkranox" target="_blank">IndieDB</a>/<a href="http://www.moddb.com/games/malevolence-the-sword-of-ahkranox" target="_blank">ModDB</a> (creating a profile on one creates one on other other, too). They get quite a lot of traffic on there, and it will actually rank your game against others (a library of about 6000 games) in terms of how much traffic you get. It also rewards your dedication to the public by putting you on the front page whenever you write up a new update post. Given the way it works, and the attention that it gets, it&#8217;s very much worth taking the time to make your profile page attractive and thorough. That&#8217;s where a bit of the psychology comes in. I have noticed that gamers who browse ModDB for new indie games are a little bit like channel surfers. They flick through profiles quickly &#8211; bam bam bam &#8211; until they find one that appeals to them very quickly, and then they&#8217;ll stop and take a deeper look. So having lots of nice, bright screenshots, thorough videos and lots of clear, solid information about your game readily accessible for them will entice them to stay and take a proper look at your game.</p>
<p>Once you notice that you&#8217;re getting more traffic, you can make a move towards putting links on your IndieDB/ModDB profile to other networks that you&#8217;re operating on. Some examples of which include YouTube channels, Facebook Fan-pages, Twitter accounts, etc. Any and all are good. Just be sure to make the links subtle. Some nice clean icons, perhaps. Gamers, I have found, dislike feeling like they are being bombarded. Do some research, take some time, look at successful pages and the way they&#8217;ve done things. It pays off.</p>
<p>The social media avenue was the next step for me with Malevolence. It started with a <a href="http://www.youtube.com/CumQuaT1337" target="_blank">YouTube channel</a> where I would make a point to do screen-captures fairly regularly showing the progress of the game&#8217;s development. Many people either don&#8217;t enjoy or don&#8217;t have the time to sit down and read lengthy blog posts (he says in a lengthy blog post) and a nice, quick video can get the whole point across much faster and with more of a sense of interaction. Even taking the time to narrate the video can easily double or triple the amount of information translated in the same time frame. Things to think about there.</p>
<p>After that came the <a href="http://www.facebook.com/MalevolenceGame" target="_blank">Facebook</a> and <a href="https://twitter.com/#%21/SwordOfAhkranox" target="_blank">Twitter</a>. I actually expected these to be the most active of the network avenues for promoting the game, but in the end they fell into roles of keeping CURRENT fans up to date, and didn&#8217;t really do much to draw new fans. Though it seems obvious now, it took me a while to work out why this is. Most people on Facebook and Twitter these days use them on their smartphones, rather than their computer. While it <em>IS </em>possible to go browsing for new content via the smartphone interfaces, they are much more designed to just keep up with what their already follow. That&#8217;s not to say that you can&#8217;t still make use of these avenues though, as they offer quick and easy mini-update portals for you to address your current fan-base en-masse, and quickly spread links to any major blog updates you do elsewhere.</p>
<p>For the longest time, Steam was one of the holy grails of indie games &#8220;making it&#8221; and <a href="http://steamcommunity.com/greenlight/" target="_blank">their new Greenlight process</a> has taken that from some dark, incomprehensible process to something more tangible. As soon as it went live I create <a href="http://steamcommunity.com/sharedfiles/filedetails/?id=93060707" target="_blank">a profile for Malevolence</a> on there thinking &#8220;wow, I might be in for a chance&#8221;, and things went fairly well for a time, but then started petering off quick quickly. Valve kept altering and adjusting the vote process for getting games approved and it was quite drastically affecting my game&#8217;s ability to get noticed on there. It&#8217;s been quite frustrating until it got me thinking&#8230; How WOULD you make an unbiased system for gauging a game&#8217;s popularity in the middle of a firmly established community of over 50 million users? The more I think about it, the more complex it becomes in my head. Sure, I have lots of problems with the way the Greenlight process works, however, since I can&#8217;t come up with a better one myself, I&#8217;m happy to leave it up to them to sort out. I&#8217;ve had many heated discussions with fellow developers about how the system should work&#8230; Mainly about the apparent pointlessness of having a &#8220;no vote&#8221; button (which I&#8217;m sure will create some lovely &#8216;discussions&#8217; in the comments) however, as I said, I&#8217;m happy to leave the process up to Valve, as they would certainly know best. Of all the networks I&#8217;ve gotten Malevolence onto, that&#8217;s the only one that hasn&#8217;t really gone anywhere yet. As the owner of it I can watch the percentage of votes go up and down, and I can&#8217;t really make sense out of it, so I&#8217;ll just keep doing what I&#8217;m doing and hope for the best. The only advice I could give to other indies attempting it would be to make sure that all of your avenues (Facebook, IndieDB, dev blogs, etc) point to your Greenlight so that you can funnel as much of your traffic into it as possible.</p>
<p>HOWEVER, all of that only depends on how badly you want to get onto Steam. I&#8217;m aware that some people don&#8217;t. Some because they just don&#8217;t like how Steam operates, others because they&#8217;re making mobile games and it&#8217;s kind of useless to them. I, personally, am trying to get on there, but that doesn&#8217;t mean that everyone SHOULD.</p>
<p>But I digress. What about the psychology mentioned earlier? Well, that is where your marketing plan comes from. Just sticking your product on some blogs and social network sites isn&#8217;t really a marketing plan. It&#8217;s just a means to give your game a &#8216;presence&#8217; on the Internet. A solid presence is a powerful thing, but it takes constant maintenance. It&#8217;s not something you can set and forget until you have a large, strong, dedicated community to do it for you. As an indie, that&#8217;s just not something that&#8217;s likely to happen straight up, so it&#8217;s something you&#8217;re going to have to do yourself. KEEP your blogs updated. RELEASE lots of screenshots. RECORD lots of videos. ANSWER lots of questions, and above all, MAKE SURE that your community is reminded regularly that you are still working on your game, lest they lose interest.</p>
<p>But what about expanding your community? That&#8217;s where your marketing plan comes into play. You&#8217;ve got your presence sorted out, you&#8217;re maintaining it well, but how do you bring new people in? That, in itself, depends on many different things:</p>
<p>TARGET AUDIENCE: What is the target audience for your game? You can&#8217;t just say &#8220;gamers&#8221; because not all gamers like tower defence games. Not all gamers like FPS games. Not all gamers like RPGs. And then, even within the types there are sub-types. In the RPG player genre there are gamers who like first person RPGs, but don&#8217;t necessarily like isometric RPGs or turn-based RPGs. So it&#8217;s a matter of specificity. Take the time to work out precisely what your target audience is with your game and market mainly towards them. There&#8217;s not much use in wasting energy trying to talk to people who aren&#8217;t interested in listening!</p>
<p>ANALYZE: Take the time to analyze the way your target audience acts. Do they talk amongst themselves? Do they operate vocal communities? Is theirs a community of sharing, or of bragging? As an overly abrupt stereotype, FPS gamers tend to have communities that are much more vocal and aggressive than communities of RPG games. I realise that&#8217;s a massive generalization, and it is most certainly not ALWAYS the case, but if you look into how the communities of your target audience operate, you can use it to your advantage when creating your marketing plan.</p>
<p>ACT AND REACT: As an indie, much of what you learn, you will learn on the fly. If you make a marketing faux pas, you will learn about it pretty quickly. Try not to be too stubbourn about things. While it can be trying at times, an indie game without fans/players, is nothing. It&#8217;s like owning a coffee shop that has no customers. Don&#8217;t be too hard-headed to change the way you operate if it&#8217;s something small and it keeps people happy. You need to be adaptive, you need to listen and you need to communicate.</p>
<p>So, with these things, you can create your marketing plan. As an example, my marketing plan for Malevolence was to make use of the RPG communities idiosyncrasies. I did my research, joining forums and following blogs, doing the whole Jane Goodall thing and &#8220;living with the apes&#8221; so to speak (not calling RPG players apes, by the way. Just using a metaphor) and I found that a common trait among them is that they are excited about indie RPG development and will quite often share links to interesting indie RPG projects that they find. BUT, at the same time, while there is a lot of link sharing going on, there isn&#8217;t much response to it. Many RPG forums will have an entire section just for sharing indie RPGs that people have found. These sections are often filled with lots of posts with links, but the posts won&#8217;t often have many responses. That doesn&#8217;t mean that people don&#8217;t follow the links, but it means that there is more excitement about sharing the links than there is about the games themselves. RPG fans seemed excited about the IDEA of new RPGs, which is cool.</p>
<p>I made a note of this and built my strategy around it. I planned to start my marketing push at the same time that Skyrim came out. Sounds crazy, right? Well, there was reason behind my madness. I started pushing the links to my various blogs, etc, on forums and other hubs while people were busy getting fussy over Skyrim. The community saw my links and shared them around, but, as expected, not much action happened other than the spreading of the links. Because of this, there ended up being many, many sites with references to this infinite indie RPG. As it spread, more people heard about it, but they didn&#8217;t focus on it because&#8230; Hey&#8230; Skyrim&#8230; But that was precisely my plan.</p>
<p>The excitement over every game, no matter how groundbreaking the game was, eventually wears off, and once the attention for Skyrim had started to dim, I was in the position where links to my game were ALL OVER the Internet, and a vast portion of the RPG community had heard something about it. Even if they couldn&#8217;t recognise it by name, when someone mentioned &#8220;Have you heard about Malevolence, that infinite indie RPG being made&#8221; more often than not they would be met with a reaction of &#8220;I think I heard something about that, yeah&#8230; Can&#8217;t remember where though.&#8221;</p>
<p>This is where the psychology of my marketing plan came in. Having another person bring it up makes them remember seeing it somewhere which inspires them to look for it again. They hit the search engines and start typing in the word &#8220;Malevolence&#8221; since they have no idea how to spell &#8220;Ahkranox&#8221; and, since I have made an effort to have a VERY strong web presence, they see this:</p>
<div></div>
<div><a href="http://4.bp.blogspot.com/-QMG92TlQd6Y/UL6mTNlN6gI/AAAAAAAABs4/2438G4NfyHM/s1600/GoogleSearch.jpg"><img class="aligncenter" src="http://4.bp.blogspot.com/-QMG92TlQd6Y/UL6mTNlN6gI/AAAAAAAABs4/2438G4NfyHM/s320/GoogleSearch.jpg" alt="" width="320" height="266" border="0" /></a></div>
<p>They barely have started typing the word Malevolence, and it shows up. Marketing plan complete. That being said, they may go to the site, look at it and hate it. I unfortunately can&#8217;t help you with that. Marketing is one thing, but your product still needs to stand on its own. I was lucky enough to have this strategy work quite well for my game, but sometimes even the most well thought out strategy will fail. Not having a strategy at all, however, will pretty much guarantee that you&#8217;ll fall short, so start early!</p>
<p>But that&#8217;s where I&#8217;ll leave off, I think. In conclusion, when marketing your game, you need to take the time to establish a web presence, develop a marketing plan based on research and analysis of your target audience and attention to detail when looking into the psychology of the way they act as a community. Stick with it. If you believe in your game strongly enough, you won&#8217;t have too much difficulty in translating that to your viewership!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/12/05/marketing-outside-the-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Game Mentor Online</title>
		<link>http://www.altdevblogaday.com/2012/12/03/game-mentor-online/</link>
		<comments>http://www.altdevblogaday.com/2012/12/03/game-mentor-online/#comments</comments>
		<pubDate>Mon, 03 Dec 2012 15:53:12 +0000</pubDate>
		<dc:creator>Lisa Brown</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[mentoring]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=26733</guid>
		<description><![CDATA[<p><img class="alignright size-medium wp-image-28746" title="GMO-logo" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/GMO-logo-300x156.jpg" alt="" width="300" height="156" /></p>
<p>I have discovered that I have a passion for helping students and aspiring game developers learn more about the industry. Part of this is because I occasionally feel like I stumbled into this career, and feel compelled to educate young people about game development in hopes of inspiring other people who were like me (potentially saving them 8 years of figuring out what they want to do with their lives).  So far, my favorite outlet for student outreach has been <a href="http://gmo.chronus.com/p/main">Game Mentor Online</a>, an online service that matches up aspiring developers with industry professionals and facilitates one-on-one mentorships.</p>
<p><a href="http://www.altdevblogaday.com/2012/12/03/game-mentor-online/" class="more-link">Read more on Game Mentor Online&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-28746" title="GMO-logo" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/GMO-logo-300x156.jpg" alt="" width="300" height="156" /></p>
<p>I have discovered that I have a passion for helping students and aspiring game developers learn more about the industry. Part of this is because I occasionally feel like I stumbled into this career, and feel compelled to educate young people about game development in hopes of inspiring other people who were like me (potentially saving them 8 years of figuring out what they want to do with their lives).  So far, my favorite outlet for student outreach has been <a href="http://gmo.chronus.com/p/main">Game Mentor Online</a>, an online service that matches up aspiring developers with industry professionals and facilitates one-on-one mentorships.</p>
<h1>About the Program</h1>
<p>Game Mentor Online is an initiative that was kicked off by Women in Games International.  Originally concocted by Karen Clark and Sheri Graner Ray in 2006, its first form was a mailing list where mentors and mentees were able to link up and communicate.  The program was able to raise funds with the help of the IGDA Women in Games SIG to convert to an online mentoring software solution, which is how it has appeared since 2011.  Game Mentor Online is entirely volunteer-run and donation based.</p>
<blockquote><p><em>We have over 100 proteges and more than 60 mentors from all over the world, and we&#8217;ve had more than 100 mentor-protege pairings since moving to the new system</em></p>
<p><em>-Karen Clark</em><br />
<em> GMO Admin</em></p></blockquote>
<p>The main function of the site is as a sort of matchmaker, trying to pair up mentors and mentees, though there is a community area with member-posted articles and questions from proteges that any mentor can answer.  As a freshly signed-up mentor, you first fill out a profile with your skills, discipline, experience and match preferences (such as how many proteges you would like to mentor at a time).  It is the responsibility of the proteges to search through available mentors, though the system does suggest potential matches based on your profile information.  A protege will then contact a potential mentor, and the administrators can set up the mentorship.</p>
<p>Once a match is made, a mentoring area is created on the site for the connection, where you and your protege can post messages to one another and set goals.  At this point it is up to the two of you to decide how the mentorship will proceed.</p>
<h1>My Experience</h1>
<div id="attachment_28759" class="wp-caption alignright" style="width: 310px"><a href="http://twisted-devlog.blogspot.com/"><img class="size-medium wp-image-28759 " title="Screen Shot" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/Screen-Shot-300x225.png" alt="" width="300" height="225" /></a><p class="wp-caption-text">TRACED, a hacking-themed game, is my protege&#8217;s side project</p></div>
<p>My protege is an aspiring designer named Kaylin Norman.  He and I plan to meet and chat about every 2 weeks, give or take depending on both of our schedules, where we dedicate at least an hour to chat over Google Talk.  These sessions can range broadly in topics, but it can be anything from answering &#8220;Day in the Life of&#8221; questions, helping with his resume, giving feedback on his game projects, discussing design tips, and answering any question that Kaylin might have encountered in his most recent game design adventures.</p>
<p>How often and what form through which you mentor your protege is decided by both of you depending on your particular circumstances.  Some mentor/protege pairs prefer to do regular Skype sessions while others carry on their mentorship primarily through email exchange.   It&#8217;s very flexible, and the online site serves mostly to facilitate the mentor relationship and get it started in a natural direction.</p>
<h1>What you bring to the table</h1>
<p>Mentoring a student has given me a lot of insights of how much knowledge I have gained (and subsequently taken for granted) since working in the industry.  There have been several times in a discussion when I would answer a question or make a suggestion of something that had become so commonplace to me that I assumed it to be common knowledge, only to find that it provided an amazing insight and learning point for my protege.</p>
<p>Besides your own experience, you also indirectly provide your protege the advantage of your professional network.  A few times Kaylin has had a question or had a situation that I wasn&#8217;t sure I could give a lot of information on from my own experience, so instead I would take the question to my other friends and colleagues in the industry.  I&#8217;d often return to my protege with responses from multiple industry veterans that he would find invaluable to his own development as a designer.</p>
<p>As far as what you can get out of mentoring relationship, I&#8217;ve found mentoring Kaylin to be incredibly rewarding.  It&#8217;s made me very proud to see him grow as a designer, see him achieve academic goals and watch him work towards others.  On days where my job has been trying or I&#8217;ve been frustrated by a design problem, chatting with Kaylin and seeing his enthusiasm about design and hearing how he is progressing proves to be quite renewing.</p>
<h1>A Growing Program</h1>
<p><a href="http://www.flickr.com/photos/mtsofan/5992122733/"><img class="size-full wp-image-28747 alignleft" title="ducks" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/ducks.jpg" alt="" width="240" height="160" /></a></p>
<p>Game Mentor Online in its current form has been around for 1-2 years, and one of their most admirable traits is how open they are to feedback about the program.  Any time I&#8217;ve had a suggestion, the administrators have responded promptly with a plan on how they could incorporate the feedback.  They are very passionate and eager to grow and improve the program.</p>
<p>As I mentioned before, Game Mentor Online is very good at facilitating the beginning of a mentoring connection by providing a formal structure through which the mentor and protege can find their footing with one another.  But it seems to be common for pairs to move to other more standard means of communication once they establish a relationship.  I think this is certainly a good thing, but it does mean that the population that actually interacts on the site appears to be kind of low.  There are occasional articles, links, and questions posted in the community areas of the site, but the activity there is minimal.</p>
<p>I don&#8217;t think this trend is necessarily a bad thing.  Afterall, if mentors and proteges are finding more natural ways of carrying out the mentoring relationship, that means the site has done its job of kicking off that connection.  However, it would be good to grow the culture of mentors posting articles and proteges posting questions to create value for proteges on the site who have not yet been connected to a mentor.</p>
<h1>Tips for Mentors</h1>
<p><a href="http://icanhas.cheezburger.com/tag/mentoring"><img class="alignright size-medium wp-image-28748" title="mentoring" src="http://www.altdevblogaday.com/wp-content/uploads/2012/12/mentoring-246x300.jpg" alt="" width="246" height="300" /></a>If you decide that you&#8217;d like to mentor an aspiring developer and sign up for Game Mentor Online, or any other mentoring program, here are a few tips I&#8217;ve picked up along the way:</p>
<ul>
<li><strong>Communication of expectations is critical.</strong>  When you get started, make it very clear what kind of time you&#8217;ll be able to commit.  Encourage your protege to share his or her expectations for what they hope to get out of the mentorship and be honest on how you think you can help fulfill those expectations.</li>
<li><strong>Be really specific about times you are available.</strong>  If you start a habit of chatting every two weeks, and then something comes up that may disrupt that pattern (like a conference or a big milestone), let your protege know early so they can expect the change.  If you have to miss a session or expect to be late, inform your protege as soon as you can.  Establishing and maintaining trust is really important for a good mentorship</li>
<li><strong>Don&#8217;t hold back sharing experiences or stories because you feel they are mundane or routine.</strong>  What your mentee may not know may surprise you, and you probably have a lot more to offer than you realize.</li>
<li><strong>There is some element of luck of the draw as far as your compatibility with your protege.</strong>  I was extremely lucky in that Kaylin and I forged a strong connection right off the bat, but it&#8217;s possible that you and your assigned mentee don&#8217;t click. I would advise not to get discouraged and to keep at it.  The default length for a mentor connection is 4 months (though you can extend it for as long as you like if you and your protege are hitting it off) and the next protege you get paired with could be a completely new experience.</li>
<li>Meanwhile, the program has an <a href="http://gmo.chronus.com/p/main/pages/555">FAQ for potential mentors</a> that I would recommend reading for more information.  I&#8217;d also suggest looking over the <a href="http://gmo.chronus.com/p/main/pages/556">FAQ for proteges</a> to get an idea of the frame of mind your mentee will be coming from when you get matched.</li>
</ul>
<h1>Other Opportunities</h1>
<p>I love Game Mentor Online because it is easy and convenient to incorporate into my busy designer life, and because I feel very comfortable with remote communication.  But there are other opportunities in our industry that I&#8217;d recommend checking out if you are interested in mentoring.</p>
<ul>
<li>If you like to do your mentoring face-to-face, check out the <a href="http://www.igda.org/scholars/mentors/">IGDA mentoring program</a>, where professionals are paired up with IGDA scholars at GDC, E3, and other industry events.  You can go to talks with your scholar, meet up and discuss different talks that you&#8217;ve seen, answer their questions in person, and introduce them to a greater professional network.</li>
<li><a href="http://www.mentornet.net/">MentorNet</a> has a similar online structure to GMO, but is more generalized for engineering and tech careers and students.  I found I didn&#8217;t have as prosperous a mentoring experience here, but part of that could be that I didn&#8217;t click with my mentee there in the same way as Game Mentor Online</li>
<li>Schools and educational institutes might have opportunities  to connect you with a student that you may be able to help.  Some schools have alumni networks for advising in career services, and sometimes it&#8217;s as much as emailing an old professor to say you&#8217;re available to answer any student questions about game development.</li>
<li>LinkedIn&#8217;s <a href="http://www.linkedin.com/groups?gid=1842071">Video Game Careers</a> group has a lot of student posters and is very active .  It creates a lot of ways to give feedback to students by reviewing portfolios and giving feedback for their projects &#8211; a good way to advise and help many students in very specific ways versus a single relationship with one person over time.</li>
</ul>
<p>If any readers know of other good mentoring opportunities, please let me know in the comments and I will add them here!</p>
<p>My Protege&#8217;s Perspective</p>
<p>I asked Kaylin if he would like to write a bit about his perspective on the program as a mentee.  Here is what he had to say:</p>
<blockquote><p><em>For the longest time, I’ve been teaching myself the aspects of game design from a young age, unsure of whether or not I was forging down the right path to reaching my goal of working in the games industry. Living within the sheltered life style that I did live in, television and the internet were the only mediums I had to explore the games industry, or at least what I had perceived to be the games industry at that time. With game schools posting commercials exploiting starry eyed aspiring developers from their funds by making them believe that the industry is this “easy place to carve out a name for yourself” along with the exclusivity of access to developers of any established company, from small studios like 5<sup>th</sup> cell and Flowplay all the way up to 343 Industries and Bethesda, there was no one in my life to tell me how the game industry really functioned and what the experience was like, until that one defining moment when I got the message the hard way &#8211;from a veteran who was very disgruntled with my misguided passion.</em></p>
<p><em>Upon meeting Lisa through Game Mentor Online, I’ve been not only enlightened about the experience of working in the games industry, but also how to think and act like a game designer—a crucial yet often taken for granted thing when the majority of students already have a network with other designers in the industry. Because of Lisa and her connections, her willingness to answer my various questions, show me certain processes that I would otherwise have to learn through private schools and simply helping me when I’m in a hard spot, I’ve transformed from a shy sheltered boy to a confident designer. Her feedback was crucial to getting my side project—TRACED off of the ground, Without her overall input over the concept and her introducing me to the process of play-testing, concept documentation, etc. I would have never managed to find the three other teammates I have working on this project and keep them working on this project for a full year.</em></p>
<p><em>Game Mentor Online and my mentor/protégé relationship with Lisa have transformed my thinking! I would recommend it to all of my aspiring friends who want to also become game developers some day! I’d rather get it from the professionals rather than school commercials!</em></p>
<p><em>- Kaylin Norman</em></p></blockquote>
<h1>Conclusion</h1>
<p>I know that our lives as professional developers are extremely busy, but we have so much that we can offer to the next generation of developers.  Game Mentor Online&#8217;s flexibility and online focus is a great opportunity to connect with a student in a way that can fit into a very full game dev life.  Even if you are new to the industry, you still have more to offer to an aspiring developer than you may realize.  If you could spare as little as an hour a month to connect with an ambitious, excited, and curious protege, I suspect you may come away from the experience feeling inspired and renewed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/12/03/game-mentor-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What they DON&#8217;T tell you about being a game developer</title>
		<link>http://www.altdevblogaday.com/2012/11/21/what-they-dont-tell-you-about-being-a-game-developer/</link>
		<comments>http://www.altdevblogaday.com/2012/11/21/what-they-dont-tell-you-about-being-a-game-developer/#comments</comments>
		<pubDate>Wed, 21 Nov 2012 01:14:24 +0000</pubDate>
		<dc:creator>Alex Norton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28725</guid>
		<description><![CDATA[<p>So I&#8217;m in an interesting position. <a title="Malevolence: The Sword of Ahkranox" href="http://www.malevolencegame.com/" target="_blank">Malevolence</a>, while not my first game by a long shot, is my first RELEASED game, and I&#8217;ve been lucky enough to have it gather a lot of attention (for an indie title) early on in its creation. From what people tell me, this does not normally happen. Normally, a developer will hit on gold after they&#8217;ve tested the waters with a few titles first, or had a hand in other game development, such as working for a AAA company.<br />
Because of this unique perspective of having a relatively successful title (despite not yet being released) on my first ever attempt, I haven&#8217;t yet developed the pessimism that often comes with being an experienced indie game developer. This has led me to want to write this new thought piece, which goes into all of the things that they DON&#8217;T tell you about being a game developer. If you want the short and sweet version, feel free to skip to the end.</p>
<p><a href="http://www.altdevblogaday.com/2012/11/21/what-they-dont-tell-you-about-being-a-game-developer/" class="more-link">Read more on What they DON&#8217;T tell you about being a game developer&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>So I&#8217;m in an interesting position. <a title="Malevolence: The Sword of Ahkranox" href="http://www.malevolencegame.com/" target="_blank">Malevolence</a>, while not my first game by a long shot, is my first RELEASED game, and I&#8217;ve been lucky enough to have it gather a lot of attention (for an indie title) early on in its creation. From what people tell me, this does not normally happen. Normally, a developer will hit on gold after they&#8217;ve tested the waters with a few titles first, or had a hand in other game development, such as working for a AAA company.<br />
Because of this unique perspective of having a relatively successful title (despite not yet being released) on my first ever attempt, I haven&#8217;t yet developed the pessimism that often comes with being an experienced indie game developer. This has led me to want to write this new thought piece, which goes into all of the things that they DON&#8217;T tell you about being a game developer. If you want the short and sweet version, feel free to skip to the end.</p>
<p><em><strong>STAGE 1 &#8211; DELUSIONS</strong></em><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Going through university I had the same delusions as most people that I would get my qualifications, build a folio and get a job at a AAA game company. Shortly thereafter, fame and riches would ensue and I would live happily ever after, making games that I love, and having everything right with the world.<br />
I finished university to find that all of my hard work would get me on a &#8220;consideration&#8221; list for a baseline, entry level QA job which would mostly consist of me being locked in a cubicle for 70+ hours a week doing some of the most repetitve, soul destroying work known to man.</p>
<div class="wp-caption aligncenter" style="width: 572px"><img src="http://art.penny-arcade.com/photos/770836278_VG7Cr-L.jpg" alt="Penny Arcade Tester Comic" width="562" height="281" /><p class="wp-caption-text">A good example of what it is to be a tester, provided by Penny Arcade.</p></div>
<p>Sure, that would give me a foot in the door to have my true skills recognised later on, however, most game companies go through and trash their QA teams at the end of every project after smothering them in NDAs which make their soul now below to the company. So that&#8217;s a minefield in itself.<br />
If, and I really mean IF, I was to be plucked from QA and given a position within the company, one of two scenarios would have happened:</p>
<p><strong>EDIT:</strong> <em>Since this seems to be causing some controversy, let me clarify that my thoughts listed below are not my opinion of ALL games companies. I am simply listing things that tend to commonly happen based on the experiences of the many developers I have spoken to, and these thoughts in no way represent what the industry is like as a whole.</em></p>
<p><strong>Programmer Position</strong> &#8211; I would be sat down and made to do scripting work for 70+ hours a week on someone else&#8217;s proprietary engine, since using third party products &#8220;speeds development&#8221; and I would learn that there is such a thing as an &#8220;acceptible sacrifice of quality for speed&#8221; which would slowly destroy my integrity as a programmer. My passion for creating new features would slowly be vampirically sucked away, and anything I made in my spare time would be contractually owned by my employer which would sap my enthusiasm for innovation even further.</p>
<p><strong>Artist Position</strong> &#8211; I might be lucky enough to get assigned work that interests me. I might be having a great time designing and modelling sci-fi assets for an amazing new shoot-em-up and enjoy watching them come to life within the engine. But one day the producer (who is computer illiterate and whose only gaming experience is with Bejewelled) would pop by and say &#8220;You know, my 10 year old niece is really into ponies right now. Change the game to be about ponies&#8221;. Because he is the money behind the masterpiece, I would now be forced to abandon all of my work and create ponies and handbags all day every day. Also, everything I make outside of work would be contractually owned by my employer, limiting my folio and preventing me from moving to another company.</p>
<p><em><strong>STAGE 2 &#8211; DETERMINATION</strong></em><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
So, having this realisation, I then turned my attention to the indie game dev scene, which was far more attractive as I was beholden to no-one, I could work on what I wanted and do it in any way that I pleased (so I thought) but there were certain demons there which no-one told me about, either.<br />
I got myself a day job to take care of living expenses and turned my spare time towards my magnum opus&#8230; Malevolence: The Sword of Ahkranox &#8211; the game of my dreams that was everything that I wanted to see in a game. I was out to show the world what a game COULD be. New technologies, new gameplay mechanics and a dash of old-school to reel in the retro crowd. It was going to be amazing and the world would be changed forever.</p>
<p>I was young. I was naive. And no-one had warned me what was coming.</p>
<p>First off, I had been playing around with a new method of procedural generation to create infinite worlds, and my favourite gaming genre was always RPGs, so I figured &#8220;why not make an infinite procedural RPG?&#8221; it seemed a good idea at the time, so I started work on it and found that it worked. I started <a title="Malevolence Dev Blog" href="http://swordofahkranox.blogspot.com.au/" target="_blank">a blog</a> about it, more for myself than anything. Things were going fairly well.</p>
<p><em><strong>STAGE 3 &#8211; REVELATIONS</strong></em><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
It was at this point that I started meeting a couple of other game devs. Before this point I didn&#8217;t really know any, and one with quite a long resume happened to start work at my day job. We got to talking and he introduced me to more people. They all seemed quite interested in my project and thought it was great that I was trying new things. This reaction gave me the motivation to make my development process a bit more public, so I started promoting Malevolence a bit more and getting more of a team together to work on the game&#8217;s shine.</p>
<p>Much to my amazement, it got quite a lot of attention (for an indie game being made by a nobody in the industry) and that made me happy, so I kept at the PR. But with positive attention comes negative attention, and it was then that I learned two important things:</p>
<ul>
<li>People, when given the anonymity and audience of the internet, can be truly horrible.</li>
<li>You can read 1000 praising comments, but if just one of them is bad, it will ruin your whole day.</li>
</ul>
<p>The fact that I was trying to do something new with my game was evidently a horrible crime to many people and I would get utterly horrible comments ranging from put-downs to persanal abuse that would get them arrested if said in person&#8230; Even one or two death threats. It&#8217;s a sad fact of life that people who are too scared to follow their own dreams will often try to talk you out of following yours. It&#8217;s easy for people to say &#8220;just ignore those comments&#8221; but that&#8217;s simply not possible.<br />
Some people who disagreed with the game&#8217;s concept gave thorough and well-written justifications for their feelings, which was good to see, but they were few and far between.<br />
I had decided early on to keep an open-doors development policy and be extremely communicative with the public. I even developed somewhat of a reputation for answering every question asked of me. Many people loved this, others took it as justification to send more abuse, because they knew someone was listening.</p>
<p>At first, I thought it was because of my new ideas and concepts that I was touting, but after meeting with other game developers I found out that it&#8217;s just what the gamer community is like. Full of angry, hateful, rude, abnoxious people who feel entitled to say anything they want to the developers who are making games for them. That&#8217;s not to say that they&#8217;re all like that. Far from it! Many, many people have been very supportive, communicative and encouraging throughout the entire process, and you have to really cling to people like that because, as a developer friend of mine once said <em>&#8220;Those people hating on your game will always complain loudly. That&#8217;s just what they do. The fact is, though, that they&#8217;ll probably still buy your game.&#8221;</em> and that&#8217;s what you need to focus on. It doesn&#8217;t matter if other people like your game. What matters is whether YOU like your game. If you love it, other people are bound to as well. Just look at how much hate has been poured upon Minecraft over the years, but Mojang have sold millions and millions of copies regardless, and you can tell that they&#8217;re super proud of their creation!</p>
<p>Being proud of what you&#8217;ve made is very important. Whenever something happens around your game that makes you feel proud, then you&#8217;ve gotta grab a hold of it and not let it go. I&#8217;ve had John Passfield sit me down and tell me that he believes that Malevolence has the makings of an epic game, I&#8217;ve been called a &#8220;visionary&#8221; by members of the Guild Wars 2 team, I&#8217;ve been recommended by RockPaperShotgun as a project to watch&#8230; These things make me glow with pride, whether I believe them or not, and whenever I&#8217;m getting slammed by ignorant haters, I remember these things to help get me through it, and that&#8217;s something you&#8217;ve just got to do to survive psychologically.</p>
<p><em><strong>STAGE 4 &#8211; HINDSIGHT</strong></em><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
So, looking back, I&#8217;ve realised there are a lot of things that people just don&#8217;t tell you about being an independant game developer:</p>
<ul>
<li><em>A large, loud portion of the public will openly hate you regardless of what you do. Learn to live with it.</em></li>
<li><em>No-one will ever take your project as seriously as you, or fully realise what you&#8217;re going through.</em></li>
<li><em>Everyone will think they know better than you about your own project.</em></li>
<li><em>Getting noticed at all is incredibly difficult .</em></li>
<li><em>The odds of you making money out of it are slim.</em></li>
<li><em>If you want to succeed, you&#8217;ll likely have to sell out. Just how MUCH you sell out is up to you.</em></li>
<li><em>You have to develop a VERY thick skin.</em></li>
<li><em>Being open with the public isn&#8217;t neccesarily smiled upon 100% of the time.</em></li>
<li><em>You will meet many &#8220;game developers&#8221; but very few people who are actually developing games.</em></li>
<li><em>You need to have the ability to listen to all advice given to you. Remember that listening to advice doesn&#8217;t mean you have to take it. But listening can&#8217;t hurt and you never know what you might learn.</em></li>
</ul>
<p>I&#8217;ve also learned lots of things to never do again which may help upcoming developers:</p>
<ul>
<li><em>Don&#8217;t make an RPG as your first released game, nor any other kind of large-scale project. Start simple. Learn the lessons. Once you&#8217;re experienced, THEN you can work on something big.</em></li>
<li><em>Never announce your release date until you are 150% sure of it.</em></li>
<li><em>Never let yourself get so enveloped in your project that other parts of your life suffer.</em></li>
<li><em>Never engage the haters.</em></li>
<li><em>Get a test team and follow strict testing practices.</em></li>
<li><em>Have a thorough plan before you start working too hard on it, and then stick to that plan come hell or high water.</em></li>
<li><em>Think carefully about having a public development process. Depending on the target audience and the project itself, it may be better to develop it silently and only open things up to the public when you&#8217;re nearing completion.</em></li>
<li><em>Never let anyone cause you to stop being proud of your work. The moment you aren&#8217;t proud of it anymore, the moment people will stop respecting you for it. If you make the game, and no money comes of it, at least you&#8217;ll have work that you&#8217;re proud of.</em></li>
</ul>
<p>Some of them are hard lessons to learn, but learn them well before you venture into the murky waters of independant game development. Consider yourself forewarned! Obviously, other people will have other bits of advice, or revelations of their own, so I&#8217;d love to hear them, too! Share them in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/21/what-they-dont-tell-you-about-being-a-game-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Formal Language for Data Definitions</title>
		<link>http://www.altdevblogaday.com/2012/11/17/a-formal-language-for-data-definitions/</link>
		<comments>http://www.altdevblogaday.com/2012/11/17/a-formal-language-for-data-definitions/#comments</comments>
		<pubDate>Sat, 17 Nov 2012 14:19:31 +0000</pubDate>
		<dc:creator>Niklas Frykholm</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[blobs]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[definition]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[layout]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28719</guid>
		<description><![CDATA[<p>Lately, I&#8217;ve started to think again about the irritating problem that there is no formal language for describing binary data layouts (at least not that I know of). So when people attempt to describe a file format or a network protocol they have to resort to vague and nondescript things like:</p>
<p><a href="http://www.altdevblogaday.com/2012/11/17/a-formal-language-for-data-definitions/" class="more-link">Read more on A Formal Language for Data Definitions&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Lately, I&#8217;ve started to think again about the irritating problem that there is no formal language for describing binary data layouts (at least not that I know of). So when people attempt to describe a file format or a network protocol they have to resort to vague and nondescript things like:</p>
<pre>Each section in the file starts with a header with the format:

4 bytes			header identifier
2 bytes			header length
0--20 bytes		extra data in header

The extra data is described below.</pre>
<p>As anyone who has tried to decipher such descriptions can testify, they are not always clear-cut, which leads to a lot of unnecessary work when trying to coax data out of a document.</p>
<p>It is even worse when I create my own data formats (for our engine&#8217;s runtime data). I would like to document those format in a clear and unambiguous way, so that others can understand them. But since I have no standardized way of doing that, I too have to resort to ad-hoc methods.</p>
<p>This whole thing reminds me of the state of mathematics before formal algebraic notation was introduced. When you had to write things like: <em>the sum of the square of these two numbers equals the square of the previous number</em>. Formal notation can bring a lot of benefits (just look at what it has done for mathematics, music, and chess).</p>
<p>For data layouts, a formal definition language would allow us to write a tool that could open any binary file (that we had a data definition) for and display its content in a human readable way:</p>
<pre>height = 128
width = 128
comment = "A funny cat animation"
frames = [
	{display_time = 0.1 image_data = [100 120 25 ...]}
	...
]</pre>
<p>The tool could even allow us to edit the readable data and save it back out as a binary file.</p>
<p>A formal language would also allow debuggers to display more useful information. By writing data definition files, we could make the debugger understand all our types and display them nicely. And it would be a lot cleaner than the hackery that is <em>autoexp.dat</em>.</p>
<p>Just to toss something out there, here&#8217;s an idea of what a data definition might look like:</p>
<pre>typdedef uint32_t StringHash;

struct Light
{
	StringHash	name;
	Vector3		color;
	float		falloff_start;
	float 		falloff_end;
};

struct Level
{
	uint32_t version;
	uint32_t num_lights;
	uoffset32_t light_data_offset;

	...

light_data_offset:
	Light lights[num_lights];
};</pre>
<p>This is a C-inspired approach, with some additions. Array lengths can be parametrized on earlier data in the file and a labels can be used to generate offsets to different sections in the file..</p>
<p>I&#8217;m still tossing around ideas in my head about what the best way would be to make a language like this a reality. Some of the things I&#8217;m thinking about are:</p>
<h2>Use Case</h2>
<p>I don&#8217;t think it would do much good to just define a langauge. I want to couple it with something that makes it immediately useful. First, for my own motivation. Second, to provide a &#8220;reality check&#8221; to make sure that the choices I make for the language are the right ones. And third, as a reference implementation for anyone else who might want to make use of the language.</p>
<p>My current idea is to write a binary-to-JSON converter. I.e., a program that given a data definition file can automatically convert back and forth between a binary and a JSON-representation of that same data.</p>
<h2>Syntax</h2>
<p>The syntax in the example is very &#8220;C like&#8221;. The advantage of that is that it will automatically understand C structs if you just paste them into the data definition file, which reduces the work required to set up a file.</p>
<p>The disadvantage is that it can be confusing with a language that is very similar to C, but not exactly C. It is easy to make mistakes. Also, C++ (we probably want some kind of template support) is quite tricky to parse. If we want to add our own enhancements on top of that, we might just make a horrible mess.</p>
<p>So maybe it would be better to go for something completely different. Something Lisp-like perhaps. (Because: Yay, Lisp! But also: Ugh, Lisp.)</p>
<p>I&#8217;m still not 100 % decided, but I&#8217;m leaning towards a restricted variant of C. Something that retains the basic syntatic elements, but is easier to parse.</p>
<h2>Completeness</h2>
<p>Should this system be able to describe <em>any</em> possible binary format out there?</p>
<p>Completeness would be nice of course. It is kind of annoying to have gone through all the trouble of defining language and creating the tools and <em>still</em> not be able to handle all forms of binary data.</p>
<p>On the other hand, there are a lot of different formats out there and some of them have a complexity that is borderline insane. The only way to be able to describe <em>everything</em> is to have a data definition language that is Turing complete and procedural (in other words, a detailed list of the instructions required to pack and unpack the data).</p>
<p>But if we go down that route, we haven&#8217;t really raised the abstraction level. In that case, why even bothering with creating a new language. The format description could just be a list of the C instructions needed to unpack the data. That doesn&#8217;t feel like a step forward.</p>
<p>Perhaps some middle ground could be found. Maybe we could make language that was simple and readable for &#8220;normal&#8221; data, but still had the power to express more esoteric constructs. One approach would be to regard the &#8220;declarative statements&#8221; as syntactic sugar in a procedural language. With this approach, the declaration:</p>
<pre>struct LightCollection
{
	unsigned num_lights;
	LightData lights[num_lights];
};</pre>
<p>Would just be syntactic sugar for:</p>
<pre>function unpack_light_collection(stream)
	local res = {}
	res.num_lights = unpack_unsigned(stream)
	res.lights = []
	for i=1,res.num_lights do
		res.lights[i] = unpack_light_data(stream)
	end
end</pre>
<p>This would allow the declarative syntax to be used in most places, but we could drop out to full-featured Turing complete code whenever needed.</p>
<p>This has also been posted to <a class="link" href="http://bitsquid.blogspot.com">The Bitsquid blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/17/a-formal-language-for-data-definitions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing with my kids helps me make better games</title>
		<link>http://www.altdevblogaday.com/2012/11/13/playing-with-my-kids-helps-me-make-better-games/</link>
		<comments>http://www.altdevblogaday.com/2012/11/13/playing-with-my-kids-helps-me-make-better-games/#comments</comments>
		<pubDate>Tue, 13 Nov 2012 01:33:01 +0000</pubDate>
		<dc:creator>Kyle-Kulyk</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28688</guid>
		<description><![CDATA[<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/Vader-Playing.jpg"><img class="alignleft  wp-image-28692" style="margin: 5px" src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/Vader-Playing.jpg" alt="" width="290" height="286" /></a>A funny thing happened to me smack in the middle of my transition from the brokerage industry to the games industry. People tell you how everything changes when you become a parent. Friends of mine tried to explain the feeling, their eyes taking on a bit of a faraway look as if they were describing an unnatural love of unicorns or some sort of mythical being while I smiled and said “Oh yeah. Oh yeah.” I often joked that agents would slip into parent’s houses at night and pump them full of endorphins while they slept because it was the only way to describe the wonder I saw in those faces at the arrival of those little, pooping, screaming, sleep deprivation units. “Everything changes,” they’d tell me and I’d nod without a shred of comprehension. Then after years of difficulties it finally happened to my wife and I and I got it. I understood why so many I knew couldn&#8217;t really put the experience into words aside from the fact that everything changes and that it’s wonderful. I don’t even bother to describe the experience to people without children now, other than to offer a genuine smile and say “Hopefully, you’ll understand one day.”</p>
<p><a href="http://www.altdevblogaday.com/2012/11/13/playing-with-my-kids-helps-me-make-better-games/" class="more-link">Read more on Playing with my kids helps me make better games&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/Vader-Playing.jpg"><img class="alignleft  wp-image-28692" style="margin: 5px" src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/Vader-Playing.jpg" alt="" width="290" height="286" /></a>A funny thing happened to me smack in the middle of my transition from the brokerage industry to the games industry. People tell you how everything changes when you become a parent. Friends of mine tried to explain the feeling, their eyes taking on a bit of a faraway look as if they were describing an unnatural love of unicorns or some sort of mythical being while I smiled and said “Oh yeah. Oh yeah.” I often joked that agents would slip into parent’s houses at night and pump them full of endorphins while they slept because it was the only way to describe the wonder I saw in those faces at the arrival of those little, pooping, screaming, sleep deprivation units. “Everything changes,” they’d tell me and I’d nod without a shred of comprehension. Then after years of difficulties it finally happened to my wife and I and I got it. I understood why so many I knew couldn&#8217;t really put the experience into words aside from the fact that everything changes and that it’s wonderful. I don’t even bother to describe the experience to people without children now, other than to offer a genuine smile and say “Hopefully, you’ll understand one day.”</p>
<p>I was never around children from the time I left home until nearly 20 years later when I had kids of my own. When I was faced with other people’s children, I often found the experience awkward and a bit uncomfortable. I had no idea how to relate to kids of any age or how to interact with them. Now with children of my own I can hardly remember a time where I didn&#8217;t know how to play with children, and in return my kids have opened my eyes to why we find certain things “fun”. I hope I can describe this idea in a way that could prove useful to aspiring developers.</p>
<p>Playing video games in my twenties and thirties I think I lost some of the understanding of why I found games fun to play when I was a kid. Video games to me were about roleplaying or they were about competition and if you had asked me why video games were fun even three years ago, I probably would have described some combination of those two factors but over the years I’d forgotten something. Perhaps not forgotten so much as overlooked. While roleplay and competition can be factors in why games are appealing long term I think what makes video games fun is much more fundamental to the way we learn. Watching my children grow and play has helped me remember what drew me to video games as a child and what still keeps me coming back now. It has to do with learning and the feeling of accomplishment when you finally master a challenging game.</p>
<p>From a very early age, babies love patterns. Nothing quite locks an infant’s gaze like faces and patterns. As they get older it doesn&#8217;t stop. We find patterns all around us all the time even when confronted with something that doesn&#8217;t seemingly have a pattern. We see shapes in clouds and we instantly look for some sort of familiar arrangement in a jumble of letters or numbers. I watched my son stare at a wooden puzzle, then progress to dumping the pieces and creating chaos only to then restore order. He would continue to play in this manner until eventually it’s no longer challenging to solve that particular puzzle and suddenly that toy is forgotten for good (or until his little sister picks up a piece). He moves onto the next challenge and that’s his day with the exception of naps and meal time.</p>
<p>To me, right there I see two fundamental pieces of what keeps us coming back to a good video game. One factor is some sort of pattern recognition mechanic and the other is a challenge. When I started looking at the video games I enjoyed as a kid and that I enjoyed now they all have, at their core, some sort of pattern recognition element and they all had increasing levels of difficulty. I’d play until I either mastered the game and it became too easy or until the difficulty became such that I grew frustrated and no longer found the experience entertaining. I see the same behaviours in the way my toddler plays. It’s fun unless the task is too difficult, and it’s fun until the task becomes too easy.</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/SpaceAce.jpg"><img class="size-full wp-image-28689 alignleft" style="margin: 5px" src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/SpaceAce.jpg" alt="" width="320" height="240" /></a></p>
<p>When I was a kid I remember spending quite a bit of time on Space Ace, among others games at my local arcade. Space Ace was a cartoon, laser disk based game along the lines of Dragon Slayer. A series of events would play out on the screen and a visual cue would signal the move to make with the timing becoming more challenging as the game progressed. Mastering a game like this in a time before strategy guides and the internet took trial and error, a good memory and a pocketful of quarters and I loved that game. That was, until I beat it. Shortly after I memorized the patterns, I moved onto the next game only occasionally popping in a quarter to feel important when throngs of kids who would gather when they’d see “that kid who can beat Space Ace” start a new game.</p>
<p>Whether it’s timing involved in arcade fighting games or if it’s strategy in an on-line shooter, when you break it down video games are all about recognizing patterns and using them within the confines of the game&#8217;s rules.  It’s an understanding of game development that in retrospect I feel I poorly implemented in the <a href="http://itzyinteractive.com/itzy3d/" target="_blank">first game</a> my team released in our efforts to appeal to a wider audience. Each level of the game was unique, but the challenge of the game, the pattern required to win didn&#8217;t vary enough and looking back at the testing, our players enjoyed the game but the question we didn&#8217;t ask was “for how long will they enjoy it?” It’s a choice we made in the interest of appealing to a broader base, but I think this choice didn&#8217;t do us any favours and by the time we realized this and updated the title with different ways to play our window of opportunity had already closed. It’s something that seems so basic a notion in hindsight but hopefully by bringing this up I can encourage other new developers to take a look at their product differently.</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/digitchase.jpg"><img class="alignright  wp-image-28691" style="margin: 5px" src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/digitchase.jpg" alt="" width="318" height="180" /></a>Playing games with a two and a half year old also helped me rethink control schemes as well. My son loves to pick up a controller and ask “Sack-boy, Daddy?” but a Playstation 3 controller and LittleBigPlanet is a bit beyond him currently. However, I sat him down with Angry Birds &#8211; Star Wars and within seconds he was flinging birds at piggies and loving it. The same goes playing “Digit Chase” on the Playstation Vita, a quick demo that has users tap numbers on the screen in sequence. There’s something undeniably intuitive about touch screen input as illustrated by how quickly children take to them, but often mobile developers try to shoehorn controller type controls into their mobile games. I&#8217;m not saying there’s anything wrong with modern game controllers, but controls needs to be intuitive. That doesn&#8217;t mean they have to be toddler approved simple, I just think the basic controls should be straightforward. This was a lesson we learned developing our first game and reaffirmed by watching my son play. Just because you have variety of ways to control your game doesn&#8217;t mean you should just throw everything in because you can. It’s tempting to do. I know because I did it.</p>
<p>I can thank the time I spend playing with my little guy for bringing me back to the basics and helping understand why we find games fun. It’s not about simplifying the games themselves, but it’s recognizing that under everything we’re always searching for patterns and looking to challenge ourselves, because that’s how we learn. It’s not about making controls dead simple, but it couldn&#8217;t hurt to imagine a scenario where your game is being played by a gamer who’s never gamed before. Will your controls confuse or will they help the player become comfortable before becoming challenging? It’s easy to lose focus on basic game-play mechanics underneath everything else that makes up modern gaming, especially for experienced gamers. Watching children play and learn helped me realize this and I look forward to gaming with both my kids for years to come, and I look forward to what they have to teach me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/13/playing-with-my-kids-helps-me-make-better-games/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Simple System to Patch your Game Content</title>
		<link>http://www.altdevblogaday.com/2012/11/12/a-simple-system-to-patch-your-game-content/</link>
		<comments>http://www.altdevblogaday.com/2012/11/12/a-simple-system-to-patch-your-game-content/#comments</comments>
		<pubDate>Mon, 12 Nov 2012 15:01:38 +0000</pubDate>
		<dc:creator>Colt McAnlis</dc:creator>
				<category><![CDATA[#gamedev]]></category>
		<category><![CDATA[Production]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28672</guid>
		<description><![CDATA[<p>This article explains why it’s important to have your own patching system, and describes how to implement a simple patching system modeled after the Quake3 file-based patching process.</p>
<p style="text-align: center"><img class="aligncenter size-full wp-image-28673" src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/software_patch.jpg" alt="" width="250" height="161" /></p>
<h1>Introduction</h1>
<p>Since the <a href="http://en.wikipedia.org/wiki/Doom_(video_game)">rise of PC games</a> in the early 90s, game developers have needed ways to quickly issue fixes, updated builds, and new content to existing users – hence the rise of ‘game patch’ systems. Over time, this method of updating games has made its ways from PCs to consoles, and is now trickling into mobile development. It may take some effort to build and use a patching system for your game content, but once you’ve got such a system up and running, it’s a very powerful tool for your development studio.</p>
<p><a href="http://www.altdevblogaday.com/2012/11/12/a-simple-system-to-patch-your-game-content/" class="more-link">Read more on A Simple System to Patch your Game Content&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>This article explains why it’s important to have your own patching system, and describes how to implement a simple patching system modeled after the Quake3 file-based patching process.</p>
<p style="text-align: center"><img class="aligncenter size-full wp-image-28673" src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/software_patch.jpg" alt="" width="250" height="161" /></p>
<h1>Introduction</h1>
<p>Since the <a href="http://en.wikipedia.org/wiki/Doom_(video_game)">rise of PC games</a> in the early 90s, game developers have needed ways to quickly issue fixes, updated builds, and new content to existing users – hence the rise of ‘game patch’ systems. Over time, this method of updating games has made its ways from PCs to consoles, and is now trickling into mobile development. It may take some effort to build and use a patching system for your game content, but once you’ve got such a system up and running, it’s a very powerful tool for your development studio.</p>
<p>&nbsp;</p>
<h2>Why have your own patching system?</h2>
<p>For modern game developers, the most popular avenue to sell games is through one of many digital distribution services like Google Play, Steam, XBLA, and the Chrome Web Store. Besides marketing games to their users, these distribution services generally handle the lion&#8217;s share of transferring game content to customers on developers’ behalf.</p>
<p>For games that need to update frequently, however, the content hosting process from such distribution services can be problematic. For example, some of the services can introduce significant <a href="http://kotaku.com/5884842/wait-it-costs-40000-to-patch-a-console-game">costs in patch creation</a>, or delays in issuing updated builds to users.  For multiplayer games, delays can let client builds get out of sync with server builds, with no way of triggering an update directly.</p>
<p>One opportunity to work around such hurdles is in embracing the ability to make your content available outside of distribution services.  In general, building your game technology on top of your own patching system gives you a great deal of control as a developer, and generally provides options that give your company and products a great deal of flexibility to move between platforms.</p>
<p>&nbsp;</p>
<h2>Reach your users directly</h2>
<p>In addition to solving the problems listed above, a patching system gives you the opportunity to reach your users directly. Nowadays every game platform is constantly connected to the interwebs, and keeping a long tail of customers happy means constantly listening to the community, fixing their issues, and furnishing new content to them. A patching system lets you market to existing users with new content, as well as news, updates, and notices relating to your game.</p>
<p>So, be your name <a href="http://en.wikipedia.org/wiki/Oh,_the_Places_You'll_Go!">Buxum or Bixby or Bray,</a> your mountain of users is waiting, patch them to happiness, and be on your way!</p>
<p>&nbsp;</p>
<h1>Patching system overview</h1>
<p>Patching systems generally have 3 components:</p>
<ol>
<li>A build server that generates builds and patches (this server resides with the developer)</li>
</ol>
<ol start="2">
<li>A content server from which to distribute builds and patches</li>
</ol>
<ol start="3">
<li>A user client that can detect differences between the local and server versions of a game, retrieve assets, and update the local version</li>
</ol>
<div id="attachment_28683" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-28683 " src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/fig1-300x70.png" alt="" width="300" height="70" /><p class="wp-caption-text">Figure 1: The components of a patching system</p></div>
<p>At its core, these are the three pillars of a patching system. You can create more fancy versions once you start getting into details, but such details tend to be game-specific and are beyond the scope of this article.</p>
<p>&nbsp;</p>
<h1>A simple patch-aware file system</h1>
<p>The <a href="http://www.idsoftware.com/games/quake/quake3-arena/">Quake3</a> source code contains an elementary example of a successful patching system. This simple system allows a patch to append new archives to the file system.  The new archives contain all the assets that differ from previous patches/builds. Another way to describe this system is that new archives are overlaid on top of existing archives. When an asset is to be read in from disk, the file system traverses the archives and selects the newest version of the asset.</p>
<p>In this simple system, over time a user who installed the original game would have multiple archive files from each progressive patch, each archive containing an updated set of assets. In contrast, a user who acquired the game much later in its life span would not have a plethora of archive files on their disk, but rather a collapsed archive representing the proper state of the world as of the time of their installation.</p>
<p>The <a href="http://fabiensanglard.net/quake3/index.php">Quake3 model</a> is hard to beat for simplicity, and offers a good starting point to address more complex topics as your patching system gets more sophisticated. The example patching system that we will implement is thus based on the Quake3 model, and has the following rules:</p>
<ol>
<li>The majority of the content is <a href="http://www.7-zip.org/">archived</a>.</li>
<li>Content in newer archives take precedence over content in older archives.
<ul>
<li>Archived content is generally not patched, but rather replaced entirely.</li>
</ul>
</li>
<li>We ignore <a href="http://en.wikipedia.org/wiki/Patch_(computing)">binary patching</a> altogether and instead include loose assets that are replaced entirely.</li>
</ol>
<p>To restate, we assume that as far as assets go, you’ll have <a href="http://en.wikipedia.org/wiki/Lion's_share">the lion’s share</a> in a small number of archives, and that new content will be shipped out in the form of additional archives, the contents of which will wholly replace older content.</p>
<p>We thus assume that there will be a series of archive files on disk.  At load time, we open the archives and merge their file lists into a global dictionary. When it’s time to read an asset, we consult the dictionary to determine what the newest version of the asset is, and which archive to pull the asset from.</p>
<p>&nbsp;</p>
<h2>Updating your build system for patching</h2>
<p>Build systems are a bit like <a href="http://www.mentalfloss.com/blogs/archives/28290">sacred rituals</a> – each company tends to have its own flavor and guards its process heavily. I’m not going to cover the concepts of a build system (or tell you how to write one); rather I assume that you’ve got that under wraps.</p>
<p>To generate a patch for a build, your build system needs to generate a list of the files that are different from the prior build (for example, between build 299 and 300, 27 <a href="http://www.youtube.com/watch?v=7bJ-D1xXEeg">textures</a> may have been updated, 3 models may have been deleted, and the rendering DLL may have been updated). Once you have the ability to generate this type of delta list, you need to combine the information into a patch definition, which is described below.</p>
<p>For our example patching system, any content that has changed or that has been added is included in the archive for a new patch. Finding new files is generally easy: Simply compare the file name listings between two folders to find what didn’t exist before. Finding existing files that have been modified can be trickier. For instance, simply testing the <a href="http://www.jb.man.ac.uk/~slowe/cpp/lastmod.html">last-modified time</a> of files may not work because of how your build system touches content. The fool-proof approach is to use a <a href="http://en.wikipedia.org/wiki/Brute-force_search">brute-force</a> comparison between all the binary data in two build folders.</p>
<p>The ease with which your build system can compute these types of file set differences depends greatly on the language and tools of the build system. For example, if your build system is driven by C++, a binary data compare of a <a href="http://us.battle.net/wow/en/">40GB build</a> would be a gnarly and less-than-ideal process. In contrast, if your build system is driven by <a href="http://www.python.org/">Python</a>, you can simply call <a href="http://docs.python.org/library/filecmp.html">dircmp</a>, which gives you all the proper delta data between files in two directories.</p>
<p>Figure 2 below shows an example of build deltas.  Blue indicates modified files, red indicates deleted files, and green indicates new files.  In our example patching system, the new and modified files are included in archives, shown on the right.</p>
<div id="attachment_28684" class="wp-caption aligncenter" style="width: 557px"><img class="size-full wp-image-28684 " src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/fig2.png" alt="" width="547" height="444" /><p class="wp-caption-text">Figure 2: Determining build deltas</p></div>
<h2>Creating a patch definition</h2>
<p>Once your build system can calculate what’s changed between two builds, the next step is to merge that data into some form that allows the client to consume it. Patch definitions are used to list key changes in builds over time, such that we can minimalistically update the client to the latest build.</p>
<p>We need a few pieces of information in each patch definition to help guide a client to the required actions to update itself. Here are a few examples of the type of information that should go into a patch definition:</p>
<ul>
<li>build number &#8211; What build is this? A simple integer is easiest to track.</li>
</ul>
<ul>
<li>target region &#8211; If you distribute your game internationally, there may be restrictions on the types of patches/content you can ship <a href="http://en.wikipedia.org/wiki/List_of_banned_video_games">to a specific region</a>.</li>
</ul>
<ul>
<li>files to add &#8211; This list should include new archives, as well as specific loose files that need to be added to the local build.</li>
</ul>
<ul>
<li>files to remove &#8211; At times, in the course of builds, you’ll succeed in completely replacing an old build, or there may be some security/privacy risk with old data existing on the client disk. Having the ability to remove files from disk in these situations is useful.</li>
</ul>
<ul>
<li>files to binary update &#8211; For files that need direct, in-place binary patching, this can present a list of tuples, the content to be patched, and the patch file to use.</li>
</ul>
<ul>
<li>patch importance &#8211; Is this patch required before the user can play? Or can it be streamed in the background?</li>
</ul>
<h2></h2>
<h2>Determining what files to download</h2>
<p>Once you can create per-build patch definitions, the next step is to allow the client to consume this information. The process is generally as follows:</p>
<ol>
<li>The client queries the patch server, sending the local version and other metadata.</li>
<li>The patch server responds with some form of file information.</li>
<li>The client processes the information and begins requesting new patch data to update the local copy.</li>
</ol>
<p>There are two primary ways (with lots of variants) to make the determination of what files to download – at the client level or at the server level.  Your choice of implementation  is highly dependent on the engineering resources that are available to you. The simplest approach in terms of server technology is to keep a text-based manifest file on the server that lists all the patches, their versions etc. This entire manifest file is passed to the client upon request, and the client is responsible for building up the series of file requests to update the local copy.</p>
<p>While simple to implement, this approach quickly runs into limitations. Significantly, this approach requires some advanced logic built into the client to parse the manifest file and generate the request list properly. If a large content-shift occurs (for example, you change the manifest file format), the client will likely need special processing to handle the changes, and may require a patch of the client itself before it’s able to update the content.</p>
<p>A much more complex but <a href="https://developers.google.com/appengine/">scalable solution</a> is to keep all the version data on the patch server, listed as entries in a database. The client provides some simple metadata about the state of the local data (easily encodable in a URL) to the server.  The server then computes the proper series of actions the client needs to perform in order to update itself, and transfers an ‘update script’ to the client for direct execution.</p>
<p>The main benefit of this server-based approach is that the computation of what the client needs to do in order to update the local state is all handled on the server. Thus, as the update logic changes, the client can remain neutral to those issues and simply react accordingly. This also allows the client to generally store less data needed for the update process (for instance, the client may only need to store its region and build number). The server can store the rest of the information needed to complete the update process, as well as provide the client with more advanced functionality, like grouping multiple patches into a single request update action.</p>
<h2></h2>
<h2>Applying patches</h2>
<p>Once the client has a clear roadmap of what’s required to update the local build, the next step is to actually update the data. For our simple system of downloading new archives, updating content is easy – we download the bits and write them to disk. <a href="http://www.youtube.com/watch?v=DazdIFMbC_4">Done. Let’s get tacos.</a></p>
<p>Eventually you will encounter a situation where you need to update the game client itself. This can be tricky if the game is running. To solve this problem, most PC games distribute a separate application that checks for patches and updates the local state, including the executable code. Typically these applications are easiest to generate as standalone applications that can patch and then launch the game itself.</p>
<p>For embedded environments, applying patches is a bit trickier.  For example, on consoles the base data is shipped on DVD, so you generally have to write patches to the hard drive and check for content there first. Mobile platforms have a whole separate set of requirements that I won’t get into. Thankfully, most of those platforms contain APIs to help out with this process of applying patches, which makes things a bit easier.</p>
<h2></h2>
<h2>Determining what files to delete</h2>
<p>Over time a client can accumulate many patches, and in some cases, it may have lots of data that is no longer needed.  For example, if all of the files in a given patch have been replaced by newer versions in subsequent patches, then the files in the original patch will never be used and are not needed. To keep the user’s machine from consuming disk space unnecessarily, it’s helpful to identify such instances and allow a patch to delete files from disk.</p>
<p>An archive that’s no longer needed is one whose assets are entirely replaced by newer archives. To test for this, your build system needs to be modified such that a target patch-archive has the ability to query newer builds to determine if it’s relevant any more; depending on how your build system is set up, adding this processing can be easy, or months of man-work, so make sure you take full stock of your system before trudging down the path of enlightenment.</p>
<h1></h1>
<h1>Notes</h1>
<h2><em>Binary-level file patches</em></h2>
<p>If you do a search for ‘patching game content’, your results will include numerous articles that describe how to minimally modify the on-disk contents of a file at a binary level. Typically this is done by computing the difference for a file and shipping only the difference to the client, resulting in a smaller transfer and a faster patching process. Unfortunately most of the research on patch generation revolves around how to patch executable files (see e.g. <a href="http://dev.chromium.org/developers/design-documents/software-updates-courgette">Courgette</a> (<a href="http://git.chromium.org/gitweb/?p=chromium.git;a=tree;f=courgette">source</a>), <a href="http://www.daemonology.net/bsdiff/">bsdiff</a>, and <a href="http://msdn.microsoft.com/en-us/library/bb417345.aspx#introductiontodeltacompression">DCA</a>). Very little (if any) research has been focused on patching binary assets like textures, models, and sounds.</p>
<p>Consequently the patching system described in this article focuses less on the traditional notion of a ‘patch’ and more on a process that allows us to distribute specific assets to clients so that we can easily update the clients to the latest build.  With <a href="http://code.google.com/p/lzham/">modern compression technologies</a> this process can result in the transfer of fairly small files to users, and the mental overhead of maintaining this type of system is significantly lower. If however you’re one of the brave souls who needs to do the more traditional version of patching, here are some quick notes.</p>
<p>As a starter, I suggest taking a look at <a href="http://code.google.com/p/xdelta/">XDelta</a>, which is a fairly straightforward command-line tool: You can run a simple command to create a patch, and another command to apply a patch to a file. The app is open-source so that you can build it into a custom part of your client executable. I haven’t seen XDelta produce amazing compression results, but it does the job fairly well in terms of patching. It’s also worth noting that XDelta doesn’t produce very small deltas for archive files, mainly because the predictive look-ahead model that it uses does not fare well with the contiguous file data laid out in archive files. You’ll quickly find that simply running XDelta on two archive files won’t produce the net savings that you’re looking to gain. As such, it may be more beneficial to generate patch files for each of your assets, and archive/compress those for transfer to the client.</p>
<p>If you’d like to roll your own patching system for arbitrary binary content, be warned that this is a tricky problem.  While it’s easy to come up with a <a href="http://www.computing.net/answers/programming/c-how-to-patch-a-file/15027.html">naive solution</a>, you’ll soon realize that there can be multiple patch points to a single file, which usually throws simple solutions out the window. You’ll also realize that the delta between two files may not be linear – it may include deletions, insertions, and replacements, which is difficult to track.  Make sure you’ve got manager approval before going down this route ;)</p>
<p>&nbsp;</p>
<h2><em>File processing and restricted systems</em></h2>
<p>Newer operating systems place restrictions on what content can be executed, mostly requiring that applications be <a href="http://en.wikipedia.org/wiki/Code_signing">signed</a> before they can be executed. Once an application is signed, the system can detect any change to the application, whether the change is introduced accidentally or by malicious code.  How to sign your assets and properly distribute/patch them to the client on a given platform is left as an exercise to you. Each OS seems to have its own policies on that process, and your actions will be depend on the systems to which you ship your game.</p>
<p>&nbsp;</p>
<h1>Conclusion</h1>
<p>It takes some effort to implement a patching system, but the benefits are well worth it. A patching system gives you increased flexibility and control over your game, lets you provide a better user experience, and gives you the opportunity to market new content to your users.</p>
<p>&nbsp;</p>
<h2>Source code</h2>
<p>My github account has some <a href="https://github.com/mainroach/sandbox/tree/master/patching-system">very simple source code</a> that implements the patching system described above.  (Be warned, it uses <a href="http://www.python.org/">Python</a>.)  The code includes a mock build system, a content server, and a client.  You can use this system with the following commands:</p>
<ol>
<li>python build/gen_patch.py</li>
<li>python server/httpd.py</li>
<li>python client/client.py</li>
</ol>
<p>Command (1) generates a patch from two builds.<br />
Command (2) starts a server from which to distribute patches.<br />
Command (3) calculates differences in the local version (assuming the client already has the initial build) and pulls down a delta patch from the content server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/12/a-simple-system-to-patch-your-game-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AltDev Student Summit &#8211; Speaker Change for Day 2</title>
		<link>http://www.altdevblogaday.com/2012/11/11/altdev-student-summit-speaker-change-for-day-2/</link>
		<comments>http://www.altdevblogaday.com/2012/11/11/altdev-student-summit-speaker-change-for-day-2/#comments</comments>
		<pubDate>Sun, 11 Nov 2012 13:03:42 +0000</pubDate>
		<dc:creator>AltDevConf</dc:creator>
				<category><![CDATA[#AltDevConf]]></category>
		<category><![CDATA[AltDev Student Summit]]></category>
		<category><![CDATA[AltDevConf]]></category>
		<category><![CDATA[Speaker Highlight]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28645</guid>
		<description><![CDATA[We have a change to our session schedule - "What is a Player Champion" by Romana Ramzan will be replaced by]]></description>
				<content:encoded><![CDATA[<p>Due to a last minute cancellation, the session &#8220;What is a Player Champion&#8221; given by Romana Ramzan will not be shown. Instead it will be replaced by &#8220;A Day in the Life of a Creative Director&#8221; given by Jurie Horneman of Mi&#8217;Pu&#8217;Mi Games:</p>
<blockquote><p><em>When preparing for this talk I made a list of all the things I do on a regular basis as the creative director of Mipumi Games. I then realized that a lot of the things I do are not what one might associate with being a creative director. I will be talking about what it takes to work on the director level at a small game development company.</em></p></blockquote>
<p>And here&#8217;s the bio for Jurie</p>
<blockquote><p><em>Jurie Horneman is the creative director of Mipumi Games, based in Vienna, Austria. He has been making games since 1991 and has worked as a game designer, producer and programmer. He got into the games industry via the Atari ST demo scene.</em></p></blockquote>
<p>We&#8217;re very grateful to Jurie for stepping in at the last minute. You can see his session at 1pm PST / 4pm EST / 9pm GMT today, Sunday 11th November.</p>
<p>We&#8217;ll be restarting the conference for Day 2 after a very successful first day in a few hours, at 11am PST / 2pm EST / 7pm GMT. Be sure not miss these <a href="http://www.altdevblogaday.com/altdev-student-summit-2012/watch-live/" title="Watch Live">great sessions live</a>, and join in the conversation using #AltDevConf on Twitter.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/11/altdev-student-summit-speaker-change-for-day-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speaker Highlight &#8211; Anne Toole</title>
		<link>http://www.altdevblogaday.com/2012/11/08/speaker-highlight-anne-toole/</link>
		<comments>http://www.altdevblogaday.com/2012/11/08/speaker-highlight-anne-toole/#comments</comments>
		<pubDate>Thu, 08 Nov 2012 15:29:28 +0000</pubDate>
		<dc:creator>AltDevConf</dc:creator>
				<category><![CDATA[#AltDevConf]]></category>
		<category><![CDATA[AltDev Student Summit]]></category>
		<category><![CDATA[AltDevConf]]></category>
		<category><![CDATA[Speaker Highlight]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28601</guid>
		<description><![CDATA[Our last speaker highlight is here, and the conference is only two days away, which is very exciting! Lastly, we'd like to introduce you to Anne Toole, and her session "Fitting Writers into the Development Process": Click through for more info!]]></description>
				<content:encoded><![CDATA[<p>Our last speaker highlight is here, and the conference is only two days away, which is very exciting! Lastly, we&#8217;d like to introduce you to Anne Toole, and her session &#8220;Fitting Writers into the Development Process&#8221;:</p>
<blockquote><p><em>Game developers are sometimes left scratching their heads on how to incorporate writers into the game development process.  This talk will take attendees through the stages of development to identify how a writer can integrate with the team and add value to the game, whether it be narrative-driven or narrative-light.</em></p></blockquote>
<p>And Anne&#8217;s bio is here:</p>
<blockquote><p><em>Anne Toole is a writer and designer who focuses on bringing fun, meaningful, and relevant content to games.  Her credits include the MMO &#8220;Wizard 101&#8243; and &#8220;The Witcher&#8221;, an RPG which earned her a Writers Guild nomination.  As a contract writer and designer, she has written games for the console, PC, and mobile in a variety of genres.  Anne has also served on staff as the first head writer for the MMO &#8220;Stargate Worlds&#8221; and has written for NBC serial &#8220;Days of Our Lives&#8221;.  Anne has spoken about games and entertainment for the inaugural Nokia OpenLab as well as at GDC Europe, GDC Online, South by Southwest, LOGIN Game Conference, and Comic-con International.  She contributed chapters to the IGDA&#8217;s Professional Techniques for Video Game Writing and Writing for Video Game Genres books and serves on the board of the Los Angeles chapter of the IGDA.  A citizen of the EU as well as the US, Anne holds a degree in Archaeology from Harvard.</em></p></blockquote>
<p><a href="http://www.eventbrite.com/event/4442293018?ref=ebtnebregn" target="_blank"><img src="http://www.eventbrite.com/custombutton?eid=4442293018" alt="Eventbrite - AltDev Student Summit" /></a></p>
<p>It&#8217;s nearly time for the Student Summit and you&#8217;ve now met all the exciting speakers we have lined up. Check out information on the <a href="http://www.altdevblogaday.com/altdev-student-summit-2012/" title="AltDev Student Summit 2012">whole event</a> and make sure that you sign up through Eventbrite!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/08/speaker-highlight-anne-toole/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starting a new game project? Ask the hard questions first</title>
		<link>http://www.altdevblogaday.com/2012/11/08/starting-a-new-game-project-ask-the-hard-questions-first/</link>
		<comments>http://www.altdevblogaday.com/2012/11/08/starting-a-new-game-project-ask-the-hard-questions-first/#comments</comments>
		<pubDate>Thu, 08 Nov 2012 00:51:38 +0000</pubDate>
		<dc:creator>Raul Aliaga Diaz</dc:creator>
				<category><![CDATA[Game design]]></category>
		<category><![CDATA[Production]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28588</guid>
		<description><![CDATA[<p>We have all been there. You wanted to start a new game project, and possibly have been dreaming of the possibilities for a long time, crafting stories, drawing sketches, imagining the dazzling effects on that particular epic moment of the game&#8230; then you start to talk to some friends about it, they give you feedback, and even might join you in the crazy journey of actually doing something about it.<br />
Fast forward some weeks or months, and you’ve been pulling too many all-nighters, having lots of junk food and heated discussions. You might even have a playable prototype, several character models, animations, a carefully crafted storyline, a website with a logo and everything but… it just doesn&#8217;t feel right. It&#8217;s not coming together and everyone involved with the project is afraid to say something. What happened? What went wrong? How such an awesome idea became this huge mess?</p>
<p><a href="http://www.altdevblogaday.com/2012/11/08/starting-a-new-game-project-ask-the-hard-questions-first/" class="more-link">Read more on Starting a new game project? Ask the hard questions first&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>We have all been there. You wanted to start a new game project, and possibly have been dreaming of the possibilities for a long time, crafting stories, drawing sketches, imagining the dazzling effects on that particular epic moment of the game&#8230; then you start to talk to some friends about it, they give you feedback, and even might join you in the crazy journey of actually doing something about it.<br />
Fast forward some weeks or months, and you’ve been pulling too many all-nighters, having lots of junk food and heated discussions. You might even have a playable prototype, several character models, animations, a carefully crafted storyline, a website with a logo and everything but… it just doesn&#8217;t feel right. It&#8217;s not coming together and everyone involved with the project is afraid to say something. What happened? What went wrong? How such an awesome idea became this huge mess?</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/ProjectGoneWrong.jpg"><img class="aligncenter size-full wp-image-28589" src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/ProjectGoneWrong.jpg" alt="" width="468" height="303" /></a></p>
<p>Usually all game projects emerge from a simple statement that quickly pushes the mind to imagine the possibilities. Depending on your particular tastes, background and peers, these statements can be like: &#8220;Ace Attorney, but solving medical cases, like House M.D.!&#8221; (Ace House™), &#8220;Wario meets Braid!&#8221; (Wraid™) , &#8220;Starcraft but casual, on a phone!&#8221; (Casualcraft™). These ideas can be just fine as starting points, but somewhere down the line the hardest question is: <em><strong>Is this game something worth doing?.</strong></em></p>
<p>When you work at a game studio and a new idea arises, that&#8217;s the first question it faces. And depending on the studio&#8217;s strengths, business strategy and past experiences, the definition of &#8220;worth&#8221; is very, very specific. It usually involves a quick set of constraints such as: time, budget, platforms, audience, team, among others. So for a particular studio that has developed Hidden Object Games and has done work for hire creating art, characters and stories for several other games, an idea like Ace House™ can be a very good fit, something they can quickly prototype and pitch to a publisher with convincing arguments to move it forward. However, in the case of a studio focused solely on casual puzzle games that has just one multi-purposed artist/designer and two programmers, it can be rather unfeasible, much more if all but one says: &#8220;What&#8217;s Ace Attorney? What&#8217;s House M.D.&#8221;?</p>
<p>Ok, you might say, &#8220;But I&#8217;m doing this on my own, so I can fly as free as I want!&#8221;. That&#8217;s not entirely true. If you want to gather a team behind an idea, all of the team members must agree that the project is worth doing, and even if you do it on your own, you must answer the question to yourself. Having less limitations can positively set you free, <em><strong>but take that freedom to find out your personal definition of worth, not to waste months on something that goes nowhere</strong></em>. Unless you can, like, literally burn money.</p>
<div id="attachment_28590" class="wp-caption aligncenter" style="width: 549px"><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/BurningMoney.jpg"><img class="size-full wp-image-28590" src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/BurningMoney.jpg" alt="" width="539" height="297" /></a><p class="wp-caption-text">The Joker Game Studios</p></div>
<p><em>Why is the project worth doing?</em> is the hardest question, and the one that must be answered with the most sincere honesty by everyone involved. The tricky part is that it is widely different for many people working on a game project out of their regular job or studies. It can be to start learning about game development, to improve a particular set of skills, to start an indie game studio, to beef up a portfolio, etc. It is O.K. to have different goals but they all must map to a mutually agreed level of time commitment, priorities and vision. But even if you figured this out, there are still other issues.</p>
<p><strong>All creative projects can be formulated as a set of risks or uncertainties, and the problem with video game development -given its highly multidisciplinary nature- is that is very easy missing to tackle the key uncertainties, and start working on the &#8220;easy&#8221; parts instead.</strong></p>
<p>So for example, for the Ace House™ project, it can be lots of fun to start imagining characters and doctors, nurses, patients and whatnot; there&#8217;s plenty of T.V. series about medical drama to draw inspiration from, and almost surely you can have a good time developing these characters, writing about them, or doing concept art of medical staff in the Ace Attorney style, but, What about the game? How do you precisely translate the mechanics from Ace Attorney to a medical drama? How is this different from a mere re-skin project? Which mechanics can be taken away? What mechanic can be unique given a medical setting? How can you ensure that Capcom won&#8217;t sue you? Are there any medic-like games already? How can we blend them? Is it possible? Is this fun at all? Is &#8220;fun&#8221; a reasonable expectation or should the experience be designed differently?</p>
<p>Let&#8217;s talk about Wraid™ now. If Konami pulled off &#8220;Parodius&#8221; doing a parody from &#8220;Gradius&#8221;, How cool would it be to do a parody of Braid using the characters from the Wario Ware franchise? Here you have a starting point for lots of laughs remembering playing Braid, and putting there Wario, <a href="http://mona.ytmnd.com/">Mona</a>, Jimmy T. and the rest of the characters on the game, wacky backgrounds, special effects and everything. But: Is this reasonable? Let&#8217;s start with the fact that Konami owns the IP of Gradius so they can do whatever they want to it. Can you get away with making a parody of both Nintendo and Jonathan Blow&#8217;s IPs? Sure, sure, the possibilities can be awesome but let&#8217;s face it: It is not going to happen. What can be a valuable spin-off though? What if Wario Ware games have a time-manipulation mechanic? What if you take Wario&#8217;s mini games and shape them around an art style and setting akin to Braid? (Professor Layton? Anyone?) How can you take the &#8220;parody&#8221; concept to the next level and just make &#8220;references&#8221; to lots of IP but the game is something completely new in itself?</p>
<p>What about Casualcraft™? Starcraft can be said to have roughly two levels of enjoyment: as an e-sport, and whatever other pleasure the other people draw from it. If we want to make it casual, it should not be an e-sport, should it? If you&#8217;re a Starcraft fan and have experience doing stuff for smartphones, you might think &#8220;This should be easy, I can make a prototype quickly&#8221;, and given that a mouse interface can be reasonably translated to touch, you start coding, and get a lot of fun implementing gameplay features that pumps all your OOP knowledge and creative juices to the roof. But… what does exactly mean &#8220;Casual Starcraft&#8221;? How can a strategy game be casual? What is the specific thing different from the e-sport experience that we want to bring to a phone? Is it the graphics? Is the unit building-leveling? Is playing with other friends? Which one of those should we aim? Can still be an RTS? What about asynchronous gameplay? Can this be played without a keyboard? Can still be fast? Would it fit on a phone? People that play on a phone: would they play this game?</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/Burst-Balloon.jpg"><img class="aligncenter size-full wp-image-28591" src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/Burst-Balloon.jpg" alt="" width="270" height="300" /></a></p>
<p>So, all these are tricky and uncomfortable questions, <em><strong>but they are meant to identify the sources of risk and figure out a way to address them</strong></em>. Maybe the ideas I presented here are plain bad, sure, but they are only for illustrational purposes. Since I started working in games, I&#8217;ve seen countless ideas from enthusiasts that are not really too far away from these examples anyway. The usual patterns I&#8217;ve seen are:</p>
<p><em><strong>Not identifying the core valuable innovation, and failing to simplify the rest: </strong></em>It is hard to innovate, much harder to do several innovations at once. Also, people have troubles learning about your game having too much simultaneous innovations and can quickly get lost, rendering your game as something they simply &#8220;don&#8217;t get&#8221;. The key is to identify what&#8217;s the core innovation or value of your idea, the one single thing that if done right, can make your game shine and then adjust all the rest to known formulas. And by &#8220;key&#8221; innovation I mean something important, critical, not stuff like &#8220;I won&#8217;t use hearts as a health meter but rainbows!&#8221;. That can be cute, but it&#8217;s not necessarily a &#8220;key innovation&#8221;.</p>
<p><em><strong>Putting known techniques and tools over the idea&#8217;s requirements: </strong></em>&#8220;I only do 3D modeling so it has to be 3D&#8221;, &#8220;I know how to use Unity so it has to be done in Unity&#8221;, &#8220;I only know RPG Maker so let&#8217;s make an RPG&#8221;. It is perfectly O.K. to stick to what you feel comfortable doing, but then choose a different idea. A game way too heavy on 3D might be awesome, but completely out of scope for a side project. Unity can be a great engine, but if all the other team members can work together on Flash on a game that it is completely agreed to live primarily on the web, it can&#8217;t hurt to learn Flash. RPG Maker is a great piece of software, but if you can&#8217;t really add new mechanics and will concentrate only in creating a story, why not just develop a story then? A comic book project is much more suitable. Why play your particular game when everyone that is into RPG&#8217;s surely has at least two awesome ones that they still can’t find the time to play them? Instead of crippling down the value or feasibility of your idea to your skills and resources, change the idea to something that fits.</p>
<p><em><strong>Obsessing over a particular area of the game (tech, story, etc): </strong></em>This usually happens when the true reason to do the project is to learn. You&#8217;re learning how to code graphic effects, or how to effectively use Design Patterns to code gameplay, a new texturing technique, vehicle and machines modeling, a story communicated through all game assets and no words, etc. You can get a huge experience and knowledge doing this. But then it&#8217;s not a game meant to be shipped, it is a learning project, or an excuse to fulfill something you feel passionate about.</p>
<p><em><strong>Failing to define constraints:</strong></em> The romantic idea of developing a game until &#8220;it feels right&#8221;. If Blizzard or Valve can do it, why can&#8217;t you? Well, because at some point, you&#8217;ll want to see something done and not feel that your time has gone to waste. The dirty little secret is that constraints almost all the time induce creativity instead of hinder it. So choose a set of constraints to start with, at least a time frame and something you would like to see done at particular milestones: Key concept, Prototype, Expanded Prototype, Game.</p>
<p><em><strong>Refusing to change the idea: </strong></em>This is usually a sign of failing to realize sunken costs. &#8220;I&#8217;ve spent so much time on this idea, I must continue until I&#8217;m done!&#8221;. The ugly truth is that if you&#8217;re having serious doubts, those will still be there and will make you feel miserable until you address them, and the sooner you act, the better. It can be that all the time you spent is effectively not wasted, but only when you frame it as your learning source to do the right things.</p>
<p>So if you&#8217;re starting a new game project, or are in the middle of one, try asking the tough questions: Do you know why is worth doing? Do all people involved agree on that? Are you making satisfying progress?<strong></strong></p>
<p><em>Are you sure there isn&#8217;t a question about your project you are afraid to ask because you fear that it can render your idea unfeasible, invaluable or messy?</em></p>
<p>Don&#8217;t be frightened, go ahead. If it goes wrong, you will learn, you will improve and the next idea will get to be shaped much better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/08/starting-a-new-game-project-ask-the-hard-questions-first/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speaker Highlight &#8211; Ted Spence</title>
		<link>http://www.altdevblogaday.com/2012/11/07/speaker-highlight-ted-spence/</link>
		<comments>http://www.altdevblogaday.com/2012/11/07/speaker-highlight-ted-spence/#comments</comments>
		<pubDate>Wed, 07 Nov 2012 12:04:06 +0000</pubDate>
		<dc:creator>AltDevConf</dc:creator>
				<category><![CDATA[#AltDevConf]]></category>
		<category><![CDATA[AltDev Student Summit]]></category>
		<category><![CDATA[AltDevConf]]></category>
		<category><![CDATA[Speaker Highlight]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28578</guid>
		<description><![CDATA[For readers of AltDevBlogADay, Ted Spence should be a familiar face. He joins the line up for the AltDev Student Summit with a session called "What Software Developers Should Expect From the Games Industry". Read on for more info.]]></description>
				<content:encoded><![CDATA[<p>For readers of AltDevBlogADay, Ted Spence should be a familiar face. He joins the line up for the AltDev Student Summit with a session called &#8220;What Software Developers Should Expect From the Games Industry&#8221;:</p>
<blockquote><p><em>Mr Spence, a twenty-year veteran of the games industry, will talk about his experience breaking into the games industry as a programmer, and how it differs from work in corporate software development.  Mr. Spence joined the CD-ROM gaming wave in the early 1990s and repeatedly switched back and forth between game development and business software / analytics, eventually resulting in the startup EEDAR, an analyst firm that provided services to all of the top 20 publishers in the videogame industry.</em></p></blockquote>
<p>For those who want to learn a bit more about Ted, here is a short bio</p>
<blockquote><p><em>Mr. Spence is a prolific video game technology consultant and developer.  In 2007, he joined EEDAR, a startup company providing analytics services to the videogame community.  As CIO, he built all technology and infrastructure for the startup as it grew from a one person company to a metadata powerhouse, providing services to all of the top 20 videogame publishers and many of the top retailers.</p>
<p>Prior to EEDAR, Mr. Spence managed technology infrastructure for Knowledge Adventure, where he ran IT and Internet operations during its spinoff from Vivendi Universal.  With a broad background and experience in a range of software and hardware technologies, Mr. Spence has developed a management methodology focusing on AGILE / SCRUM, and he writes about it regularly for gaming development websites AltDevBlogADay and Gamasutra.</p>
<p>Mr. Spence holds a Bachelor of Arts, Philosophy, from California State University, Fullerton, and lives in Oceanside with his wife and daughter.</em></p></blockquote>
<p><a href="http://www.eventbrite.com/event/4442293018?ref=ebtnebregn" target="_blank"><img src="http://www.eventbrite.com/custombutton?eid=4442293018" alt="Eventbrite - AltDev Student Summit" /></a></p>
<p>It&#8217;s nearly time for the Student Summit and Ted, and all the other speakers, are working hard to create excellent content for you this weekend. Check out information on the <a href="http://www.altdevblogaday.com/altdev-student-summit-2012/" title="AltDev Student Summit 2012">whole event</a> and make sure that you sign up through Eventbrite!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/07/speaker-highlight-ted-spence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AltDev Student Showcase &#8211; The Judges</title>
		<link>http://www.altdevblogaday.com/2012/11/06/altdev-student-showcase-the-judges/</link>
		<comments>http://www.altdevblogaday.com/2012/11/06/altdev-student-showcase-the-judges/#comments</comments>
		<pubDate>Tue, 06 Nov 2012 12:08:26 +0000</pubDate>
		<dc:creator>AltDevConf</dc:creator>
				<category><![CDATA[#AltDevConf]]></category>
		<category><![CDATA[AltDev Student Showcase]]></category>
		<category><![CDATA[AltDev Student Summit]]></category>
		<category><![CDATA[AltDevConf]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28574</guid>
		<description><![CDATA[We've announced the finalists for the AltDev Student Showcase already, but we keep talking about the expert judges who are going to be giving their feedback and deciding who will be going home with the Grand Prizes that Unity Technologies have put up. So, it's time to introduce the judges!]]></description>
				<content:encoded><![CDATA[<p>We&#8217;ve announced the finalists for the AltDev Student Showcase already, but we keep talking about the expert judges who are going to be giving their feedback and deciding who will be going home with the Grand Prizes that Unity Technologies have put up. So, it&#8217;s time to introduce the judges!</p>
<p>We&#8217;ve got an exciting array of talent and a diverse spread of skills and experience lined up to tell our competitors exactly what they think of their projects. We&#8217;re going to be running two sessions of the Student Showcase, one on each day of the AltDev Student Summit, and we&#8217;ll be changing the panel completely between sessions.</p>
<p>On Saturday, the Session 1 of the Student Showcase will take place at 13:00 PST / 16:00 EST / 21:00 GMT / 06:00 JST. Our panelists for this one will be:</p>
<ul>
<li>Kristen Bornemann &#8211; Development Director at ArenaNet</li>
<li>Phil Carlisle &#8211; AI Guy at Mindflock</li>
<li>Alex Darby &#8211; Technical Director at GamerCamp</li>
<li>Shawn Kirsch &#8211; Senior Production Services Technician at Sony Imageworks</li>
</ul>
<p>The second session will be held on Sunday at 11:00 PST / 14:00 EST / 19:00 GMT / 04:00 JST and will be judged by</p>
<ul>
<li>Mike Acton &#8211; Engine Director at Insomniac Games</li>
<li>Claire Blackshaw &#8211; Technical Designer at Climax Studios</li>
<li>Marcus Montgomery &#8211; Senior Designer at Backbone Entertainment</li>
<li>Pier Tortorelli &#8211; Associate Producer at Ubisoft Reflections</li>
</ul>
<p><a href="http://www.eventbrite.com/event/4442293018?ref=ebtnebregn" target="_blank"><img src="http://www.eventbrite.com/custombutton?eid=4442293018" alt="Eventbrite - AltDev Student Summit" /></a></p>
<p>The AltDev Student Showcase is just one of the exciting things we have lined up as part of the AltDev Student Summit. Please check out the <a href="http://www.altdevblogaday.com/altdev-student-summit-2012/" title="AltDev Student Summit 2012">mini-site</a> for more information and don&#8217;t forget to register to join us for this chance to learn how the pros assess projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/06/altdev-student-showcase-the-judges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AltDev Student Summit &#8211; Microtalks</title>
		<link>http://www.altdevblogaday.com/2012/11/05/altdev-student-summit-microtalks/</link>
		<comments>http://www.altdevblogaday.com/2012/11/05/altdev-student-summit-microtalks/#comments</comments>
		<pubDate>Mon, 05 Nov 2012 12:00:48 +0000</pubDate>
		<dc:creator>AltDevConf</dc:creator>
				<category><![CDATA[#AltDevConf]]></category>
		<category><![CDATA[AltDev Student Summit]]></category>
		<category><![CDATA[AltDevConf]]></category>
		<category><![CDATA[Speaker Highlight]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28564</guid>
		<description><![CDATA[<p>We offered speakers the opportunity to do some shorter sessions, following more of a microtalk format, and here they are.</p>
<p><strong><u>George Kokoris &#8211; The Cutting Room Floor</u></strong></p>
<p>Session &#8211; <em>Game design schools usually spend a little time teaching students about scope, but it&#8217;s not always given the importance it really deserves. Scope can make or break any project, from the smallest 48-hour game jam entry to the most opulently funded AAA blockbuster. Scoping mistakes are one of the most common reasons that game projects fail, but they are also avoidable with a little perspective and determination.</em></p>
<p><a href="http://www.altdevblogaday.com/2012/11/05/altdev-student-summit-microtalks/" class="more-link">Read more on AltDev Student Summit &#8211; Microtalks&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>We offered speakers the opportunity to do some shorter sessions, following more of a microtalk format, and here they are.</p>
<p><strong><u>George Kokoris &#8211; The Cutting Room Floor</u></strong></p>
<p>Session &#8211; <em>Game design schools usually spend a little time teaching students about scope, but it&#8217;s not always given the importance it really deserves. Scope can make or break any project, from the smallest 48-hour game jam entry to the most opulently funded AAA blockbuster. Scoping mistakes are one of the most common reasons that game projects fail, but they are also avoidable with a little perspective and determination.</em></p>
<p>Bio &#8211; <em>George is an ex-cinematographer, a graduate of Full Sail University, and a game designer at Microsoft Studios. As a member of game development collective Colorcave, he&#8217;s contributed code and design to small-scale indie titles as well as to Microsoft&#8217;s AAA portfolio. He&#8217;s a stubborn advocate for rapid prototyping and iterative design, and will ramble at great length about both if given half a chance. George currently resides in the Pacific Northwest.</em></p>
<p><strong><u>Travis Sanchez &#8211; The Blue Screen of Death</u></strong></p>
<p>Session &#8211; <em>Game crashing for everyone but you? It happens to all of us. Learn how professionals deal with bugs before shipping their game, and how you can improve your own beta or first deployment.</em></p>
<p>Bio &#8211; <em>Travis is a graduate of New Mexico Tech with a BS in CS who worked for 4 years at High Impact Games shipping games across PSP, PS2, PS3, XBox 360, Wii and 3ds.  Travis is primarily a programmer who has worked on optimising code and developing efficient multithreaded implementations for the XBox 360 and PS3, amongst many other things. Travis recently left the games industry to take a position at Google, where he is a Software Engineer</em></p>
<p><a href="http://www.eventbrite.com/event/4442293018?ref=ebtnebregn" target="_blank"><img src="http://www.eventbrite.com/custombutton?eid=4442293018" alt="Eventbrite - AltDev Student Summit" /></a></p>
<p>These great sessions and many more are taking place as part of the AltDev Student Summit, this coming weekend. Check out more information on the conference <a href="http://www.altdevblogaday.com/altdev-student-summit-2012/" title="AltDev Student Summit 2012">mini-site</a> and make sure you sign up through Eventbrite to be kept up to date.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/05/altdev-student-summit-microtalks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speaker Highlight &#8211; Mitu Khandaker</title>
		<link>http://www.altdevblogaday.com/2012/11/04/speaker-highlight-mitu-khandaker/</link>
		<comments>http://www.altdevblogaday.com/2012/11/04/speaker-highlight-mitu-khandaker/#comments</comments>
		<pubDate>Sun, 04 Nov 2012 11:58:27 +0000</pubDate>
		<dc:creator>AltDevConf</dc:creator>
				<category><![CDATA[#AltDevConf]]></category>
		<category><![CDATA[AltDev Student Summit]]></category>
		<category><![CDATA[AltDevConf]]></category>
		<category><![CDATA[Speaker Highlight]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28561</guid>
		<description><![CDATA[UK developer Mitu Khandaker is our next speaker highlight, in a session she has titled "A Day in the Life of a Solo Developer". Click through for more info.]]></description>
				<content:encoded><![CDATA[<p>UK developer Mitu Khandaker is our next speaker highlight, in a session she has titled &#8220;A Day in the Life of a Solo Developer&#8221;.</p>
<blockquote><p><em>Lessons from the lonely frontier of being a solo indie developer, from the one-woman team behind The Tiniest Shark Ltd, currently developing first commercial title, Redshirt. As a solo developer for the last 18 months (bonus content: while also trying to finish a PhD), Mitu chronicles the highs, the lows, and the cold, hard truths behind a day in the life of a new lone indie. and how you can prepare if you&#8217;re thinking of doing the same.</em></p></blockquote>
<p>Mitu&#8217;s bio is right here for you to learn more about her:</p>
<blockquote><p><em>Mitu Khandaker is an independent games developer at one-woman studio, The Tiniest Shark Ltd, currently developing its first commercial title, Redshirt. She is also a PhD researcher in games at the University of Portsmouth, UK. She occasionally writes for publications such as Continue Magazine, and was also named one of Develop Magazine&#8217;s Top 30 Under 30 upcoming game developers of 2012.</em></p></blockquote>
<p><a href="http://www.eventbrite.com/event/4442293018?ref=ebtnebregn" target="_blank"><img src="http://www.eventbrite.com/custombutton?eid=4442293018" alt="Eventbrite - AltDev Student Summit" /></a></p>
<p>We&#8217;re really pleased to have Mitu and all our speakers involved in this great event, and we hope you&#8217;ll join us. You can read more information, including the full schedule, on the <a href="http://www.altdevblogaday.com/altdev-student-summit-2012/" title="AltDev Student Summit 2012">conference mini-site</a>, and don&#8217;t forget to register through Eventbrite.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/04/speaker-highlight-mitu-khandaker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AltDev Student Summit &#8211; Breaking In Panel</title>
		<link>http://www.altdevblogaday.com/2012/11/03/altdev-student-summit-breaking-in-panel/</link>
		<comments>http://www.altdevblogaday.com/2012/11/03/altdev-student-summit-breaking-in-panel/#comments</comments>
		<pubDate>Sat, 03 Nov 2012 12:53:52 +0000</pubDate>
		<dc:creator>AltDevConf</dc:creator>
				<category><![CDATA[#AltDevConf]]></category>
		<category><![CDATA[AltDev Student Summit]]></category>
		<category><![CDATA[AltDevConf]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28524</guid>
		<description><![CDATA[Knowing how to get your start in the industry can be tough. There's no one fixed route to ensure that you get hired - if getting hired is even your aim. In this panel session, we've assembled some recent entrants into the world of professional video game development who have various points of view. Click through for more information.]]></description>
				<content:encoded><![CDATA[<p>Knowing how to get your start in the industry can be tough. There&#8217;s no one fixed route to ensure that you get hired &#8211; if getting hired is even your aim. In this panel session, we&#8217;ve assembled some recent entrants into the world of professional video game development who have various points of view. They&#8217;ve approached the problem different ways already, and achieved different things, and during the panel they&#8217;ll be discussing what worked, what didn&#8217;t and sharing their experiences with the audience in order to help them to &#8220;Break In&#8221;.</p>
<p>Our four panelists are:</p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/260458_1875664811451_344879_n-1.jpg"><img src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/260458_1875664811451_344879_n-1-e1351946460899-150x150.jpg" alt="" title="260458_1875664811451_344879_n (1)" width="150" height="150" class="alignleft size-thumbnail wp-image-28527" /></a></p>
<p style="padding-top:25px"><strong>Becky Taylor (Stomp Games)</strong> &#8211; Becky has been PC-gaming since she was 2 and front-end web programming since she was 7. Becky is a very determined individual, getting published in the Davis Art Publication&#8217;s Communicating by Graphic Design series whilst still in highschool, and being named Fitchburg State University&#8217;s Interactive Media Student of the Year for 2012. Becky graduated with a Bachelor&#8217;s of Science in Communications Media with a concentration in Interactive Media. She currently works at Stomp Games as a Marketing Associate for Robot Rising.</p>
<p><br style="clear:both;" /></p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/ben.jpg"><img src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/ben-150x150.jpg" alt="" title="ben" width="150" height="150" class="alignleft size-thumbnail wp-image-28526" /></a></p>
<p style="padding-top:25px"><strong>Ben Holschuh (2K Games)</strong> &#8211; Ben is currently working as a Production Assistant at 2K Games based out of Novato, CA. While no producer-y things can be directly seen in the games, he has worked on both Borderlands 2 and Bioshock Infinite in his short 6 months with the company so far. In 2011 he traveled to the IGDA Summit and Casual Connect conferences as an IGDA Scholar; an experience that helped him get where he is today. He graduated from Ohio University with a degree in Digital Media, a minor in Japanese, and a burning passion for all things games.</p>
<p><br style="clear:both;" /></p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/sarah.jpg"><img src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/sarah-150x150.jpg" alt="" title="sarah" width="150" height="150" class="alignleft size-thumbnail wp-image-28525" /></a></p>
<p style="padding-top:25px"><strong>Sarah Howarth (d3t)</strong> &#8211; Sarah is an electronics engineer and programmer, currently working at d3t Ltd. Her career began at Juiced Games as part of her high school work experience, and she hasn&#8217;t looked back as she has moved through Bizarre Creations and TT-Fusion, working on a number of titles such as James Bond: Bloodstone, Lego Pirates of the Caribbean and Lego Harry Potter: Years 5-7. At d3t, Sarah focuses on expanding the range of services offered by the company, as well as developing new approaches for platforms such as Playstation Mobile.</p>
<p><br style="clear:both;" /></p>
<p><a href="http://www.altdevblogaday.com/wp-content/uploads/2012/11/tyler1.jpg"><img src="http://www.altdevblogaday.com/wp-content/uploads/2012/11/tyler1-150x150.jpg" alt="" title="tyler" width="150" height="150" class="alignleft size-thumbnail wp-image-28529" /></a></p>
<p style="padding-top:25px"><strong>Tyler Coleman (Retora Game Studios)</strong> &#8211; Tyler is Founder and Creative Director of Retora Game Studios, an independent game studio in Phoenix, Arizona. In the past year, he has worked on multiple titles, with the first mobile release earlier this year. His passions include procedural generation, community involvement, game education, and Lua.</p>
<p><br style="clear:both;" /></p>
<p><a href="http://www.eventbrite.com/event/4442293018?ref=ebtnebregn" target="_blank"><img src="http://www.eventbrite.com/custombutton?eid=4442293018" alt="Eventbrite - AltDev Student Summit" /></a></p>
<p>With panelists with such diverse views on how you can get your start in the games industry, this should be a session not to be missed. You can read more about the whole event at the <a href="http://www.altdevblogaday.com/altdev-student-summit-2012/" title="AltDev Student Summit 2012">conference mini-site</a>, and please don&#8217;t forget to register to join us, November 10th and 11th from 11am PST / 2pm EST / 7pm GMT / 4am JST.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/03/altdev-student-summit-breaking-in-panel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speaker Highlight &#8211; Brandii Grace</title>
		<link>http://www.altdevblogaday.com/2012/11/02/speaker-highlight-brandii-grace/</link>
		<comments>http://www.altdevblogaday.com/2012/11/02/speaker-highlight-brandii-grace/#comments</comments>
		<pubDate>Fri, 02 Nov 2012 12:00:04 +0000</pubDate>
		<dc:creator>AltDevConf</dc:creator>
				<category><![CDATA[#AltDevConf]]></category>
		<category><![CDATA[AltDev Student Summit]]></category>
		<category><![CDATA[AltDevConf]]></category>
		<category><![CDATA[Speaker Highlight]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28490</guid>
		<description><![CDATA[<p>Next up is Brandii Grace with a session called &#8220;The Intern&#8217;s Secret Survival Guide&#8221;:</p>
<blockquote><p><em>I hear the same tragic story over and over: You finally landed an internship at a major game company! You just know this is your &#8220;big break&#8221; and can&#8217;t wait to get to work! Problem is&#8230; no one has given you any work to do. In fact, no one seems to know what to do with you or have time to figure it out. Before you know it, the internship is over and all you&#8217;ve done is sit around catching-up on webcomics. Learn the secret tricks my students used to transform internships into full time positions!</em></p></blockquote>
<p><a href="http://www.altdevblogaday.com/2012/11/02/speaker-highlight-brandii-grace/" class="more-link">Read more on Speaker Highlight &#8211; Brandii Grace&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Next up is Brandii Grace with a session called &#8220;The Intern&#8217;s Secret Survival Guide&#8221;:</p>
<blockquote><p><em>I hear the same tragic story over and over: You finally landed an internship at a major game company! You just know this is your &#8220;big break&#8221; and can&#8217;t wait to get to work! Problem is&#8230; no one has given you any work to do. In fact, no one seems to know what to do with you or have time to figure it out. Before you know it, the internship is over and all you&#8217;ve done is sit around catching-up on webcomics. Learn the secret tricks my students used to transform internships into full time positions!</em></p></blockquote>
<p>And as always, here is where you can learn a little bit more about Brandii:</p>
<blockquote><p><em>Brandii Grace is the Chief Creative Officer of Transform Entertainment – a pioneering company recently featured on Gamasutra for working to create AAA console games specifically targeting the growing women’s market. Brandii has nearly 10 years  of design and development experience in the games industry working with a wide array of platforms, genres, and markets for games ranging from giant AAA MMO’s to award-winning indie titles. Brandii, who graduated from Western Washington University with a Bachelor’s in Computer Science, is an alumna of the IGDA Scholars program and received the 2012 IGDA MVP award. She has taught game design innovation, been published in respected game development textbooks, and helped start more than one collegiate game program.</em></p></blockquote>
<p><a href="http://www.eventbrite.com/event/4442293018?ref=ebtnebregn" target="_blank"><img src="http://www.eventbrite.com/custombutton?eid=4442293018" alt="Eventbrite - AltDev Student Summit" /></a></p>
<p>Brandii&#8217;s session is just one part of what&#8217;s promising to be an excellent event. You can learn more at the <a href="http://www.altdevblogaday.com/altdev-student-summit-2012/" title="AltDev Student Summit 2012">conference mini-site</a>, and we really hope that you will join us November 10th and 11th to learn more from these excellent speakers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/02/speaker-highlight-brandii-grace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bitsquid Foundation Library</title>
		<link>http://www.altdevblogaday.com/2012/11/01/bitsquid-foundation-library/</link>
		<comments>http://www.altdevblogaday.com/2012/11/01/bitsquid-foundation-library/#comments</comments>
		<pubDate>Thu, 01 Nov 2012 21:42:31 +0000</pubDate>
		<dc:creator>Niklas Frykholm</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bitsquid]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[foundation]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[memory management]]></category>
		<category><![CDATA[stl]]></category>

		<guid isPermaLink="false">http://www.altdevblogaday.com/?p=28508</guid>
		<description><![CDATA[<p>Today I want to talk a bit about the <a class="link" href="https://bitbucket.org/bitsquid/foundation/overview">Bitsquid Foundation Library</a> that we recently released on Bitbucket (under the permissive MIT license).</p>
<p>It&#8217;s a minimalistic &#8220;foundation&#8221; library with things like memory management and collection classes. The idea is to have something that can be used as a reasonable starting-off point for other open source projects.</p>
<p><a href="http://www.altdevblogaday.com/2012/11/01/bitsquid-foundation-library/" class="more-link">Read more on Bitsquid Foundation Library&#8230;</a></p>
]]></description>
				<content:encoded><![CDATA[<p>Today I want to talk a bit about the <a class="link" href="https://bitbucket.org/bitsquid/foundation/overview">Bitsquid Foundation Library</a> that we recently released on Bitbucket (under the permissive MIT license).</p>
<p>It&#8217;s a minimalistic &#8220;foundation&#8221; library with things like memory management and collection classes. The idea is to have something that can be used as a reasonable starting-off point for other open source projects.</p>
<p>The library makes some interesting design choices that touches on topics that I have already talked about in this blog and that I think are worth elaborating on a bit further. It also serves an example on how these techniques can be used in &#8220;real world&#8221; code.</p>
<h2>Separation of data and code</h2>
<p>The foundation library implements the idea of separating data definitions and function implementation, that I talked about in <a class="link" href="http://www.altdevblogaday.com/2012/09/03/a-new-way-of-organizing-header-files/">this article</a>.</p>
<p>Data is stored in structs with public members (prefixed with an underscore to indicate that you should not mess with them unless you know what you are doing) that are found in <em>*_types.h</em> files. Functions that operate on the data are written outside of the struct, in separate <em>*.h</em> files (and organized into namespaces).</p>
<p>For example, the data definition for the dynamic <em>Array&lt;T&gt;</em> class is found in <em>collection_types.h:</em></p>
<pre>template&lt;typename T&gt; struct Array
{
    Array(Allocator &amp;a);
    ~Array();
    Array(const Array &amp;other);
    Array &amp;operator=(const Array &amp;other);
    
    T &amp;operator[](uint32_t i);
    const T &amp;operator[](uint32_t i) const;

    Allocator *_allocator;
    uint32_t _size;
    uint32_t _capacity;
    T *_data;
};</pre>
<p>The struct contains only the data used by the array and the operators which C++ forces us to implement as member functions. </p>
<p>The implementation of these functions, as well as the declaration and definition of all other functions that operate on the arrays are found in the <em>array.h</em> file. It contains things like:</p>
<pre>namespace array
{
    template&lt;typename T&gt;
    inline uint32_t size(const Array&lt;T&gt; &amp;a)
    {return a._size;}
    
    template&lt;typename T&gt;
    inline bool any(const Array&lt;T&gt; &amp;a)
    {return a._size != 0;}
    
    template&lt;typename T&gt;
    inline bool empty(const Array&lt;T&gt; &amp;a)
    {return a._size == 0;}
}

template &lt;typename T&gt;
inline Array&lt;T&gt;::Array(Allocator &amp;allocator) :
    _allocator(&amp;allocator), _size(0), _capacity(0), _data(0)
{}</pre>
<p>This way of arranging data and code fills two purposes.</p>
<p>First, it improves compile times by reducing header inclusion. Header files that want to make use of arrays only need to include <em>collection_types.h</em>, which just contains a few struct definitions. They don&#8217;t have to drag in <em>array.h</em>, with all its inline code.</p>
<p>Headers including other headers indiscriminately because they need their types is what leads to exploding compile times. By only including the minimal thing we need (the type definitions), compile times are minimized.</p>
<p>Second, and more importantly, this design allows the collection types to be freely extended. Is there anything you miss in the <em>array</em> interface? Perhaps you would like <em>shift()</em> and <em>unshift()</em> methods? Or <em>binary_search()?</em></p>
<p>No problem. If you want them you can just add them, and you don&#8217;t even need to modify <em>array.h</em>. Just create your own file <em>array_extensions.h</em> or whatever, and add some new functions to the <em>array</em> namespace, that manipulate the data in the <em>Array&lt;T&gt;</em> interface. The functions you create will be just as good as the functions I have created.</p>
<p>Note that this isn&#8217;t true for traditional class designs, where you have first-class citizens (methods) and second-class citizens (external functions).</p>
<p>The foundation library has some interesting examples of this. For example, the <em>string_stream</em> functions don&#8217;t operate on any special <em>StringStream</em> class, they just directly use an <em>Array&lt;char&gt;</em>. Also, the <em>hash</em> and <em>multi_hash</em> interfaces both work on the same underlying <em>Hash&lt;T&gt;</em> struct.</p>
<p>I believe that this design leads to simpler, more orthogonal code that is easier to extend and reuse.</p>
<h2>Memory management</h2>
<p>The library implements the allocator system mentioned in <a class="link" href="http://bitsquid.blogspot.se/2010/09/custom-memory-allocation-in-c.html">this article</a>. There is an abstract <em>Allocator</em> interface, and implementations of that interface can provide different allocation strategies (e.g. ArenaAllocator, HeapAllocator, SlotAllocator, etc). </p>
<p>Since I want to keep the library platform independent, I haven&#8217;t implemented a <em>PageAllocator</em>. Instead, the <em>MallocAllocator</em> is used as the lowest allocator level. If you want to, you can easily add a <em>PageAllocator</em> for your target platform.</p>
<p>For the same reason, I haven&#8217;t added any critical section locking to the allocators, so they aren&#8217;t thread safe. (I&#8217;m thinking about adding an interface for that though, so that you can plug in a critical section implementation if needed.)</p>
<p>The system for temporary allocations is kind of interesting and deserves a bit further explanation.</p>
<p>Most games have a need for temporary memory. For example, you might need some temporary memory to hold the result of a computation until it is done, or to allow a function to return an array of results.</p>
<p>Allocating such memory using the ordinary allocation system (i.e., malloc) puts a lot of unnecessary stress on the allocators. It can also create fragmentation, when long lived allocations that need to stay resident in memory are mixed with short lived temporary allocations.</p>
<p>The foundation library has two allocators for dealing with such temporary allocations, the <em>ScratchAllocator</em> and the <em>TempAllocator</em>.</p>
<p>The <em>ScratchAllocator</em> services allocation requests using a fixed size ring buffer. An <em>allocate</em> pointer advances through the buffer as memory is allocated, and a corresponding <em>free</em> pointer advances as memory is freed. Memory can thus be allocated and deallocated with simple pointer arithmetic. No calls need to be made to the underlying memory management system.</p>
<p>If the scratch buffer is exhausted (the <em>allocate</em> pointer wraps around and catches up with the <em>free</em> pointer), the <em>ScratchAllocator</em> will revert to using the ordinary <em>MallocAllocator</em> to service requests. So it won&#8217;t crash or run out of memory. But it will run slower, so try to avoid this by making sure that your scratch buffer is large enough.</p>
<p>If you forget to free something allocated with the <em>ScratchAllocator</em>, or if you accidentally mix in a long-lived allocation among the short-lived ones, that allocation will block the <em>free</em> pointer from advancing, which will eventually exhaust your scratch buffer, so keep an eye out for such situations.</p>
<p><em>TempAllocator&lt;BYTES&gt;</em> is a scoped allocator that automatically frees all its allocated memory when it is destroyed (meaning you don&#8217;t have to explicitly call <em>deallocate()</em>, you can just let the allocator fall out of scope). This means you can use it everywhere where you need a little extra memory in a function scope:</p>
<pre>void test()
{
     TempAllocator1024 ta;
     Array&lt;char&gt; message(ta);
     ...
}</pre>
<p>The <em>BYTES</em> argument to <em>TempAllocator&lt;BYTES&gt;</em> specifies how much stack space the allocator should reserve. The <em>TempAllocator</em> contains <em>char buffer[BYTES]</em> that gets allocated on the stack together with the <em>TempAllocator</em>.</p>
<p>Allocation requests are first serviced from the stack buffer, then (if the stack buffer is exhausted) from the <em>ScratchAllocator</em>.</p>
<p>This means that <em>TempAllocator</em> gives you an allocator that can be used by all collection classes and will use the fastest allocation method possible (local stack memory, followed by scratch buffer memory, followed by malloc() if all else fails).</p>
<h2>Minimalistic collection types</h2>
<p>The collection classes in the library are distinctly anti-STL. Some of the important differences:</p>
<ul>
<li>
<p>They use the allocation system described above (taking an <em>Allocator</em> as argument to the constructor). They can thus be used sensibly with different allocators (unlike STL types).</p>
</li>
<li>
<p>The use the data/function separation also described above, which means that the headers are cheap to include, and that you can extend them with your own functionality.</p>
</li>
<li>
<p>They use a minimalistic design. They assume that the stored data consists of plain-old-data objects (PODs). Constructors and destructors are not called for the stored objects and they are moved with raw <em>memmove()</em> operations rather than with copy constructors.</p>
</li>
</ul>
<p>This simplifies the code and improves the performance (calling constructors and destructors is not free). It also saves us the headache of dealing with storing objects that must be constructed with Allocators.</p>
<p>Personally I like this minimalistic approach. If I want to keep non-POD data in a collection, I prefer to store it as pointers anyway, so I have control over when and how the data is constructed and destroyed. I don&#8217;t like those things happening &#8220;behind my back&#8221;. You may disagree of course, but in that case you are probably happy to use STL (or boost).</p>
<p>Another example of choosing minimalism is the <em>Hash&lt;T&gt;</em> class. The hash uses a fixed key type which is a <em>uint64_t</em>. If you want to use a key that doesn&#8217;t fit into 64 bits, you have to hash it yourself before using it to access the data.</p>
<h2>And more?</h2>
<p>I&#8217;m planning to add some basic math code to the library, but haven&#8217;t gotten around to it yet.</p>
<p>Is there anything else you&#8217;d like to see in a library like this?</p>
<p>This has also been posted to <a class="link" href="http://bitsquid.blogspot.se/">the Bitsquid blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.altdevblogaday.com/2012/11/01/bitsquid-foundation-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 2.190 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2013-05-22 11:16:28 -->
<!-- Compression = gzip -->