<?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>Shaun Smith</title>
	<atom:link href="http://shaun.boyblack.co.za/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://shaun.boyblack.co.za/blog</link>
	<description>Flex, Ruby, Mongo - London, UK</description>
	<lastBuildDate>Sun, 16 Jun 2013 17:48:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Robotlegs 2 Released</title>
		<link>http://shaun.boyblack.co.za/blog/2013/06/16/robotlegs-2-released/</link>
		<comments>http://shaun.boyblack.co.za/blog/2013/06/16/robotlegs-2-released/#comments</comments>
		<pubDate>Sun, 16 Jun 2013 17:48:27 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[RL2]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1165</guid>
		<description><![CDATA[If you&#8217;ve been waiting for Robotlegs 2 you&#8217;ve been waiting a long time. Sorry about that! It&#8217;s been hard to find motivation in the face of the Flash Platform&#8217;s rapid decline. Fewer users, less feedback and less collaboration. And other things. Regardless, after 8 public betas, RL2 is finally out! Huge props to all the contributors: https://github.com/robotlegs/robotlegs-framework/contributors As always, you can download the release over at: http://www.robotlegs.org/ For general support please use the Knowledgebase: http://knowledge.robotlegs.org/ And please report any issues &#8230; <a href="http://shaun.boyblack.co.za/blog/2013/06/16/robotlegs-2-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;ve been waiting for Robotlegs 2 you&#8217;ve been waiting a long time. Sorry about that! It&#8217;s been hard to find motivation in the face of the Flash Platform&#8217;s rapid decline. Fewer users, less feedback and less collaboration. And other things.</p>
<p>Regardless, after 8 public betas, RL2 is finally out! Huge props to all the contributors:</p>
<p><a href="https://github.com/robotlegs/robotlegs-framework/contributors">https://github.com/robotlegs/robotlegs-framework/contributors</a></p>
<p>As always, you can download the release over at:</p>
<p><a href="http://www.robotlegs.org/">http://www.robotlegs.org/</a></p>
<p>For general support please use the Knowledgebase:</p>
<p><a href="http://knowledge.robotlegs.org/">http://knowledge.robotlegs.org/</a></p>
<p>And please report any issues you might discover:</p>
<p><a href="https://github.com/robotlegs/robotlegs-framework/issues">https://github.com/robotlegs/robotlegs-framework/issues</a></p>
<p><span id="more-1165"></span></p>
<h3>Personal Thanks</h3>
<p>Without getting too soppy I&#8217;d like to say a special thank you to <a href="https://twitter.com/stray_and_ruby">@stray_and_ruby</a> for pioneering much of the RL2 codebase and for putting up with me in my darker moments. Also, to <a href="https://twitter.com/camillereynders">@camillereynders</a> for getting involved and pushing things forward. And to <a href="https://twitter.com/OndinaDF">@OndinaDF</a> for the incredible energy she injects into the support forum on a daily basis. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2013/06/16/robotlegs-2-released/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>RL2 Framework Size</title>
		<link>http://shaun.boyblack.co.za/blog/2013/05/30/rl2-framework-size/</link>
		<comments>http://shaun.boyblack.co.za/blog/2013/05/30/rl2-framework-size/#comments</comments>
		<pubDate>Thu, 30 May 2013 16:50:48 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1159</guid>
		<description><![CDATA[Just a quickie. I thought it might be fun to calculate the size of the RL2 framework (when compiled in Release mode using the old compiler.. &#8216;cos ASC2 is still hella broken). Here are some numbers (subject to change): Compiled SWF Size: Sprite as SWF: 286 bytes (non-debug, release compile) + Injector: 12416 bytes + Context: 21111 bytes + MVCS: 43633 bytes Injector = 12130 bytes (11.8 KB) Context = 8695 bytes (8.5 KB) MVCS = 22522 bytes (22 KB) &#8230; <a href="http://shaun.boyblack.co.za/blog/2013/05/30/rl2-framework-size/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Just a quickie. I thought it might be fun to calculate the size of the RL2 framework (when compiled in Release mode using the old compiler.. &#8216;cos ASC2 is still hella broken).</p>
<p>Here are some numbers (subject to change):</p>
<p><span id="more-1159"></span>Compiled SWF Size:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Sprite as SWF: 286 bytes (non-debug, release compile)<br />
+ Injector: 12416 bytes<br />
+ Context: 21111 bytes<br />
+ MVCS: 43633 bytes</div></div>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Injector = 12130 bytes (11.8 KB)<br />
Context = 8695 bytes (8.5 KB)<br />
MVCS = 22522 bytes (22 KB)</div></div>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Framework + Injector + MVCS all included = 43347 bytes (42.3 KB)</div></div>
<p>So, the framework is still pretty small. Thank goodness.</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2013/05/30/rl2-framework-size/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Second-system Syndrome</title>
		<link>http://shaun.boyblack.co.za/blog/2013/05/27/second-system-syndrome/</link>
		<comments>http://shaun.boyblack.co.za/blog/2013/05/27/second-system-syndrome/#comments</comments>
		<pubDate>Mon, 27 May 2013 20:05:52 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1154</guid>
		<description><![CDATA[The second-system effect (also known as second-system syndrome) refers to the tendency of small, elegant, and successful systems to have elephantine, feature-laden monstrosities as their successors. http://en.wikipedia.org/wiki/Second-system_effect The battle continues&#8230;]]></description>
				<content:encoded><![CDATA[<blockquote><p>
The second-system effect (also known as second-system syndrome) refers to the tendency of small, elegant, and successful systems to have elephantine, feature-laden monstrosities as their successors.
</p></blockquote>
<p><a href="http://en.wikipedia.org/wiki/Second-system_effect">http://en.wikipedia.org/wiki/Second-system_effect</a></p>
<p>The battle continues&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2013/05/27/second-system-syndrome/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CheapPost &#8211; RL2 Donations</title>
		<link>http://shaun.boyblack.co.za/blog/2013/05/24/cheappost-rl2-donations/</link>
		<comments>http://shaun.boyblack.co.za/blog/2013/05/24/cheappost-rl2-donations/#comments</comments>
		<pubDate>Fri, 24 May 2013 16:37:19 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[CheapPost]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[donations]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1145</guid>
		<description><![CDATA[In the spirit of cheap and lazy blog posts, here is an excerpt from a mail I sent out in response to the question: &#8220;How can I donate to Robotlegs?&#8221;. I&#8217;m so glad to hear that Robotlegs has been working well for you. Thank you very much for the offer of a donation, but we don&#8217;t accept monetary donations. However, there are plenty of other ways to help the project. For example: 1. Write a blog post about your experiences &#8230; <a href="http://shaun.boyblack.co.za/blog/2013/05/24/cheappost-rl2-donations/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>In the spirit of cheap and lazy blog posts, here is an excerpt from a mail I sent out in response to the question: &#8220;How can I donate to Robotlegs?&#8221;.<span id="more-1145"></span></p>
<blockquote><p>
I&#8217;m so glad to hear that Robotlegs has been working well for you.</p>
<p>Thank you very much for the offer of a donation, but we don&#8217;t accept monetary donations. However, there are plenty of other ways to help the project. For example:</p>
<p>1. Write a blog post about your experiences with RL2<br />
2. Write a tutorial on using RL2<br />
3. Build a demo application and post the code to GitHub<br />
4. Provide feedback on the API, and raise issues on GitHub<br />
5. Sign up to the support forum and help to answer other people&#8217;s questions ( <a href="http://knowledge.robotlegs.org">http://knowledge.robotlegs.org</a> ).<br />
6. Help us to design a new website! Or give advice on making a better website ( <a href="https://github.com/robotlegs/robotlegs.github.com">https://github.com/robotlegs/robotlegs.github.com</a> ).<br />
7. Submit pull requests to help improve the codebase<br />
8. Write a cool extension and submit it</p>
<p>Have great weekend!
</p></blockquote>
<p>Speaking of the <a href="http://www.robotlegs.org/">Robotlegs website</a>&#8230;</p>
<p>The site is hosted on GitHub (with a simple CName tweek to point the domain to their servers) and is statically generated using <a href="http://jekyllrb.com/">Jekyll</a>. As such, you can simply fork the <a href="https://github.com/robotlegs/robotlegs.github.com">repo</a> and submit a pull request with your design or content tweaks.</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2013/05/24/cheappost-rl2-donations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CheapPost &#8211; Dispatch Speed</title>
		<link>http://shaun.boyblack.co.za/blog/2013/05/24/cheappost-dispatch-speed/</link>
		<comments>http://shaun.boyblack.co.za/blog/2013/05/24/cheappost-dispatch-speed/#comments</comments>
		<pubDate>Fri, 24 May 2013 16:25:35 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[CheapPost]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[signals]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1140</guid>
		<description><![CDATA[It seems that I&#8217;ve forgotten how to blog. Instead of fixing the problem directly I thought I might just share some content from emails that I&#8217;ve sent out. This one touches on Robotlegs 2, Dispatch Speed and critical pathways in an application, and, more specifically, why it doesn&#8217;t matter that Events in AS3 are a little &#8220;slow&#8221;. I&#8217;d recommend Robotlegs 2 &#8211; especially for modular designs. I was never happy with the modular solutions for RL1. The library is stable &#8230; <a href="http://shaun.boyblack.co.za/blog/2013/05/24/cheappost-dispatch-speed/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>It seems that I&#8217;ve forgotten how to blog. Instead of fixing the problem directly I thought I might just share some content from emails that I&#8217;ve sent out.<span id="more-1140"></span></p>
<p>This one touches on Robotlegs 2, Dispatch Speed and critical pathways in an application, and, more specifically, why it doesn&#8217;t matter that Events in AS3 are a little &#8220;slow&#8221;.</p>
<blockquote><p>
I&#8217;d recommend Robotlegs 2 &#8211; especially for modular designs. I was never happy with the modular solutions for RL1.</p>
<p>The library is stable (I&#8217;ve been using it in production for months); the only reason for the beta status is that I don&#8217;t feel like enough people have given feedback on the API. Also, I haven&#8217;t had much time lately to review all the code &#8211; but that should change over the holidays.</p>
<p>Regarding the MessageDispatcher &#8211; it is a fairly low level tool for synchronous and asynchronous message passing. It is used to bootstrap the framework for example, but it is not a replacement for Signals or Events. Each tool has its place. However, if you are worried about speed&#8230;</p>
<p>The Event system in the Flash Player is a very well thought out and well designed Observer pattern implementation. It is good at what it does: offering a way to observe objects. But the performance critical pathways through an application should not be implemented using an observer pattern. Which is why I don&#8217;t see Signals as a valid alternative to Events. They might be faster in some situations, but they are still observers. For ultimate speed make direct method calls! If you need an extra layer of abstraction, use callbacks.</p>
<p>Of course, I really need to write a detailed blog post about all of this, but the point is: Events/Signals are observers and you shouldn&#8217;t stick them in the middle of performance critical pathways. The performance sensitive aspects of a system should flow through direct method calls (and as few as possible!). For everything else, Events are good enough, and have much better tooling support than Signals if you use a modern IDE.
</p></blockquote>
<p>Haha, &#8220;I really need to write a detailed blog post about all of this&#8221;.. pffft.</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2013/05/24/cheappost-dispatch-speed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Games And Entity Systems</title>
		<link>http://shaun.boyblack.co.za/blog/2012/08/04/games-and-entity-systems/</link>
		<comments>http://shaun.boyblack.co.za/blog/2012/08/04/games-and-entity-systems/#comments</comments>
		<pubDate>Sat, 04 Aug 2012 18:18:26 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[ash]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1114</guid>
		<description><![CDATA[Last week I delved into Ash &#8211; an ActionScript Entity System by Richard Lord: https://github.com/richardlord/Ash I built this little shooter: http://www.boyblack.net/proto/hunted/TopDown.html What&#8217;s That Then? Entity Systems offer an approach to object design that fits well with games, where requirements and behaviours need to be tweaked or swapped out constantly. Traditional object oriented design falls over a little bit in that environment. In an application (as opposed to a game), objects and collaborations are usually clearly defined and do not change &#8230; <a href="http://shaun.boyblack.co.za/blog/2012/08/04/games-and-entity-systems/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Last week I delved into Ash &#8211; an ActionScript Entity System by Richard Lord:</p>
<p><a href="https://github.com/richardlord/Ash">https://github.com/richardlord/Ash</a></p>
<p>I built this little shooter:</p>
<p><a href="http://www.boyblack.net/proto/hunted/TopDown.html">http://www.boyblack.net/proto/hunted/TopDown.html</a></p>
<p><span id="more-1114"></span></p>
<h2>What&#8217;s That Then?</h2>
<p>Entity Systems offer an approach to object design that fits well with games, where requirements and behaviours need to be tweaked or swapped out constantly. Traditional object oriented design falls over a little bit in that environment.</p>
<p>In an application (as opposed to a game), objects and collaborations are usually clearly defined and do not change after startup. Objects play specific roles, and for the most part, those roles don&#8217;t change much.</p>
<p>In a game, however, the behaviours of &#8220;actors&#8221; within the system can change significantly during gameplay. An enemy may be stunned, for a period, losing the ability to attack. The hero may pick up a weapon, become invincible, or learn to fly. Time may slow down, speed up, or change direction.</p>
<p>Class inheritance is obviously not a good choice here (it rarely is anyway). But actually, many object oriented design approaches are at odds with these requirements.</p>
<h2>Ash</h2>
<p>Ash breaks things down into Components, Entities, Nodes and Systems.</p>
<h3>Components</h3>
<p>Components are simple value objects:</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Position<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Display<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> displayObject<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=displayobject%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:displayobject.html"><span style="color: #004993;">DisplayObject</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Components do not contain any code, logic or behaviour. They store state, that&#8217;s it.</p>
<h3>Entities</h3>
<p>Entities are buckets that hold components:</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">const entity<span style="color: #000066; font-weight: bold;">:</span>Entity = <span style="color: #0033ff; font-weight: bold;">new</span> Entity<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Position<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Display<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> SomeSprite<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
game<span style="color: #000066; font-weight: bold;">.</span>addEntity<span style="color: #000000;">&#40;</span>entity<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>An entity does not need a name or unique identifier &#8211; it is merely the sum of its components. Components can be added to it and removed from it at runtime, changing what the entity does and what role it plays.</p>
<h3>Nodes And Systems</h3>
<p>So, if components and entities do not contain any actual code, where does the logic go?</p>
<p>This is perhaps the biggest difference between the Entity System approach and typical object oriented programming. Normally, objects encapsulate and hide their data. They expose well defined APIs, but they keep their inner workings, and the data they operate on, private.</p>
<p>There are very good reasons for this, but what it means is that all the emphasis is placed on methods and message passing and not on the data. Sharing mutable data between objects in an object oriented system is almost always a bad idea. Somebody else may change your data &#8220;behind your back&#8221; and leave you in an invalid state.</p>
<p>In an Entity System data is kept separate from the systems that operate on that data. The data is not encapsulated. Any system may operate on any data that it wants to mutate.</p>
<p>In Ash, specifically, Systems operate on lists of Nodes. A Node is a combination of one or more Components:</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> RenderNode <span style="color: #0033ff; font-weight: bold;">extends</span> Node<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> display<span style="color: #000066; font-weight: bold;">:</span>Display<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">:</span>Position<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>When an entity is given both a Display and a Position component a Render node will be created for that entity. If either of those components is removed from the entity the Render node for that entity will be destroyed.</p>
<p>A System that processes such Render nodes might do this in its update loop:</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> renderNode<span style="color: #000066; font-weight: bold;">:</span>RenderNode<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>renderNode = _renderNodes<span style="color: #000066; font-weight: bold;">.</span>head<span style="color: #000066; font-weight: bold;">;</span> renderNode<span style="color: #000066; font-weight: bold;">;</span> renderNode = renderNode<span style="color: #000066; font-weight: bold;">.</span>next<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> displayObject<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=displayobject%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:displayobject.html"><span style="color: #004993;">DisplayObject</span></a> = renderNode<span style="color: #000066; font-weight: bold;">.</span>display<span style="color: #000066; font-weight: bold;">.</span>displayObject<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">:</span>Position = renderNode<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; displayObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; displayObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>We loop through a linked list of nodes, access the components attached to those nodes, and do whatever it is we want to do with those components. We don&#8217;t care about the entities that those components are attached to.</p>
<p>A NodeList has signals for the addition and removal of nodes from the list which is handy when you need to prepare nodes before processing them. For example, in the RenderSystem we add DisplayObjects to the stage and remove them again when Render nodes are created and destroyed:</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addToGame<span style="color: #000000;">&#40;</span>game<span style="color: #000066; font-weight: bold;">:</span>Game<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; _renderNodes = game<span style="color: #000066; font-weight: bold;">.</span>getNodeList<span style="color: #000000;">&#40;</span>RenderNode<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; _renderNodes<span style="color: #000066; font-weight: bold;">.</span>nodeAdded<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span>addRenderNode<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; _renderNodes<span style="color: #000066; font-weight: bold;">.</span>nodeRemoved<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span>removeRenderNode<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> addRenderNode<span style="color: #000000;">&#40;</span>node<span style="color: #000066; font-weight: bold;">:</span>RenderNode<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>node<span style="color: #000066; font-weight: bold;">.</span>display<span style="color: #000066; font-weight: bold;">.</span>displayObject<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeRenderNode<span style="color: #000000;">&#40;</span>node<span style="color: #000066; font-weight: bold;">:</span>RenderNode<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>node<span style="color: #000066; font-weight: bold;">.</span>display<span style="color: #000066; font-weight: bold;">.</span>displayObject<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<h2>What&#8217;s It All Good For?</h2>
<p>Adding and removing components from entities at runtime changes the nodes associated with those entities, in turn changing which systems operate on those entities. This effectively allows us to change the roles and behaviours of entities on the fly.</p>
<p>Imagine the hero &#8211; the character that you control in the game:</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">const entity<span style="color: #000066; font-weight: bold;">:</span>Entity = <span style="color: #0033ff; font-weight: bold;">new</span> Entity<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Position<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Motion<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> KeyControl<span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?q=keyboard%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboard.html"><span style="color: #004993;">Keyboard</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=keyboard%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboard.html"><span style="color: #004993;">Keyboard</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">RIGHT</span><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?q=keyboard%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboard.html"><span style="color: #004993;">Keyboard</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">UP</span><span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=keyboard%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboard.html"><span style="color: #004993;">Keyboard</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DOWN</span><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?q=keyboard%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboard.html"><span style="color: #004993;">Keyboard</span></a><span style="color: #000066; font-weight: bold;">.</span>Z<span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=keyboard%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboard.html"><span style="color: #004993;">Keyboard</span></a><span style="color: #000066; font-weight: bold;">.</span>A<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Gun<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Display<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> HeroView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>By adding the KeyControl component the hero becomes user controlled. Later we could do this:</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; entity<span style="color: #000066; font-weight: bold;">.</span>remove<span style="color: #000000;">&#40;</span>KeyControl<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; entity<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> AIControl<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Suddenly our main character is no longer under our control and is instead moved about by some AIControlSystem.</p>
<h2>Hands On</h2>
<p>To get to grips with all of this I built a simple game using Ash and Starling. It&#8217;s a top-down shooter with baddies that circle and attack you. You can check it out here:</p>
<p><a href="http://www.boyblack.net/proto/hunted/TopDown.html">http://www.boyblack.net/proto/hunted/TopDown.html</a></p>
<p>It takes a while to start feeling comfortable with the Entity System approach, and I&#8217;m certainly not there yet. But I have to say, it&#8217;s really fun! It forced me to approach problems from different angles, and helped me to build something pretty flexible.</p>
<p>Here&#8217;s a quick breakdown of the some of the core Components, Nodes and Systems I ended up with:</p>
<h3>Components</h3>
<p>Under each component is a list of the properties that make up the component</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Bullet<br />
&nbsp; damage<br />
&nbsp; range<br />
<br />
Display<br />
&nbsp; object<br />
&nbsp; layer<br />
<br />
Enemy<br />
&nbsp; prey<br />
<br />
Gun<br />
&nbsp; timeSinceLastShot<br />
&nbsp; bulletLifetime<br />
<br />
Hero (marker class)<br />
<br />
HeroControl<br />
&nbsp; leftKey, rightKey, upKey, downKey<br />
&nbsp; attackKey, runKey<br />
&nbsp; rotationSpeed<br />
<br />
Life<br />
&nbsp; health, maxHealth<br />
&nbsp; stamina, maxStamina<br />
<br />
Motion<br />
&nbsp; velocityX, velocityY<br />
&nbsp; friction<br />
<br />
Position<br />
&nbsp; x, y, rotation<br />
<br />
Predator<br />
&nbsp; prey<br />
<br />
Prey<br />
&nbsp; predator<br />
<br />
Stalker<br />
&nbsp; prey</div></div>
<h3>Nodes</h3>
<p>Under each node is a list of the components that define that node</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">BulletCollisionNode<br />
&nbsp; Bullet<br />
&nbsp; Position<br />
&nbsp; Motion<br />
<br />
EnemyCollisionNode<br />
&nbsp; Enemy<br />
&nbsp; Life<br />
&nbsp; Position<br />
&nbsp; Motion<br />
<br />
GunControlNode<br />
&nbsp; Gun<br />
&nbsp; HeroControl<br />
<br />
HeroCollisionNode<br />
&nbsp; Hero<br />
&nbsp; Position<br />
<br />
HeroControlNode<br />
&nbsp; HeroControl<br />
&nbsp; Position<br />
&nbsp; Motion<br />
<br />
LivingNode<br />
&nbsp; Life<br />
<br />
MovementNode<br />
&nbsp; Motion<br />
&nbsp; Position<br />
<br />
PredatorNode (similar to PreyNode and StalkerNode)<br />
&nbsp; Predator<br />
&nbsp; Position<br />
&nbsp; Motion<br />
&nbsp; Life<br />
<br />
RenderNode<br />
&nbsp; Display<br />
&nbsp;Position</div></div>
<h3>Systems</h3>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">BulletRangeSystem<br />
&nbsp; Operates on BulletCollisionNodes<br />
&nbsp; Destroys bullets after a given time threshold<br />
<br />
CollisionSystem<br />
&nbsp; Operates on EnemyCollisionNodes, BulletCollisionNodes and HeroCollisionNodes<br />
&nbsp; Runs through the various collision nodes and damages enemies etc.<br />
<br />
EnemyRadarSystem<br />
&nbsp; Operates on EnemyCollisionNodes<br />
&nbsp; Places markers around the edge of the screen showing you where enemies are (but only when there are very few enemies left)<br />
<br />
GunControlSystem<br />
&nbsp; Operates on GunControlNodes and EnemyCollisionNodes<br />
&nbsp; Fires bullets from your gun and auto-aims at nearby enemies<br />
<br />
HeroControlSystem<br />
&nbsp; Operates on HeroControlNodes<br />
&nbsp; Controls player movement<br />
<br />
LifeSystem<br />
&nbsp; Operates on LivingNodes<br />
&nbsp; Removes entities when their health reaches zero<br />
<br />
MovementSystem<br />
&nbsp; Operates on MovementNodes<br />
&nbsp; Applies velocity to position<br />
<br />
PredatorSystem, PreySystem and StalkerSystem<br />
&nbsp; Operates on PredatorNodes, PreyNodes and StalkerNodes<br />
&nbsp; Updates the motion and position components of these nodes to control enemies in various ways<br />
&nbsp; Adding more of these kinds of systems will make the game more fun<br />
<br />
RenderSystem<br />
&nbsp; Operates on RenderNodes<br />
&nbsp; Updates the position and rotation of display objects<br />
<br />
WaveSystem<br />
&nbsp; Operates on EnemyCollisionNodes and HeroCollisionNodes<br />
&nbsp; Creates waves of enemies</div></div>
<h2>Some Thoughts And Observations</h2>
<h3>Marker Classes</h3>
<p>I ended up with some &#8220;marker&#8221; components. Marker classes generally make me feel uncomfortable, but they seem slightly less evil in an Entity System.</p>
<h3>Garbage</h3>
<p>Making an entity and adding a bunch of components to it creates a lot of objects. Consider the bullets in my game:</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> createUserBullet<span style="color: #000000;">&#40;</span>gun<span style="color: #000066; font-weight: bold;">:</span>Gun<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>Entity<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; const speed<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #000000; font-weight:bold;">700</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; const velocityX<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = speed <span style="color: #000066; font-weight: bold;">*</span> <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">rotation</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; const velocityY<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = speed <span style="color: #000066; font-weight: bold;">*</span> <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">rotation</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; const entity<span style="color: #000066; font-weight: bold;">:</span>Entity = <span style="color: #0033ff; font-weight: bold;">new</span> Entity<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Bullet<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">,</span> gun<span style="color: #000066; font-weight: bold;">.</span>bulletLifetime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Position<span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">6</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Motion<span style="color: #000000;">&#40;</span>velocityX<span style="color: #000066; font-weight: bold;">,</span> velocityY<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Display<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> BulletView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> Display<span style="color: #000066; font-weight: bold;">.</span>BULLET<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; _game<span style="color: #000066; font-weight: bold;">.</span>addEntity<span style="color: #000000;">&#40;</span>entity<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> entity<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>We end up creating 6 throw-away objects for every bullet. The solution here is to implement object pooling, but that adds a lot of boilerplate. I&#8217;ll probably add pooling for the bullets, but avoid it for the other actors unless it becomes an issue.</p>
<h3>Design</h3>
<p>It&#8217;s challenging trying to decide how to slice up behaviours. Do I need a new system for this? Should I just add some extra code to an existing system? Do I need a new Node definition?</p>
<h2>Where To?</h2>
<p>Check out Richard&#8217;s blog posts:</p>
<p>1. <a href="http://www.richardlord.net/blog/introducing-ash">http://www.richardlord.net/blog/introducing-ash</a><br />
2. <a href="http://www.richardlord.net/blog/what-is-an-entity-framework">http://www.richardlord.net/blog/what-is-an-entity-framework</a><br />
3. <a href="http://www.richardlord.net/blog/why-use-an-entity-framework">http://www.richardlord.net/blog/why-use-an-entity-framework</a></p>
<p>I found the Asteroids example in the Ash source really helpful:</p>
<p><a href="https://github.com/richardlord/Ash/tree/master/examples/no-dependencies/asteroids/net/richardlord/asteroids">https://github.com/richardlord/Ash/tree/master/examples/no-dependencies/asteroids/net/richardlord/asteroids</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2012/08/04/games-and-entity-systems/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Flex App Scaling Issue</title>
		<link>http://shaun.boyblack.co.za/blog/2012/03/29/flex-app-scaling-issue/</link>
		<comments>http://shaun.boyblack.co.za/blog/2012/03/29/flex-app-scaling-issue/#comments</comments>
		<pubDate>Thu, 29 Mar 2012 21:25:18 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1098</guid>
		<description><![CDATA[Just in case you were silly enough to deploy a fullscreen Flash/Flex app to the web, browse to it on a Flash enabled mobile device or tablet, and expect it to look nice: To be fair, it&#8217;s not a Flash/Flex issue at all, but rather a mobile browser detail worth knowing about: http://www.html-5.com/metatags/index.html#viewport-meta-tag Essentially, mobile browsers assume a default viewport width of 980px at 72dpi for any given web page and scale the content according to the actual device DPI. &#8230; <a href="http://shaun.boyblack.co.za/blog/2012/03/29/flex-app-scaling-issue/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Just in case you were silly enough to deploy a fullscreen Flash/Flex app to the web, browse to it on a Flash enabled mobile device or tablet, and expect it to look nice:</p>
<script src="https://gist.github.com/2243929.js"></script><noscript><pre><code class="language-html html">&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0,
  minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,
  target-densitydpi=device-dpi&quot;/&gt;</code></pre></noscript>
<p>To be fair, it&#8217;s not a Flash/Flex issue at all, but rather a mobile browser detail worth knowing about:</p>
<p><a href="http://www.html-5.com/metatags/index.html#viewport-meta-tag">http://www.html-5.com/metatags/index.html#viewport-meta-tag</a></p>
<p>Essentially, mobile browsers assume a default viewport width of 980px at 72dpi for any given web page and scale the content according to the actual device DPI.</p>
<p>Good for HTML; probably not want you want for your fullscreen Flash/Flex app. Use the tag above to prevent scaling.</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2012/03/29/flex-app-scaling-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Level Up</title>
		<link>http://shaun.boyblack.co.za/blog/2012/03/12/level-up/</link>
		<comments>http://shaun.boyblack.co.za/blog/2012/03/12/level-up/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 16:58:14 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[learning]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1086</guid>
		<description><![CDATA[Holy crap, it&#8217;s only a week away! What surprised me most about the first Try { Harder } was just how intense the whole thing was. At other conferences you can often just sit back and learn at your own pace (provided the material is actually technical enough to keep you interested). T{H}2011 was different. I remember feeling completely exhausted at the end of each day &#8211; but it was accompanied by that lovely feeling you get when you know &#8230; <a href="http://shaun.boyblack.co.za/blog/2012/03/12/level-up/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Holy crap, it&#8217;s only a week away!</p>
<p>What surprised me most about the first <a title="Try Harder" href="http://www.tryharder.org.uk/">Try { Harder }</a> was just how intense the whole thing was. At other conferences you can often just sit back and learn at your own pace (provided the material is actually technical enough to keep you interested). <a href="http://www.tryharder.org.uk/how-try-harder-works/tryharder-2011/">T{H}2011</a> was different.<span id="more-1086"></span></p>
<p>I remember feeling completely exhausted at the end of each day &#8211; but it was accompanied by that lovely feeling you get when you know you&#8217;ve worked and grown as much as you can in a single day. Sleep is pretty epic after days like that!</p>
<p>However, it wasn&#8217;t just the talks and workshops that did this, it was meeting and talking to those folks whose blogs you read. Those people who you chat to on twitter but haven&#8217;t met in real life. That was, perhaps, the best part for me.</p>
<p>Now, I&#8217;m not the most social person in the world at the best of times, so this aspect was also quite overwhelming. Fortunately the week started off with an amazing talk that helped put everyone at ease. I can&#8217;t share the details but everyone agreed: it was the perfect way to reduce the inevitable resultant anxiety of a bunch of smart nerds meeting each other for the first time. This is just one example of the thought that went into the conference as a whole.</p>
<h3>Try { Harder } Level Up: 19th &#8211; 23rd March 2012</h3>
<p>I believe there are a couple of spots left for T{H}LU. If you can, you should come join us next week. It&#8217;ll be fun!</p>
<p><a href="http://www.tryharder.org.uk/level-up-2012/">http://www.tryharder.org.uk/level-up-2012/</a></p>
<p><strong>Update</strong>: Pricing for freelancers has dropped to £699 (including accommodation).</p>
<p><strong>Update2</strong>: <a href="http://www.jetbrains.com/">JetBrains</a> are supporting the event by offering personal licences of <a href="http://www.jetbrains.com/idea/">IntelliJ IDEA</a> to all attendees!</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2012/03/12/level-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Readme</title>
		<link>http://shaun.boyblack.co.za/blog/2012/02/04/readme/</link>
		<comments>http://shaun.boyblack.co.za/blog/2012/02/04/readme/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 17:04:25 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[readme]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1069</guid>
		<description><![CDATA[Have I mentioned that I love GitHub? When you put a readme file into a folder that file is formatted and presented nicely through GitHub&#8217;s file browser. For example: https://github.com/visionmedia/uikit Scrolling down a little we can see a nicely formatted readme file. GitHub strongly recommends adding a readme file to the root of your repository, but what I didn&#8217;t realise until recently was that it works for any folder in your repo. GitHub already has the best online file browser &#8230; <a href="http://shaun.boyblack.co.za/blog/2012/02/04/readme/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Have I mentioned that I love <a href="https://github.com/">GitHub</a>?</p>
<p>When you put a readme file into a folder that file is formatted and presented nicely through GitHub&#8217;s file browser. For example:</p>
<p><a href="https://github.com/visionmedia/uikit">https://github.com/visionmedia/uikit</a></p>
<p>Scrolling down a little we can see a nicely formatted readme file.<span id="more-1069"></span></p>
<p>GitHub strongly recommends adding a readme file to the root of your repository, but what I didn&#8217;t realise until recently was that it works for any folder in your repo. GitHub already has the best online file browser out there, but this specific feature can turn your source tree into your documentation.</p>
<p>For <a href="https://github.com/robotlegs/robotlegs-framework">Robotlegs 2</a> I decided to try it out:</p>
<p><a href="https://github.com/darscan/robotlegs-framework/tree/version2/src/robotlegs/bender/core/async">Async</a><br />
<a href="https://github.com/darscan/robotlegs-framework/tree/version2/src/robotlegs/bender/core/messaging">MessageDispatcher</a><br />
<a href="https://github.com/darscan/robotlegs-framework/tree/version2/src/robotlegs/bender/extensions">Extensions</a></p>
<p>Almost every package in the entire repo has a readme file. The best way to learn about Robotlegs 2 is to browse the <a href="https://github.com/robotlegs/robotlegs-framework">source and readme files</a> on GitHub.</p>
<p><img class="alignnone size-full wp-image-1075" title="github-logo" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2012/02/github-logo.png" alt="" width="512" height="512" /></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2012/02/04/readme/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RL Reloaded</title>
		<link>http://shaun.boyblack.co.za/blog/2012/01/23/rl-reloaded/</link>
		<comments>http://shaun.boyblack.co.za/blog/2012/01/23/rl-reloaded/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 12:03:13 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[framework]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1023</guid>
		<description><![CDATA[I&#8217;ve been worried for quite a long time. Robotlegs 1 is small and simple but a little difficult to extend. I want Robotlegs 2 to be flexible without becoming overly large or complex. Timing To extend any framework you need to be able to hook into that framework&#8217;s initialization process. That Damned Context The Robotlegs 1 context class was, to be frank, rubbish &#8211; it set defaults, configured dependencies and controlled initialization. Worse, to hook into the initialization process or &#8230; <a href="http://shaun.boyblack.co.za/blog/2012/01/23/rl-reloaded/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been worried for quite a long time. <a href="http://www.robotlegs.org/">Robotlegs 1</a> is small and simple but a little difficult to extend. I want <a href="https://github.com/robotlegs/robotlegs-framework">Robotlegs 2</a> to be flexible without becoming overly large or complex.</p>
<h2>Timing</h2>
<p>To extend any framework you need to be able to hook into that framework&#8217;s initialization process.</p>
<h2>That Damned Context</h2>
<p>The Robotlegs 1 context class was, to be frank, rubbish &#8211; it set defaults, configured dependencies and controlled initialization. Worse, to hook into the initialization process or change the defaults, users had to extend the class itself resulting in the proliferation of funny looking words like SignalDrivenCovariantlyMediatedModularShellContext.<span id="more-1023"></span></p>
<h2>How Could You Let That Happen?</h2>
<p>Extending the context was a silly idea &#8211; and I knew it at the time. It made me sad, deep down inside, but I knew that if I waited for a better solution to emerge the framework might never ship.</p>
<p>Also, my goals for Robotlegs 1 were:</p>
<p>1. Make it small<br />
2. Make it fast<br />
3. Release it</p>
<p>A ton of compromises were made to keep the number of classes down to an absolute minimum. That&#8217;s not how I usually write code. Besides&#8230;</p>
<h2>Small Only Goes So Far</h2>
<p>I always start by doing the simplest thing possible &#8211; it&#8217;s a good way to feel out a problem space. &#8220;<strong>What</strong> am I trying to do?&#8221;. The &#8220;<strong>how</strong>&#8221; doesn&#8217;t matter yet, but becomes important much later when I ask &#8220;How would I <strong>like</strong> to do this?&#8221;.</p>
<p>When writing actual code, however, I&#8217;m constantly faced with this annoying question: &#8220;Should I break this out?&#8221;. When doing the simplest thing possible I often decide against extraction: I&#8217;ve got a specific task to complete (like getting a test to pass) and I can refactor later if the idea proves itself to be worthwhile. Also, I know that extraction inevitably leads to a new set of design decisions. And I&#8217;ll have to start with a test &#8211; for something whose purpose I am only just discovering. And it ups the class count.</p>
<p>Keeping class count down for it&#8217;s own sake is almost always a bad idea. However, I don&#8217;t think Robotlegs 1 would have experienced the same adoption if it had had hundreds of classes instead of the quite digestible 15 presently in its belly. OK, 24 total if you add the interfaces.</p>
<p>When browsing open source libraries I get happy feelings from projects with a limited number of source files &#8211; it gives me a sense that if I really wanted to I could read through the entire codebase and understand it.</p>
<p>But there&#8217;s a point where that simplicity inverts. Profit becomes debt. Without good abstractions in place every participant in the system ends up doing too much. At that point the question becomes: &#8220;Do I need to introduce a new layer of abstraction?&#8221;.</p>
<h2>Now You Have Two Problems</h2>
<p>The introduction of a system wide abstraction layer fueled by a mid feature code extraction will do one of two things: it will strengthen the system or it will weaken it. A bad abstraction might solve the immediate design issues (like duplication) just fine but end up adding complexity and reducing quality overall.</p>
<h2>Extensions? Timing?</h2>
<p>So anyway, I want Robotlegs to be extensible in a sensible way. Users should be able to install custom extensions easily. Those extensions need a way to hook into the context initialization process:</p>
<p>Some extensions may need to be configured before others. Some may need to pause the initialization process and wait for a resource to become available. Some might directly depend on others and may need to wait for those extensions to be fully configured before self initializing. Some may only come to life after the entire context has been initialized.</p>
<p>It&#8217;s clear that the initialization process needs to be asynchronous. But without a good abstraction in place for dealing with asynchronous processing the context will be burdened with co-ordinating a complex series of events. Event soup is not delicious.</p>
<h2>Events, Signals, Tokens, Tasks, Promises, Futures, Callbacks</h2>
<p>There are a number of patterns for dealing with asynchronous processes. They have wildly different properties.</p>
<p>Some are low level, like the callback pattern. Some are high level, like the promise pattern. Some are guaranteed to be asynchronous, while others have the potential to be synchronous. Some are only good for observing. Some can be terminated, while others can be suspended and resumed. Some can be composed and chained. Some necessitate the instantiation of throw-away objects and put stress on the garbage collector. Some put stress on the stack.</p>
<h2>Take Your Pick</h2>
<p>I wanted something fairly low level that enabled asynchronous processing without adding unnecessary overhead in the cases where things could be synchronous (or skipped entirely).</p>
<p>I tried a number of things. For the most part: floppy, verbose and annoying implementations that moved the core problems around in less-than-useful ways.</p>
<h2>Dispatch</h2>
<p>Slowly it dawned on me. In this case all I wanted was an asynchronous message dispatcher. With a well defined set of callback conventions I could write something resembling an Event Dispatcher but without the overhead of creating throw-away objects (events) and with the ability to suspend and resume the dispatch when desired:</p>
<p><a title="Async Conventions" href="https://github.com/robotlegs/robotlegs-framework/blob/version2/src/robotlegs/bender/core/async/readme.md">Some Async Conventions</a></p>
<p><a href="https://github.com/robotlegs/robotlegs-framework/blob/version2/src/robotlegs/bender/core/messaging/readme.md">The Message Dispatcher</a></p>
<h2>Initialization, Extension, Please Continue</h2>
<p>Very well. Suppose that context initialization comprises 3 steps: preInitialize, selfInitialize and postInitialize. When told to initialize the context moves through those steps in sequence. Anyone can listen in and halt the process as required at any point. What we end up with is in essence just a simple state machine where the observers have the potential to be guards.</p>
<h2>The End</h2>
<p>Well, that&#8217;s where the re-write started anyway.</p>
<p><a href="https://github.com/robotlegs/robotlegs-framework/tree/version2/src">Robotlegs 2</a></p>
<p><img class="alignnone size-full wp-image-1083" title="Robotlegs Logo" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2012/01/RobotlegsDrop512.png" alt="" width="512" height="512" /></p>
<p>p.s. I dropped a bunch of stuff from the version2 branch. I&#8217;ll be going back to pull out any functionality that might have been lost shortly. If you come across anything that&#8217;s missing feel free to adapt it to the new codebase and send a pull request. Or drop an issue on the tracker. For quick reference, here&#8217;s the old version2 branch: <a href="https://github.com/robotlegs/robotlegs-framework/tree/version2-old">version2-old</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2012/01/23/rl-reloaded/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.111 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2013-06-18 00:01:55 -->

<!-- Compression = gzip -->