<?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>Mark Danks &#187; Code</title>
	<atom:link href="http://www.danks.org/mark/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danks.org/mark</link>
	<description></description>
	<lastBuildDate>Thu, 03 Sep 2009 05:52:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flexibility in Development</title>
		<link>http://www.danks.org/mark/2009/09/02/flexibility-in-development/</link>
		<comments>http://www.danks.org/mark/2009/09/02/flexibility-in-development/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 04:59:18 +0000</pubDate>
		<dc:creator>mdanks</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://www.danks.org/mark/?p=312</guid>
		<description><![CDATA[Moving back to development with my studio means that I have seen a lot about what publishers are looking for these days.  Wii is, of course, very popular, but there is generally a desire to be &#8220;casual.&#8221;  The interesting thing is that most publishers are unsure what that means.  They want the [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><img class="alignright size-full wp-image-317" style="float: right;" title="joystick" src="http://www.danks.org/mark/wp-content/uploads/2009/09/joystick.jpg" alt="joystick" width="89" height="100" />Moving back to development with my studio means that I have seen a lot about what publishers are looking for these days.  Wii is, of course, very popular, but there is generally a desire to be &#8220;casual.&#8221;  The interesting thing is that most publishers are unsure what that means.  They want the popularity of the Wii, but still want to make games like they did for the PS2 and before.</p>
<p>A few publishers have figured out that the Wii market is different than the hardcore market from before, but that requires an understanding of a very different demographic than has bought Doom, Gears of War, and Call of Duty in the past.</p>
<p>Now that Microsoft&#8217;s Natal and Sony&#8217;s motion controller have been announced, the day for the joystick might seem to be limited.  However, not every player nor every gamer wants to jump around the room, regardless of the genre.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danks.org/mark/2009/09/02/flexibility-in-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zoe Mode San Francisco</title>
		<link>http://www.danks.org/mark/2009/05/19/zoe-mode-san-francisco/</link>
		<comments>http://www.danks.org/mark/2009/05/19/zoe-mode-san-francisco/#comments</comments>
		<pubDate>Tue, 19 May 2009 14:13:04 +0000</pubDate>
		<dc:creator>mdanks</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://www.danks.org/mark/?p=290</guid>
		<description><![CDATA[I am incredibly excited to launch my studio today.  I am the co-studio head for Zoë Mode San Francisco!  We are hard at work on a number of games and I am extremely honored to be working with such a great group of people.
Press release
Interview at GamesIndustry.biz
]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><img class="alignright size-full wp-image-291" style="float: right;" title="Zoe Mode" src="http://www.danks.org/mark/wp-content/uploads/2009/05/logo.gif" alt="Zoe Mode" width="169" height="76" />I am incredibly excited to launch my studio today.  I am the co-studio head for <a href="http://www.zoemode.com/">Zoë Mode San Francisco</a>!  We are hard at work on a number of games and I am extremely honored to be working with such a great group of people.</p>
<p style="text-align: left;"><a href="http://www.zoemode.com/news-011.html">Press release</a></p>
<p><a href="http://www.gamesindustry.biz/articles/sony-vets-open-new-us-studio-for-zoe-mode">Interview at GamesIndustry.biz</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.danks.org/mark/2009/05/19/zoe-mode-san-francisco/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asynch File Loading</title>
		<link>http://www.danks.org/mark/2009/05/18/asynch-file-loading/</link>
		<comments>http://www.danks.org/mark/2009/05/18/asynch-file-loading/#comments</comments>
		<pubDate>Tue, 19 May 2009 03:43:23 +0000</pubDate>
		<dc:creator>mdanks</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://www.danks.org/mark/?p=284</guid>
		<description><![CDATA[In most modern games, asynchronous file loading is a standard requirement.  This is especially true for open world games or games which never want to show a loading screen.  On the surface, it seems like an easy thing to do: spawn a new thread and load files on request.  However, there are a few complications [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><img class="alignright size-full wp-image-288" style="float: right;" title="Buckets" src="http://www.danks.org/mark/wp-content/uploads/2009/05/buckets.jpg" alt="Buckets" width="288" height="183" />In most modern games, asynchronous file loading is a standard requirement.  This is especially true for open world games or games which never want to show a loading screen.  On the surface, it seems like an easy thing to do: spawn a new thread and load files on request.  However, there are a few complications which get in the way.</p>
<p>One of the most obvious issues is knowing when the file has actually been loaded.  In an asynch environment, you issue a request, and some time later, the request is fulfilled.  Most systems return a handle which the game can check periodically to see if the data has been read.  This is fairly easy to implement, works well in a multithreaded environment, and is pretty easy to debug.  Other alternatives are to use a callback mechanism or put the calling thread to sleep until the data is loaded.  The sleep option is usually done in custom scripting languages, instead of trying to do it in C++.</p>
<p>A standard approach is to compress the data at build time and decompress at run time.  If you are reading from <a href="http://en.wikipedia.org/wiki/Dvd">DVD</a> <span id="more-284"></span>or <a href="http://en.wikipedia.org/wiki/Blu_ray">Blu-ray</a>, then it is practically a requirement due to the slow read speeds of those media.  On the <a href="http://en.wikipedia.org/wiki/Ps3">PS3 </a>or <a href="http://en.wikipedia.org/wiki/Xbox360">XBox360</a>, it is common to have your file system decompress on the fly, either on the <a href="http://en.wikipedia.org/wiki/Synergistic_Processing_Unit">SPUs </a>or on another core.  The complication is that you are no longer loading the data directly where it will be used.  Instead, you need to load it a temporary buffer, decompress the data, then write it to the final memory location.</p>
<p>On some <a href="http://en.wikipedia.org/wiki/Ps3">consoles</a>, there is not unified memory.  This means that you need to decide either ahead of time or at load time where the data will be loaded.  On the PS3, half of the memory is &#8220;main RAM&#8221; while the other half in &#8220;graphics memory&#8221; (<em>ignoring that data can be moved and read between the two systems</em>).  A simplistic approach is to put the data in the RAM segment based on the type of data&#8230;geometry to RSX memory, AI parameters to system RAM.  Since some types of data can be in either segment, this approach limits how flexibility the memory arrangement is.</p>
<p>Most file systems use a Table of Contents (ToC) to manage where and how the data is loaded.  Having a ToC for the data which is loaded gives:</p>
<ul>
<li>Position on disc</li>
<li>Memory segment to load into</li>
<li>Compression parameters</li>
<li>Data type</li>
<li>Resource Id</li>
<li>Human readable name</li>
</ul>
<p>A ToC also gives you flexibility during development.  The ToC can either contain all of the data in a single packed file, or it can simply list the files which need to be loaded.  Assembling a packed file can take a lot of time during development, especially when you have just changed one file.  This arrangement also makes it easy to do single file overrides.  Your nightly build system creates packed files for the game from checked in assets, but individuals can modify single files which are loaded seperately from the main packed file.</p>
<p>If you can override individual files, then you should look into hot-reloading of data: reloading data in the middle of the game so that artists can see texture changes without restarting, etc.  On the prototype I&#8217;m working on, I have a PC app which monitors my processed file directory and sending a message over the network to the game to reload it.  I have the file change logic on the PC in a single app, while the hot reloading is based in the game itself.  Since I&#8217;m working on a multiplatform game, this makes it easy for any new platform to load in the file.  Even the PC version registers itself with the file monitor app instead of scanning the directories explicitly.</p>
<p>One minor point to mention is that DX9 is not fully multithreaded.  This means that if you are allocating vertex, index, or texture buffers, they all have to be done from the render thread.  Microsoft explains it fairly well in <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=D6940B55-B805-46B5-B683-B8A2FE9B3D00&amp;displaylang=en">this presentation</a>.  This restriction makes it a bit more complicated, but it mostly involves extra signaling between the loading and render thread.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danks.org/mark/2009/05/18/asynch-file-loading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hard to Develop For</title>
		<link>http://www.danks.org/mark/2009/03/02/hard-to-develop-for/</link>
		<comments>http://www.danks.org/mark/2009/03/02/hard-to-develop-for/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 05:25:46 +0000</pubDate>
		<dc:creator>mdanks</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://www.danks.org/mark/?p=273</guid>
		<description><![CDATA[ A recent CNET article has much of the blog-o-sphere commenting away like crazy.  The article contains a quote from Kaz Hirai from SCE that the PS3 is hard to develop for.  In reading the article, the author does not appear to have thought much about why Kaz might have said that.
As a note, these [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><img class="alignright size-full wp-image-274" style="float: right;" title="PS3" src="http://www.danks.org/mark/wp-content/uploads/2009/03/sony_playstation_3_20_gb_270x270.jpg" alt="PS3" width="270" height="270" /> A recent CNET article has much of the blog-o-sphere commenting away like crazy.  The article contains a quote from <a href="http://en.wikipedia.org/wiki/Kaz_hirai">Kaz Hirai</a> from SCE that the PS3 is <a href="http://news.cnet.com/8301-13506_3-10173656-17.htm">hard to develop for</a>.  In reading the article, the author does not appear to have thought much about why Kaz might have said that.</p>
<p>As a note, these are only my views and do not represent my current employer, <a href="http://www.us.playstation.com/">SCE</a>, <a href="http://www.ea.com">EA</a>, or any past employers.  These views are also not based on any &#8220;inside&#8221; information, but instead are based on many years in the video games industry.</p>
<p>It is absolutely true that of the current consoles (PS3, XBox360, and Wii), the PS3 is the most complicated.  However, there are two aspects to developing on a console.  1) The hardware and 2) the development environment.  The thing that the author of the CNET article seemed to forget is that (excluding <a href="http://www.nintendo.com">Nintendo</a>), selling software is what makes the money, not selling the hardware.</p>
<p><span id="more-273"></span>The games industry makes most of its money from sequels and yearly franchises.  The <a href="http://www.metacritic.com/games/platforms/ps3/maddennfl09">Madden&#8217;s</a>, the <a href="http://www.metacritic.com/games/platforms/ps3/guitarheroworldtour">Guitar Hero&#8217;s</a>, etc.  These publishers need to have consumers buy their games every year.  If there isn&#8217;t something which makes the game better each year, then why would consumers purchase it?  This concept extends to franchises such as <a href="http://www.metacritic.com/games/platforms/xbox360/halo3">Halo </a>and <a href="http://www.metacritic.com/games/platforms/ps2/godofwar2">God of War</a>.  While I would love it if new stories and gameplay drove game sales, it is not not borne out by the sales numbers each month.</p>
<p>For the XBox360, there is a very easy to understand hardware and a great development environment.  This means that the games made today are not going to be much different from the XBox360 games of &#8220;tomorrow.&#8221;</p>
<p>For the PS3, it is a complicated hardware and historically is not a great development environment.  This means that games towards the end of the console will look much better than those at the start as developers learn how to take advantage of the hardware.  Keep in mind that currently, many hardcore consumers are looking for the better shiny object and realistically do not care about &#8220;story&#8221; and &#8220;gameplay innovation.&#8221;</p>
<p>Between the hardware and development environment, one of these can change over the course of a console&#8217;s lifecycle (and it isn&#8217;t the hardware&#8230;).  While the PS3 is still difficult to develop for, it has gotten much better over the past couple of years.  This means that developers are able to use more of the hardware and make their games better looking.  On the XBox360, how different is <a href="http://www.metacritic.com/games/platforms/xbox360/gearsofwar">Gears of War 1</a> from <a href="http://www.metacritic.com/games/platforms/xbox360/gearsofwar2">Gears of War 2</a>?  On the PS3, it will be interesting to compare <a href="http://www.metacritic.com/games/platforms/ps3/uncharteddrakesfortune">Uncharted 1</a> to <a href="http://www.metacritic.com/games/platforms/ps3/uncharted2amongthieves">Uncharted 2</a> this next holiday season.</p>
<p>So put Kaz&#8217;s comments into perspective.   If the software looks the same every year, then why would consumers buy the next version of something?  If the software gets better every year, then consumers are likely to purchase it to be on the best and brightest.  This philosophy served Sony very well on the PS2.  The question is if it will work on the PS3&#8230;especially when it does not have the same market share.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danks.org/mark/2009/03/02/hard-to-develop-for/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Objects, components, and services</title>
		<link>http://www.danks.org/mark/2008/12/21/objects-components-and-services/</link>
		<comments>http://www.danks.org/mark/2008/12/21/objects-components-and-services/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 20:51:07 +0000</pubDate>
		<dc:creator>mdanks</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.danks.org/mark/?p=242</guid>
		<description><![CDATA[Due to the holidays, I actually have some time to get back to programming.  Up until now, my code has been focused on the machine and engine layers&#8230;rendering, memory management, job control, debug scaffolding, etc.  All of the items which are needed to get things on screen, but do not have any of the behavior [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><img class="alignright size-full wp-image-243" style="float: right;" title="Tree of Life" src="http://www.danks.org/mark/wp-content/uploads/2008/12/tree_of_life.jpg" alt="Tree of Life" width="200" height="200" />Due to the holidays, I actually have some time to get back to programming.  Up until now, my code has been focused on the machine and engine layers&#8230;rendering, memory management, job control, debug scaffolding, etc.  All of the items which are needed to get things on screen, but do not have any of the behavior nor game play parts.</p>
<p style="text-align: left;">Most game engines have gone away from trying to describe game objects with explicit C++ class hierarchies.  Very quickly, there is a base object called <em>CObject</em> which has everything but <a href="http://en.wikipedia.org/wiki/Everything_but_the_kitchen_sink">the kitchen sink</a> in it.  This also creates an interconnected mess between the tick cycles for the object and all of the game systems.  It is very hard to parallelize the tick loop and impossible to move the objects off to extra processors such as the <a href="http://en.wikipedia.org/wiki/Synergistic_Processing_Unit">SPUs</a>.</p>
<p><span id="more-242"></span>A number of years ago when I was refactoring an engine, I realized that game objects really do not fit into a hierarchy, but rather are a collection of behaviors or components.  This has become a fairly common way to deal with objects in game engines these days.</p>
<p>Possible components are:</p>
<ul>
<li>Render</li>
<li>Animated</li>
<li>Physics</li>
<li>Tick</li>
<li>Position</li>
<li>Script</li>
<li>AI</li>
<li>HP and stats</li>
<li>etc</li>
</ul>
<p>A door object might consist of:</p>
<ul>
<li>Render -&gt; Draw object</li>
<li>Physics -&gt; Collision calculations</li>
<li>Position -&gt; Location in world including rotation</li>
<li>Script -&gt; Interactions</li>
</ul>
<p>An enemy character would have all of the components.  A non-interactive boulder might just have Render and Position.</p>
<p>The best situation is if the individual components are separable from other  component types and from the object itself.  For example, if all of the physics components are registered with a central manager, then the manager can &#8220;tick&#8221; all of the physics components without pulling in other data nor object dependencies.  This is an ideal situation for using the SPUs.</p>
<p>So far, this is all fairly standard engine design.</p>
<p>If an object is constructed from components, then how do you deal with temporary affects and behaviors?  For example, the player steps onto a burning floor and needs to take damage for some period of time while they are on fire.  This is not a component.  And you do not want to have the burning floor directly affect the player, especially since you do not know how many characters might walk through that floor space.</p>
<p>The additional part which I added was the concept of services.  Services tick every frame on an object and have a defined lifetime.  In the burning affect, the service would be a &#8220;take damage with fire pfx&#8221; which lasts for 10 seconds.  When the character walks through the burning floor, a burning service is attached to the character.  Every frame, the service is ticked.  It applies damage to the character and checks how long it has been in existence.  If its lifetime is up, then it is removed.  This does not require any involvement from the burning floor object once it has been attached to the character.</p>
<p>Another example is a <a href="http://en.wikipedia.org/wiki/Buff_(computer_gaming)">buff</a>.  A player casts a spell to increase their strength for a period of time.  The &#8220;spell&#8221; is a service which is applied to the player which increases the strength stat.  In the game, all of the spells are different variations on a service.  Ones which also change the rendering of the character are services which manipulate the rendering component in addition to the stats component.</p>
<p>Notice that in both the spell buff and the burning damage, the object does not have to have any special capabilities to use the service.  The service might depend on a component, but even that can be an optional (non-fatal) situation.  Adding new spells, new object affects, etc. can be done without needing to change the object hierarchy nor components.  Often, services can be defined in scripts and the C++ service is simply &#8220;run script service.&#8221;</p>
<p>Generally, services are very light weight computation or affects which do not require much processing time.  Because they are run directly with the object (and not batched up like the components and their managers), it is difficult to parallelize them.  Also, there tends to be more pointer chasing so DMA&#8217;ing them to the SPUs is problematic as well.</p>
<p>By creating a separation between components and services, the rule for deciding what something is becomes very simple.  If the behavior or affect starts when the object is created and only stops when the object is destroyed, it is a component.  If the behavior or affect only lasts for some period for time, then it is a service.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danks.org/mark/2008/12/21/objects-components-and-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last Day at Sony</title>
		<link>http://www.danks.org/mark/2008/11/14/last-day-at-sony/</link>
		<comments>http://www.danks.org/mark/2008/11/14/last-day-at-sony/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 05:26:48 +0000</pubDate>
		<dc:creator>mdanks</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://www.danks.org/mark/?p=228</guid>
		<description><![CDATA[I made the leap.  Today was my last day at Sony.  It has been an amazing time there and I am truly honored to have worked with such talented people.
&#8230;but something came up&#8230;
I am starting a new game studio in San Francisco.
]]></description>
			<content:encoded><![CDATA[<p>I made the leap.  Today was my last day at Sony.  It has been an amazing time there and I am truly honored to have worked with such talented people.</p>
<p>&#8230;but something came up&#8230;</p>
<p>I am starting a new game studio in San Francisco.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danks.org/mark/2008/11/14/last-day-at-sony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SPU Seminar</title>
		<link>http://www.danks.org/mark/2008/10/21/spu-seminar/</link>
		<comments>http://www.danks.org/mark/2008/10/21/spu-seminar/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 04:03:13 +0000</pubDate>
		<dc:creator>mdanks</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Travel]]></category>

		<guid isPermaLink="false">http://www.danks.org/mark/?p=211</guid>
		<description><![CDATA[I am heading off for the next few days to an SPU seminar that I am running.  At work, I spend a lot of my time dealing with the SPUs on the PS3.  In fact, if you are using the libswcache libraries in your game, then you are using code that I wrote.  The SPUs [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-212" style="float: right;" title="cell-processor" src="http://www.danks.org/mark/wp-content/uploads/2008/10/cell-processor.jpg" alt="" width="199" height="224" />I am heading off for the next few days to an <a href="http://en.wikipedia.org/wiki/Cell_microprocessor">SPU </a>seminar that I am running.  At <a href="http://www.us.playstation.com/">work</a>, I spend a lot of my time dealing with the SPUs on the PS3.  In fact, if you are using the libswcache libraries in your game, then you are using code that I wrote.  The SPUs are interesting beasts for multiprocessor work.  They are not as easy as the homogeneous multicore solution for the <a href="http://en.wikipedia.org/wiki/Xbox360">XBox360</a>, but for raw processor power, not much can beat the SPUs right now.</p>
<p>My work tends to be around making the SPUs easier for developers to use.  <a href="http://portal.acm.org/citation.cfm?id=509083">Software caching</a> (like libswcache) are ways to deal with non-uniform memory systems and making the architectural complexities more transparent to the end programmer.  I have a lot of experience with C++, so I have been looking at how <a href="http://en.wikipedia.org/wiki/Template_(programming)">templates </a>and <a href="http://en.wikipedia.org/wiki/Auto_ptr">auto_ptr</a>&#8217;s can help.  Libraries like these do not give you the peak performance, but it makes it much easier for the general gameplay programmers to work on the SPUs.  I have found that game development is a constant trade off between easy to use architectures which any generalist programmer can code for and extremely high performance architectures which require a specialist.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danks.org/mark/2008/10/21/spu-seminar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Lua</title>
		<link>http://www.danks.org/mark/2008/10/12/adding-lua/</link>
		<comments>http://www.danks.org/mark/2008/10/12/adding-lua/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 00:03:59 +0000</pubDate>
		<dc:creator>mdanks</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.danks.org/mark/?p=206</guid>
		<description><![CDATA[I spent the afternoon adding Lua to my code.  It only took about an hour to get the Lua library compiling and running.  The rest of the time was setting up the various hooks to make the scripting language actually functional.  I did not have time to add an interactive parser, that is on my [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-207" style="float: right;" title="Lua logo" src="http://www.danks.org/mark/wp-content/uploads/2008/10/logo.gif" alt="" width="128" height="128" />I spent the afternoon adding <a href="http://www.lua.org">Lua</a> to my code.  It only took about an hour to get the Lua library compiling and running.  The rest of the time was setting up the various hooks to make the scripting language actually functional.  I did not have time to add an interactive parser, that is on my list of things to do.</p>
<p>I have used Lua on previous games and never been that happy with it.  It tends to run slowly and require more memory than you would expect.  Also, most people tend to use it during development by reading in text files and doing on demand parsing.  This scares me since I prefer doing type checking and variable checking at a compile time&#8230;one typo and suddenly your run-time can blow up.  In some games, I have made the memory allocator throw an assertion if someone tried to allocate a var, string, etc. that was not seen before.  This seems to stop the typo problem, assuming that the game (and testers) have coverage over every script.</p>
<p><span id="more-206"></span>There is always a trade off between writing your own scripting language and using a prebuilt one.  I think a lot has to do with how much time and customization you require.  At Stormfront Studios, level designers never wrote any scripts by hand, but used a visual editor which made machine generated scripts.  Since most of those games were level-based, adventure games, most of the game play was triggers.  This meant that if there was an error, we needed to know immediately.  It also meant that the games ran everything in script (back on the PS2) so performance and memory was serious issue.  On MySims, the &#8220;level designers&#8221; were engineers who wrote scripts all day.  They were comfortable with full blown programming languages and encoded the actual game play and mini-games into the scripts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danks.org/mark/2008/10/12/adding-lua/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multithreaded Task System Arguments</title>
		<link>http://www.danks.org/mark/2008/08/13/multithreaded-task-system-arguments/</link>
		<comments>http://www.danks.org/mark/2008/08/13/multithreaded-task-system-arguments/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 05:08:09 +0000</pubDate>
		<dc:creator>mdanks</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://www.danks.org/mark/?p=91</guid>
		<description><![CDATA[I have implemented a task system for my brushing program.  In many ways, it emulates a PS3 by creating 6 threads which sleep until told to do something.  That &#8220;something&#8221; is a function which does a task and then exits.  There are two issues with this that I am resolving at the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-157" style="float: right;" title="spaghetti" src="http://www.danks.org/mark/wp-content/uploads/2008/08/spaghetti.jpg" alt="" width="175" height="178" />I have implemented a task system for my brushing program.  In many ways, it emulates a PS3 by creating 6 threads which sleep until told to do something.  That &#8220;something&#8221; is a function which does a task and then exits.  There are two issues with this that I am resolving at the moment.</p>
<ol>
<li>It is hard to debug the tasks when there are hundreds or thousands a frame</li>
<li>I want to emulate the PS3 SPU local store, which means segmenting my memory space</li>
</ol>
<p>To make each of these easier to deal with, all of the task entry functions take an argument.  This argument is a pointer to a ClTaskArg class.  Tasks are expected to derive from this class to get their arguments into, and potentially out of, the task function.</p>
<p><span id="more-91"></span></p>
<p>Here is the basic flow chart for how a task gets executed in my app.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-167" title="Task Flowchart" src="http://www.danks.org/mark/wp-content/uploads/2008/08/core.jpg" alt="" width="536" height="642" /></p>
<p>The decision points are mainly decided by the settings in the argument.  This is different from how most PC or XBox360 apps would work, since they have unified memory.  By creating a Local Store for the Task Function, it forces the app to think about how memory is handled and when to actually do a writeback.  The nice thing about my system is that a fair amount of the memory handling is done automatically without having to explicitly do the memcpy() in the user&#8217;s code.</p>
<p>A simplified and incomplete version of my ClTaskArg follows.   It mimics the PS3 by using EA &#8211; Effective Address.  The implementation is missing, as well as a lot of the header itself, but it should give an idea of how I deal with the argument into the Task Entry Function.</p>
<pre>class ClTaskArg
{
    public :

        //////////
        // Get the size of this structure
        int            getSizeOfStruct() const    { return(mcSizeOfStruct); }

        //////////
        // Get the write back address
        // [out] ClTaskArg * - the pointer in main RAM.  NULL if no write back
        ClTaskArg      *getThisEA() const         { return(mpThisEA); }

        //////////
        bool           breakOnEntry() const       { return(mBreakOnEntry); }

        //////////
        ClAlloc        *getLocalAllocator()       { return(mpLocalAlloc); }

    protected :

        //////////
        // Constructor
        // [in] sizeOfStruct - the full size of the structure to transfer
        // [in] writeBackStruct
        //        - should the structure be written back to main RAM on exit?
        ClTaskArg(int sizeOfStruct, bool writeBackStruct)
            : mpThisEA(0), mcSizeOfStruct(sizeOfStruct), mBreakOnEntry(false)
        {
            if (writeBackStruct)
            {
                mpThisEA = this;
            }
        }

    private :

        // Address of this structure in main RAM
        ClTaskArg    *mpThisEA;
        // The memory allocator for this core
        ClAlloc      *mpLocalAlloc;
        // The size of the structure
        const int    mcSizeOfStruct;
        // Should the thread break on entry?
        bool         mBreakOnEntry;
};</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.danks.org/mark/2008/08/13/multithreaded-task-system-arguments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiprocessor Programming</title>
		<link>http://www.danks.org/mark/2008/07/08/multiprocessor-programming/</link>
		<comments>http://www.danks.org/mark/2008/07/08/multiprocessor-programming/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 03:23:50 +0000</pubDate>
		<dc:creator>mdanks</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.danks.org/mark/?p=92</guid>
		<description><![CDATA[I am only 20 pages into it, but The Art of Multiprocessor Programming has become my new reference book.  It deals with all kinds of lock-free algorithms, queues, and synchronization methods.
Going forward, it is critical that programmers understand how to deal with multiprocessor systems.  While this book focuses on shared memory systems, the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-94" style="float: right;" title="Multiprocessor Book" src="http://www.danks.org/mark/wp-content/uploads/2008/07/couverturecgi1.jpg" alt="" width="115" height="150" />I am only 20 pages into it, but <a href="http://www.amazon.com/Art-Multiprocessor-Programming-Maurice-Herlihy/dp/0123705916/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1215573746&amp;sr=8-1">The Art of Multiprocessor Programming</a> has become my new reference book.  It deals with all kinds of lock-free algorithms, queues, and synchronization methods.</p>
<p>Going forward, it is critical that programmers understand how to deal with multiprocessor systems.  While this book focuses on shared memory systems, the concepts are still applicable to the PS3 (which does not have a shared memory system due to the SPUs).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danks.org/mark/2008/07/08/multiprocessor-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
