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

<channel>
	<title>GamesTopica.Net &#187; patterns</title>
	<atom:link href="http://www.gamestopica.net/tag/patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gamestopica.net</link>
	<description>Topics and Ideas for all sort of Game Creations</description>
	<lastBuildDate>Sat, 19 Mar 2011 18:58:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>The Visitor Pattern in C#</title>
		<link>http://www.gamestopica.net/2009/01/the-visitor-pattern-in-c/</link>
		<comments>http://www.gamestopica.net/2009/01/the-visitor-pattern-in-c/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 07:00:23 +0000</pubDate>
		<dc:creator>extrakun</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Games Implementation]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://www.gamestopica.net/?p=280</guid>
		<description><![CDATA[<p>Sometimes in an arcade game where you have different types of entities, the most difficult part is to resolve the collision. Nope, the issue is not <em>detecting collision</em> (which is already one big headache by itself), but rather &#8211; &#8220;So something did collide; so what&#8217;s next?&#8221;<br />
<span id="more-280"></span></p>
<p>There are two questions to this:</p>
<ol>
<li>Who hit me?</li>
<li>Knowing who hit me, what do I do next?</li>
</ol>
<p>Of course, you could use RTTI to figure that out and resolve that (<a href="http://www.allegro.cc/forums/thread/226837" target="_blank">here&#8217;s an article on RTTI</a>). However, for those who prefer not to, you can use the visitor pattern as described in a <a href="http://www.gamestopica.net/2009/01/collision-handling-using-double-dispatch/" target="_blank">previous post on double dispatch</a> to implement this. Here is a C# sample which you can download to see how it works. There will be more coming later on how it works and some pitfalls to look out for.<a href="http://www.gamestopica.net/wordpress/wp-content/uploads/2009/01/visitortest.rar"> You can download the C# Sample of the Vistior Pattern from this link.</a></p>
<h2>Double Dispatch?</h2>
<p>Here&#8217;s the &#8220;un-computer science&#8221; explanation of double dispatch. C++ and C# are languages which support polymorphic functions (or virtual functions). This means that methods (or member functions, according to C++) are resolved at the run-time at object level. This is the basic premise of polymorphism (you can find more details at <a href="http://www.dotnetuncle.com/csharp/123_polymorphism.aspx" target="_blank">DotNetUncle</a>).</p>
<p>The issue is that there is no polymorphism at the function signature level; this means that suppose you have an abstract class called Entity. You have a whole hierarchy of objects, such as Missile, Asteriod and Ship. If you have a function which says have the signature CollideWith(Entity e), and the various variants &#8211; CollideWith(Asteriod a), CollideWith(Ship s) and CollideWith(Missile m), CollideWith(Entity e) would always be called if you do not cast the object to the child. (Sucky explanation, I know. I&#8217;ll try to come up with a detailed example).</p>
<h2>Other readings</h2>
<p>Other places on the Internet has grappled with resolving collision resolving in an OO manner too, such as <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=330048" target="_blank">this forum post on a GameDev.Net forum.</a></p>
<div style="display:block"><small><em>by Extrakun <br />&copy;2012 <a href="http://www.gamestopica.net">GamesTopica.Net</a>. All Rights Reserved.from <a href="http://www.gamestopica.net">GamesTopica.Net</a></em></small></div>]]></description>
			<content:encoded><![CDATA[<p>Sometimes in an arcade game where you have different types of entities, the most difficult part is to resolve the collision. Nope, the issue is not <em>detecting collision</em> (which is already one big headache by itself), but rather &#8211; &#8220;So something did collide; so what&#8217;s next?&#8221;<br />
<span id="more-280"></span></p>
<p>There are two questions to this:</p>
<ol>
<li>Who hit me?</li>
<li>Knowing who hit me, what do I do next?</li>
</ol>
<p>Of course, you could use RTTI to figure that out and resolve that (<a href="http://www.allegro.cc/forums/thread/226837" target="_blank">here&#8217;s an article on RTTI</a>). However, for those who prefer not to, you can use the visitor pattern as described in a <a href="http://www.gamestopica.net/2009/01/collision-handling-using-double-dispatch/" target="_blank">previous post on double dispatch</a> to implement this. Here is a C# sample which you can download to see how it works. There will be more coming later on how it works and some pitfalls to look out for.<a href="http://www.gamestopica.net/wordpress/wp-content/uploads/2009/01/visitortest.rar"> You can download the C# Sample of the Vistior Pattern from this link.</a></p>
<h2>Double Dispatch?</h2>
<p>Here&#8217;s the &#8220;un-computer science&#8221; explanation of double dispatch. C++ and C# are languages which support polymorphic functions (or virtual functions). This means that methods (or member functions, according to C++) are resolved at the run-time at object level. This is the basic premise of polymorphism (you can find more details at <a href="http://www.dotnetuncle.com/csharp/123_polymorphism.aspx" target="_blank">DotNetUncle</a>).</p>
<p>The issue is that there is no polymorphism at the function signature level; this means that suppose you have an abstract class called Entity. You have a whole hierarchy of objects, such as Missile, Asteriod and Ship. If you have a function which says have the signature CollideWith(Entity e), and the various variants &#8211; CollideWith(Asteriod a), CollideWith(Ship s) and CollideWith(Missile m), CollideWith(Entity e) would always be called if you do not cast the object to the child. (Sucky explanation, I know. I&#8217;ll try to come up with a detailed example).</p>
<h2>Other readings</h2>
<p>Other places on the Internet has grappled with resolving collision resolving in an OO manner too, such as <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=330048" target="_blank">this forum post on a GameDev.Net forum.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gamestopica.net/2009/01/the-visitor-pattern-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Collision Handling using Double Dispatch</title>
		<link>http://www.gamestopica.net/2009/01/collision-handling-using-double-dispatch/</link>
		<comments>http://www.gamestopica.net/2009/01/collision-handling-using-double-dispatch/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 06:48:05 +0000</pubDate>
		<dc:creator>extrakun</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Games Implementation]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://gamestopica.net/?p=225</guid>
		<description><![CDATA[<p>A type-safe, object oriented method of resolving the aftermaths of a collision detection using <a href="http://wiki.ahnfelt.dk/DoubleDispatch.html" target="_blank">double-dispatch</a>.</p>
<div style="display:block"><small><em>by Extrakun <br />&copy;2012 <a href="http://www.gamestopica.net">GamesTopica.Net</a>. All Rights Reserved.from <a href="http://www.gamestopica.net">GamesTopica.Net</a></em></small></div>]]></description>
			<content:encoded><![CDATA[<p>A type-safe, object oriented method of resolving the aftermaths of a collision detection using <a href="http://wiki.ahnfelt.dk/DoubleDispatch.html" target="_blank">double-dispatch</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gamestopica.net/2009/01/collision-handling-using-double-dispatch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

