<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Isn&#8217;t XML clever?</title>
	<atom:link href="http://www.citiesinthesky.co.uk/2009/08/09/isnt-xml-clever/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.citiesinthesky.co.uk/2009/08/09/isnt-xml-clever/</link>
	<description>Floating islands, and what happens when you build on them</description>
	<lastBuildDate>Mon, 05 Oct 2009 22:47:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Ben</title>
		<link>http://www.citiesinthesky.co.uk/2009/08/09/isnt-xml-clever/comment-page-1/#comment-3300</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Thu, 10 Sep 2009 12:22:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.citiesinthesky.co.uk/?p=224#comment-3300</guid>
		<description>Hah, you can blame Wordpress&#039; default comment system for that :)

This is something I haven&#039;t read much about on the web so far (well, nothing talking about concrete details) so I think it would indeed be fairly useful for me to write about my approach. I&#039;ll write an article some time soon, when time permits!

In a nutshell though, although I love strongly typed and very strict languages, I&#039;ve gone for a more relaxed system here, since what I&#039;ve noticed through doing gameplay coding is that gameplay code tends not to really &#039;fit&#039; that kind of system too well. I&#039;ll eventually be adding testing and so on to verify correctness, but for now it&#039;s a fairly simple system, with two methods of communication between components (which is part of what the &#039;dependency&#039; you mention is about).

Firstly users of an object can request components by type, using something like:

&lt;code lang=&quot;cpp&quot; escaped=&quot;false&quot; tab_size=&quot;1&quot; nowrap=&quot;true&quot;&gt;
template&lt;typename T&gt;
boost::shared_ptr&lt;T&gt;
GameObject::getComponent();
// note you can use &lt;code lang=&quot;cpp&quot;&gt; tags for code now, and don&#039;t need to escape anything within them if you do :)
&lt;/code&gt;

Then of course they have the interface they want and can communicate directly with it. For now this is what I use for messages or requests, like &quot;have you built yet?&quot;. I&#039;ll be expanding this into a proper message passing scheme later if I feel it&#039;s necessary (and it may well be with scripting).

The other way of communicating, for continual updates like position and so on, is also very simple. Each object holds a map&lt;string, boost::any&gt; of properties and exposes an interface to this. Then, for example, the Physics component can set the &quot;position&quot; property every frame (and check for changes in case e.g. a script wants to teleport!), and later that frame the Graphics component will read the &quot;position&quot; property. There&#039;s plenty of potential for typos there since they&#039;re string IDs, but that&#039;s what testing will be for :)

So it&#039;s nothing particularly clever. If a dependency is missing, the component that needs it will just not work particularly well (the Graphics component won&#039;t update its position if &quot;property&quot; is missing, or is the wrong type). Of course you could easily detect this so they&#039;re not stealth errors.

I find code gen approaches interesting, yet... strange? I don&#039;t know, I just don&#039;t like the idea that there are files I control only indirectly! Also I don&#039;t know how well that would work with data-driven behaviour like scripting - one of the reasons I&#039;ve picked such a &quot;string ID&quot;-like way of doing things is that it&#039;s super-easy to do scripting with (and requires little maintenance).

Anyway, thanks for the comment(s)!</description>
		<content:encoded><![CDATA[<p>Hah, you can blame WordPress&#8217; default comment system for that <img src='http://www.citiesinthesky.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This is something I haven&#8217;t read much about on the web so far (well, nothing talking about concrete details) so I think it would indeed be fairly useful for me to write about my approach. I&#8217;ll write an article some time soon, when time permits!</p>
<p>In a nutshell though, although I love strongly typed and very strict languages, I&#8217;ve gone for a more relaxed system here, since what I&#8217;ve noticed through doing gameplay coding is that gameplay code tends not to really &#8216;fit&#8217; that kind of system too well. I&#8217;ll eventually be adding testing and so on to verify correctness, but for now it&#8217;s a fairly simple system, with two methods of communication between components (which is part of what the &#8216;dependency&#8217; you mention is about).</p>
<p>Firstly users of an object can request components by type, using something like:</p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span><br />
boost<span style="color: #008080;">::</span><span style="color: #007788;">shared_ptr</span><span style="color: #000080;">&lt;</span>T<span style="color: #000080;">&gt;</span><br />
GameObject<span style="color: #008080;">::</span><span style="color: #007788;">getComponent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #666666;">// note you can use &lt;code lang=&quot;cpp&quot;&gt; tags for code now, and don't need to escape anything within them if you do :)</span></div></div>
<p>Then of course they have the interface they want and can communicate directly with it. For now this is what I use for messages or requests, like &#8220;have you built yet?&#8221;. I&#8217;ll be expanding this into a proper message passing scheme later if I feel it&#8217;s necessary (and it may well be with scripting).</p>
<p>The other way of communicating, for continual updates like position and so on, is also very simple. Each object holds a map<string , boost::any> of properties and exposes an interface to this. Then, for example, the Physics component can set the &#8220;position&#8221; property every frame (and check for changes in case e.g. a script wants to teleport!), and later that frame the Graphics component will read the &#8220;position&#8221; property. There&#8217;s plenty of potential for typos there since they&#8217;re string IDs, but that&#8217;s what testing will be for <img src='http://www.citiesinthesky.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So it&#8217;s nothing particularly clever. If a dependency is missing, the component that needs it will just not work particularly well (the Graphics component won&#8217;t update its position if &#8220;property&#8221; is missing, or is the wrong type). Of course you could easily detect this so they&#8217;re not stealth errors.</p>
<p>I find code gen approaches interesting, yet&#8230; strange? I don&#8217;t know, I just don&#8217;t like the idea that there are files I control only indirectly! Also I don&#8217;t know how well that would work with data-driven behaviour like scripting &#8211; one of the reasons I&#8217;ve picked such a &#8220;string ID&#8221;-like way of doing things is that it&#8217;s super-easy to do scripting with (and requires little maintenance).</p>
<p>Anyway, thanks for the comment(s)!</string></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.citiesinthesky.co.uk/2009/08/09/isnt-xml-clever/comment-page-1/#comment-3293</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Wed, 09 Sep 2009 14:58:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.citiesinthesky.co.uk/?p=224#comment-3293</guid>
		<description>WTF! I guess this blog doesn&#039;t like angled brackets!
ILogic OPENANGLEDBRACKET CSmallHouseDebris CLOSEANGLEDBRACKET

I was going to use &amp;lt and &amp;gt but if that didn&#039;t work either I&#039;d look like a right tit. Hmm, if the preceeding sentence doesn&#039;t make sense either ...</description>
		<content:encoded><![CDATA[<p>WTF! I guess this blog doesn&#8217;t like angled brackets!<br />
ILogic OPENANGLEDBRACKET CSmallHouseDebris CLOSEANGLEDBRACKET</p>
<p>I was going to use &amp;lt and &amp;gt but if that didn&#8217;t work either I&#8217;d look like a right tit. Hmm, if the preceeding sentence doesn&#8217;t make sense either &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.citiesinthesky.co.uk/2009/08/09/isnt-xml-clever/comment-page-1/#comment-3291</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Wed, 09 Sep 2009 13:35:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.citiesinthesky.co.uk/?p=224#comment-3291</guid>
		<description>The above should read &quot;The logic component is dervied from something like ILogic&quot;</description>
		<content:encoded><![CDATA[<p>The above should read &#8220;The logic component is dervied from something like ILogic&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.citiesinthesky.co.uk/2009/08/09/isnt-xml-clever/comment-page-1/#comment-3290</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Wed, 09 Sep 2009 13:32:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.citiesinthesky.co.uk/?p=224#comment-3290</guid>
		<description>Declaritive component-orientated objects are very cool but I&#039;ve yet to master how to connect components to &#039;logic&#039; in an efficient manner, and also the best way to share state. 

In CITS how do you manage the dependency of the graphics component on the updated translationOffset from the Physics component? I&#039;ve used a &#039;logic&#039; component (specific to a game object type) which looks-up the graphics and other components by name, casts them the expected type, and then invoke methods on them. This worked ok but it felt a little nasty with the performance and memeory overhead and error-prone not being able to strongly type references to the components.

I&#039;m currently experimenting with a code gen approach which takes a game object structure definition (similar to your example without the data values), and builds the named Entity (eg CSmallHouseDebris), Resource (object instance data object), Factory (builds Entity instance from a Resource), ViewState interfaces and classes. Then at construction, Logic and View component instances are injected into the entity by IoC. I have a Entity, Logic, View separation. The logic component is dervied from something like ILogic.

Using this system you can&#039;t just declare a new game object in xml and run it - you first need to perform the code gen and compilation, but you do get declaritive game objects with strongly typed references.

I&#039;d really like to read more about your implementation if you have the time to blog it. Thanks for the article.</description>
		<content:encoded><![CDATA[<p>Declaritive component-orientated objects are very cool but I&#8217;ve yet to master how to connect components to &#8216;logic&#8217; in an efficient manner, and also the best way to share state. </p>
<p>In CITS how do you manage the dependency of the graphics component on the updated translationOffset from the Physics component? I&#8217;ve used a &#8216;logic&#8217; component (specific to a game object type) which looks-up the graphics and other components by name, casts them the expected type, and then invoke methods on them. This worked ok but it felt a little nasty with the performance and memeory overhead and error-prone not being able to strongly type references to the components.</p>
<p>I&#8217;m currently experimenting with a code gen approach which takes a game object structure definition (similar to your example without the data values), and builds the named Entity (eg CSmallHouseDebris), Resource (object instance data object), Factory (builds Entity instance from a Resource), ViewState interfaces and classes. Then at construction, Logic and View component instances are injected into the entity by IoC. I have a Entity, Logic, View separation. The logic component is dervied from something like ILogic.</p>
<p>Using this system you can&#8217;t just declare a new game object in xml and run it &#8211; you first need to perform the code gen and compilation, but you do get declaritive game objects with strongly typed references.</p>
<p>I&#8217;d really like to read more about your implementation if you have the time to blog it. Thanks for the article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.citiesinthesky.co.uk/2009/08/09/isnt-xml-clever/comment-page-1/#comment-3117</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Wed, 12 Aug 2009 12:53:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.citiesinthesky.co.uk/?p=224#comment-3117</guid>
		<description>You obviously fall into the &quot;programmer in a field a bit less backwards than video games&quot; category :)

Yes, I suppose it is a similar thing. It&#039;s not done purely to manage dependencies though, it&#039;s a nice concept too, and great for providing optimisation opportunities and allowing multithreading.

This way, rather than updating each game object in order, you can update all the input components, then all the physics, then graphics and so on. Conceptually nice and avoids nasty multithreading problems, and allows each system to implement whatever multithreading strategy it wants, and of course is much more scaleable than putting graphics, physics etc. on their own threads (typically the number of entities is much greater than the number of systems).

Plus there are added benefits to storing types in assets - hot reloading is one of my favourites, though I&#039;ve got a way to go before I achieve that :)</description>
		<content:encoded><![CDATA[<p>You obviously fall into the &#8220;programmer in a field a bit less backwards than video games&#8221; category <img src='http://www.citiesinthesky.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Yes, I suppose it is a similar thing. It&#8217;s not done purely to manage dependencies though, it&#8217;s a nice concept too, and great for providing optimisation opportunities and allowing multithreading.</p>
<p>This way, rather than updating each game object in order, you can update all the input components, then all the physics, then graphics and so on. Conceptually nice and avoids nasty multithreading problems, and allows each system to implement whatever multithreading strategy it wants, and of course is much more scaleable than putting graphics, physics etc. on their own threads (typically the number of entities is much greater than the number of systems).</p>
<p>Plus there are added benefits to storing types in assets &#8211; hot reloading is one of my favourites, though I&#8217;ve got a way to go before I achieve that <img src='http://www.citiesinthesky.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alastair Smith</title>
		<link>http://www.citiesinthesky.co.uk/2009/08/09/isnt-xml-clever/comment-page-1/#comment-3108</link>
		<dc:creator>Alastair Smith</dc:creator>
		<pubDate>Mon, 10 Aug 2009 09:52:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.citiesinthesky.co.uk/?p=224#comment-3108</guid>
		<description>This sounds like a specialised IoC container.  Or have I misunderstood?</description>
		<content:encoded><![CDATA[<p>This sounds like a specialised IoC container.  Or have I misunderstood?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
