<?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; Scripting Language</title>
	<atom:link href="http://www.doolwind.com/blog/tag/scripting-language/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>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>
		<item>
		<title>Flexibility vs. Speed</title>
		<link>http://www.doolwind.com/blog/flexibility-vs-speed/</link>
		<comments>http://www.doolwind.com/blog/flexibility-vs-speed/#comments</comments>
		<pubDate>Wed, 30 Aug 2006 07:44:23 +0000</pubDate>
		<dc:creator>Doolwind</dc:creator>
				<category><![CDATA[CIC]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Scripting Language]]></category>

		<guid isPermaLink="false">http://www.doolwind.com/blog/?p=59</guid>
		<description><![CDATA[In software development there are many goals that we aim for in designing our software, some of which compete against each other. Two such goals are flexibility and speed. While they may not always be in competition, I&#8217;ve found in the past that they quite often are, and particularly so when it comes to game [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.doolwind.com/images/blog/ew.jpg"><img src="http://www.doolwind.com/images/blog/ew.jpg" alt="" width="219" height="172" align="right" /></a>In software development there are many goals that we aim for in designing our software, some of which compete against each other.  Two such goals are flexibility and speed.  While they may not always be in competition, I&#8217;ve found in the past that they quite often are, and particularly so when it comes to game development.  What exactly do I mean by these two terms?  Flexibility can mean anything from allowing multiple development languages to cross-platform support.  When I talk about speed I&#8217;m talking about actual run-time performance of your application.  Today I&#8217;m going to speak specifically about my time adding both <a href="http://www.somedude.net/gamemonkey/">GameMonkey</a> (GM) for scripting support and minimax for AI.</p>
<p><span id="more-59"></span></p>
<p><strong>The Mini-Game</strong></p>
<p>As part of a mini-game for CIC I wanted players to be able to play a chess-like game allowing one of the 4 or 5 players per ship to conduct &#8216;Electronic Warfare&#8217; against other ships they were battling with.  I needed to do a lot of prototyping of the game rules testing different types of units, different board sizes etc.  For the greatest flexibility in prototyping I decided to implement the entire game logic in script files allowing rule changes on the fly.  After investigating the different options for scripting languages, I chose to go with GM Script.  It also gave me the added benefit of trying out GM Script on a small sized project to help decide if I should use it for the high-level AI in the rest of CIC.</p>
<p>During the creation of the board game engine I first created chess and checkers, using script files only, to make sure I had enough features for a full chess-like game.  I then created a separate script file with the rules and unit types for my &#8216;Electronic Warfare&#8217; game.  It shows just how flexible scripting languages can be, with a simple change in script file completely changing the game.</p>
<p><strong>Game Monkey Script</strong></p>
<p>GM Script is &#8220;a simple, small, game / application extension language for C++ coders&#8221;.  It&#8217;s similar to Lua, but designed with C/C++ game programmers in mind.  Using a C style language it allows script (.gm) files to be loaded and executed at run-time.  The script files allow many useful features from configurable variables to complex functions.  I found it easy to use, simple to integrate with my own code, and generally a great benefit to the project.  I highly recommend anyone to check out GM script for any scripting solutions they need in the future, and feel free to contact me for any more detailed info or questions.</p>
<p><strong>MiniMax (with alpha-beta pruning)</strong></p>
<p>Thinking back to my AI subjects at university I remembered that minimax tree traversal was one of the best forms of AI for chess-like games.  After some investigation I decided I&#8217;d implement minimax for my chess game, and after a few hours of coding had simplistic tree generation and traversal implemented.  The basic concept of minimax tree traversal requires you to generate a tree of possible moves from the current board layout (and all moves from each of those moves etc).  Each set of moves is a new level in the tree, and the children for each node are all the possible moves from that board configuration.  The number of nodes in the tree quickly blows out with only looking ahead a small number of moves (currently I look forward 3 or 4 moves).  To allow looking forward this far I needed the game to run a lot faster.  I added my own memory pool, I compressed my board and unit class sizes as far as I could and ran AMD&#8217;s optimizer (<a href="http://developer.amd.com/downloads.aspx">CodeAnalyst</a>) over my game to find any bottlenecks.  After squeezing as much performance as I could out of the code I ended up running into a brick wall, I couldn&#8217;t have both the flexibility of a scripting language and still have the speed to run the minimax algorithm properly.</p>
<p><strong>Script vs. AI</strong></p>
<p>As a lot of the core gameplay was implemented as functions within GM script, every time I called them I had a major run-time hit which wasn&#8217;t a problem during regular play, but when generating thousands of possible moves it soon grinds to a halt.  Don&#8217;t get me wrong, I&#8217;m not saying you shouldn&#8217;t use scripting in your games; it&#8217;s just that you have to choose where you use it wisely.  One area of the GM script that allows your app to still have excellent run-time performance is configuration variables.  By loading all of the definitions in at once (at load time) and storing them in regular C++ structs/class you can then access them at full speed while still having the flexibility of originally loading them in from script.  There is no native support for binding GM config files to C++ struct/classes however it&#8217;s a simple task to create this yourself.  Using configuration variables I&#8217;ve managed to get around the problem for now, however it means I can&#8217;t have any of the extra features (like special moves such as castling in chess) working with the AI.</p>
<p>The main performance problem will occur if you use script in a time critical part of the game loop.  Scripting languages when compiled to non-native byte code will be 10-100 times slower than native code.</p>
<p><strong>Conclusion</strong></p>
<p>So in summary, GM script could be a great addition to your game, in moderation, and minimax is an excellent algorithm to use in any chess-like game.  Minimax has fairly limited uses outside of that scope, however it was fun to implement and only took a few hours to get up and running, with a few extra hours optimizing it.  I now have the fun task of making the AI smarter through the &#8216;score&#8217; it gives to a particular board configuration, the better the algorithm, the smarter the AI will be.  Once I&#8217;m happy with the AI I&#8217;ll look to start integrating it within CIC and see how it plays with the rest of the game.  Then it&#8217;s on to implementing all of the fancy features I&#8217;ve come up with over the past few months of design.  I&#8217;d like to thank <a href="http://www.squidtank.com/">Shauno</a> for working on the art for my &#8216;Electronic Warfare&#8217; game, it goes to show again just how much better a game looks when a real artist has spent even a few hours on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doolwind.com/blog/flexibility-vs-speed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
