<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GoGo-Robot</title>
	<atom:link href="http://www.gogo-robot.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gogo-robot.com</link>
	<description>Independent Games Developer</description>
	<lastBuildDate>Sat, 24 Mar 2012 11:25:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title></title>
		<link>http://www.gogo-robot.com/1970/01/01/350/</link>
		<comments>http://www.gogo-robot.com/1970/01/01/350/#comments</comments>
		<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=350</guid>
		<description><![CDATA[Below you can find information on a selection of the games we have worked on, both for clients and in-house. Some of our clients include:]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">Below you can find information on a selection of the games we have worked on, both for clients and in-house. Some of our clients include:</p>
<p style="text-align: center;"><a href="http://radiationburn.net/"><img src="http://www.gogo-robot.com/wp-content/uploads/2011/05/RBLogo_Small2.png" alt="" title="RadiationBurn" width="514" height="140" class="alignnone size-full wp-image-362" /></a><br /><a href="http://www.iguana-entertainment.com"><img src="http://www.gogo-robot.com/wp-content/uploads/2010/01/iguana_logo-300x124.png" alt="Iguana Entertainment" title="iguana_logo" width="300" height="124" class="size-medium wp-image-16" /></a> <a href="http://www.tower-studios.co.uk/"><img src="http://www.gogo-robot.com/wp-content/uploads/2010/01/towerstudios_logo.bmp" alt="Tower Studios" title="towerstudios_logo" class="alignnone size-full wp-image-17" /></a> <a href="http://www.themustardcorporation.com/"><img src="http://www.gogo-robot.com/wp-content/uploads/2010/12/logo-300x93.png" alt="" title="The Mustard Corporation" width="300" height="93" class="alignnone size-medium wp-image-276" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/1970/01/01/350/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memory Management &#8211; Part 2</title>
		<link>http://www.gogo-robot.com/2012/03/24/memory-management-part-2/</link>
		<comments>http://www.gogo-robot.com/2012/03/24/memory-management-part-2/#comments</comments>
		<pubDate>Sat, 24 Mar 2012 11:23:54 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[Developer Blog]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=392</guid>
		<description><![CDATA[In part one, we looked at some simple memory management in C, and why we need to be careful with what we do with our memory. Now, we&#8217;ll take a look at some more advanced topics, including garbage collectors, reference counting and automatic memory management. Our previous rule works great for simple programs, but there [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.gogo-robot.com/2012/01/25/memory-management-part-1/" title="Memory Management – Part 1">part one</a>, we looked at some simple memory management in C, and why we need to be careful with what we do with our memory. Now, we&#8217;ll take a look at some more advanced topics, including garbage collectors, reference counting and automatic memory management.</p>
<p><span id="more-392"></span></p>
<p>Our previous rule works great for simple programs, but there is a problem. Because we&#8217;ve defined a single owner for a piece of memory, our memory is only valid during the lifetime of its owner. Consider the following example:</p>
<p></p>
<p style="text-align: center;"><img src="http://www.gogo-robot.com/wp-content/uploads/2011/06/ObjectLifetime.png" alt="" title="ObjectLifetime" width="640" height="584" class="alignnone size-full wp-image-393" /></p>
<p></p>
<p>To solve this problem, we have to duplicate memory for use by other objects via a <b>Copy</b>, to ensure that memory is not deallocated before we&#8217;re done. This is OK for small objects, but when we&#8217;re having to duplicate large objects, we can quickly run out of memory.</p>
<p>Furthermore, if we decide to have Object2 make a copy of &#8220;Some Memory&#8221;, to ensure it stays around while we need it, then Object1 modifies the original, those changes won&#8217;t appear in Object2&#8242;s copy. Depending on the program, this may or may not be what we want, but it&#8217;s starting to get complicated. How can we make sure we&#8217;ve always got access to the memory we want, even if the object that created it is long gone?</p>
<p>As programming languages and practices have evolved, two main solutions to this problem have arisen. One is <b>Reference Counting</b>, used in languages such as Objective-C (when developing on iOS), which is what we&#8217;ll cover first. The other is the concept of a <b>Garbage Collector</b>, which is used in languages like C# and Java (and Objective-C when developing on OSX). Both concepts revolve around the idea that instead of being gready and having one owner for a piece of memory, we can in fact have many owners. Most of the principles talked about here can be applied to any language, but most of the more modern have been designed around one or the other of these memory management techniques.</p>
<h1>Reference Counting</h1>
<p>The idea with reference counting is that, along with the memory itself, we store a number of how many people currently own it (i.e. a <b>count</b> of how many <b>references</b> there are to the object). Every time a new owner wants to use the memory, we add 1 to that number. When someone is done with it, we subtract 1. When the number is at 0, we know there are no more owners, so we free up the memory. Take the following example:</p>
<ul>
<li>John buys a car.
<ul>
<li>The car now has 1 owner &#8211; (John)</li>
</ul>
</li>
<li>Jimmy likes the car and, because everyone is nice in this world, is allowed to become an owner too.
<ul>
<li>The car now has 2 owners &#8211; (John &#038; Jimmy)</li>
</ul>
</li>
<li>John no longer wants the car, as he has now died.
<ul>
<li>The car now has 1 owner (Jimmy)</li>
</ul>
</li>
<li>Jimmy decides he is done with the car, and relinquishes his ownership.
<ul>
<li>The car now has 0 owners, and so gets taken to the scrap yard and is recycled.</li>
</ul>
</li>
</ul>
<p>Great! We successfully shared a car between two people and cleaned up after ourselves when we were done. No more old, unwanted cars filling up the streets, and even better, we didn&#8217;t destroy the car with Jimmy still inside!</p>
<p>So, how do we use this system? Well, it&#8217;s actually pretty straight forward. All we need to do is store our reference count (i.e. how many people own the memory) along with the memory itself. This part comes down to which language you&#8217;re using. Remember we said previously that some languages were designed with reference counting in mind? Well, Objective-C is one of those languages. Every object in Objective-C stores its reference count (called a <b>retain count</b> in Objective-C) in the object itself. For other languages, you can have a few options. C++, for example, doesn&#8217;t currently have any inbuilt support for reference counting, so your options are either to roll your own solution, or to use an automatic one such as <a href="http://www.boost.org/doc/libs/1_46_1/libs/smart_ptr/shared_ptr.htm">Boost&#8217;s Shared Pointer</a>. These type of pointers are sometimes referred to as &#8220;smart pointers&#8221;.</p>
<h2>C++</h2>
<p>The way Boosts Shared Pointer works is that it is actually an object that wraps up the pointer to the memory and a pointer to its reference count. The shared pointer class implements a copy constructor and an assignment operator so that when shared pointers are copied / assigned to each other, they will copy the two pointers (the one to the memory and the one to the reference count), and then they will increment the reference count. When a shared pointer is destroyed, its destructor decrements the reference count and checks if it is 0. If it is, then the reference count and the object the shared pointer is pointing to are both deleted, thus freeing up the memory. See the animation below for a demonstration of this.</p>
<p></p>
<p style="text-align: center;"><img src="http://www.gogo-robot.com/wp-content/uploads/2012/03/Reference-Counting.gif" alt="" title="Reference Counting" width="544" height="416" class="alignnone size-full wp-image-443" /></p>
<p></p>
<h2>Objective-C (Reference counted)</h2>
<p><i>Note that this section aims to give an overview of how manual reference counting works in Objective-C. If you&#8217;re reading this, you&#8217;re most likely working on iOS (or just curious <img src='http://www.gogo-robot.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ), in which case you should really be using Automatic Reference Counting (ARC), which was introduced in iOS SDK 5.0 (Xcode 4.2), and is available when targetting iOS 4.0 and above. You should probably still read this to get an idea of how retain/release works, then read up on ARC, which handles all your retains/releases for you. There is a good blog post on it <a href="http://longweekendmobile.com/2011/09/07/objc-automatic-reference-counting-in-xcode-explained/">here</a>.</i></p>
<p>When using reference counting in Objective-C (Objective-C supports both reference counting and garbage collection, but garbage collection is only available on OSX, not iOS), up until iOS SDK 5.0, you need to manually retain/release your objects. Every time you call [myObject retain], you&#8217;re adding 1 to the reference count. Calling [myObject release] will subtract 1 from the reference count. When the reference count is 0, the object is deallocated. Note that when you alloc/init, new or copy an object, it has a retain count of 1. See the <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html">memory management documentation on Apple&#8217;s website</a> for more information.</p>
<p>Objective-C also has the idea of an autorelease pool, which allows objects to have <i>release</i> called on them at a later date. Objects can be added to the autorelease pool by calling [myObject autorelease]. Whenever the autorelease pool is drained, every object that has been autoreleased will have [myObject release] called on it. This is useful for allowing you to allocate and autorelease an object in one line, so you don&#8217;t have to worry about cleaning up. For example, in iOS, you might see something like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// The label is allocated and added to the autorelease pool in one line</span>
<span style="color: #11740a; font-style: italic;">// myLabel is created with a retain count of 1</span>
UILabel<span style="color: #002200;">*</span> myLabel <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span> labelFrame<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// The label is added to the main view</span>
<span style="color: #11740a; font-style: italic;">// Internally, the main view will retain myLabel, giving it a retain</span>
<span style="color: #11740a; font-style: italic;">// count of 2</span>
<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span> myLabel<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// ...</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// Your function exits, and the next time the autorelease pool is drained,</span>
<span style="color: #11740a; font-style: italic;">// myLabel will have release called on it, which will decrement the retain count</span>
<span style="color: #11740a; font-style: italic;">// As myLabel is still retained by the main view, it will not be deallocated</span>
<span style="color: #11740a; font-style: italic;">// until it is also released by the main view</span></pre></div></div>

<p>Autorelease pools are quite useful, as you don&#8217;t need to make sure you call release when you&#8217;re done with an object, just make sure you always call autorelease on the same line you alloc/new/copy. Note that each thread has its own autorelease pool, and if you create your own threads, you need to manually create an autorelease pool for your thread. See the documentation for <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html">NSAutoreleasePool</a>.</p>
<p>So that hopefully gives you a bit more insight into reference counted memory management. In the final part of these posts, we&#8217;ll look at garbage collection.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2012/03/24/memory-management-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Newton Vs The Horde Released On WiiWare</title>
		<link>http://www.gogo-robot.com/2012/01/27/newton-vs-the-horde-released-on-wiiware/</link>
		<comments>http://www.gogo-robot.com/2012/01/27/newton-vs-the-horde-released-on-wiiware/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 11:09:25 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[horde]]></category>
		<category><![CDATA[newton]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[wii]]></category>
		<category><![CDATA[wiiware]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=427</guid>
		<description><![CDATA[Newton Vs The Horde has been released on WiiWare in North America (Stay tuned for a release date for Europe sometime in February). You can download Newton Vs The Horde by accessing the Wii Shop Channel on your Wii console. Got a Wii but don&#8217;t know how to access WiiWare? Take a look at these [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.nintendo.com/games/detail/vIc-myJq6PyZniBoHTvA39RkTvl_BEl4" title="Newton Vs The Horde - WiiWare"><img src="http://www.gogo-robot.com/wp-content/uploads/2011/05/WNSP_NewtonVsTheHorde_Banner_WiiWare_All1.png" alt="Newton Vs The Horde" title="Newton Vs The Horde" width="740" height="190" class="alignnone size-full wp-image-404" /></a><br />
Newton Vs The Horde has been released on <a href="http://www.nintendo.com/games/detail/vIc-myJq6PyZniBoHTvA39RkTvl_BEl4" title="Newton Vs The Horde - WiiWare">WiiWare</a> in North America (Stay tuned for a release date for Europe sometime in February). You can download Newton Vs The Horde by accessing the Wii Shop Channel on your Wii console.<br />
<a href="http://www.nintendo.com/games/detail/vIc-myJq6PyZniBoHTvA39RkTvl_BEl4"><img src="http://www.gogo-robot.com/wp-content/uploads/2012/01/WiiWareLogo_Box_4c.png" alt="" title="WiiWare" width="300" height="242" class="alignnone size-full wp-image-428" /></a><br />
Got a Wii but don&#8217;t know how to access WiiWare? Take a look at these helpful sites from Nintendo:<br />
<a href="http://us.wii.com/connect/">Connect your Wii to the internet</a><br />
<a href="http://www.nintendo.com/wii/online/wiiware/">Nintendo WiiWare</a>
</p>
<p><span id="more-427"></span></p>
<p style="text-align: center;">Find out more about Newton Vs The Horde from the <a href="http://newton.radiationburn.net">RadiationBurn website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2012/01/27/newton-vs-the-horde-released-on-wiiware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memory Management &#8211; Part 1</title>
		<link>http://www.gogo-robot.com/2012/01/25/memory-management-part-1/</link>
		<comments>http://www.gogo-robot.com/2012/01/25/memory-management-part-1/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 23:50:41 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[Developer Blog]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=420</guid>
		<description><![CDATA[I was originally going to post a piece on iOS memory management, but it turned into a much larger piece on memory manangement in general. So, here&#8217;s the first part &#8211; other parts will follow later&#8230; Understanding what memory management is and why you need to do it. There are two main points that form [...]]]></description>
			<content:encoded><![CDATA[<p>I was originally going to post a piece on iOS memory management, but it turned into a much larger piece on memory manangement in general. So, here&#8217;s the first part &#8211; other parts will follow later&#8230;</p>
<p><span id="more-420"></span></p>
<h1>Understanding what memory management is and why you need to do it.</h1>
<p>There are two main points that form the basis of all of this:</p>
<ul>
<li>Every device has a limited amount of memory available, which means it can only store a limited amount of information. Imagine the memory as a pile of empty boxes, ready to be filled with stuff.</li>
<li>Every time you create an object, you are grabbing one of these empty boxes and using it to store your object in. That object will now hapilly live inside the box for the rest of its life.</li>
</ul>
<p>Note the term &#8220;<i>for the rest of its life</i>&#8221; &#8211; this is the important bit. While an object exists, it holds on to its box, so nothing else can live in it. If you want to create another object, you&#8217;ve got to grab another box from the pile for it to live in, and so on.<br /><!--more--><br />
Now, if you destroy an object, its box becomes empty again and gets thrown back onto the pile, ready to get used again.</p>
<p>OK, so now what happens if we keep creating objects, but never destroy them when we&#8217;re done using them? (Incidently, this is what is known as a <i>memory leak</i>) Well, we keep needing empty boxes to put our objects in. But remember, our device only has a limited amount of memory, so we&#8217;re going to run out eventually. And when that happens, it&#8217;s game over. A number of things can happen to your application, depending on the device and operating system, including:</p>
<ul>
<li>An exception is thrown when you try and create a new object when there&#8217;s no more space</li>
<li>The operating system can just force your application to close and grab back all of its memory without even notifying you</li>
<li>Nothing happens, but your memory allocation returns an invalid address. If you try and use this address, your application and device might just crash</li>
</ul>
<p>Obviously, we don&#8217;t want any of these to occur, so we&#8217;d better make sure we tidy up after ourselves and put the boxes back.</p>
<h1>Memory management in C</h1>
<p>Firstly, we&#8217;ll look at the basic functions for managing memory. Starting with plain C, we&#8217;ve got:</p>
<table style="border-collapse:collapse; border: 1px solid black; width: 100%;">
<tr style="border: 1px solid black; background-color: #a0a0a0;">
<td style="border: 1px solid black; padding: 0.25em;"><b>Function</b></td>
<td style="border: 1px solid black; padding: 0.25em;"><b>Description</b></td>
<td style="border: 1px solid black; padding: 0.25em;"><b>Example</b></td>
</tr>
<tr style="border: 1px solid black;">
<td style="border: 1px solid black; padding: 0.25em;"><a href="http://www.cplusplus.com/reference/clibrary/cstdlib/malloc/">malloc</a></td>
<td style="border: 1px solid black; padding: 0.25em;">Allocates a chunk of memory from the heap*.</td>
<td style="border: 1px solid black; padding: 0.25em;"><span style="font-family:'Courier New', Monospace">char* pMyMemory = (char*)malloc(200); // Allocate a block of 200 bytes</span></td>
</tr>
<tr style="border: 1px solid black;">
<td style="border: 1px solid black; padding: 0.25em;"><a href="http://www.cplusplus.com/reference/clibrary/cstdlib/free/">free</a></td>
<td style="border: 1px solid black; padding: 0.25em;">Frees up a chunk of memory and returns it back to the heap.</td>
<td style="border: 1px solid black; padding: 0.25em;"><span style="font-family:'Courier New', Monospace">free(pMyMemory);</span></td>
</tr>
</table>
<p><i>* &#8211; The heap is our pile of boxes (i.e. all of our application&#8217;s memory)</i></p>
<p>Simple. We&#8217;ve got our function that grabs some memory, and one that puts it back. This is great for basic programs, but in larger applications, you&#8217;ll soon realise that you need to be <i>very</i> careful about what you do with that memory. Take the following:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// This function returns a copy of a C-style string</span>
<span style="color: #993333;">char</span><span style="color: #339933;">*</span> String_Copy<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> pString<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> SizeOfMemoryNeeded <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span><span style="color: #339933;">*</span> pMemoryToReturn <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Get the length of the string</span>
	SizeOfMemoryNeeded <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>pString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Add 1 byte on for the null terminator</span>
	<span style="color: #666666; font-style: italic;">// strlen returns the number of characters in the string,</span>
	<span style="color: #666666; font-style: italic;">// but C-style strings need a byte at the end set to 0</span>
	<span style="color: #666666; font-style: italic;">// to mark where the string stops. (This is known as being null-terminated)</span>
	SizeOfMemoryNeeded <span style="color: #339933;">+=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Allocate our memory</span>
	pMemoryToReturn <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span>SizeOfMemoryNeeded<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Copy our string</span>
	strcpy<span style="color: #009900;">&#40;</span>pMemoryToReturn<span style="color: #339933;">,</span> pString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Return the newly allocated memory</span>
	<span style="color: #b1b100;">return</span> pMemoryToReturn<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">const</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> pMyString <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;This is my string&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span><span style="color: #339933;">*</span> pCopiedString <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Copy MyString</span>
	pCopiedString <span style="color: #339933;">=</span> String_Copy<span style="color: #009900;">&#40;</span>pMyString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Now we have a pointer, pCopiedString, which</span>
	<span style="color: #666666; font-style: italic;">// points at the memory we grabbed in String_Copy.</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// ....</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// We pass our copied string into a function</span>
	SomeFunction<span style="color: #009900;">&#40;</span>pCopiedString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// ....</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// So now we decide we're going to play nice and clean up</span>
	<span style="color: #666666; font-style: italic;">// our memory that we allocated:</span>
	free<span style="color: #009900;">&#40;</span>pCopiedString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h1>Ownership</h1>
<p>So that&#8217;s all fine and good. We&#8217;ve played nice and put our box back on the pile when we&#8217;re done with it. Then one day, after lots of code has been added to our project, suddenly we get <b>BOOM!</b> when we try and free our memory. What gives? Well, after hours of searching, we eventually find this travesty somewhere deep in the program:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> SomeFunctionDeepInTheProgram<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span> pAString<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Do some stuff</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// We don't need the string any more, so lets delete it</span>
	free<span style="color: #009900;">&#40;</span>pAString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Gah! Whoever wrote that should be shot. It turns out that our copied string was being passed into this function, and the function was freeing up its memory ready to be used by something else.</p>
<p>The key here is <b>ownership</b>. Who&#8217;s in charge of the memory that was created in String_Copy? Who should be the one that frees it up? One good way to decide this is through the use of certain key words in our function names. We can define a simple rule that we&#8217;ll always stick to:</p>
<ul>
<li>If a function with the word Copy or Create in its name returns memory, then whoever called that function owns the memory.</li>
</ul>
<p>See how our main() function calls String_<b>Copy</b>? Under our rule, that means that the main() function is responsible for cleaning up that memory, and no one else. SomeFunctionDeepInTheProgram is being naughty, because it&#8217;s trying to free up memory that it didn&#8217;t get via a Copy or Create function. If everyone follows our simple rule, then we can avoid this situation.</p>
<p>Hopefully that gives you a bit of an introduction into why you need to really think about memory management. Next time we&#8217;ll talk about more complex memory management, garbage collectors, reference counting and automatic memory management.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2012/01/25/memory-management-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Newton Vs The Horde (iPad) Reviewed</title>
		<link>http://www.gogo-robot.com/2012/01/04/newton-vs-the-horde-ipad-reviewed/</link>
		<comments>http://www.gogo-robot.com/2012/01/04/newton-vs-the-horde-ipad-reviewed/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 10:31:37 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[horde]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[newton]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=416</guid>
		<description><![CDATA[Newton Vs The Horde on the iPad gets its 1st review by Calm Down Tom. Thanks guys! You can read the review in full at the link below: http://calmdowntom.com/2011/12/newton-vs-the-horde-hd-review-ipad/]]></description>
			<content:encoded><![CDATA[<p>Newton Vs The Horde on the iPad gets its 1st review by Calm Down Tom. Thanks guys! You can read the review in full at the link below:<br />
<a href="http://calmdowntom.com/2011/12/newton-vs-the-horde-hd-review-ipad/">http://calmdowntom.com/2011/12/newton-vs-the-horde-hd-review-ipad/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2012/01/04/newton-vs-the-horde-ipad-reviewed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Newton Vs The Horde</title>
		<link>http://www.gogo-robot.com/2011/12/15/newton-vs-the-horde-2/</link>
		<comments>http://www.gogo-robot.com/2011/12/15/newton-vs-the-horde-2/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 10:43:34 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[horde]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[newton]]></category>
		<category><![CDATA[wiiware]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=412</guid>
		<description><![CDATA[Newton Vs The Horde is out now on WiiWare &#038; iPad, and coming soon to Android. Find out more about Newton Vs The Horde from the RadiationBurn website.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.nintendo.com/games/detail/vIc-myJq6PyZniBoHTvA39RkTvl_BEl4" title="Newton Vs The Horde - WiiWare"><img src="http://www.gogo-robot.com/wp-content/uploads/2011/05/WNSP_NewtonVsTheHorde_Banner_WiiWare_All1.png" alt="Newton Vs The Horde" title="Newton Vs The Horde" width="740" height="190" class="alignnone size-full wp-image-404" /></a><br />
Newton Vs The Horde is out now on <a href="http://www.nintendo.com/games/detail/vIc-myJq6PyZniBoHTvA39RkTvl_BEl4" title="Newton Vs The Horde - WiiWare">WiiWare</a> &#038; <a href="http://itunes.apple.com/us/app/newton-vs-the-horde-hd/id488124994?mt=8&amp;uo=4">iPad</a>, and coming soon to Android.<br />
<a href="http://itunes.apple.com/us/app/newton-vs-the-horde-hd/id488124994?mt=8&amp;uo=4"><img src="http://www.gogo-robot.com/wp-content/uploads/2011/05/App_Store_Badge21.png" alt="Newton Vs The Horde" title="Newton Vs The Horde" width="160" height="54" class="alignnone size-full wp-image-410" /></a></p>
<p><span id="more-412"></span></p>
<p style="text-align: center;">Find out more about Newton Vs The Horde from the <a href="http://newton.radiationburn.net">RadiationBurn website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2011/12/15/newton-vs-the-horde-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA Skinned Model Animations</title>
		<link>http://www.gogo-robot.com/2011/05/30/xna-skinned-model-animations/</link>
		<comments>http://www.gogo-robot.com/2011/05/30/xna-skinned-model-animations/#comments</comments>
		<pubDate>Mon, 30 May 2011 15:36:33 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[Developer Blog]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[skinning]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=379</guid>
		<description><![CDATA[The Skinned Model sample from the App Hub education catalogue is great for getting animated characters into your game, but there&#8217;s a bit of a flaw with the export process. The problem is, when you export your character from 3DS Max (and possibly other modelling programs), all you get is one animation, named &#8216;Take 001&#8242;. [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://create.msdn.com/en-US/education/catalog/sample/skinned_model">Skinned Model</a> sample from the App Hub education catalogue is great for getting animated characters into your game, but there&#8217;s a bit of a flaw with the export process. The problem is, when you export your character from 3DS Max (and possibly other modelling programs), all you get is one animation, named &#8216;Take 001&#8242;. Wouldn&#8217;t it be nice if we could define different animations for different parts of the animation timeline? Well, we&#8217;re going to do just that <img src='http://www.gogo-robot.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . As an added bonus, we&#8217;ll also be adding in events, so you can be notified when certain parts of your animation are hit.
<p><span id="more-379"></span></p>
<p>This tutorial is based on the Skinned Model sample, so grab it from the <a href="http://create.msdn.com/en-US/education/catalog/sample/skinned_model">App Hub</a> if you want to follow along, or skip to the end if you want the final version (which is released under the same license as the original).</p>
<p>What we&#8217;ll be doing is creating an XML file to go with our exported model, which will define our animation clips and events. The animations defined in this file will replace animations defined in the source model file. So, first thing is to define the class that will be represented by the XML file. Create a class in the SkinnedModelPipeline project named AnimationDefinition, like so:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Content</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Content.Pipeline</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Content.Pipeline.Serialization</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> SkinnedModelPipeline
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// A class for storing our animation definitions</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> AnimationDefinition
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The original clip name that was exported by the modelling package</span>
        <span style="color: #008080; font-style: italic;">/// Usually this will be Take 001</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> OriginalClipName
        <span style="color: #008000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The number of frames in the original animation</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> OriginalFrameCount
        <span style="color: #008000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// A class for storing information about individual clips that we want to create</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ClipPart
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// The name we have given the clip</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> ClipName
            <span style="color: #008000;">&#123;</span>
                get<span style="color: #008000;">;</span>
                set<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// The starting frame of the clip</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> StartFrame
            <span style="color: #008000;">&#123;</span>
                get<span style="color: #008000;">;</span>
                set<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// The ending frame of the clip</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> EndFrame
            <span style="color: #008000;">&#123;</span>
                get<span style="color: #008000;">;</span>
                set<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// A class for defining events in an animation</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> <span style="color: #0600FF; font-weight: bold;">Event</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
                <span style="color: #008080; font-style: italic;">/// The name of the event</span>
                <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
                <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name
                <span style="color: #008000;">&#123;</span>
                    get<span style="color: #008000;">;</span>
                    set<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
                <span style="color: #008080; font-style: italic;">/// The frame that the event fires on</span>
                <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
                <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Keyframe
                <span style="color: #008000;">&#123;</span>
                    get<span style="color: #008000;">;</span>
                    set<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Our list of events in this animation clip</span>
            <span style="color: #008080; font-style: italic;">/// Animation clips do not require events, so this is marked as optional</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Xna</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Framework</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ContentSerializer</span><span style="color: #008000;">&#40;</span>Optional <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> List<span style="color: #008000;">&lt;</span><span style="color: #0600FF; font-weight: bold;">Event</span><span style="color: #008000;">&gt;</span> Events
            <span style="color: #008000;">&#123;</span>
                get<span style="color: #008000;">;</span>
                set<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The list of clip parts that we are breaking the original clip into</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> List<span style="color: #008000;">&lt;</span>ClipPart<span style="color: #008000;">&gt;</span> ClipParts
        <span style="color: #008000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>Next, we&#8217;ll need to modify the runtime project to add information about our events to the animations. Create a class in the SkinnedModelWindows project named AnimationEvent, with this in it:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080;">#region Using Statements</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #008080;">#endregion</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> SkinnedModel
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Information about an event in our animation</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> AnimationEvent
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The name of the event</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">String</span> EventName
        <span style="color: #008000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The time of the event</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> TimeSpan EventTime
        <span style="color: #008000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>Now, we need to add our events store to the animation clip, as well as the clip name. So open up AnimationClip.cs, and add this to the end of the class:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Callback events for the animation clips</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008000;">&#91;</span>ContentSerializer<span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> List<span style="color: #008000;">&lt;</span>AnimationEvent<span style="color: #008000;">&gt;</span> Events <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// The name of the clip</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008000;">&#91;</span>ContentSerializer<span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>We also need to modify the constructor so that we can pass in the list of animation events when we create the clip. Our new constructor looks like this:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Constructs a new animation clip object.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> AnimationClip<span style="color: #008000;">&#40;</span>TimeSpan duration, List<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span> keyframes, List<span style="color: #008000;">&lt;</span>AnimationEvent<span style="color: #008000;">&gt;</span> events, <span style="color: #6666cc; font-weight: bold;">string</span> name<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Duration <span style="color: #008000;">=</span> duration<span style="color: #008000;">;</span>
            Keyframes <span style="color: #008000;">=</span> keyframes<span style="color: #008000;">;</span>
            Events <span style="color: #008000;">=</span> events<span style="color: #008000;">;</span>
            Name <span style="color: #008000;">=</span> name<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>Almost there. We need to modify the SkinnedModelProcessor class so that it reads in our XML files describing our animations and stores them in the model file that it generates, replacing the original animation (the Take 001). So, in SkinnedModelProcessor.cs, in the ProcessAnimations function, we need to first check if an animation definition file exists that we will use to override the ones in the model. By having this check, it means that we don&#8217;t need to create an animation definition for every skinned model, just the ones that we want custom animations on. You&#8217;ll also need to modify the ProcessAnimations function to take two extra parameters, which are the ContentProcessorContext and ContentIdentity. We use these to get information about the current file we are processing, so we can look for an animation definition with the same name. The below code is the updated ProcessAnimations function:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Converts an intermediate format content pipeline AnimationContentDictionary</span>
        <span style="color: #008080; font-style: italic;">/// object to our runtime AnimationClip format.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">static</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, AnimationClip<span style="color: #008000;">&gt;</span> ProcessAnimations<span style="color: #008000;">&#40;</span>
            AnimationContentDictionary animations, IList<span style="color: #008000;">&lt;</span>BoneContent<span style="color: #008000;">&gt;</span> bones,
            ContentProcessorContext context, ContentIdentity sourceIdentity<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Build up a table mapping bone names to indices.</span>
            Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> boneMap <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> bones<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> boneName <span style="color: #008000;">=</span> bones<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>boneName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    boneMap<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>boneName, i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Convert each animation in turn.</span>
            Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, AnimationClip<span style="color: #008000;">&gt;</span> animationClips<span style="color: #008000;">;</span>
            animationClips <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, AnimationClip<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// We process the original animation first, so we can use their keyframes</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, AnimationContent<span style="color: #008000;">&gt;</span> animation <span style="color: #0600FF; font-weight: bold;">in</span> animations<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                AnimationClip processed <span style="color: #008000;">=</span> ProcessAnimation<span style="color: #008000;">&#40;</span>animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span>, boneMap, animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                animationClips<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>, processed<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Check to see if there's an animation clip definition</span>
            <span style="color: #008080; font-style: italic;">// Here, we're checking for a file with the _Anims suffix.</span>
            <span style="color: #008080; font-style: italic;">// So, if your model is named dude.fbx, we'd add dude_Anims.xml in the same folder</span>
            <span style="color: #008080; font-style: italic;">// and the pipeline will see the file and use it to override the animations in the</span>
            <span style="color: #008080; font-style: italic;">// original model file.</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> SourceModelFile <span style="color: #008000;">=</span> sourceIdentity<span style="color: #008000;">.</span><span style="color: #0000FF;">SourceFilename</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> SourcePath <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDirectoryName</span><span style="color: #008000;">&#40;</span>SourceModelFile<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> AnimFilename <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFileNameWithoutExtension</span><span style="color: #008000;">&#40;</span>SourceModelFile<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            AnimFilename <span style="color: #008000;">+=</span> <span style="color: #666666;">&quot;_Anims.xml&quot;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> AnimPath <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">Combine</span><span style="color: #008000;">&#40;</span>SourcePath, AnimFilename<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>AnimPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Add the filename as a dependency, so if it changes, the model is rebuilt</span>
                context<span style="color: #008000;">.</span><span style="color: #0000FF;">AddDependency</span><span style="color: #008000;">&#40;</span>AnimPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Load the animation definition from the XML file</span>
                AnimationDefinition AnimDef <span style="color: #008000;">=</span> context<span style="color: #008000;">.</span><span style="color: #0000FF;">BuildAndLoadAsset</span><span style="color: #008000;">&lt;</span>XmlImporter, AnimationDefinition<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ExternalReference<span style="color: #008000;">&lt;</span>XmlImporter<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>AnimPath<span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Break up the original animation clips into our new clips</span>
                <span style="color: #008080; font-style: italic;">// First, we check if the clips contains our clip to break up</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>animationClips<span style="color: #008000;">.</span><span style="color: #0000FF;">ContainsKey</span><span style="color: #008000;">&#40;</span>AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalClipName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">// Grab the main clip that we are using</span>
                    AnimationClip MainClip <span style="color: #008000;">=</span> animationClips<span style="color: #008000;">&#91;</span>AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalClipName</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// Now remove the original clip from our animations</span>
                    animationClips<span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalClipName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// Process each of our new animation clip parts</span>
                    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>AnimationDefinition<span style="color: #008000;">.</span><span style="color: #0000FF;">ClipPart</span> Part <span style="color: #0600FF; font-weight: bold;">in</span> AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">ClipParts</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #008080; font-style: italic;">// Calculate the frame times</span>
                        TimeSpan StartTime <span style="color: #008000;">=</span> GetTimeSpanForFrame<span style="color: #008000;">&#40;</span>Part<span style="color: #008000;">.</span><span style="color: #0000FF;">StartFrame</span>, AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalFrameCount</span>, MainClip<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Ticks</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        TimeSpan EndTime <span style="color: #008000;">=</span> GetTimeSpanForFrame<span style="color: #008000;">&#40;</span>Part<span style="color: #008000;">.</span><span style="color: #0000FF;">EndFrame</span>, AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalFrameCount</span>, MainClip<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Ticks</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                        <span style="color: #008080; font-style: italic;">// Get all the keyframes for the animation clip</span>
                        <span style="color: #008080; font-style: italic;">// that fall within the start and end time</span>
                        List<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span> Keyframes <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Keyframe AnimFrame <span style="color: #0600FF; font-weight: bold;">in</span> MainClip<span style="color: #008000;">.</span><span style="color: #0000FF;">Keyframes</span><span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>AnimFrame<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span> <span style="color: #008000;">&gt;=</span> StartTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>AnimFrame<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span> <span style="color: #008000;">&lt;=</span> EndTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #008000;">&#123;</span>
                                Keyframe NewFrame <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Keyframe<span style="color: #008000;">&#40;</span>AnimFrame<span style="color: #008000;">.</span><span style="color: #0000FF;">Bone</span>, AnimFrame<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span> <span style="color: #008000;">-</span> StartTime, AnimFrame<span style="color: #008000;">.</span><span style="color: #0000FF;">Transform</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                                Keyframes<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>NewFrame<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            <span style="color: #008000;">&#125;</span>
                        <span style="color: #008000;">&#125;</span>
&nbsp;
                        <span style="color: #008080; font-style: italic;">// Process the events</span>
                        List<span style="color: #008000;">&lt;</span>AnimationEvent<span style="color: #008000;">&gt;</span> Events <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>AnimationEvent<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Part<span style="color: #008000;">.</span><span style="color: #0000FF;">Events</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            <span style="color: #008080; font-style: italic;">// Process each event</span>
                            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>AnimationDefinition<span style="color: #008000;">.</span><span style="color: #0000FF;">ClipPart</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Event</span> <span style="color: #0600FF; font-weight: bold;">Event</span> <span style="color: #0600FF; font-weight: bold;">in</span> Part<span style="color: #008000;">.</span><span style="color: #0000FF;">Events</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #008000;">&#123;</span>
                                <span style="color: #008080; font-style: italic;">// Get the event time within the animation</span>
                                TimeSpan EventTime <span style="color: #008000;">=</span> GetTimeSpanForFrame<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">Event</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Keyframe</span>, AnimDef<span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalFrameCount</span>, MainClip<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Ticks</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                                <span style="color: #008080; font-style: italic;">// Offset the event time so it is relative to the start of the animation</span>
                                EventTime <span style="color: #008000;">-=</span> StartTime<span style="color: #008000;">;</span>
&nbsp;
                                <span style="color: #008080; font-style: italic;">// Create the event</span>
                                AnimationEvent NewEvent <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> AnimationEvent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                                NewEvent<span style="color: #008000;">.</span><span style="color: #0000FF;">EventTime</span> <span style="color: #008000;">=</span> EventTime<span style="color: #008000;">;</span>
                                NewEvent<span style="color: #008000;">.</span><span style="color: #0000FF;">EventName</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">Event</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
                                Events<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>NewEvent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            <span style="color: #008000;">&#125;</span>
                        <span style="color: #008000;">&#125;</span>
&nbsp;
                        <span style="color: #008080; font-style: italic;">// Create the clip</span>
                        AnimationClip NewClip <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> AnimationClip<span style="color: #008000;">&#40;</span>EndTime <span style="color: #008000;">-</span> StartTime, Keyframes, Events, Part<span style="color: #008000;">.</span><span style="color: #0000FF;">ClipName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        animationClips<span style="color: #008000;">&#91;</span>Part<span style="color: #008000;">.</span><span style="color: #0000FF;">ClipName</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> NewClip<span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>animationClips<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidContentException<span style="color: #008000;">&#40;</span>
                            <span style="color: #666666;">&quot;Input file does not contain any animations.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> animationClips<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets a TimeSpan value for a frame index in an animation</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> TimeSpan GetTimeSpanForFrame<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> FrameIndex, <span style="color: #6666cc; font-weight: bold;">int</span> TotalFrameCount, <span style="color: #6666cc; font-weight: bold;">long</span> TotalTicks<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">float</span> MaxFrameIndex <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>TotalFrameCount <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">float</span> AmountOfAnimation <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>FrameIndex <span style="color: #008000;">/</span> MaxFrameIndex<span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">float</span> NumTicks <span style="color: #008000;">=</span> AmountOfAnimation <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>TotalTicks<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> TimeSpan<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">long</span><span style="color: #008000;">&#41;</span>NumTicks<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>What we do is process the original animations, so that all the keyframe data is there, then we check for an animation definition file and, if it exists, use it to replace the animation clips from the original model. We also need to modify ProcessAnimation to handle the new AnimationClip constructor:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Converts an intermediate format content pipeline AnimationContent</span>
        <span style="color: #008080; font-style: italic;">/// object to our runtime AnimationClip format.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">static</span> AnimationClip ProcessAnimation<span style="color: #008000;">&#40;</span>AnimationContent animation,
                                              Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> boneMap,
                                              <span style="color: #6666cc; font-weight: bold;">string</span> clipName<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            List<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span> keyframes <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// For each input animation channel.</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, AnimationChannel<span style="color: #008000;">&gt;</span> channel <span style="color: #0600FF; font-weight: bold;">in</span>
                animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Channels</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Look up what bone this channel is controlling.</span>
                <span style="color: #6666cc; font-weight: bold;">int</span> boneIndex<span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>boneMap<span style="color: #008000;">.</span><span style="color: #0000FF;">TryGetValue</span><span style="color: #008000;">&#40;</span>channel<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>, <span style="color: #0600FF; font-weight: bold;">out</span> boneIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidContentException<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span>
                        <span style="color: #666666;">&quot;Found animation for bone '{0}', &quot;</span> <span style="color: #008000;">+</span>
                        <span style="color: #666666;">&quot;which is not part of the skeleton.&quot;</span>, channel<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Convert the keyframe data.</span>
                <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>AnimationKeyframe keyframe <span style="color: #0600FF; font-weight: bold;">in</span> channel<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    keyframes<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Keyframe<span style="color: #008000;">&#40;</span>boneIndex, keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span>,
                                               keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Transform</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Sort the merged keyframes by time.</span>
            keyframes<span style="color: #008000;">.</span><span style="color: #0000FF;">Sort</span><span style="color: #008000;">&#40;</span>CompareKeyframeTimes<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>keyframes<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidContentException<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Animation has no keyframes.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span> <span style="color: #008000;">&lt;=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">Zero</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidContentException<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Animation has a zero duration.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> AnimationClip<span style="color: #008000;">&#40;</span>animation<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span>, keyframes, <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>AnimationEvent<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, clipName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>OK, so now we can override animations in the models using our XML file. Before I show you an example file, there&#8217;s one last thing to do, which is to add in the event callback system into the runtime. So, we need to add in a place to register our event callbacks into the AnimationPlayer class. At the end of the &#8216;Fields&#8217; region, we need to add:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #008080; font-style: italic;">// The delegate template for the event callbacks</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">delegate</span> <span style="color: #6666cc; font-weight: bold;">void</span> EventCallback<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> <span style="color: #0600FF; font-weight: bold;">Event</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// The reigstered events</span>
        Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, EventCallback<span style="color: #008000;">&gt;&gt;</span> registeredEvents <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, EventCallback<span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, EventCallback<span style="color: #008000;">&gt;&gt;</span> RegisteredEvents
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> registeredEvents<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>And initialise the registeredEvents dictionary in the constructor:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #008080; font-style: italic;">// Construct the event dictionaries for each clip</span>
        <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> clipName <span style="color: #0600FF; font-weight: bold;">in</span> skinningData<span style="color: #008000;">.</span><span style="color: #0000FF;">AnimationClips</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Keys</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            registeredEvents<span style="color: #008000;">&#91;</span>clipName<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, EventCallback<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>Now we can add events, so the last thing to do is to add the code that calls them, then we&#8217;ll be done. In the UpdateBoneTransforms function in AnimationPlayer, we need to modify it like so:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Helper used by the Update method to refresh the BoneTransforms data.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> UpdateBoneTransforms<span style="color: #008000;">&#40;</span>TimeSpan time, <span style="color: #6666cc; font-weight: bold;">bool</span> relativeToCurrentTime<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>currentClipValue <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> InvalidOperationException<span style="color: #008000;">&#40;</span>
                            <span style="color: #666666;">&quot;AnimationPlayer.Update was called before StartClip&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Store the previous time</span>
            TimeSpan lastTime <span style="color: #008000;">=</span> time<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Update the animation position.</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>relativeToCurrentTime<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                lastTime <span style="color: #008000;">=</span> currentTimeValue<span style="color: #008000;">;</span>
                time <span style="color: #008000;">+=</span> currentTimeValue<span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Check for events</span>
                CheckEvents<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> time, <span style="color: #0600FF; font-weight: bold;">ref</span> lastTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// If we reached the end, loop back to the start.</span>
                <span style="color: #6666cc; font-weight: bold;">bool</span> hasLooped <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>time <span style="color: #008000;">&gt;=</span> currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    hasLooped <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    time <span style="color: #008000;">-=</span> currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// If we've looped, reprocess the events</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>hasLooped<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    CheckEvents<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> time, <span style="color: #0600FF; font-weight: bold;">ref</span> lastTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>time <span style="color: #008000;">&lt;</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">Zero</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">&#40;</span>time <span style="color: #008000;">&gt;=</span> currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> ArgumentOutOfRangeException<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;time&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// If the position moved backwards, reset the keyframe index.</span>
            <span style="color: #6666cc; font-weight: bold;">bool</span> HasResetKeyframe <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>time <span style="color: #008000;">&lt;</span> currentTimeValue<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                HasResetKeyframe <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                currentKeyframe <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                skinningDataValue<span style="color: #008000;">.</span><span style="color: #0000FF;">BindPose</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CopyTo</span><span style="color: #008000;">&#40;</span>boneTransforms, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            currentTimeValue <span style="color: #008000;">=</span> time<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Read keyframe matrices.</span>
            IList<span style="color: #008000;">&lt;</span>Keyframe<span style="color: #008000;">&gt;</span> keyframes <span style="color: #008000;">=</span> currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Keyframes</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>currentKeyframe <span style="color: #008000;">&lt;</span> keyframes<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                Keyframe keyframe <span style="color: #008000;">=</span> keyframes<span style="color: #008000;">&#91;</span>currentKeyframe<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Stop when we've read up to the current time position.</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span> <span style="color: #008000;">&gt;</span> currentTimeValue<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>HasResetKeyframe<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Use this keyframe.</span>
                boneTransforms<span style="color: #008000;">&#91;</span>keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Bone</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Transform</span><span style="color: #008000;">;</span>
&nbsp;
                currentKeyframe<span style="color: #008000;">++;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>HasResetKeyframe<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    currentTimeValue <span style="color: #008000;">=</span> keyframe<span style="color: #008000;">.</span><span style="color: #0000FF;">Time</span><span style="color: #008000;">;</span>
                    HasResetKeyframe <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>And add the CheckEvents function:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Checks to see if any events have passed</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> CheckEvents<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> TimeSpan time, <span style="color: #0600FF; font-weight: bold;">ref</span> TimeSpan lastTime<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> eventName <span style="color: #0600FF; font-weight: bold;">in</span> registeredEvents<span style="color: #008000;">&#91;</span>currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Keys</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Find the event</span>
                <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>AnimationEvent animEvent <span style="color: #0600FF; font-weight: bold;">in</span> currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Events</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>animEvent<span style="color: #008000;">.</span><span style="color: #0000FF;">EventName</span> <span style="color: #008000;">==</span> eventName<span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        TimeSpan eventTime <span style="color: #008000;">=</span> animEvent<span style="color: #008000;">.</span><span style="color: #0000FF;">EventTime</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>lastTime <span style="color: #008000;">&lt;</span> eventTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>time <span style="color: #008000;">&gt;=</span> eventTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            <span style="color: #008080; font-style: italic;">// Call the event</span>
                            registeredEvents<span style="color: #008000;">&#91;</span>currentClipValue<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>eventName<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#40;</span>eventName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>So now we can define custom animations with events. Lets see it in action&#8230;</p>
<p>Add a new file to your content project, giving it the same name as the model, but with _Anims.xml. In our case, our model file is dude.fbx, so we want dude_Anims.xml. We don&#8217;t actually want the content pipeline to build this directly, so set the Build Action property to None, the Content Processor to No Processing Required, and Copy to Output Directory to Do not copy. Our XML looks like this:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;XnaContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Asset</span> <span style="color: #000066;">Type</span>=<span style="color: #ff0000;">&quot;SkinnedModelPipeline.AnimationDefinition&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- The original name of the clip we are breaking up --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;OriginalClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Take 001<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/OriginalClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- The total number of frames in the original clip --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;OriginalFrameCount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>100<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/OriginalFrameCount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- The new parts we want --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ClipParts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #808080; font-style: italic;">&lt;!-- Each item is one of our new clips --&gt;</span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Idle<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StartFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StartFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EndFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>50<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/EndFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Fire<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ClipName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StartFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>51<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StartFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EndFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/EndFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- We can register events in this clip, so we can know when certain frames are hit --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Events<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FireFrame<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Keyframe<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>70<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Keyframe<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Events<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ClipParts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Asset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/XnaContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</p>
<p>Now we can play our new clips like normal. We can also add callbacks for events. For example, the FireFrame event, we add like this:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">            <span style="color: #008080; font-style: italic;">// Create an animation player, and start decoding an animation clip.</span>
            animationPlayer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> AnimationPlayer<span style="color: #008000;">&#40;</span>skinningData<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Register an event</span>
            animationPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisteredEvents</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Fire&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FireFrame&quot;</span>, <span style="color: #008000;">new</span> AnimationPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">EventCallback</span><span style="color: #008000;">&#40;</span>OnFire<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            AnimationClip clip <span style="color: #008000;">=</span> skinningData<span style="color: #008000;">.</span><span style="color: #0000FF;">AnimationClips</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Fire&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            animationPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">StartClip</span><span style="color: #008000;">&#40;</span>clip<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

</p>
<p>And our function just looks like this:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnFire<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> EventName<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Do something here like create a bullet</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>So there you have it. You can download the updated sample <a href="downloads/skinnedmodelsample/SkinningSample_4_0_WithCustomAnims.zip">here</a>. You can use the &#8217;1&#8242; and &#8217;2&#8242; keys to switch between animation clips. The second one has a callback registered to it. One thing to note is that you&#8217;ll have to make sure you do a Rebuild Solution if you&#8217;re adding an animation XML to an existing model, because the content pipeline doesn&#8217;t know that the model depends on the animation definition until after it has built it once with the animation file there. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2011/05/30/xna-skinned-model-animations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jobs</title>
		<link>http://www.gogo-robot.com/2011/05/25/jobs/</link>
		<comments>http://www.gogo-robot.com/2011/05/25/jobs/#comments</comments>
		<pubDate>Wed, 25 May 2011 12:30:47 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[Jobs]]></category>
		<category><![CDATA[job]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=375</guid>
		<description><![CDATA[GoGo-Robot are not currently recruiting, but please keep checking back, as all job listings will be posted here.]]></description>
			<content:encoded><![CDATA[<p>GoGo-Robot are not currently recruiting, but please keep checking back, as all job listings will be posted here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2011/05/25/jobs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Newton Vs The Horde</title>
		<link>http://www.gogo-robot.com/2011/05/10/newton-vs-the-horde/</link>
		<comments>http://www.gogo-robot.com/2011/05/10/newton-vs-the-horde/#comments</comments>
		<pubDate>Tue, 10 May 2011 08:25:01 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=365</guid>
		<description><![CDATA[Developed in association with RadiationBurn, Newton Vs The Horde is now available for WiiWare (North America out now, European version coming February) and iOS, with an Android version coming in Februrary 2012. WiiWare You can download Newton Vs The Horde by accessing the Wii Shop Channel on your Wii console. Got a Wii but don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://newton.radiationburn.net"><img class="alignnone size-full wp-image-404" title="Newton Vs The Horde" src="http://www.gogo-robot.com/wp-content/uploads/2011/05/WNSP_NewtonVsTheHorde_Banner_WiiWare_All1.png" alt="Newton Vs The Horde" width="740" height="190" /></a></p>
<p style="text-align: center;"><a href="http://www.gogo-robot.com/wp-content/uploads/2011/05/IMG_0021.png"><img class="alignnone size-medium wp-image-405" title="Newton Screenshot 1" src="http://www.gogo-robot.com/wp-content/uploads/2011/05/IMG_0021-300x225.png" alt="Newton Vs The Horde Screenshot" width="300" height="225" /></a> <a href="http://www.gogo-robot.com/wp-content/uploads/2011/05/Screenshot-2011.12.09-14.51.33.png"><img class="alignnone size-medium wp-image-406" title="Newton Vs The Horde" src="http://www.gogo-robot.com/wp-content/uploads/2011/05/Screenshot-2011.12.09-14.51.33-300x225.png" alt="Newton Vs The Horde Screenshot 2" width="300" height="225" /></a> <a href="http://www.gogo-robot.com/wp-content/uploads/2011/05/Screenshot-2011.12.10-00.42.08.png"><img class="alignnone size-medium wp-image-407" title="Newton Vs The Horde" src="http://www.gogo-robot.com/wp-content/uploads/2011/05/Screenshot-2011.12.10-00.42.08-300x225.png" alt="Newton Vs The Horde Screenshot 3" width="300" height="225" /></a></p>
<p style="text-align: center;">Developed in association with <a href="http://radiationburn.net">RadiationBurn</a>, Newton Vs The Horde is now available for <a href="http://www.nintendo.com/games/detail/vIc-myJq6PyZniBoHTvA39RkTvl_BEl4">WiiWare</a> (North America out now, European version coming February) and <a href="http://itunes.apple.com/us/app/newton-vs-the-horde-hd/id488124994?mt=8&amp;uo=4">iOS</a>, with an Android version coming in Februrary 2012.</p>
<h1 style="text-align: center;">WiiWare</h1>
<p style="text-align: center;"><a href="http://www.nintendo.com/games/detail/vIc-myJq6PyZniBoHTvA39RkTvl_BEl4"><img src="http://www.gogo-robot.com/wp-content/uploads/2012/01/WiiWareLogo_Box_4c.png" alt="" title="WiiWare" width="300" height="242" class="alignnone size-full wp-image-428" /></a><br />
You can download Newton Vs The Horde by accessing the Wii Shop Channel on your Wii console.<br />
Got a Wii but don&#8217;t know how to access WiiWare? Take a look at these helpful sites from Nintendo:<br />
<a href="http://us.wii.com/connect/">Connect your Wii to the internet</a><br />
<a href="http://www.nintendo.com/wii/online/wiiware/">Nintendo WiiWare</a></p>
<h1 style="text-align: center;">iOS</h1>
<p style="text-align: center;"><a href="http://itunes.apple.com/us/app/newton-vs-the-horde-hd/id488124994?mt=8&amp;uo=4"><img class="alignnone size-full wp-image-408" title="Newton Icon" src="http://www.gogo-robot.com/wp-content/uploads/2011/05/114_iconOF.png" alt="Newton Vs The Horde Icon" width="114" height="114" /></a> <a href="http://itunes.apple.com/us/app/newton-vs-the-horde-hd-lite/id488255456?mt=8&amp;uo=4"><img class="alignnone size-full wp-image-409" title="Newton Lite" src="http://www.gogo-robot.com/wp-content/uploads/2011/05/114_iconOF1.png" alt="Newton Vs The Horde" width="114" height="114" /></a></p>
<p style="text-align: center;"><a href="http://itunes.apple.com/us/app/newton-vs-the-horde-hd/id488124994?mt=8&amp;uo=4"><img src="http://www.gogo-robot.com/wp-content/uploads/2011/05/App_Store_Badge21.png" alt="" title="App_Store_Badge21" width="160" height="54" class="alignnone size-full wp-image-410" /></a></p>
<p><span id="more-365"></span></p>
<p style="text-align: center;">Newton Vs The Horde pits you against a horde of stinky zombies across 4 varied locations. Build traps to squish, throw, spear and splat the zombies, or watch them explode when hit with light bulbs. Featuring a full physics engine, players can create all sorts of traps to stop the zombies in their tracks.</p>
<p style="text-align: center;">The original Dream Build Play 2010 Old Spice Challenge winning version of the game is available for download on Xbox360 from the <a href="http://marketplace.xbox.com/en-US/Product/Newton-Vs-The-Horde/66acd000-77fe-1000-9115-d802585504a8">Xbox Live Marketplace</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2011/05/10/newton-vs-the-horde/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>History Of The World</title>
		<link>http://www.gogo-robot.com/2010/12/05/history-of-the-world/</link>
		<comments>http://www.gogo-robot.com/2010/12/05/history-of-the-world/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 03:36:10 +0000</pubDate>
		<dc:creator>Rew</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[OpenFeint]]></category>
		<category><![CDATA[world]]></category>

		<guid isPermaLink="false">http://www.gogo-robot.com/?p=273</guid>
		<description><![CDATA[Developed in association with RadiationBurn and The Mustard Corporation, History Of The World is a fun and challenging game of saving the world! Available right now for iPhone and iPad. DESTROY PLANET KILLERS! With taps of your mighty digit shatter asteroids as they hurtle towards the Earth, allowing precious life to evolve in peace. Rack [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://itunes.apple.com/app/history-of-the-world/id399219779?mt=8"><img src="http://www.gogo-robot.com/wp-content/uploads/2010/12/HOTW.png" alt="History Of The World" title="History Of The World" width="312" height="316" class="size-full wp-image-274" /></a></p>
<p style="text-align: center;"><a href="http://itunes.apple.com/app/history-of-the-world/id399219779?mt=8"><img src="http://www.gogo-robot.com/wp-content/uploads/2009/09/AppStore.png" alt="Available on the App Store" title="Available on the App Store" width="208" height="72" class="alignnone size-full wp-image-150" /></a></p>
<p><span id="more-273"></span></p>
<p>Developed in association with <a href="http://radiationburn.net">RadiationBurn</a> and <a href="http://www.themustardcorporation.com/">The Mustard Corporation</a>, History Of The World is a fun and challenging game of saving the world! Available right now for <a href="http://itunes.apple.com/app/history-of-the-world/id399219779?mt=8">iPhone</a> and <a href="http://itunes.apple.com/app/history-of-the-world-hd/id401142962?mt=8">iPad</a>.</p>
<h4>DESTROY PLANET KILLERS!</h4>
<p>With taps of your mighty digit shatter asteroids as they hurtle towards the Earth, allowing precious life to evolve in peace. Rack up lofty high scores by stringing together flawless chains of destruction.</p>
<h4>SHAPE THE EARTH’S HISTORY</h4>
<p>Did you ever want to get a sense of where humanity fits into the grand scheme of evolution? Curious about what would have happened if the dinosaurs hadn’t been wiped out? If you’re skilful enough to protect them from harm you get to find out and Nature has more than a surprise or two up its sleeve.</p>
<h4>REPEL ALIEN INVADERS OR LET THEM LAND – YOUR CHOICE!</h4>
<p>Protect our blue planet from alien invaders who seek to conquer, or change the course of history, allow them to land and see what happens.</p>
<p style="text-align: center;"><a href="http://radiationburn.net"><img src="http://www.gogo-robot.com/wp-content/uploads/2010/12/RBLogo.png" alt="RadiationBurn" title="RadiationBurn" width="160" height="205" class="alignnone size-thumbnail wp-image-275" /></a><a href="http://www.themustardcorporation.com/"><img src="http://www.gogo-robot.com/wp-content/uploads/2010/12/logo.png" alt="The Mustard Corporation" title="The Mustard Corporation" width="240" height="75" class="alignnone size-thumbnail wp-image-276" /></a></p>
<p><!--more--></p>
<p style="text-align: center;"><a href="http://www.gogo-robot.com/wp-content/uploads/2010/12/HOTW_iPad_1.png"><img src="http://www.gogo-robot.com/wp-content/uploads/2010/12/HOTW_iPad_1-300x234.png" alt="" title="History Of The World HD" width="300" height="234" class="alignnone size-medium wp-image-284" /></a> <a href="http://www.gogo-robot.com/wp-content/uploads/2010/12/HOTW_iPad_2.png"><img src="http://www.gogo-robot.com/wp-content/uploads/2010/12/HOTW_iPad_2-300x234.png" alt="" title="History Of The World HD" width="300" height="234" class="alignnone size-medium wp-image-285" /></a></p>
<p style="text-align: center;"><a href="http://www.gogo-robot.com/wp-content/uploads/2010/12/HOTW_iPhone_2.png"><img src="http://www.gogo-robot.com/wp-content/uploads/2010/12/HOTW_iPhone_2-300x162.png" alt="" title="History Of The World" width="300" height="162" class="alignnone size-medium wp-image-286" /></a> <a href="http://www.gogo-robot.com/wp-content/uploads/2010/12/HOTW_iPhone_1.png"><img src="http://www.gogo-robot.com/wp-content/uploads/2010/12/HOTW_iPhone_1-300x162.png" alt="" title="History Of The World" width="300" height="162" class="alignnone size-medium wp-image-287" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gogo-robot.com/2010/12/05/history-of-the-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

