<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Systematic Gaming</title>
	<atom:link href="http://systematicgaming.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://systematicgaming.wordpress.com</link>
	<description>Systems programming for games</description>
	<lastBuildDate>Sat, 27 Aug 2011 11:41:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='systematicgaming.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Systematic Gaming</title>
		<link>http://systematicgaming.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://systematicgaming.wordpress.com/osd.xml" title="Systematic Gaming" />
	<atom:link rel='hub' href='http://systematicgaming.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Asset Management Checklist</title>
		<link>http://systematicgaming.wordpress.com/2009/07/23/asset-management-checklist/</link>
		<comments>http://systematicgaming.wordpress.com/2009/07/23/asset-management-checklist/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 05:45:49 +0000</pubDate>
		<dc:creator>systematicgaming</dc:creator>
				<category><![CDATA[asset management]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://systematicgaming.wordpress.com/?p=661</guid>
		<description><![CDATA[Now that we&#8217;ve looked at the layers of asset management, let&#8217;s reflect upon the key points and see how we can improve our existing engine and pipelines. Each of these questions targets a specific part of the asset pipeline that deserve consideration.  By reflecting on these points you can see ways to improve your own [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=661&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Now that we&#8217;ve looked at the layers of asset management, let&#8217;s reflect upon the key points and see how we can improve our existing engine and pipelines.</p>
<p>Each of these questions targets a specific part of the asset pipeline that deserve consideration.  By reflecting on these points you can see ways to improve your own asset pipeline and workflow.</p>
<h2>Runtime</h2>
<p>Are shared assets duplicated unnecessarily?</p>
<p>Are instanced assets handled efficiently?  With minimal overhead and waste?</p>
<p>Do you support generated (procedural) assets seamlessly?</p>
<p>Are you wasting memory on strings or filenames?</p>
<p>Do you avoid unnecessary loading or reloading between levels?</p>
<h2>Processing</h2>
<p>Are you processing data to make runtime asset management more efficient?</p>
<p>Do you pack referenced assets together for faster loading?</p>
<p>Do you optimize disc layout based on asset usage?  (Duplicate data, sort of dependency graph, etc)</p>
<h2>Content &amp; Workflow</h2>
<p>Is your source data versioned?</p>
<p>Can you re-create a previous version of your data?</p>
<p>Can you identify who last changed an asset? And why?</p>
<p>Are your tools integrated with your asset management system?</p>
<p>How many steps are required by a user to add a new asset?  How many to update or tweak an asset?</p>
<p>How long does it take to view a data change in game?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/systematicgaming.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/systematicgaming.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/systematicgaming.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/systematicgaming.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/systematicgaming.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/systematicgaming.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/systematicgaming.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/systematicgaming.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/systematicgaming.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/systematicgaming.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/systematicgaming.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/systematicgaming.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/systematicgaming.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/systematicgaming.wordpress.com/661/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=661&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://systematicgaming.wordpress.com/2009/07/23/asset-management-checklist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">systematicgaming</media:title>
		</media:content>
	</item>
		<item>
		<title>Asset Management &#8211; Content</title>
		<link>http://systematicgaming.wordpress.com/2009/07/16/asset-management-content/</link>
		<comments>http://systematicgaming.wordpress.com/2009/07/16/asset-management-content/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 06:14:04 +0000</pubDate>
		<dc:creator>systematicgaming</dc:creator>
				<category><![CDATA[asset management]]></category>
		<category><![CDATA[workflow]]></category>
		<category><![CDATA[game programming]]></category>

		<guid isPermaLink="false">http://systematicgaming.wordpress.com/?p=505</guid>
		<description><![CDATA[We&#8217;ve already looked at the runtime and processing layers of asset management, now we&#8217;re ready to look at the most involved and complex layer &#8211; the content layer. This is the layer where the content producers &#8211; artists, level designers, sound artists,  anyone who creates game content truly interfaces with the game engine. At this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=505&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve already looked at the <a href="http://systematicgaming.wordpress.com/2009/07/06/asset-management-runtime/">runtime </a>and <a href="http://systematicgaming.wordpress.com/2009/07/06/asset-management-processing/">processing</a> layers of asset management, now we&#8217;re ready to look at the most involved and complex layer &#8211; the content layer.</p>
<p>This is the layer where the content producers &#8211; artists, level designers, sound artists,  anyone who creates game content truly interfaces with the game engine. At this level we&#8217;re not just dealing with runtime data &#8211; we need to manage digital content creation (DCC) tool data, such as PhotoShop PSD files, Maya files, etc.  In addition to custom data types produced from in-house tools or game engines.</p>
<p>This layer is all about how content creators use and interact with data and the game engine.  The key components of this layer are:</p>
<ul>
<li>Asset tracking and versioning</li>
<li>Tool integration and workflow</li>
</ul>
<p><span id="more-505"></span></p>
<h2>Tracking and Versioning</h2>
<p>The central issue of asset management is not loading, processing or low-level data manipulation.  At its core asset management is all about identifying and tracking data.  We need to know where data comes from and what state it&#8217;s in.  This information is important for a number of reasons:</p>
<ul>
<li>It lets us track project progress &#8211; if we know only 3 of 10 levels have been built we know we&#8217;re at most only 30% done</li>
<li>It lets us track bugs &#8211; if our licensed logo needs to be fixed because the TM is slightly off center we need to be able to find and fix all instances of that logo in our game</li>
<li>Proper tracking can be used to identify problem areas &#8211; why do we have two brick wall textures?</li>
<li>Tracking will identify how modifying an asset will affect the game &#8211; if you update the brick wall texture what levels are affected?</li>
</ul>
<p>The bottom line is that asset tracking and versioning lets us know what data is in our game.  This may sound simple, but I&#8217;ve worked on projects where source data only existed on some artists desktop folder.  Data was put in the game simply by copying it to some network drive.</p>
<p>This creates huge problems when the artist leaves and their hard drive is formatted, or you try and port to a new system and can&#8217;t find the &#8220;c:\bobs_work\head.tga&#8221; file.  In a complete asset management system these situations shouldn&#8217;t be possible.  All game data would be properly tracked.</p>
<p>What do we mean by tracking data?  The idea isn&#8217;t really that different from managing code &#8211; any competent programming team is using source control and some form of bug tracking.  We just need to create a parallel for managing data.  The key features we want are:</p>
<ul>
<li><strong>Version control </strong>- there is a need to see who changed what, when it was changed and the reason for change.  We also have need to revert to older versions of data for testing and bug fixing purposes</li>
<li><strong>Authoritative version</strong> &#8211; we need some way of identifying the &#8220;official&#8221;  version of our data</li>
<li><strong>Asset tracking</strong> &#8211; we need to know the path data takes to get into the game (e.g. head.psd is exported to head.tga which builds the texture &#8220;head&#8221;)</li>
</ul>
<p><strong>Version control</strong> can be done a multitude of ways with the simplest being using an existing source control system, like Perforce or Subversion.  Some, such as AlienBrain are designed to work with source art data.  Some systems are faster than others, some cheaper than others, but as long as you can add/remove/update/restore versions of your data your set to go.</p>
<p><strong>Authoritative versions</strong> of data require you have some means of identifying (or re-creating) the exact version of data you intend to build.  It is important to know exactly what data is on the DVD you&#8217;re creating.  There has been more than one game that shipped with inappropriate &#8220;placeholder&#8221; assets still on the disc &#8211; later discovered by curious gamers.  Any proper version control system will let you do this easily &#8211; usually through a  tagging or branching mechanism.</p>
<p><strong>Asset tracking</strong> can be difficult to solve with technology &#8211; there&#8217;s so many possible paths for data.  At the very least you need to be able to clearly associate your runtime data with the source data that generated it.  Whether this is done by some tracking software or simply file convention and documentation (e.g. runtime asset name = source file name), it&#8217;s important that the relation is well understood by both the game engine team and the content producers.</p>
<p>Just like with programming you manage your source information, not your output.  Like in programming, proper asset management requires version control.  Version control lets us know exactly what data is being used in our game.  This can be very important if you have to change something like a licensed logo that needs to be fixed or removed. It also lets us ensure we&#8217;ve backed up our data properly.  Another common reason for controlling source data is for sequels and ports &#8211; for good or bad outsourcing such products is very common, having versioned and controlled access to source assets makes this a more efficient  process.</p>
<h2>Tool Integration and Workflow</h2>
<p>Tools and workflow are important areas of game development. Workflow is especially important &#8211; with today&#8217;s content heavy games you need to be able to add, adjust and improve content efficiently.  Asset management plays a large part in a smooth workflow.</p>
<p>Game content is often authored by different people using a variety of tools.  Each step in this process &#8211; called the <strong>pipeline </strong>- may require a separate specialized tool.  This series of tools results in what we call a <strong>tool chain</strong> &#8211; basically a set of tools that we need work with our data.</p>
<p>To meet our goals of tracking and versioning assets, we should be managing the assets as they pass through the entire development pipeline.  It&#8217;s clearly desirable that asset management be integrated closely with our entire tool chain.  Close integration will then allow us to track and version data at each and every stage of our pipeline.</p>
<p><strong>Tool integration</strong> means our tools understand our underlying asset management system.  This may simply mean that a tool can load/edit/commit changes to our source control.  It can be expanded to include automatically build runtime data whenever we make changes to source assets.  This tightly-coupled integration between tools, pipeline and runtime provides an efficient workflow for content creators.</p>
<p>How we integrate with tools varies a lot from tool to tool.  In-house developed tools can be most easily integrated since we have complete control over them.  External tools &#8211; such as Maya and Photoshop &#8211; are a bit more difficult.  Some, like Maya, allow for extensive customization and have their own scripting environments.  With effort we can mold them to integrate with our asset management systems.  Some tools have only minor customization &#8211; via plugins &#8211; or none at all.  This means we have a less than seamless integration, any may require some manual step to import/export data.   Alternatively we may choose to develop an external management system, such as a custom GUI asset management program, a Windows Explorer extension or even a lowly set of batch files from which to manage our assets.</p>
<p>Ultimately we need to make the experience of managing assets simple, seamless and error free as possible.  Remember &#8211; the target audience of these tools aren&#8217;t usually programmers and generally won&#8217;t fully understand the end-to-end pipeline.  So we should try to automate as much as possible with out removing control when needed.  There will always be a balance between simplicity and control, you&#8217;ll have to find your own balance to meet your project&#8217;s needs.</p>
<p><strong>Workflow </strong>is what people do on a day to day basis.  The key there is <strong>people</strong>.  Workflow is all about how people operate and work with our game engine and tools.  Where the <strong>pipeline</strong> is the path that data travels to get into our game, the <strong>workflow</strong> is the collection of processes people follow to create and manipulate our assets.  The distinction is important because we can implement every technical requirement I&#8217;ve mentioned: versioning, optimized data packing, runtime ready data, and still have a poor workflow.</p>
<p>Where asset management comes in is with a <strong>managed workflow</strong> &#8211; which ties the human process of content creation to the underlying asset management system.  The exact details of a managed workflow are very task specific &#8211; each type of content, each stage of a process may have very different requirments.  However, a few common high-level issues that asset management can improve are:</p>
<ul>
<li><strong>Locating </strong>- we have thousands of assets in our game, how do we find the one we need right now?</li>
<li><strong>Sharing </strong>- content may pass through many hands and tools, how do we smoothly pass data between different people?</li>
<li><strong>Validating </strong>- how do we know if our data is correct? Functional?  High quality?</li>
</ul>
<p><strong>Locating</strong> assets is actually a very large problem, difficult to locate data makes creating composite assets time consuming.  The simplest methods are simply searching by asset name &#8211; but this requires consistent and logical naming.  Creating a consistent and logical naming convention for assets is more difficult than it first sounds, and often leads to ugly names &#8211; e.g. dg043_bark.wav, hd_093_spec_03.tga.  Which may be perfectly logical &#8211; but not very easy to remember.</p>
<p>We should attempt to match the way we locate data with the way to use data.  This can be as simple as adding categories to each asset (tag-like metadata).  Perhaps it&#8217;s better to visually represent data if possible &#8211; a thumbnail gallery for textures is one possibility.  Even better still to allow both &#8211; categorized galleries.  The ultimate may be a context senstive editor that automatically displays appropriate assets &#8211; rock and tree textures when editing a forest level, bricks and rusty metal for your urban scenes.  However, the needs of your animator may be completely different.</p>
<p><strong>Sharing</strong> assets is more and more important as teams grow and roles are specialized.  Once upon a time a single game artist may do it all &#8211; modeling, texturing, rigging and animation.  Now it likely that separate people &#8211; even separate teams &#8211; are resonsible for each of the above steps.  You need to optimize this workflow by providing an efficient way of passing assets through this pipeline.  Maybe just adding a &#8220;status&#8221; tag to each asset is enough, maybe you need to add some notification to the next person along the pipeline when a stage is completed.  Whatever you do you need to ensure that you manage these transitions when tracking your assets.</p>
<p><strong>Validating</strong> assets involves testing the data in the actual game before releasing it to the wider team.  Each stage of a pipeline may need to be reviewed before passing along to the next.  In level design often a &#8220;level designer&#8221; will create a basic block level, pass it along to an artist to texture and polish, then pass it to a lighter who&#8217;ll add lighting to the scene.  At each stage we may need an art director or gameplay lead to review the work before passing along to the next person in the pipeline.  Asset management needs to accomidate these reviews, and similar to the sharing, allow the status of assets to be know.</p>
<h2>Summary</h2>
<p>The highest level of asset management you&#8217;ll notice there aren&#8217;t as many clear answers or technical solutions to the issues.  This is because content creation &#8211; where we design and compose our assets &#8211; is not about implementing technolgy to solve our problems.  Its about finding creative people and helping them create assets.</p>
<p>Hopefully you can now see how asset management is involved with every stage of the data pipeline and how we can improve our workflow and game engines by leveraging proper asset management.</p>
<ul>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:3385px;width:1px;height:1px;">
<pre>   Vector3 position;
   Vector3 rotation;
   Vector3 scale;</pre>
</div>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/systematicgaming.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/systematicgaming.wordpress.com/505/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/systematicgaming.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/systematicgaming.wordpress.com/505/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/systematicgaming.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/systematicgaming.wordpress.com/505/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/systematicgaming.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/systematicgaming.wordpress.com/505/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/systematicgaming.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/systematicgaming.wordpress.com/505/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/systematicgaming.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/systematicgaming.wordpress.com/505/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/systematicgaming.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/systematicgaming.wordpress.com/505/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=505&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://systematicgaming.wordpress.com/2009/07/16/asset-management-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">systematicgaming</media:title>
		</media:content>
	</item>
		<item>
		<title>Asset Management &#8211; Processing</title>
		<link>http://systematicgaming.wordpress.com/2009/07/02/asset-management-processing/</link>
		<comments>http://systematicgaming.wordpress.com/2009/07/02/asset-management-processing/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 04:21:47 +0000</pubDate>
		<dc:creator>systematicgaming</dc:creator>
				<category><![CDATA[asset management]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://systematicgaming.wordpress.com/?p=622</guid>
		<description><![CDATA[Last time we looked into the lowest levels of asset management, which can be handled by referencing counting and intelligent loading.  With the next level, the processing layer, we look at how we prepare assets for our runtime.  This is an important step and where a lot of optimization occurs.  We can break the processing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=622&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last time we looked into the <a href="http://systematicgaming.wordpress.com/2009/06/28/asset-management-runtime/">lowest levels of asset management</a>, which can be handled by referencing counting and intelligent loading.  With the next level, the <strong>processing layer</strong>, we look at how we prepare assets for our runtime.  This is an important step and where a lot of optimization occurs.  We can break the processing layer down into a few distinct stages:</p>
<ul>
<li>Asset referencing</li>
<li>Building (or baking)</li>
<li>Packing</li>
</ul>
<p><span id="more-622"></span></p>
<h2>Asset Referencing</h2>
<p>Asset referencing is the act of having one asset use another.  A material using a texture for example.  We mentioned <strong>composite assets</strong> in the runtime layer but didn&#8217;t go into detail on how we should actually maintain those references, or links.</p>
<p>Some links are <strong>implicit</strong> and some are <strong>explicit</strong>.  Implicit links are ones that are assumed by the engine, for example a model named &#8220;monster3&#8243; might always use the material named &#8220;monster3&#8243;.  Implicit links are based on game or engine specific rules and are quite common.  Explicit links are specified by the asset itself and are the general way assets reference each other.</p>
<p>The naive approach for supporting references is to store asset file names for each link.  This is quite straightforward to implement, but has a number of drawbacks.  File names require us to store and manipulate strings, which is waste of CPU time and memory. It also means assets are tightly coupled to our file system, which doesn&#8217;t always make sense for generated assets.</p>
<p>One way is to improve this is to assign each asset a unique id and reference the id instead of a file name.  This means we can save memory and processing time since we only need to store the asset id for each reference.  This id can be be assigned externally (from some central database) or simply be a hash of the asset name.</p>
<p>For example we could uses a simple CRC hash such as CRC(&#8220;Texture:Monster3Head&#8221;).  Hashes are nice because we can generate them on the fly if needed.   Alternatively, with assigned asset ids, asset references can remain stable even if the linked asset&#8217;s name changes.  In addition we don&#8217;t have to worry about hash collisions.  However, we do need a way to assign unique ids.</p>
<p>Either method means that we can store references compactly and uniquely identify each asset.  We&#8217;ll go into more depth about asset ids when we talk about the higher levels of asset management.</p>
<h2>Data Building</h2>
<p>Data building is actually a very involved process, involving converting data from artist created formats to runtime ready data.  A detailed description of the actual data conversion process, sometimes called <strong>baking</strong>, is outside the scope of this article.  However there are some important optimizations and considerations that are influenced by asset management.</p>
<p>One important optimization in building data is the idea of a load and go format &#8211; creating data than can be loaded and used right away with no post-load processing.  This can really help reduce memory fragmentation and the CPU cost of loading data. However the type of asset we are building will influence our data layout.</p>
<p>Let&#8217;s take an animated model as our example.  Our model will consist of a hierarchy of animated joints (Node) each with geometry (Mesh) attached.  One way of organizing this data could be:</p>
<blockquote>
<pre>struct Model
{
   int numNodes;
   Node nodes[numNodes];
};

struct Node
{
   Transform transform;
   Mesh mesh;
};

struct Transform
{
   Vector3 position;
   Vector3 rotation;
   Vector3 scale;
}

struct Mesh { ... };</pre>
</blockquote>
<p>This is a fairly straightforward way of processing our model.  However, since our model is animated we will need a per-instance copy of each Node&#8217;s transforms.  We could walk through the array of nodes and make a copy of each transform when we create a new instance.  But it would make updating the transforms when we draw difficult and messy as well a causing us to walk a relatively large structure.</p>
<p>By simply reorganizing the model&#8217;s data structures we can make a data layout that&#8217;s more friendly to asset management:</p>
<blockquote>
<pre>struct Model
{
   int numNodes;
   Transform transforms[numNodes];
   Mesh meshes[numNodes];
};</pre>
</blockquote>
<p>All we&#8217;ve done is separated the transform and mesh data into separate arrays, but now the data we want to copy per-instance is cleanly separated.  Also, it makes instanced models easier to handle at runtime, because we&#8217;ve separated mesh data from transform data we can more easily structure our code to handle transforms and meshes separately.</p>
<p>This is just one example of how we need to build our data with asset management in mind.</p>
<h2>Data Packing</h2>
<p>In my series on <a href="http://systematicgaming.wordpress.com/2008/09/16/load-times-packfiles/">load times</a> I mentioned the importance of packing files together to reduce load times.  The <strong>processing layer</strong> of asset management is where we perform this optimization and more.</p>
<p>Proper asset management allows us to track which assets reference each other. This means we can easily group these assets together on disc or within the same packfile.  In some cases we can merge assets into a single data set.</p>
<p>This allows us to intelligently duplicate data on the disc if needed. If an asset, such as a texture, is shared by multiple assets it may make sense to place multiple copies of the shared asset near assets that reference it.  We would then load the closest copy when the shared asset is needed.</p>
<p>In a open world game, where assets are streamed continuously as the player moves, we can use our asset management system to layout data such that data is organized by in-game proximity.  Since we know the world layout and the position of assets in the world, we can put assets that are close in game, close on disc.  Reducing seeks and allowing more efficient streaming.  We can also use our knowledge of asset references to determine how much memory is required to load a section of the game.</p>
<p>Clearly asset management, especially asset references, has many useful applications we can apply during the data processing phase.</p>
<p>Next article we&#8217;ll examine the highest level of asset management &#8211; where tools and designers interact with our engine and pipelines.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/systematicgaming.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/systematicgaming.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/systematicgaming.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/systematicgaming.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/systematicgaming.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/systematicgaming.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/systematicgaming.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/systematicgaming.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/systematicgaming.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/systematicgaming.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/systematicgaming.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/systematicgaming.wordpress.com/622/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/systematicgaming.wordpress.com/622/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/systematicgaming.wordpress.com/622/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=622&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://systematicgaming.wordpress.com/2009/07/02/asset-management-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">systematicgaming</media:title>
		</media:content>
	</item>
		<item>
		<title>Asset Management &#8211; Runtime</title>
		<link>http://systematicgaming.wordpress.com/2009/06/25/asset-management-runtime/</link>
		<comments>http://systematicgaming.wordpress.com/2009/06/25/asset-management-runtime/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 01:00:21 +0000</pubDate>
		<dc:creator>systematicgaming</dc:creator>
				<category><![CDATA[asset management]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://systematicgaming.wordpress.com/?p=599</guid>
		<description><![CDATA[The runtime layer is the lowest level of asset management encompassing:  file loading, reference counting, instancing and even procedural asset generation.  To meaningfully discuss handling assets at runtime we&#8217;ll need to define the different types of assets.  Here&#8217;s a few basic types of assets: Raw data Instanced data Procedural assets Composite data Raw data refers [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=599&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The runtime layer is the lowest level of asset management encompassing:  file loading, reference counting, instancing and even procedural asset generation.  To meaningfully discuss handling assets at runtime we&#8217;ll need to define the different types of assets.  Here&#8217;s a few basic types of assets:</p>
<ol>
<li>Raw data</li>
<li>Instanced data</li>
<li>Procedural assets</li>
<li>Composite data</li>
</ol>
<p><span id="more-599"></span></p>
<p><strong>Raw data </strong>refers to data that is static, meaning it doesn&#8217;t change during the game&#8217;s execution, and loaded off disc when needed.  Textures, sound, music, mesh data, character dialog, and many other types of content would be considered <strong>raw data</strong> assets.  I&#8217;d say that most data &#8211; when measured by bytes &#8211; falls into this category.  <strong>Raw data</strong> is the simplest type of asset to manage &#8211; it&#8217;s either in memory or not, and since it&#8217;s static you know it won&#8217;t be changed during gameplay.  This means<strong> raw data </strong>only needs to be loaded once and can be shared trivially.</p>
<p><img class="alignnone size-full wp-image-601" title="asset_management_refcount" src="http://systematicgaming.files.wordpress.com/2009/06/asset_management_refcount1.png?w=459&#038;h=150" alt="asset_management_refcount" width="459" height="150" /></p>
<p><strong>Instanced data</strong> is similar to <strong>raw data</strong>, in that it represents a single piece of content.  The key difference is that some (or even all) of the data will be modified during game.  This means we can&#8217;t simply share this asset; some part of the data will be different each time we use this asset.  Which is where the term <strong>instanced data</strong> comes from: each instance of this data is slightly different.</p>
<p>A common example of <strong>instanced data</strong> is an animated model: the polygon data can be shared, but the animated pose of the  joints would be different for each character using the model.</p>
<p><img class="alignnone size-full wp-image-602" title="asset_management_instanced" src="http://systematicgaming.files.wordpress.com/2009/06/asset_management_instanced.png?w=500&#038;h=266" alt="asset_management_instanced" width="500" height="266" /></p>
<p><strong>Generated data</strong> is an asset that is generated by the game engine.  This type of data includes everything from 100% procedurally generated content to customized data, such as a texture that is re-coloured after loading.  Pretty much all user-generated content can be considered <strong>generated data</strong>.  Engine-generated data, such as shadow maps or particle vertex buffers, can be considered as generated assets.  The key point is that not all assets are necessarily loaded from disc, where <strong>raw</strong> and <strong>instanced</strong> data are usually represented by file, <strong>generated data</strong> can be more abstract.</p>
<p>It should be mentioned that <strong>generated data</strong> can also be static like <strong>raw data</strong>, or act like <strong>instanced data</strong> or be completely dynamic &#8211; as the case is for shadow buffers.</p>
<p><strong>Composite data</strong> is an asset that references other assets.  Many assets are almost always build from smaller pieces of data.  Take a simple level from most games: it&#8217;s composed of sets of geometry, materials, textures, ambient sounds even gameplay scripts.  A level asset is really just <strong>composite data</strong> that tells the engine what <em>other </em>assets are needed.</p>
<p>In fact, most game content is <strong>composite data</strong> in some form, and proper management of these references that forms the goal of any asset management system.</p>
<p><img class="alignnone size-full wp-image-603" title="asset_management_composite" src="http://systematicgaming.files.wordpress.com/2009/06/asset_management_composite.png?w=600&#038;h=305" alt="asset_management_composite" width="600" height="305" /></p>
<p>An important point to note is that these asset classifications aren&#8217;t mutually exclusive.  You can have instanced generated assets, composite instanced assets, or just about any combination that makes sense.  It&#8217;s probably best to think of the above categories as asset properties.</p>
<p>For example you could have a composite generated asset.  It&#8217;s even possible to consider instanced assets as a combination of raw data &#8211; for the static portion- and a generated asset for the instanced portion.</p>
<h2>Low-level Management</h2>
<p>Now that we know the basic types of assets, we can figure out how to handle them in our runtime. Our goals are simple: we want to minimize resources (memory) while supporting the various asset types described above.</p>
<p>If we look at our description of a composite asset above, we can best picture it as an acyclic directed graph of data usage &#8211; one asset references one or more other assets.  The leaf nodes of our graph are the raw and instanced assets.</p>
<p>It&#8217;s now possible to design out system as a simple referenced counted graph.  When an asset is needed we load the referenced data and increment the count.  When we delete an asset, we decrement its references and unload data with a zero count.</p>
<p>This gives us nice and simple system.  To load an assets you just have to load or generate the associated assets and increment the reference count for each shared asset.  You continue recursively until you have no links and only raw data.  Each reference will performs the appropriate action for instanced assets, copying data as necessary.</p>
<p>An asset dependency graph doesn&#8217;t just allow us to track which assets need to be loaded, it allows us to reduce load times between levels.  Assuming that two levels have one or more assets in common, we can keep them in memory by loading intelligently:</p>
<ol>
<li>Increment the refcount of assets in the <strong>next</strong> level</li>
<li>Decrement the refcount of assets in the <strong>current</strong> level</li>
<li>Remove all assets with refcount = 0</li>
<li>Load assets from the <strong>next</strong> level</li>
</ol>
<p>That simple procedure will keep the shared assets in memory between levels.  The order is important &#8211; we must unload the unneeded assets from the current level or we may not have enough memory for the assets in the next level.  Also, loading and unloading assets this way can cause memory fragmentation, so we may choose to handle assets in groups or if possible defragment memory after step 3.  This also requires we have some way of knowing which assets are needed before we begin loading the next level.  We&#8217;ll look at these issues in the next article.</p>
<p>As we can see, basic refcounting provides a very simple, yet powerful, way of sharing assets.  Combined with proper data instancing we can manage our assets at runtime with a minumum of overhead and waste.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/systematicgaming.wordpress.com/599/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/systematicgaming.wordpress.com/599/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/systematicgaming.wordpress.com/599/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/systematicgaming.wordpress.com/599/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/systematicgaming.wordpress.com/599/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/systematicgaming.wordpress.com/599/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/systematicgaming.wordpress.com/599/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/systematicgaming.wordpress.com/599/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/systematicgaming.wordpress.com/599/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/systematicgaming.wordpress.com/599/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/systematicgaming.wordpress.com/599/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/systematicgaming.wordpress.com/599/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/systematicgaming.wordpress.com/599/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/systematicgaming.wordpress.com/599/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=599&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://systematicgaming.wordpress.com/2009/06/25/asset-management-runtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">systematicgaming</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2009/06/asset_management_refcount1.png" medium="image">
			<media:title type="html">asset_management_refcount</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2009/06/asset_management_instanced.png" medium="image">
			<media:title type="html">asset_management_instanced</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2009/06/asset_management_composite.png" medium="image">
			<media:title type="html">asset_management_composite</media:title>
		</media:content>
	</item>
		<item>
		<title>Asset Management</title>
		<link>http://systematicgaming.wordpress.com/2009/06/24/asset-management/</link>
		<comments>http://systematicgaming.wordpress.com/2009/06/24/asset-management/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 02:25:57 +0000</pubDate>
		<dc:creator>systematicgaming</dc:creator>
				<category><![CDATA[asset management]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://systematicgaming.wordpress.com/?p=597</guid>
		<description><![CDATA[Modern games have gigabytes of data, and thousands of individual assets.  Managing all this data well can be a very complex task, and impacts game development at all levels, from concept artist to low level bit-pushing coder.  The next few articles will look at the issues of asset management in games.  First we must clarify [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=597&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Modern games have gigabytes of data, and thousands of individual assets.  Managing all this data well can be a very complex task, and impacts game development at all levels, from concept artist to low level bit-pushing coder.  The next few articles will look at the issues of asset management in games.  First we must clarify our goals with some simple definitions.</p>
<h3>What exactly is an <strong>asset</strong>?</h3>
<p>For the purpose of this series we&#8217;ll define an asset as a set of piece of data used by the game.  This is very inclusive, and should help illustrate the scope of the problem.  A texture, a model, an sound, an AI script, really just about any data used can be considered an asset.</p>
<h3>What is <strong>asset management</strong>?</h3>
<p>Its the process of tracking data used by the game: when it is used, how it is used and how individual pieces of data relate to each other.  For example, to load a character we need to need: a model, the material and shaders, the textures, the animation data, and possibly more (such as AI or motion graphs).  Asset management is an integral part of workflow, data processing and runtime optimizations.</p>
<p>Proper asset management is a major issue in game development.  Solid asset management is required to handle the amount of content modern games use.</p>
<p>In this series we&#8217;ll take a closer look at the major layers of asset management:</p>
<ul>
<li>Runtime Layer &#8211; Where the game engine deals with assets</li>
<li>Processing Layer &#8211; Where assets are processed for the engine</li>
<li>Content Layer &#8211; Where assets are created and used by designers</li>
</ul>
<p>Each layer has its own issues to handle, and we&#8217;ll investigate these issues and look into possible management solutions.</p>
<p>Part 1: <a href="http://systematicgaming.wordpress.com/2009/06/23/asset-management-runtime/">The Runtime Layer</a></p>
<p>Part 2: <a href="http://systematicgaming.wordpress.com/2009/07/02/asset-management-processing/">The Processing Layer</a></p>
<p>Part 3: <a href="http://systematicgaming.wordpress.com/2009/07/16/asset-management-content/">The Content Layer</a></p>
<p>Finally we have a <a href="http://systematicgaming.wordpress.com/2009/07/23/asset-management-checklist/">checklist of important points</a> to consider when building and maintaining your asset management system.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/systematicgaming.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/systematicgaming.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/systematicgaming.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/systematicgaming.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/systematicgaming.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/systematicgaming.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/systematicgaming.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/systematicgaming.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/systematicgaming.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/systematicgaming.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/systematicgaming.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/systematicgaming.wordpress.com/597/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/systematicgaming.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/systematicgaming.wordpress.com/597/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=597&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://systematicgaming.wordpress.com/2009/06/24/asset-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">systematicgaming</media:title>
		</media:content>
	</item>
		<item>
		<title>Game-Tool Communication</title>
		<link>http://systematicgaming.wordpress.com/2009/01/31/game-tool-communication/</link>
		<comments>http://systematicgaming.wordpress.com/2009/01/31/game-tool-communication/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 00:20:13 +0000</pubDate>
		<dc:creator>systematicgaming</dc:creator>
				<category><![CDATA[game programming]]></category>
		<category><![CDATA[workflow]]></category>
		<category><![CDATA[console]]></category>

		<guid isPermaLink="false">http://systematicgaming.wordpress.com/?p=563</guid>
		<description><![CDATA[Modern games are extremely content heavy &#8211; most of the people on a game team are part of the art or design departments.  The larger a the team get the greater the portion of content producers becomes, and the trend will only continue. So what does this have to do with game systems programming? The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=563&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Modern games are extremely content heavy &#8211; most of the people on a game team are part of the art or design departments.  The larger a the team get the greater the portion of content producers becomes, and the trend will only continue.</p>
<p>So what does this have to do with game systems programming?</p>
<p>The more content you game has the better your tools have to be.  The best tools are robust, efficient and as seamless as possible.  The key to a seamless workflow is close integration with your tools and game engine.</p>
<p>There are basically two ways to accomplish this:</p>
<ul>
<li>Direct integration of the game engine with the tool</li>
<li>Remote integration via a communication layer</li>
</ul>
<h2><span id="more-563"></span></h2>
<h2>Direct Integration</h2>
<p>Essentially, direct integration is embedding you game engine into a tool.  How much you embed &#8211; just the rendering engine or the entire game &#8211; depends on the tool and the level of integration you need. Direct integration can provide the most seamless experience, since the tool is essentially running the game.  Changes in the tool can quite easily be immediately updated in the engine.  However this often incurs a great deal of engineering time. Consider the amount of effort required to implement a full-blown 3D editing package on top an entire game engine.</p>
<p>Often direct integration is reserved for custom tools that create and edit custom data.  For example it&#8217;s very common to have a particle effect tool that uses the game&#8217;s rendering engine and allows effect artists to view their changes in real-time.  However, embedding a game engine with a 3D package like Maya is a nearly impossible engineering feat.</p>
<p>Direct integration is often only really useful on games with a working PC version.  Many console-only games have some running PC version &#8211; often not near shipping quality, but functional.  The GUI limitations of console platforms means that they don&#8217;t make very good editing environments.  Real-time editing is usually reserved for some basic debug menu functionality.  Also screen space is limited on TVs, a problem PCs don&#8217;t suffer from.</p>
<h2>Remote Integration</h2>
<p>Remote integration refers to having a tool communicate with another process which may or may not be running on another device like a console.  The key point is that the tool and game engine are in separate processes, meaning you can&#8217;t just start poking at memory to change stuff.  You need a method of communication and a protocol for communicating.</p>
<p>The simplest and most common way is a simple IP connection between the processes.  This works well because TCP is well supported on most platforms so it&#8217;s fairly portable.  Not all consoles have a network interface suitable for development usage, usually they do support some sort of data connectivity and you can often implement a IP-like layer yourself.</p>
<p>Remote integration requires effort to expose the engine&#8217;s internals to the communication layer.  Each feature you want to integrate will usually need some sort of communication code.  The amount of effort directly depends on the level of integration desired.  Setting a specific variable can be done easily by sending a simple message (e.g. &#8220;SetColorRGB(1, 0.5, 0.3)&#8221;). If the engine has a scripting system already it may be best to simply integration your communication layer on top of the scripting engine, allowing you to script the game remotely.</p>
<p>It gets more complicated when you want real time data <em>from </em>the game displayed in the tool.  Networking often doesn&#8217;t have the bandwidth or latency to keep up with a 60fps engine.</p>
<h2>Direct or Remote?</h2>
<p>So how do you choose to integrate a tool direction or remotely?</p>
<p>Often you don&#8217;t have a choice &#8211; the tool may not support the level of customization required, this is common for 3rd party tools.  Even if you can integrate directly, you may choose not to because it&#8217;s just too much work.  Unfortunately some 3rd party tools don&#8217;t really support any customization, so integration of any kind is a moot point.</p>
<p>For first party tools you of course have the freedom do what ever you want.  So how do you decide?  Here are some of the main factors I take into consideration:</p>
<ul>
<li>What data does the tool work with?</li>
<li>Who is the main user of the tool?</li>
<li>What platforms are you targeting?</li>
<li>How much effort is required?</li>
</ul>
<p>The data a tool operates on is important &#8211; tools that work with large data sets like textures and models can be difficult to use through remote communication efficiently.  If a tool works on small data sets, like character attributes (hit points, damage), a remove communication can work quite effectively.  Where a directly integrated engine can update textures directly, a remove tool may have to settle for sending a &#8220;reload&#8221; message to the engine, and have the engine do the heavy lifting.</p>
<p>The user of a tool is also very important.  Some users require faster feedback than others.  Designers who are trying to balance your game will probably want real-time tuning of data.  However modelers don&#8217;t usually need that kind of instant feedback.  Not that it wouldn&#8217;t be useful, just not really needed.</p>
<p>The target environment is important, if you&#8217;re making a console-only game then you don&#8217;t care too much about tuning your windows build.  Sure, it should be a reasonable representation of your game, but what really matters is your final target platform.  Generally if you&#8217;re focused on console development, you want to manipulate your core data on the PC and be able to tune and adjust values on the console.</p>
<p>Of course effort of integration is very important.  A complex feature may need a very complex communication protocol to allow remote integration.  A old, or 3rd party tool may require a great deal of effort to directly integrate with a newer game engine.</p>
<p>In general &#8211; you want direct integration when dealing with large data sets or intensive operations.  For example a custom map editor works well with direct engine integration.   You can see changes to levels in real-time and with may game engine features instantly available.  For tuning simple values &#8211; like AI parameters or material and simple graphical settings &#8211; remote integration works well, and is very console friendly.</p>
<h2>In the end&#8230;</h2>
<p>The only thing that really matters is you have a solid, seamless way of interfacing your tools to your game.  Direct and remote integration and just the two basic approaches.  It&#8217;s quite feasable and common to have some support for both &#8211; like a PC tool that&#8217;s directly integrated with your engine and able to communicate remotely with your console version. Both your tools and workflow must be constantly evolving and improving and game-tool integration is a key component.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/systematicgaming.wordpress.com/563/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/systematicgaming.wordpress.com/563/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/systematicgaming.wordpress.com/563/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/systematicgaming.wordpress.com/563/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/systematicgaming.wordpress.com/563/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/systematicgaming.wordpress.com/563/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/systematicgaming.wordpress.com/563/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/systematicgaming.wordpress.com/563/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/systematicgaming.wordpress.com/563/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/systematicgaming.wordpress.com/563/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/systematicgaming.wordpress.com/563/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/systematicgaming.wordpress.com/563/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/systematicgaming.wordpress.com/563/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/systematicgaming.wordpress.com/563/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=563&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://systematicgaming.wordpress.com/2009/01/31/game-tool-communication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">systematicgaming</media:title>
		</media:content>
	</item>
		<item>
		<title>Performance: C# vs C++ &#8211; Part 2</title>
		<link>http://systematicgaming.wordpress.com/2009/01/13/performance-c-vs-c-part-2/</link>
		<comments>http://systematicgaming.wordpress.com/2009/01/13/performance-c-vs-c-part-2/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 13:01:49 +0000</pubDate>
		<dc:creator>systematicgaming</dc:creator>
				<category><![CDATA[c++ vs c#]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://systematicgaming.wordpress.com/?p=549</guid>
		<description><![CDATA[I was pretty content with my previous tests on C# sorting performance, which were pretty disappointing.  Normally I&#8217;d be happy to move on, but one commenter did pique my curiosity pointing to a MSDN article about how lousy the 2.0 CLR is with structs.  So I downloaded the Visual Studio 2008 Express Edition to give [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=549&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was pretty content with my <a href="http://systematicgaming.wordpress.com/2009/01/03/performance-c-vs-c/">previous</a> <a href="http://systematicgaming.wordpress.com/2009/01/04/performance-c-vs-c-revistedperformance-c-vs-c-revisted/">tests</a> on C# sorting performance, which were pretty disappointing.  Normally I&#8217;d be happy to move on, but one commenter did pique my curiosity pointing to a <a href="http://blogs.msdn.com/clrcodegeneration/archive/2007/11/02/how-are-value-types-implemented-in-the-32-bit-clr-what-has-been-done-to-improve-their-performance.aspx">MSDN article</a> about how lousy the 2.0 CLR is with structs.  So I downloaded the Visual Studio 2008 Express Edition to give it a try.  I admit, I was a bit surprised and impressed with the differences.</p>
<p><span id="more-549"></span>First things first, <a href="http://systematicgaming.wordpress.com/code-cache-pressure-c-2008code-cache-pressure-c-2008/">here&#8217;s the code I ran</a> &#8211; it&#8217;s pretty much the same as the last test with a few fixes I noted in my &#8220;Revisited&#8221; post, like fixing the byte/char mistake and even getting rid of that pesky fixed keyword that had so many people worked up.</p>
<p>Here&#8217;s the direct results of 2005 vs 2008 (or perhaps better said CLR 2.0 vs 3.5), with lower being faster:</p>
<p><img class="alignnone size-full wp-image-561" title="cs_2008_20052" src="http://systematicgaming.files.wordpress.com/2009/01/cs_2008_20052.png?w=754&#038;h=660" alt="cs_2008_20052" width="754" height="660" /></p>
<p>Ok, so the chart itself is a little crowded, but the trend is clear 2008 is a clear improvement over 2005.  Just how much is easier to see in this chart which show the percentage that 2008 has improved, higher being faster:</p>
<p><img class="alignnone size-full wp-image-555" title="cs_2008_2005_percent" src="http://systematicgaming.files.wordpress.com/2009/01/cs_2008_2005_percent.png?w=620&#038;h=415" alt="cs_2008_2005_percent" width="620" height="415" /></p>
<p>Now we&#8217;re getting decent improvement all around, with most of the generic sort versions doubling in speed.  The fact that we&#8217;re seeing a fairly constant improvement with respect to data size leads me to believe the improvement is entirely in the CLR rather than any algorithmic improvement in sorting.  Which is really no surprise, it&#8217;s not like CLR 2.0 was using bubble sort.</p>
<p>What else can we learn from these graphs?  Well for one, something is a little off with the Sort&lt;Key, Items&gt;.  The the percentage comparison the 1024-length array isn&#8217;t seeing the same improvements that the other lengths are seeing, also the first graph shows a hiccup.  If you look back at my <a href="http://systematicgaming.wordpress.com/2008/12/23/patterns-in-performance-cache-pressure/">original C++ article</a>, you can see that the indirect sort needs a second array to copy into, so it&#8217;s pretty likely the C# sort is allocating some temporary memory behind our backs.</p>
<p>In the interest of a fair comparison to C++, I reimplemented my C++ indirect in C# to do a direct comparison and remove any &#8220;hidden&#8221; work that may be done in the Array.Sort&lt;Key, Items&gt; method.  (It&#8217;s the SortTestIndirect2 method in the code linked at the start, if you&#8217;re interested).  Let&#8217;s see how this hand rolled indirect sort compares to the one supplied in the Array class:</p>
<p><img class="alignnone size-full wp-image-556" title="cs_2008_2005_indirect" src="http://systematicgaming.files.wordpress.com/2009/01/cs_2008_2005_indirect.png?w=620&#038;h=397" alt="cs_2008_2005_indirect" width="620" height="397" /></p>
<p>You can see that the custom indirect sort has a much straighter curve, especially on small sizes.  Since the graphs do converge at longer arrays, we&#8217;re mostly seeing a constant or near-constant overhead in the Array.Sort method.</p>
<p>Now for what every one&#8217;s been waiting for: C++ vs C# 2008.  This is the same C++ code ran previously, re-compiled with 2008 (with no appreciable difference from 2005) compared against the new C# indirect sort.</p>
<p><img class="alignnone size-full wp-image-557" title="cs_cpp_vs2008" src="http://systematicgaming.files.wordpress.com/2009/01/cs_cpp_vs2008.png?w=620&#038;h=397" alt="cs_cpp_vs2008" width="620" height="397" /></p>
<p>The end result is we&#8217;re seeing about 2.5 times difference between C# and C++.  That&#8217;s certainly better than the 10 times we saw against 2005 in the last comparison (admittedly comparing two different sort algorithms).</p>
<p>A two times speed difference is still significant, and will impact the maximum performance you&#8217;ll be able to squeeze out of C#, especially in intensive apps.  Which is a shame for people using XNA &#8211; because they&#8217;ll hit a performance wall much sooner than if they&#8217;d have used C++.  But still credit should be given where credit is due, the CLR folks over at Microsoft have been putting notable effort into optimizing C# since 2005.  Hopefully Visual Studio 2010 brings similar improvments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/systematicgaming.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/systematicgaming.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/systematicgaming.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/systematicgaming.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/systematicgaming.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/systematicgaming.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/systematicgaming.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/systematicgaming.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/systematicgaming.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/systematicgaming.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/systematicgaming.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/systematicgaming.wordpress.com/549/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/systematicgaming.wordpress.com/549/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/systematicgaming.wordpress.com/549/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=549&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://systematicgaming.wordpress.com/2009/01/13/performance-c-vs-c-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">systematicgaming</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2009/01/cs_2008_20052.png" medium="image">
			<media:title type="html">cs_2008_20052</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2009/01/cs_2008_2005_percent.png" medium="image">
			<media:title type="html">cs_2008_2005_percent</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2009/01/cs_2008_2005_indirect.png" medium="image">
			<media:title type="html">cs_2008_2005_indirect</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2009/01/cs_cpp_vs2008.png" medium="image">
			<media:title type="html">cs_cpp_vs2008</media:title>
		</media:content>
	</item>
		<item>
		<title>Performance: C# vs C++ &#8211; Revisted</title>
		<link>http://systematicgaming.wordpress.com/2009/01/04/performance-c-vs-c-revisted/</link>
		<comments>http://systematicgaming.wordpress.com/2009/01/04/performance-c-vs-c-revisted/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 02:18:40 +0000</pubDate>
		<dc:creator>systematicgaming</dc:creator>
				<category><![CDATA[c++ vs c#]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://systematicgaming.wordpress.com/?p=545</guid>
		<description><![CDATA[I thought I&#8217;d comment on my own post about C# vs C++ performance.  The purpose of the test was to compare the time to sort 128-byte objects in C++ vs C#, nothing more.  Again if you understood that, then you can propbably see that the performance measured has more to do with execution envrionments than [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=545&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I thought I&#8217;d comment on my own post about <a href="http://systematicgaming.wordpress.com/2009/01/03/performance-c-vs-c/">C# vs C++ performance</a>.  The purpose of the test was to compare the time to sort 128-byte objects in C++ vs C#, nothing more.  Again if you understood that, then you can propbably see that the performance measured has more to do with execution envrionments than languange differences.</p>
<p>That said, I&#8217;d like to address out the following issues in my testing:</p>
<ol>
<li>I used a <em>char</em> array in C# to simulate a similar <em>char</em> array in C++.  This incorrect since C# chars are 16 bits while C++ they are only 8 bits.  I admit this was pretty sloppy.  Replacing <em>char</em> with <em>byte</em> fixes this, and the result is the C# version runs about 15% faster.  Faster, yes, but still not fast enough to make a significant difference.  The most striking thing is that halving the memory usage <em>only</em> gives a 15% difference, in C++ the memory had direct linear impact on runtime.</li>
<li>Some people complained about using the <em>fixed</em> keyword to make the array part of the Data struct.  It&#8217;s trivial to replace it with a number of <em>int</em> or <em>float</em> to create a 128-byte struct and makes no difference in performance.  The point was to approximate C++ <em>and</em> to represent a larger class, <em>fixed </em>was a simple way to do this.</li>
<li>Some people complained this isn&#8217;t an apple to apple comparison &#8211; I disagree.  It&#8217;s about as direct a way as possible of comparing two very different languages and operating environments &#8211; perform the same task and see how long it takes.</li>
<li>I was running Visual Studio 2005 SP1 for both tests, newer/different versions may have varying results.</li>
</ol>
<p>The purpose of the previous post isn&#8217;t to claim that C++ is better than C#, but many people seem to think that I am &#8211; I suppose this is what I get for posting such an inflammatory title. I use C# on a daily basis and like it.</p>
<p>There were a number of comments on my last post claiming to &#8220;debunk&#8221; my tests referring to what is  <a href="http://journal.stuffwithstuff.com/2009/01/03/debunking-c-vs-c-performance/">posted here</a>.  This debunking itself admits it&#8217;s comparing apples to oranges &#8211; however it completely misses the point of creating a fixed size array in the first place.   Replacing the fixed array with a heap pointer shows nothing about C# performance &#8211; only that copying a smaller struct is faster than copying a larger one.  This is a fact I <a href="http://systematicgaming.wordpress.com/2008/12/23/patterns-in-performance-cache-pressure/">addressed previously</a>.</p>
<p>The claim is made that this test isn&#8217;t representative of what a C# programmer would write.  True, a C# programmer would very rarely used a struct with a <em>fixed</em> array.  However, it&#8217;s fairly easy to create objects with 128-bytes or more of data.  That&#8217;s 32 4-bytes variables, which isn&#8217;t a huge amount of variables to have in a class, especially one with a few parent classes each with a few member variables.</p>
<p>Anyways, other that the char/byte mistake, I stand by the original results &#8211; C# takes about 10 times longer to sort an array on my computer, compared to a similar C++ verision.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/systematicgaming.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/systematicgaming.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/systematicgaming.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/systematicgaming.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/systematicgaming.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/systematicgaming.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/systematicgaming.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/systematicgaming.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/systematicgaming.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/systematicgaming.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/systematicgaming.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/systematicgaming.wordpress.com/545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/systematicgaming.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/systematicgaming.wordpress.com/545/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=545&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://systematicgaming.wordpress.com/2009/01/04/performance-c-vs-c-revisted/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">systematicgaming</media:title>
		</media:content>
	</item>
		<item>
		<title>Performance: C# vs C++</title>
		<link>http://systematicgaming.wordpress.com/2009/01/03/performance-c-vs-c/</link>
		<comments>http://systematicgaming.wordpress.com/2009/01/03/performance-c-vs-c/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 06:02:18 +0000</pubDate>
		<dc:creator>systematicgaming</dc:creator>
				<category><![CDATA[c++ vs c#]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://systematicgaming.wordpress.com/?p=530</guid>
		<description><![CDATA[In my last post I discussed cache pressure and how important the cache is for performance.  Out of mild curiosity and a bit of boredom, I decided to see how the same code (or near enough) performed in C#.  Why C#?  A lot of tools are written in C# now, mostly because it&#8217;s a nice [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=530&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my last post I discussed <a href="http://systematicgaming.wordpress.com/2008/12/23/patterns-in-performance-cache-pressure/">cache pressure</a> and how important the cache is for performance.  Out of mild curiosity and a bit of boredom, I decided to see how the same code (or near enough) performed in C#.  Why C#?  A lot of tools are written in C# now, mostly because it&#8217;s a nice language with fantastic library support and solid GUI integration.  It&#8217;s a more productive environment for all those programs that don&#8217;t have to run at 60 fps.</p>
<p>Now given how straightforward the test is &#8211; sorting an array &#8211; I&#8217;d expected performance to not differ by much compared to the C++ version. Before I ran this code I was guessing that C# would be maybe 50% slower and at most half the speed than the C++ version.  Especially since the sorting should be mostly algorithmically and memory bandwidth bound.</p>
<p>You can get both versions of the code here: <a href="http://systematicgaming.wordpress.com/code-cachepressure/">C++</a>, <a href="http://systematicgaming.wordpress.com/code-cachepressure-c/">C#</a> to test for yourself. [EDIT: fixed link to C# code]</p>
<p>Now for the results.</p>
<p>[EDIT: a number of issues were raised about this test in the comments and elsewhere - <a href="http://systematicgaming.wordpress.com/2009/01/04/performance-c-vs-c-revisted/">here's my response</a>]</p>
<p><span id="more-530"></span>The first issue was to figure out how to actually sort my array in C# &#8211; there are a variety of ways to store and sort objects in C# so I first tried the various combinations of Sort &amp; ICompare,  Sort&lt;T&gt; &amp; ICompare&lt;T&gt;, using a Comparison function pointer and even C#&#8217;s built-in indirect sort Sort(Keys, Items).  Let&#8217;s set the raw results:</p>
<p><img class="alignnone size-full wp-image-535" title="cs_cpp_various" src="http://systematicgaming.files.wordpress.com/2009/01/cs_cpp_various.png?w=620&#038;h=397" alt="cs_cpp_various" width="620" height="397" /></p>
<p>There&#8217;s nothing too surprising really &#8211; the generic version of Sort&lt;T&gt; is faster than the non-generic one, probably because the CLR can remove dynamic casts or something.  Also no surprise that the indirect Sort&lt;Key, Items&gt; version is much, much faster than all the other version &#8211; this is what we looked into in my original <a href="http://systematicgaming.wordpress.com/2008/12/23/patterns-in-performance-cache-pressure/">Cache Pressure</a> post.  The only surprise to me is that the IComparer version of the sort is faster than the Comparison function pointer version &#8211; I have no idea why, I&#8217;d expect both to be nearly identical.</p>
<p>Anyways, we&#8217;re here to compare C++ to C#, so lets put the results from our Cache Pressure test side by side with these C# tests:</p>
<p><img class="alignnone size-full wp-image-536" title="cs_cpp_vs" src="http://systematicgaming.files.wordpress.com/2009/01/cs_cpp_vs.png?w=620&#038;h=397" alt="cs_cpp_vs" width="620" height="397" /></p>
<p>So here&#8217;s the graph of the C++ direct sort vs the generic Sort&lt;T&gt;, IComparer&lt;T&gt; version.  In case you can&#8217;t read that properly, the C++ version is <strong>10 times faster</strong> than the C# version.  You can also see that the lines are nice and parallel, so that&#8217;s no algorithmic difference in sorting routines, both implementations have the same runtime complexity.  We&#8217;re seeing <strong>10 times overhead</strong> in execution.</p>
<p>Damn!  That&#8217;s pretty pathetic C#!</p>
<p>And you know what&#8217;s even sadder?  Here&#8217;s a chart of the slow direct C++ sort versus the fastest indirect C# sort:</p>
<p><img class="alignnone size-full wp-image-537" title="cs_cpp_vs2" src="http://systematicgaming.files.wordpress.com/2009/01/cs_cpp_vs2.png?w=620&#038;h=397" alt="cs_cpp_vs2" width="620" height="397" /></p>
<p>So C++ still comes out  a head, over <strong>twice as fast </strong>in fact.  Considering this is the &#8220;fast&#8221; C# implementation and the &#8220;slow&#8221; C++ implementation beats is hands down, you can&#8217;t help but be disappointed by C# here.  I won&#8217;t even bother comparing C#&#8217;s sort to C++&#8217;s faster indirect sort, we already know the outcome.</p>
<h2>Conclusion</h2>
<p>So mostly I&#8217;ll let the number speak for themselves, the programs I ran are freely available for you to confirm for yourself.  I don&#8217;t pretend to be any type of C# expert, but my code is pretty much a textbook (or MSDN example) implementation.  I even use the exact timing method as the C++ version.</p>
<p>I was very surprised by how much faster C++ ran.  I never expected a 10 times difference in performance.  This doesn&#8217;t mean I&#8217;ll stop using C# &#8211; it&#8217;s still a very productive development environment, especially for GUI tools, which is still often a more important factor than exectuion time.  It does mean that I&#8217;ll probably think twice about implementing high-performance code in C#.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/systematicgaming.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/systematicgaming.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/systematicgaming.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/systematicgaming.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/systematicgaming.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/systematicgaming.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/systematicgaming.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/systematicgaming.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/systematicgaming.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/systematicgaming.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/systematicgaming.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/systematicgaming.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/systematicgaming.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/systematicgaming.wordpress.com/530/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=530&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://systematicgaming.wordpress.com/2009/01/03/performance-c-vs-c/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">systematicgaming</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2009/01/cs_cpp_various.png" medium="image">
			<media:title type="html">cs_cpp_various</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2009/01/cs_cpp_vs.png" medium="image">
			<media:title type="html">cs_cpp_vs</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2009/01/cs_cpp_vs2.png" medium="image">
			<media:title type="html">cs_cpp_vs2</media:title>
		</media:content>
	</item>
		<item>
		<title>Patterns in Performance: Cache Pressure</title>
		<link>http://systematicgaming.wordpress.com/2008/12/23/patterns-in-performance-cache-pressure/</link>
		<comments>http://systematicgaming.wordpress.com/2008/12/23/patterns-in-performance-cache-pressure/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 03:16:42 +0000</pubDate>
		<dc:creator>systematicgaming</dc:creator>
				<category><![CDATA[game programming]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[patterns in performance]]></category>

		<guid isPermaLink="false">http://systematicgaming.wordpress.com/?p=506</guid>
		<description><![CDATA[I&#8217;ve been mentioning memory and the cache a lot, because proper cache utilization really is a critical to good performance. This time we&#8217;ll look at cache pressure &#8211; a term that refers to overworking the memory cache with too many or wasteful memory accesses.  Basically putting pressure on the memory cache means you&#8217;re wasting time [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=506&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been mentioning memory and the cache a lot, because proper cache utilization really is a critical to good performance.  This time we&#8217;ll look at <strong>cache pressure</strong> &#8211; a term that refers to overworking the memory cache with too many or wasteful memory accesses.  Basically putting pressure on the memory cache means you&#8217;re wasting time accessing more memory than you need to.  The main cause is inefficient data access, often by using data structures that are too large, or too sparse reducing any benefit from memory locality.</p>
<p><span id="more-506"></span></p>
<p>Let&#8217;s look at a common example &#8211; <strong>sorting</strong>.  Sorting is a computer science staple, and is very common in the real world.  A common usage in games is sorting draw calls.  There are a number of reasons to sort draws: front-to-back to optimize for Z rejection, back-to-front for alpha sorting and by shader or material to reduce state changes.</p>
<p>A naive implementation might look something like this:</p>
<blockquote>
<pre>class DrawCall
{
   int sortKey;
   bool operator&lt; (const DrawCall &amp;dc) { return sortKey &lt; dc.sortKey; }

   int shaderIndex;
   Mesh *mesh;
   RenderState state;
   Color color;
   Matrix baseMatrix;
   // etc...
};</pre>
</blockquote>
<p>Basically we have a class that stores the information we need to draw a mesh and it&#8217;s sorting index or key.  We can simply sort our list of visible objects like so:</p>
<blockquote>
<pre>std::sort(drawCallList, drawCallList + numDrawCalls);

for (int i  = 0;  i &lt; numDrawCalls; i++)
{
   drawCallList[i]-&gt;Draw();
}</pre>
</blockquote>
<p>Simple right? Yep.  Fast? Well, let&#8217;s look at some numbers.</p>
<p>Here&#8217;s the time in milliseconds it took to sort a similar 512 byte structure, for just up to just over a million items.</p>
<p><img class="alignnone size-full wp-image-512" title="cache_pressure_5121" src="http://systematicgaming.files.wordpress.com/2008/12/cache_pressure_5121.png?w=515&#038;h=311" alt="cache_pressure_5121" width="515" height="311" /></p>
<p>We don&#8217;t sort millions of items each frame in a normal game.  We do however often sort hundreds or a few thousand of draw calls in a single frame.  Our chart shows this will take 2-10ms to sort that many items.  That is a big chunk of time, and really is too slow to be useful.  We&#8217;re putting too much pressure on the cache. Or at least that&#8217;s what I claim.</p>
<p>Let&#8217;s take a more scientific approach and do an experiment or two.  My hypothesis is that our 512-byte object is too large and is putting too much pressure on the cache.  So by reducing the size of the object we&#8217;ll reduce the time required to sort.  Here are the results of sorting items of various size:</p>
<p><img class="alignnone size-full wp-image-513" title="cache_pressure_sizes" src="http://systematicgaming.files.wordpress.com/2008/12/cache_pressure_sizes.png?w=518&#038;h=575" alt="cache_pressure_sizes" width="518" height="575" /></p>
<p>Ok, that&#8217;s a pretty clear picture.  The larger the object we&#8217;re sorting the longer it takes, as predicted. But what&#8217;s really important is the impact the size has on performance &#8211; 4 byte objects (well, 4 bytes + a 4 byte sorting key) sort almost two magnitudes faster than 512 byte objects.</p>
<p>The reason for this is pretty simple.  At the center of any comparison based sort (like the std::sort above) we&#8217;ll have a line like this:</p>
<blockquote>
<pre>if (item[i] &lt; item[j])
   swap(item[i], item[j]);</pre>
</blockquote>
<p>That means for each comparison that swaps we&#8217;re copying two large objects structures, touching over hundreds of bytes of memory.  Those copies are putting a lot of pressure on the cache.  Especially since we only really need the sort key to order our DrawCall objects, and it&#8217;s only 4 bytes.  We have a lot of wasted memory access.</p>
<p>An improved method sorts a second indirect list of smaller structures than can then be used to access or sort the original list of larger objects.</p>
<blockquote>
<pre>struct IndirectObject
{
   int sortKey;
   int objectIndex;

   bool operator&lt; (const DrawCall &amp;dc) { return sortKey &lt; dc.sortKey; }
}</pre>
</blockquote>
<p>We can initialize a list of these indirect objects from the original list, sort them, and then use the sorted indirect objects to access our larger objects in sorted order.</p>
<blockquote>
<pre>for (int i  = 0;  i &lt; numDrawCalls; i++)
{
   indirectList[i].sortKey = drawCallList[i].sortKey;
   indirectList[i].sortKey = i;
}

std::sort(indirectList, indirectList + numDrawCalls);

for (int i  = 0;  i &lt; numDrawCalls; i++)
{
   int index = indirectList[i].index;
   drawCallList[index]-&gt;Draw();
}</pre>
</blockquote>
<p>So, just how much faster is this?  Let&#8217;s take a look:</p>
<p><img class="alignnone size-full wp-image-514" title="cache_pressure_indirect" src="http://systematicgaming.files.wordpress.com/2008/12/cache_pressure_indirect.png?w=518&#038;h=312" alt="cache_pressure_indirect" width="518" height="312" /></p>
<p>Again we&#8217;re looking a order of magnitude in speed difference.  The indirect line represents sorting the indirect array and then copying the draw calls into sorted order &#8211; so the end result is identical to the directly sorted array.  The no-copy line represents the time to sort the indirect array.  So if you only need to access your items in sorted order you&#8217;re probably best sorting an indirect array accessing your list indirectly.  This also has the advantage that you can keep sorted arrays around for different purposes &#8211; front to back, by material, etc., with out having to re-sort all the time or have multiple copies of the list.</p>
<p>Here&#8217;s the <a href="http://systematicgaming.wordpress.com/code-cachepressurecode-cachepressure/">code</a> if you want to run the tests yourself.</p>
<p>I think this is one of the clearest examples you&#8217;ll see on the impact of memory on performance.  This technique can be applied in a number of data structures to reduce the pressure on the cache. and as demonstrated can significantly affect performance.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/systematicgaming.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/systematicgaming.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/systematicgaming.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/systematicgaming.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/systematicgaming.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/systematicgaming.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/systematicgaming.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/systematicgaming.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/systematicgaming.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/systematicgaming.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/systematicgaming.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/systematicgaming.wordpress.com/506/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/systematicgaming.wordpress.com/506/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/systematicgaming.wordpress.com/506/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=systematicgaming.wordpress.com&amp;blog=4421368&amp;post=506&amp;subd=systematicgaming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://systematicgaming.wordpress.com/2008/12/23/patterns-in-performance-cache-pressure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">systematicgaming</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2008/12/cache_pressure_5121.png" medium="image">
			<media:title type="html">cache_pressure_5121</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2008/12/cache_pressure_sizes.png" medium="image">
			<media:title type="html">cache_pressure_sizes</media:title>
		</media:content>

		<media:content url="http://systematicgaming.files.wordpress.com/2008/12/cache_pressure_indirect.png" medium="image">
			<media:title type="html">cache_pressure_indirect</media:title>
		</media:content>
	</item>
	</channel>
</rss>
