<?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>Doolwind&#039;s Game Coding Blog &#187; C++</title>
	<atom:link href="http://www.doolwind.com/blog/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.doolwind.com/blog</link>
	<description>Pragmatic Thoughts On Game Development</description>
	<lastBuildDate>Wed, 28 Jul 2010 22:53:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Fluent Game Design With Fluent Interfaces</title>
		<link>http://www.doolwind.com/blog/fluent-game-design-with-fluent-interfaces/</link>
		<comments>http://www.doolwind.com/blog/fluent-game-design-with-fluent-interfaces/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 08:00:08 +0000</pubDate>
		<dc:creator>Doolwind</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Game Coding]]></category>
		<category><![CDATA[Game Designer]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Scripting Language]]></category>

		<guid isPermaLink="false">http://www.doolwind.com/blog/?p=419</guid>
		<description><![CDATA[Game designers often find themselves writing code in modern games.  Often, they have little to no programming experience and therefore must be taught the basics of programming (sequence, conditionals and loops).  I propose utilizing a technique that simplifies the code written by game designers in their games.  This technique is known as “Fluent Interfaces”. What [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.doolwind.com/images/blog/fluentinterfaces.jpg"><img class="alignright" title="Fluent Interfaces" src="http://www.doolwind.com/images/blog/fluentinterfacessm.jpg" alt="" width="200" height="125" /></a>Game designers often find themselves writing code in modern games.  Often, they have little to no programming experience and therefore must be taught the basics of programming (sequence, conditionals and loops).  I propose utilizing a technique that simplifies the code written by game designers in their games.  This technique is known as “<a href="http://en.wikipedia.org/wiki/Fluent_interface">Fluent Interfaces</a>”.</p>
<p><span id="more-419"></span></p>
<p><strong>What is Fluent?</strong></p>
<p>Fluent interfaces allow game designers to <span class="pullquote pqRight">write more fluid and readable code</span>.  Through the use of method chaining, English like sentences can be written to express game functionality.  Fluent interfaces can be implemented in any object oriented programming language.  Below is an example of a line in the game design document, a standard implementation example and a fluent example:</p>
<p><span style="text-decoration: underline;">Game Design Document:</span></p>
<p>&#8220;Do 5 damage to all enemy tanks within range 2 of an entity&#8221;</p>
<p><span style="text-decoration: underline;">Standard Example:</span></p>
<pre class="csharpcode"><span class="csharp05">foreach</span><span class="csharp10">(</span><span class="csharp00"> </span>var<span class="csharp00"> </span>unit<span class="csharp00"> </span><span class="csharp05">in</span><span class="csharp00"> </span>player<span class="csharp10">.</span>UnitsWithinRange<span class="csharp10">(</span><span class="csharp04">2</span><span class="csharp10">)</span><span class="csharp00"> </span><span class="csharp10">)</span><span class="csharp00">
</span><span class="csharp10">{</span><span class="csharp00">
    </span><span class="csharp05">if</span><span class="csharp10">(!</span>unit<span class="csharp10">.</span>IsType<span class="csharp10">(</span>Enemy<span class="csharp10">)</span><span class="csharp00"> </span><span class="csharp10">||</span><span class="csharp00"> </span><span class="csharp10">!</span>unit<span class="csharp10">.</span>IsType<span class="csharp10">(</span>Tank<span class="csharp10">))</span><span class="csharp00">
        </span><span class="csharp05">continue</span><span class="csharp10">;</span><span class="csharp00">

    </span>unit<span class="csharp10">.</span>Damage<span class="csharp10">(</span>5<span class="csharp10">);</span><span class="csharp00">
</span><span class="csharp10">}</span><span class="csharp00">
</span></pre>
<p><span style="text-decoration: underline;">Fluent Example:</span></p>
<pre class="csharpcode">player<span class="csharp10">.</span>UnitsWithinRange<span class="csharp10">(</span><span class="csharp04">2</span><span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Enemy<span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Tank<span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>DoDamage<span class="csharp10">(</span><span class="csharp04">5</span><span class="csharp10">);</span></pre>
<p>This fluent example closely matches the design document and is easier to read.  It also uses less language constructs like loops and conditions.  With Intellisense, designers are given a context sensitive list of operations they can perform.  Designers simply build up the expression that describes the original line in the game design document they are implementing.</p>
<p><strong>How to implement Fluent Interfaces </strong></p>
<p>Fluent interfaces are actually quite easy to implement.  Objects expose methods that return a reference to the object itself allowing method chaining.  The best way to describe this is by showing the implementation required for the examples above.</p>
<p>First, we create the object we will be working on (I’ve called it UnitsList in my examples).  This gives us the first part of the fluent call (Get.UnitsWithinRange(2)).</p>
<pre class="csharpcode"><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">class</span><span class="csharp00"> </span>ScriptObject<span class="csharp00">
</span><span class="csharp10">{</span><span class="csharp00">
    </span>UnitsList<span class="csharp00"> </span>UnitsWithinRange<span class="csharp10">(</span><span class="csharp05">int</span><span class="csharp00"> </span>range<span class="csharp10">)</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span><span class="csharp05">return</span><span class="csharp00"> </span><span class="csharp05">new</span><span class="csharp00"> </span>UnitsList<span class="csharp10">(</span>range<span class="csharp10">);</span><span class="csharp00">
    </span><span class="csharp10">}</span><span class="csharp00">
</span><span class="csharp10">}</span><span class="csharp00">
</span></pre>
<p>The UnitsList object must have a set of methods that return references to the object itself allowing method chanining:</p>
<pre class="csharpcode"><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">class</span><span class="csharp00"> </span>UnitsList<span class="csharp00">
</span><span class="csharp10">{</span><span class="csharp00">
    </span><span class="csharp05">public</span><span class="csharp00"> </span>UnitsList<span class="csharp00"> </span>Where<span class="csharp10">(</span>UnitIs<span class="csharp00"> </span>condition<span class="csharp10">)</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span><span class="csharp05">this</span><span class="csharp10">.</span>conditions<span class="csharp10">.</span>Add<span class="csharp10">(</span>condition<span class="csharp10">);</span><span class="csharp00">
        </span><span class="csharp05">return</span><span class="csharp00"> </span><span class="csharp05">this</span><span class="csharp10">;</span><span class="csharp00">
    </span><span class="csharp10">}</span></pre>
<p>The fluent expressions are terminated by returning void from a function.  This lets the designer know they have no more options and often that the actual operation will be performed.</p>
<pre class="csharpcode"><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">class</span><span class="csharp00"> </span>UnitsList<span class="csharp00">
</span><span class="csharp10">{</span><span class="csharp00">
    </span><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">void</span><span class="csharp00"> </span>DoDamage<span class="csharp10">(</span><span class="csharp05">int</span><span class="csharp00"> </span>damage<span class="csharp10">)</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span><span class="csharp05">foreach</span><span class="csharp10">(</span><span class="csharp00"> </span>var<span class="csharp00"> </span>unit<span class="csharp00"> </span><span class="csharp05">in</span><span class="csharp00"> </span><span class="csharp05">this</span><span class="csharp10">.</span>mainUnit<span class="csharp10">.</span>UnitsWithinRange<span class="csharp10">(</span>range<span class="csharp10">)</span><span class="csharp00"> </span><span class="csharp10">)</span><span class="csharp00">
        </span><span class="csharp10">{</span><span class="csharp00">
            </span><span class="csharp05">if</span><span class="csharp10">(!</span>PassesConditions<span class="csharp10">(</span>unit<span class="csharp10">))</span><span class="csharp00">
                </span><span class="csharp05">continue</span><span class="csharp10">;</span><span class="csharp00">

            </span>unit<span class="csharp10">.</span>Damage<span class="csharp10">(</span>damage<span class="csharp10">);</span><span class="csharp00">
        </span><span class="csharp10">}</span><span class="csharp00">
    </span><span class="csharp10">}</span><span class="csharp00">

    </span><span class="csharp05">private</span><span class="csharp00"> </span><span class="csharp05">bool</span><span class="csharp00"> </span>PassesConditions<span class="csharp10">(</span>Unit<span class="csharp00"> </span>unit<span class="csharp10">)</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span><span class="csharp05">foreach</span><span class="csharp10">(</span><span class="csharp00"> </span>var<span class="csharp00"> </span>condition<span class="csharp00"> </span><span class="csharp05">in</span><span class="csharp00"> </span>conditions<span class="csharp10">)</span><span class="csharp00">
        </span><span class="csharp10">{</span><span class="csharp00">
            </span><span class="csharp05">if</span><span class="csharp10">(!</span>unit<span class="csharp10">.</span>IsType<span class="csharp10">(</span>condition<span class="csharp10">))</span><span class="csharp00">
                </span><span class="csharp05">return</span><span class="csharp00"> </span><span class="csharp05">false</span><span class="csharp10">;</span><span class="csharp00">
        </span><span class="csharp10">}</span><span class="csharp00">
        </span><span class="csharp05">return</span><span class="csharp00"> </span><span class="csharp05">true</span><span class="csharp10">;</span><span class="csharp00">
    </span><span class="csharp10">}</span><span class="csharp00">
</span><span class="csharp10">}</span><span class="csharp00">
</span></pre>
<p>There are a couple of key things to notice:</p>
<ol>
<li>This last code example      looks a lot like the original standard example</li>
<li>A lot more “engine” code      is required to setup a fluent interface than a standard interface</li>
</ol>
<p>So, in effect, an extra layer of abstraction is being placed over the original code.  Rather than designers working on loops and conditions, they are calling (well named) methods.  This makes their life a lot easier and simplifies maintenance of their gameplay code.  It pushes the burden of maintenance down from the gameplay to the engine level and therefore on programmers, who are better suited to maintaining code.  If there is a change in the engine or game, this extra level of abstraction serves to buffer the designers and reduce the amount of code that needs to be written.</p>
<p><strong>Good Interface Design</strong></p>
<p>Care needs to be taken when designing the interfaces and exposing methods to the designers.  Rather than exposing all functions off a single object my recommendation is to define different objects for different situations.  The example provided starts with the player and retrieves a list of units around it.  Filters are then added before the final operation is performed on the resulting list.  By limiting the methods available to the designer to simple filters there is little risk of them making a mistake.  Also, the fact that the &#8220;DoDamage&#8221; function returns void stops them from chaining anything further.</p>
<p><strong>Other Syntaxes</strong></p>
<p>One small point is that designers can structure their fluent “sentences” in any way they please:</p>
<pre class="csharpcode">player<span class="csharp10">.</span>UnitsWithinRange<span class="csharp10">(</span><span class="csharp04">2</span><span class="csharp10">).</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Enemy<span class="csharp10">).</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Tank<span class="csharp10">).</span>DoDamage<span class="csharp10">(</span><span class="csharp04">5</span><span class="csharp10">);</span></pre>
<pre class="csharpcode">player<span class="csharp10">.</span>UnitsWithinRange<span class="csharp10">(</span><span class="csharp04">2</span><span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Enemy<span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Tank<span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>DoDamage<span class="csharp10">(</span><span class="csharp04">5</span><span class="csharp10">);</span></pre>
<p>There is no difference between the above two examples.  It’s simply a matter of coding style preferred by the writer.</p>
<p><strong>Conclusion</strong></p>
<p>What do you think of Fluent Interfaces?  Have you used a similar technique before?  Do you think the extra engine code and maintenance is too much hassle for the gain in clarity to designers?</p>
<p>As an experiment, try exposing a small set of functionality through a fluent interface and see whether your designers like working with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doolwind.com/blog/fluent-game-design-with-fluent-interfaces/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Pragmatic Game Development</title>
		<link>http://www.doolwind.com/blog/pragmatic-game-development/</link>
		<comments>http://www.doolwind.com/blog/pragmatic-game-development/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 21:11:07 +0000</pubDate>
		<dc:creator>Doolwind</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Pragmatic]]></category>

		<guid isPermaLink="false">http://www.doolwind.com/blog/?p=269</guid>
		<description><![CDATA[Games take a lot of time and money to create.  Many companies can&#8217;t afford this ever increasing drain on their resources, particularly independent game developers.  Developers need to become more pragmatic in the way they developer their games.  This article describes the steps we&#8217;ve been taking to focus on releasing a good game, in the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.doolwind.com/images/blog/pragmatic.jpg"><img class="alignright" title="Pragmatic" src="http://www.doolwind.com/images/blog/pragmatic.jpg" alt="" width="173" height="130" /></a>Games take a lot of time and money to create.  Many companies can&#8217;t afford this ever increasing drain on their resources, particularly independent game developers.  Developers need to become more pragmatic in the way they developer their games.  This article describes the steps we&#8217;ve been taking to focus on releasing a good game, in the shortest time possible.</p>
<p><span id="more-269"></span></p>
<p><strong>Leverage existing technology</strong></p>
<p>Game developers have a bad habit of re-inventing the wheel.  The easiest way to run a game into the ground is to spend all our time creating new technology that already exists in the world.  We need to swallow our pride and use technology someone else has spent time and money creating.  Our core focus is making games, not game technology.  Let the experts handle the technology for us.</p>
<p>For programmers, there are countless engines we can take advantage of from Unity3D to Torque to UDK.  Project managers have access to countless tools to streamline the management process and keep them focussed on running a good team.</p>
<p>Learn to spend money where it&#8217;s needed.  Development time costs money.  If a problem has an off-the-shelf solution, we compare the cost of buying this to developing the solution in-house.  Nine times out of ten, it will be far cheaper to go with the former.</p>
<p><strong>Aim Small</strong></p>
<p>Projects always grow over time, sometimes uncontrollably.  We aim to start small, and keep a keen eye out for features that can be cut, checking the cost-to-benefit ratio of everything we do.  Ordering features by this ratio and cutting features from the bottom of the list when time runs out.</p>
<p>Feature creep is a killer on projects of all sizes.  By keeping milestones short we minimize the opportunities for us to diverge too far from our main goal.  If a feature grows in complexity beyond the scope of the initial design we take a step back and re-evaluate whether that feature is necessary given the new estimate on how long it will take to complete.</p>
<p><strong>Build what you need, not what you think you need</strong></p>
<p>Too many developers spend months working on the technology for their next game before starting the game itself.  Sometimes, they never make it to developing the game!  The most pragmatic solution to this is using someone else&#8217;s engine.  However, if we must create our own technology then we only create what we need right now.</p>
<p>A trap many developers fall into is thinking &#8220;we&#8217;ll be using this feature in the next five games, so it&#8217;s worth putting a lot of time into it now&#8221;.  If we do this for all our features, we won&#8217;t create our first game, let alone the next five.  My rule is that I don&#8217;t have enough information to make a generalised solution until I&#8217;ve implemented it at least a couple of times.</p>
<p>A great way of achieving these goals is adopting an agile development practice.  We are using Scrum for our current game which helps to keep us focussed on creating just enough to reach each sprint/milestone.</p>
<p><strong>It&#8217;s done when people are happy to pay for it</strong></p>
<p>A game is never going to be perfect.  I&#8217;m not advocating the release of buggy, broken games, but we do need to be practical when deciding whether our game is ready for release.  Creating constant playable builds is the best way to make sure the game is always fun and always meets a pre-determined quality bar set by the team.</p>
<p>It&#8217;s easy to fall into the trap of not wanting to release the game until it&#8217;s perfect.  After working on a game for months or years, it feels like your baby and you don&#8217;t want it out in the real world before it&#8217;s ready.  Being pragmatic means making the tough decision of deciding when the time is right to release the game even if you&#8217;re not 100% happy with it.</p>
<p>It is often better to cut a feature to give time to polish the existing gameplay which leads me to my next point&#8230;</p>
<p><strong>&#8220;We&#8217;ll do that in version 2&#8243;</strong></p>
<p>Release early and release often.  The best way to break the hit-driven nature of the games industry is to break the usual tradition of a big release with minimal updates after.  Plan to give away free (or cheap) &#8220;expansions&#8221; of core gameplay pushing the development of these features back until after initial release.  This has a number of key benefits:</p>
<ul>
<li>Begin to earn revenue sooner</li>
<li>Drive the initial cost of the game down by      releasing additional content in a paid or subscription format (e.g. DLC, in-game      assets)</li>
<li>Valuable feedback on the direction to take the      game</li>
<li>Focus on the bare minimum set of features to      sell the game, minimizing feature creep</li>
<li>Form a closer relationship with gamers by      giving them constant updates</li>
</ul>
<p><strong>Use the highest level of abstraction possible</strong></p>
<p>The higher the level of abstraction, the more time can be spent working on the game, rather than working on technology.  We are happy to give up some of the control over run-time performance for an increase in development speed.  Programmers can use a programming language like C# allowing them to spend time making a fun game, rather than managing memory and resources.  Artists can use a tool like ZBrush to create good looking models more easily and quickly.<strong></strong></p>
<p><strong>Automate</strong></p>
<p>Any repetitive day-to-day tasks should be automated by technology.  From build creation to the art pipeline.  We keep our time focussed on making a better game, not performing menial, repetitive tasks.  Programmers need to get in the mindset of spending a few hours per week working on tools to make everyone&#8217;s life better.  A programmer spending a few hours adding a new tool or updating an existing one can save weeks of work for the rest of the team.  Artists can learn batch operations in 3DSMax and Photoshop to help this process</p>
<p><strong>Conclusion</strong></p>
<p>This gives an insight into the ways we are being pragmatic in the development of our game.  By constantly focussing on the final product we make sure our time is spent on the most important tasks at all time.</p>
<p>How pragmatic are you in game development?  Do you have any other tips for minimizing cost and time?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doolwind.com/blog/pragmatic-game-development/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using C# For a Commercial Game</title>
		<link>http://www.doolwind.com/blog/using-csharp-for-a-commercial-game/</link>
		<comments>http://www.doolwind.com/blog/using-csharp-for-a-commercial-game/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 03:27:13 +0000</pubDate>
		<dc:creator>Doolwind</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Game Coding]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Scripting Language]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://www.doolwind.com/blog/?p=260</guid>
		<description><![CDATA[Does the title of this article make you cringe?  People have mixed feelings when it comes to C# and the .NET framework.  Just like many hardcore game developers 10 years ago swore that games should only be made in straight C, many developers today say that C++ is the only way to go.  This article [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.doolwind.com/images/blog/csharpcommercial.jpg"><img class="alignright" title="C# Commercial" src="http://www.doolwind.com/images/blog/csharpcommercial.jpg" alt="" width="109" height="82" /></a>Does the title of this article make you cringe?  People have mixed feelings when it comes to C# and the .NET framework.  Just like many hardcore game developers 10 years ago swore that games should only be made in straight C, many developers today say that C++ is the only way to go.  This article outlines my reasoning for using C# for a commercial game on PC.</p>
<p><span id="more-260"></span></p>
<p><strong>Rapid Application Development</strong></p>
<p>The primary reason for using C# is because coding in it is more productive than any other language I&#8217;ve used.  Language features like interfaces, generics and delegates make it a cleaner language than C++.  Development practices such as unit testing and dependency injection are also easier to use in C#.  This clarity translates to more readable code and less bugs, particularly when working with a larger or younger team of developers.</p>
<p>The second productivity gain comes from having access to the .NET framework.  From its XML handling for configuration, to built-in math libraries, many of the core functions you can think of are taken care of.  This saves you writing the code yourself and lets a reliable, tested framework do the heavy lifting in areas you don&#8217;t want to spend your time.</p>
<p>C# lets you focus on making a game rather than writing an engine, or learning someone else&#8217;s engine.</p>
<p><strong>Unified Code &#8211; Client, Server, Tools, Scripting</strong></p>
<ul>
<li><strong>Server</strong> &#8211; I&#8217;m writing the server      architecture (matchmaking, leaderboard, etc) in ASP.NET and C#.  This lets me share libraries between the      client and server and makes calling web services from the client a breeze.</li>
<li><strong>Tools</strong> &#8211; All our tools are also      written in C#.  This means that our      tools can have rendering within them, can reuse libraries and simplifies      the creation of in-game tools.</li>
<li><strong>Scripting &#8211; </strong>As I&#8217;ve mentioned in a <a href="http://www.doolwind.com/blog/why-you-should-use-csharp-for-your-scripting-language/">previous article</a>, I&#8217;m using C# for the scripting      language in our game.</li>
</ul>
<p><strong>Better Software Development</strong></p>
<p>C# supports better software development practices in a number of key ways:</p>
<ul>
<li><strong>Refactoring      Tools</strong> &#8211;      Visual Studio has great refactoring support such as renaming identifiers      and extracting methods &amp; interfaces.</li>
<li><strong>Separation of      Concerns</strong> &#8211;      Splitting a project into separate .dll&#8217;s is trivial in C#.  This helps with maintainability and encapsulation      of code and encourages good separation of concerns.</li>
<li><strong>Unit Testing</strong> &#8211; C# has great support for      unit testing through NUnit or MSTest.       As I&#8217;ve <a href="http://www.doolwind.com/blog/test-driven-game-development/">previously discussed</a>, unit      testing fits perfectly in certain areas of game development.  The easier unit testing is to achieve,      the more people are likely to adopt it.</li>
</ul>
<p><strong>In-Game Web Browser</strong></p>
<p>As part of the game engine we are developing we decided all interaction with the server for matchmaking would be through http/html.  This reduces the need for creating such a complex in-game UI system and simplifies communication with the server.  The .NET web browser control is extremely easy to use and communication between the browser and host application (the game) is a simple.</p>
<p><strong>Run-time isn&#8217;t too large</strong></p>
<p>I&#8217;m currently targeting the .NET 2 framework.  This put&#8217;s the footprint at around 20MB.  The latest .NET frameworks (3.5 and 4) both have a &#8220;client profile&#8221;.  This is a subset of the .NET framework that comes in at about 30MB.  My plan is to use the .NET 4 client profile once it is released as it gives me access to all the latest language features (Linq, lambda expressions, dynamic objects, etc).  MS is <a href="http://blogs.msdn.com/jgoldb/">currently planning</a> to make .NET 4 client profile a windows update meaning the .NET framework will finally become (almost) ubiquitous among PC&#8217;s running windows.</p>
<p><strong>Negatives</strong></p>
<p>There are obvious drawbacks to using C# for a commercial game engine which we took into consideration when making our decisions.</p>
<ul>
<li><strong>Not Cross      Platform</strong> &#8211;      While engines like Unity have proven that C# can run on multiple      platforms, this does not occur out of the box.  As we&#8217;re targeting PC&#8217;s exclusively for      our first release this was not a problem.</li>
<li><strong>Xbox run-time      not great</strong> &#8211;      C# can run on the Xbox as part of XNA game studio, however the run-time      performance isn&#8217;t great.  Garbage      collection is a particular problem which requires refactoring code to      achieve acceptable frame rates.<strong></strong></li>
<li><strong>Harder to use      C++ libraries</strong> &#8211; Linking to straight C++ (non-COM) libraries is not trivial like it is      connecting to other .NET libraries.       Extra time is required if there is a requirement to use existing      libraries such as RakNet.<strong></strong></li>
<li><strong>Some performance      concerns</strong> &#8211; C#      does have some performance concerns with garbage collection and certain      double math operations.  However the      algorithmic gains received from working with such a great language outweigh      the small performance issues in certain areas.  As with any language, bad code will run      slow.<strong></strong></li>
</ul>
<p><strong>Conclusion</strong></p>
<p>C# is a great language.  I thoroughly enjoy coding for it and I find it makes me more productive when creating games.  I plan to release my MVC engine in the future as an open source project.  Until then, I&#8217;m continuing to develop our engine and I&#8217;ll keep you up to date with the progress.</p>
<p>For reference, here are a couple of commercial games using C#:</p>
<p><strong>Arena Wars</strong> -<a href=" http://www.arenawars.net"> http://www.arenawars.net</a><strong></strong></p>
<p><strong>AI War Fleet Command</strong> &#8211; <a href="http://www.arcengames.com/aiwar_features.php">http://www.arcengames.com/aiwar_features.php</a></p>
<p><strong>Sacraboar</strong> &#8211; <a href="http://www.sacraboar.com">http://www.sacraboar.com</a></p>
<p>Have you used C# for game development?  Are you sick of chasing memory leaks and crashes in your C++ applications?  Do you think game developers will move on from C++ now or in the future?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doolwind.com/blog/using-csharp-for-a-commercial-game/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Why You Should Use C# For Your Scripting Language</title>
		<link>http://www.doolwind.com/blog/why-you-should-use-csharp-for-your-scripting-language/</link>
		<comments>http://www.doolwind.com/blog/why-you-should-use-csharp-for-your-scripting-language/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 21:37:59 +0000</pubDate>
		<dc:creator>Doolwind</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Game Engine]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Scripting Language]]></category>

		<guid isPermaLink="false">http://www.doolwind.com/blog/?p=240</guid>
		<description><![CDATA[I&#8217;ve used a lot of scripting languages over the years when developing games.  For my latest engine, I decided I’d use C# as the scripting language.  I’ve been amazed by how well C# works as a scripting language so I thought I’d share my experiences.  The technique I’m about to discuss gives game designers access to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.doolwind.com/images/blog/csharp.jpg"><img class="alignright" title="C#" src="http://www.doolwind.com/images/blog/csharp.jpg" alt="" width="154" height="96" /></a>I&#8217;ve used a lot of scripting languages over the years when developing games.  For my latest engine, I decided I’d use C# as the scripting language.  I’ve been amazed by how well C# works as a scripting language so I thought I’d share my experiences.  The technique I’m about to discuss gives game designers access to a fully-featured language and IDE with compile-time checking all while allowing run-time changes.  I use run-time compilation to achieve the flexibility of a scripting language combined with the power of a .NET language.</p>
<p><span id="more-240"></span></p>
<p><strong>Advantages</strong></p>
<p>There are a number of key advantages to using C# as a scripting language in your game engine.  I’ll list these first then describe how I achieve them.</p>
<ul>
<li><strong>Designers use Visual Studio.</strong> Most designers are stuck using notepad (or similar) when writing      their scripts.  With my technique,      designers can use Visual Studio, gaining the full power of the IDE.  Including:<strong> </strong>
<ul>
<li><strong>Intellisense</strong>. Letting them know what functions exist on all       of the objects you’ve exposed, as well as documentation you’ve provided       in code.<strong> </strong></li>
<li><strong>Compilation</strong>.<strong> </strong>Designers can compile their scripts       while making changes to catch any compile-time problems.<strong> </strong></li>
<li><strong>Full Debugging Support. </strong>Another       area lacking in most scripting languages is the debugging support.  Designers have access to all of Visual       Studios debugging functionality to help them find and fix issues with       their code.<strong> </strong></li>
</ul>
</li>
<li><strong>Run-Time Changes.</strong> Designers still have complete control to change their scripts at      run-time.  Scripts can be reloaded      automatically when files are changed, or (more likely) a “reset” button      can be exposed in the game engine that allows them to reset the level and reload      all scripts.<strong></strong></li>
<li><strong>Compile scripts into the executable for release.</strong> You have the option to use the scripts      compiled into the executable if you prefer, protecting your files.<strong></strong></li>
<li><strong>Complete Access to game objects, or whatever you want designers to      access.</strong> Designers are working      in the same language you are developing in.  They have full access to the game      objects or to a subset you decide on.       I use an interface and expose what I want them to use.<strong></strong></li>
<li><strong>FAST Run-time performance. </strong> The C# code is compiled not interpreted      meaning the run-time performance is as good as the rest of the engine.  The slight performance bottleneck of      reflecting the function can be removed by compiling scripts into      executable if required.<strong></strong></li>
<li><strong>No Binding Required.</strong> Binding is automatic between the game engine and the script.  You don’t need to write any plumbing and      exposing a new function is as easy as adding it to the engine.<strong></strong></li>
</ul>
<p><strong>How It Works</strong></p>
<p>The setup is surprisingly easy, designers follow these steps and their up and running:</p>
<ol>
<li>Add the script file to the      Visual Studio project (preferably in its own directory)</li>
<li>Create an Init() function      in the script class which will automatically be called by the engine</li>
<li>Create callbacks for events      and implement the game logic</li>
<li>Run the game and make      changes to scripts in real-time as needed</li>
</ol>
<p>I use the run-time compilation functionality of the .NET framework to compile and run the code on- the-fly.  This has a small performance hit during compilation however the run-time performance is excellent.</p>
<p><strong>Some Examples</strong></p>
<p>Below are a few examples I put together today to show the power of the system.</p>
<p>The first script below creates an entity at the beginning of the game and then sets up a callback that will fire every 5 seconds.  The TestScript object’s lifetime is until the scripting system is reset allowing stateful object creation.</p>
<pre class="csharpcode"><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">class</span><span class="csharp00"> </span>TestScript<span class="csharp00"> </span><span class="csharp10">:</span><span class="csharp00"> </span>BaseScript<span class="csharp00">
</span><span class="csharp10">{</span><span class="csharp00">
    </span><span class="csharp05">int</span><span class="csharp00"> </span>team<span class="csharp00"> </span><span class="csharp10">=</span><span class="csharp00"> </span><span class="csharp04">1</span><span class="csharp10">;</span><span class="csharp00">
    </span><span class="csharp05">int</span><span class="csharp00"> </span>xPos<span class="csharp00"> </span><span class="csharp10">=</span><span class="csharp00"> </span><span class="csharp04">15</span><span class="csharp10">;</span><span class="csharp00">
    </span><span class="csharp05">int</span><span class="csharp00"> </span>yPos<span class="csharp00"> </span><span class="csharp10">=</span><span class="csharp00"> </span><span class="csharp04">2</span><span class="csharp10">;</span><span class="csharp00">

    </span><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">void</span><span class="csharp00"> </span>Init<span class="csharp10">()</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span>script<span class="csharp10">.</span>CreateEntity<span class="csharp10">(</span><span class="csharp06">"Healer"</span><span class="csharp10">,</span><span class="csharp00"> </span>team<span class="csharp10">,</span><span class="csharp00"> </span>xPos<span class="csharp10">,</span><span class="csharp00"> </span>yPos<span class="csharp10">);</span><span class="csharp00">
        </span>script<span class="csharp10">.</span>CallEveryXSeconds<span class="csharp10">(</span>MyCallback<span class="csharp10">,</span><span class="csharp00"> </span><span class="csharp04">5</span><span class="csharp10">);</span><span class="csharp00">
    </span><span class="csharp10">}</span><span class="csharp00">

    </span><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">void</span><span class="csharp00"> </span>MyCallback<span class="csharp10">()</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span>script<span class="csharp10">.</span>CreateEntity<span class="csharp10">(</span><span class="csharp06">"Tank"</span><span class="csharp10">,</span><span class="csharp00"> </span>team<span class="csharp10">,</span><span class="csharp00"> </span>xPos<span class="csharp10">,</span><span class="csharp00"> </span>yPos<span class="csharp10">++);</span><span class="csharp00">
    </span><span class="csharp10">}</span><span class="csharp00">
</span><span class="csharp10">}</span><span class="csharp00">
</span></pre>
<p>The next script shows how simple customizing a game entity can be.  Whenever an effect is added or removed from a game entity, the following two functions are called allowing designers complete control over gameplay.  Notice the designer is given access only to what they need while still having complete control to change any settings or values of the entity.  An interface could be used to restrict what operations can be performed on entities as required.</p>
<pre class="csharpcode"><span class="csharp05">class</span><span class="csharp00"> </span>SpeedUpEffect<span class="csharp00">
</span><span class="csharp10">{</span><span class="csharp00">
    </span><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">void</span><span class="csharp00"> </span>AddEffect<span class="csharp10">(</span>GameEntity<span class="csharp00"> </span>entity<span class="csharp10">)</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span>entity<span class="csharp10">.</span>Speed<span class="csharp00"> </span><span class="csharp10">+=</span><span class="csharp00"> </span><span class="csharp04">1</span><span class="csharp10">;</span><span class="csharp00">
    </span><span class="csharp10">}</span><span class="csharp00">

    </span><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">void</span><span class="csharp00"> </span>RemoveEffect<span class="csharp10">(</span>GameEntity<span class="csharp00"> </span>entity<span class="csharp10">)</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span>entity<span class="csharp10">.</span>Speed<span class="csharp00"> </span><span class="csharp10">-=</span><span class="csharp00"> </span><span class="csharp04">1</span><span class="csharp10">;</span><span class="csharp00">
    </span><span class="csharp10">}</span><span class="csharp00">
</span><span class="csharp10">}</span><span class="csharp00">
</span></pre>
<p><strong>Conclusion</strong></p>
<p>As I said, I was amazed both at how simple all of this was to set up (only a few hours) and how powerful the system is.  If anyone is interested I’d be happy to share the source code for how I achieved this.  As I continue development of my engine I will be experimenting more with this scripting system and will release more information as I develop it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doolwind.com/blog/why-you-should-use-csharp-for-your-scripting-language/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Unified Game Development Scripting Language</title>
		<link>http://www.doolwind.com/blog/unified-game-development-scripting-language/</link>
		<comments>http://www.doolwind.com/blog/unified-game-development-scripting-language/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 23:55:13 +0000</pubDate>
		<dc:creator>Doolwind</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Game Engine]]></category>
		<category><![CDATA[Game Programming]]></category>
		<category><![CDATA[Scripting Language]]></category>
		<category><![CDATA[Unreal]]></category>

		<guid isPermaLink="false">http://www.doolwind.com/blog/?p=194</guid>
		<description><![CDATA[What is the best scripting language for game development?  Every different game engine has its own scripting language making for a difficult choice.  Game programmers have a unified language in C++ however game designers are left with whatever language their engine supports.  I propose a unified scripting language that all engines/platforms can share. Problem When [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.doolwind.com/images/blog/scriptinglanguages.jpg"><img class="alignright" title="Scripting Languages" src="http://www.doolwind.com/images/blog/scriptinglanguages.jpg" alt="" width="86" height="75" /></a>What is the best scripting language for game development?  Every different game engine has its own scripting language making for a difficult choice.  Game programmers have a unified language in C++ however game designers are left with whatever language their engine supports.  I propose a unified scripting language that all engines/platforms can share.</p>
<p><span id="more-194"></span></p>
<p><strong>Problem</strong></p>
<p>When you chose an engine or platform to develop for, you’re locking yourself into its scripting language.  This has the following core problems:</p>
<ul>
<li><strong>Difficult cross platform development</strong>.  Cross platform development is hard      enough without the worry of porting gameplay code.  Gameplay code should not be platform      specific, and therefore there is no reason to have a different language      per platform/engine.</li>
<li><strong>Immature languages</strong>.       With each company re-inventing the wheel when they implement a new      language designers are left with immature languages.</li>
<li><strong>Too many languages</strong>.       Designers must learn a new language whenever they develop for a new      engine/platform.  This increases      development time and reduces fluency in a language.  A designer cannot be free to fully      express themselves until they are fluent in the language they describe      their gameplay in.</li>
</ul>
<p><strong>Solution</strong></p>
<p>The solution to these problems is to have a unified scripting language shared by all engines/platforms.  Written specifically for game development it would take the best of current scripting languages.  The games industry as a whole would “own” the language allowing it to evolve with the needs of the industry as each new generation of hardware is released.</p>
<p><strong>Advantages</strong></p>
<p>There are a number of key advantages for moving towards a unified scripting language.</p>
<ul>
<li><strong>Single gameplay codebase</strong>.       Gameplay doesn’t change dramatically between similar platforms      (e.g. 360 and PS3 or flash and iPhone).       A unified language would allow a single codebase to kept across      multiple platforms helping with porting and maintenance.</li>
<li><strong>Specific to game development needs</strong>.  A language created specifically for game      development could cater to the needs of the industry.</li>
<li><strong>Single language for designers to use.</strong> Small nuances in existing languages can      create major issues for non-programmer designers.  A single unified language reduces these      problems and makes the learning path for students clearer.</li>
<li><strong>Less Wheel Re-Invention</strong>.       An open-source unified scripting language would allow anyone to      submit changes to the language to improve it, rather than re-inventing a      whole new language.</li>
<li><strong>Unified Toolset</strong>.  A      unified set of tools could sit on top of a unified scripting language.<strong></strong></li>
</ul>
<p><strong>Genre Specific</strong></p>
<p>The core language will hold the basic building blocks for all games.  In the future, small libraries can be built by studios or the community for each specific genre.  For example a library of functions common to most FPS or RTS games could be created and shared between developers.   A unified scripting language makes this sharing possible and encourages people to develop well thought out, robust libraries they can reuse from engine to engine.  It also serves to soften the blow for designers when changing engines as their common set of functions will move across with them.</p>
<p><strong>How</strong></p>
<p>There are two main options for the creation of a new unified scripting language:</p>
<ul>
<li><strong>Large studio forks their current language</strong>.  For example Epic could open up Unreal      Script and give out the source code for its implementation (let&#8217;s call it      OpenUnrealScript).</li>
<li><strong>Community Driven</strong>.  A      simple codeplex/google code project with a couple of leaders and a team of      developers would allow for rapid development, while meeting the needs of      multiple teams.  Early adopters      would drive the initial feature-set and help to drive its development.<strong></strong></li>
</ul>
<p><strong>Conclusion</strong></p>
<p>My dream is to see the next generation of consoles and other platforms (PC, iPhone, Flash) all supporting a unified language.  I&#8217;m interested in people&#8217;s thoughts on this idea and candidates for which language to use.  It&#8217;s less about language features and just agreeing on a core language everyone can use to develop games and bring all developers onto the same page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doolwind.com/blog/unified-game-development-scripting-language/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
