<?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>Troy Gilbert &#187; C/C++</title>
	<atom:link href="http://troygilbert.com/category/cplusplus/feed/" rel="self" type="application/rss+xml" />
	<link>http://troygilbert.com</link>
	<description>Gamedev 2.0</description>
	<lastBuildDate>Mon, 01 Aug 2011 02:18:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Stuck in Limbo</title>
		<link>http://troygilbert.com/2006/10/stuck-in-limbo/</link>
		<comments>http://troygilbert.com/2006/10/stuck-in-limbo/#comments</comments>
		<pubDate>Tue, 10 Oct 2006 18:44:13 +0000</pubDate>
		<dc:creator>Troy</dc:creator>
				<category><![CDATA[AS3 & Flash]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[Indie Game Dev]]></category>

		<guid isPermaLink="false">http://troygilbert.com/2006/10/10/stuck-in-limbo/</guid>
		<description><![CDATA[I'm looking forward to getting stuck in <a href="http://www.limbogame.org/">Limbo</a>. He's <a href="http://www.playthrough.net/2006/10/games/limbo-hiring-a-c-programmer/">looking for C++ programmers</a>, but I was first struck with how perfectly this game could be done in Flash. With Flash's new filters and improved performance, I'd guess he could get the exact same results, cross-platform and with a lot less development pain than C++.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m looking forward to getting stuck in <a href="http://www.limbogame.org/">Limbo</a>. He&#8217;s <a href="http://www.playthrough.net/2006/10/games/limbo-hiring-a-c-programmer/">looking for C++ programmers</a>, but I was first struck with how perfectly this game could be done in Flash. With Flash&#8217;s new filters and improved performance, I&#8217;d guess he could get the exact same results, cross-platform and with a lot less development pain than C++.</p>
<p>It&#8217;s a great example, though, of the kind of results we&#8217;ll see as more people with classic art and graphic design backgrounds (with a sprinkling of programming experience) are brought into the gamedev fold. The in-development footage on his sight is hauntingly beautiful, and an inspiration to say the least. Makes me remember those first few hours playing <em>Out of this World</em>, still one of the few games to deliver so much on so little.</p>
<p>Speaking of <em>Out of this World</em>, I&#8217;ve always thought it&#8217;d be awesome to see that game remade in Flash (it&#8217;s largely rotoscoped with a vector-like graphic style, very applicable to Flash development). Hell, if it fit on a 1.44MB floppy and ran on a 286, surely it can run full-speed in Flash on a modern day machine? Those are the kind of side-scrollers people need to be making&#8230; there&#8217;s a lot of life left in that very simple mechanic! (And the side-scroller view? Well, that aesthetic has worked for &#8220;comics&#8221; for a hundred years.)</p>
<div id="tweetbutton69" class="tw_button" style="margin-bottom: 10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Ftroygilbert.com%2F2006%2F10%2Fstuck-in-limbo%2F&amp;via=troygilbert&amp;text=Stuck%20in%20Limbo&amp;related=&amp;lang=en&amp;count=horizontal" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://troygilbert.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://troygilbert.com/2006/10/stuck-in-limbo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Resource Management</title>
		<link>http://troygilbert.com/2004/09/resource-management/</link>
		<comments>http://troygilbert.com/2004/09/resource-management/#comments</comments>
		<pubDate>Wed, 08 Sep 2004 19:31:34 +0000</pubDate>
		<dc:creator>Troy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Game Dev]]></category>

		<guid isPermaLink="false">http://troygilbert.com/2004/09/08/resource-management/</guid>
		<description><![CDATA[There have been some posts recently to GD-Algorithms concerning resource management. This happens to be an area I&#8217;ve investigated recently as part of my Sandbox project (which, btw, is becoming more of an excuse to experiment with different design patterns than actually doing game-code at the moment). I&#8217;m going to define a resource manager as [...]]]></description>
			<content:encoded><![CDATA[<p>There have been some posts recently to <a href="http://lists.sourceforge.net/lists/listinfo/gdalgorithms-list">GD-Algorithms</a> concerning resource management. This happens to be an area I&#8217;ve investigated recently as part of my Sandbox project (which, btw, is becoming more of an excuse to experiment with different design patterns than actually doing game-code at the moment).</p>
<p>I&#8217;m going to define a resource manager as needing to have the following qualities:</p>
<ul>
<li>Provide universal access to all modules needing to retrieve externally persisted data (resources).</li>
<li>Ensure that resources exists as a single, shared instance in memory.</li>
<li>Ensure that resources are properly garbage-collected as necessary.</li>
<li>Allow resources to be retrieved/referenced by unique key.</li>
</ul>
<p>These requirements immediately evoke several classic design patterns that we should be leveraging. First, the <em>universal access</em> requirement means that the resource manager should be a <em>singleton</em>. Second, the two requirements of <em>shared instance</em> and <em>garbage-collected</em> means smart pointers. Finally, <em>retrieving by unique key</em> smells of some variation on the factory method.</p>
<p><span id="more-27"></span>The current implementation I&#8217;m playing with is based off of templates. The two key template parameters are the resource&#8217;s type and the unique key&#8217;s type. My implementation could also be thought of as a specialization of the <em>std::map</em> to automatically construct an object if it doesn&#8217;t exist in the map. Here&#8217;s an example of how a resource is retrieved:</p>
<pre>Texture *texture = Resources&lt;Texture&gt;::Get("mytexture.tga");
Mesh *mesh = Resources&lt;Mesh, int&gt;::Get(37);</pre>
<p>The first method is using a <em>const char *</em> as the unique key (this is the default type for the template) and the second is using an int as the unique key. Either can be useful. The only drawback to making this a template parameter is that you cannot mix them; in other words, resources retrieved by string are managed separately (and are considered unique from) resources retrieved by integer.</p>
<p>I&#8217;m also debating whether the resource manager should have its <em>singleton</em> aspect factored out of it. In this scenario, we could have local resource managers of the following form:</p>
<pre>Resources&lt;Texture&gt; localResMgr;
Texture *texture = localResMgr.Get("mytexture.tga");</pre>
<p>This may be desirable in reusing the code for internal resource management inside of particular sub-systems.</p>
<p>Another aspects of the resource manager is the desire to register <em>resource creators</em>. Creators are invoked when a resource is first accessed. The canoncial creator is one that uses an existing API to load a resource (for example, a text file creator simply creates a buffer filled with the contents of the text file, basically a giant string). My template above also allows the user to specify a creator functor to invoke when creating a specific type of resource (this is where the hints of the factory method come in). So far, I&#8217;ve not found a particularly good replacement creator, but building in that generalization is trivial (and free with templates).</p>
<p>A question that should likely be addressed in this scenario, and in most low-level system development, is whether we are creating a service or a type. When sitting down to write code, particularly code where you can envision most of its usage scenarios, this distinction may not be clear. But, having dealt with library code (RenderWare) for three years now, the difference between designing services and designing types seems pretty clear to me (I apologize if the terminology is wrong).</p>
<p>I see services as representing functional hooks for manipulating data, while types provide new classes of data (with their manipulations implicit to their definition). I guess this could be seen as the debate of functional vs. object-oriented programming. In the case of my resource manager, do I desire to have a resource management <em>type</em> that I can use throughout various systems, or do I desire a resource management <em>service</em> that I can use throughout various sytems.</p>
<p>The first invocation I showed at the top of this post would be an example of providing the resource manager as a service. It may be enclosed in a class, but this is actually just an implementation detail (there are differences between how template default parameters work for templated functions and templated classes, so I had to use a class). What the original resource manager does is define an interace for retrieving resources, and since it is essentially a single function, it is doing so globally (which was the original desire).</p>
<p>The second invocation of the resource manager shown demonstrates its definition as a <em>type</em> of object. If I desired for it to be globally accessible (like a <em>service</em> conceptually would be), then I can make it the specific type of a singleton template. This touches on my key point, I guess&#8230;</p>
<p>Decomposing this problem into its component pieces is the right path to go because it allows me to choose either <em>service</em> or <em>type</em> without changing the implementation details. For example:</p>
<pre>Singleton&lt;Resources&lt;Texture&gt; &gt; ResourceManagerService;
Texture *texture = ResourceManagerService.theInstance().Get("mytexture.tga");</pre>
<p>The above exposes my resource manager as a service. Using the exact same implementation of the Resources template, I can create a resource manager type to be used locally in a sub-system:</p>
<pre>Resources&lt;WaveData&gt; AudioResourceManager;
WaveData *waves = AudioResourceManager.Get("mysound.wav");</pre>
<p>So, what&#8217;s the point of this exercise? The point is this: go out right now and purchase <a href="http://www.moderncppdesign.com/">Modern C++ Design by Andrei Alexandrescu</a>. This book is devoted to maximizing your use of C++&#8217;s template facilities to get this type of easy, easy code construction. It&#8217;s the ultimate in generic programming.</p>
<div id="tweetbutton27" class="tw_button" style="margin-bottom: 10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Ftroygilbert.com%2F2004%2F09%2Fresource-management%2F&amp;via=troygilbert&amp;text=Resource%20Management&amp;related=&amp;lang=en&amp;count=horizontal" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://troygilbert.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://troygilbert.com/2004/09/resource-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Events</title>
		<link>http://troygilbert.com/2004/08/events/</link>
		<comments>http://troygilbert.com/2004/08/events/#comments</comments>
		<pubDate>Sun, 01 Aug 2004 11:40:45 +0000</pubDate>
		<dc:creator>Troy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Game Dev]]></category>

		<guid isPermaLink="false">http://troygilbert.com/2004/08/01/events/</guid>
		<description><![CDATA[Continuing to push forward on the Sandbox game framework. Attempting to tackle the event system. I see three different techniques to choose from for the event system: Windows-style messaging, Java-style listeners, and the Chain-of-Responsibility pattern. Windows-style messaging takes the form of a message handler function (WndProc under Win32) that receives all of the messages. This [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing to push forward on the Sandbox game framework. Attempting to tackle the event system. I see three different techniques to choose from for the event system: Windows-style messaging, Java-style listeners, and the Chain-of-Responsibility pattern.</p>
<p><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues.asp">Windows-style messaging</a> takes the form of a message handler function (WndProc under Win32) that receives all of the messages. This function is then responsible for dispatching them appropriately, usually through a large switch statement. By default, your message handler will be notified of all messages without have to specifically express interest for them.</p>
<p><a href="http://leepoint.net/notes-java/30GUI/15events/15listeners.html">Java-style listeners</a> are very lightweight but are hard-coded, not dat-driven. In this case you create a class that handles a specific message (or group of related messages). The class handles the messages by implementing a specific interface for specific messages, i.e. handleMouseMove, handleMouseDown, etc. This interface works for implementing UI widgets but does not handle soft-binding of messages at run-time, or scenarios where senders and receivers are unaware of each other.</p>
<p>This is where the <a href="http://www.dofactory.com/Patterns/PatternChain.aspx">Chain-of-Responsibility</a> pattern comes into play. This pattern separates sender from receiver. It also allows event handlers to prematurely discontinue the handling of events by simply not pass the event further down the chain. This seems like the preferred approach.</p>
<p>Well, not much more to say right now. The implementation is not finished so it may end up looking different. And it&#8217;s 3:40am, so it&#8217;s time to stop posting&#8230;</p>
<div id="tweetbutton24" class="tw_button" style="margin-bottom: 10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Ftroygilbert.com%2F2004%2F08%2Fevents%2F&amp;via=troygilbert&amp;text=Events&amp;related=&amp;lang=en&amp;count=horizontal" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://troygilbert.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://troygilbert.com/2004/08/events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

