<?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>Promethe's Blog &#187; Game</title>
	<atom:link href="http://blog.promethe.net/tag/game/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.promethe.net</link>
	<description>Web, RIAs and chocolate spaghettis...</description>
	<lastBuildDate>Tue, 29 Jun 2010 09:24:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Load and display Quake 2&#8242;s Maps in Flash 10</title>
		<link>http://blog.promethe.net/2009/10/01/load-and-display-quake-2s-maps-in-flash-10/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=load-and-display-quake-2s-maps-in-flash-10</link>
		<comments>http://blog.promethe.net/2009/10/01/load-and-display-quake-2s-maps-in-flash-10/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 17:37:26 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Quake 2]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=433</guid>
		<description><![CDATA[The Quake-series is really awesome. Not only in terms of gameplay but also technically. Quake 1, 2 and 3 are especially impressive. No wonder why Quake's graphics engine, maps or models file formats have been reused in many many games such as Half Life, Call of Duty or Medal of Honnor! So why not in [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>Quake-series is really awesome</strong>. Not only in terms of gameplay but also <strong>technically</strong>. Quake 1, 2 and 3 are especially impressive. No wonder why Quake's graphics engine, maps or models file formats have been reused in many many games such as <strong>Half Life</strong>, <strong>Call of Duty</strong> or <strong>Medal of Honnor</strong>! So why not in your own Flash 10 game?</p>
<p>There are so many reasons why loading Quake 2 files inside the Flash player would be considered as just "impossible". Performance would be the first and main one. One would just consider that Flash is not fast enough to display complex 3D graphics, not even those of a game as old as Quake 2 (published in 1996!). But using Flash 10 latests features such as the Vector and GraphicsTrianglePath classes, it is actually quite doable!</p>
<p><strong>Details, pictures and a demo application right after the jump!</strong></p>
<p><span id="more-433"></span></p>
<h4>Quake 2's maps file format</h4>
<p>But the really big advantage here is inside the Quake 2 maps file format itself. Each map is a *.BSP file and the BSP file format might be the best ratio in terms of ease of implementation against performance optimization. As you might have guessed, *.BSP files actually store a pre-compiled <a href="http://en.wikipedia.org/wiki/Binary_space_partitioning" target="_blank">Binary Space Partitionning</a> tree of the map itself. For those who don't already know about BSP trees, just imagine that it is actually the best known method to handle a polygon-perfect z-sorting in Flash when dealing with 3D. But computing a good BSP tree of a large and complex 3D model such as a map takes a lot of time... that is why having a pre-compiled and ready to load BSP tree is just great!</p>
<p>You can find a lot of good documents on the Quake 2 BSP file format. The one hosted on <a href="http://www.flipcode.com/archives/Quake_2_BSP_File_Format.shtml" target="_blank">flipcode</a> is quite complete and easy to understand. It is actually the one I used to create my BSP loader. Reading the file formats specifications shows that *.BSP files also include "visibility information". This data is also very important because it makes the user able to know which area of the map is visible from any other area. This way, only the areas visible from the area where the player stands have to be displayed which is an incredible performance boost!</p>
<p>The following application is a proof of concept of a Flash powered Quake 2 *.BSP loader :</p>
<div id="attachment_434" class="wp-caption aligncenter" style="width: 508px"><a rel="shadowbox[quake2_proof];width=500;height=375" href="http://blog.promethe.net/wp-content/uploads/2009/10/MinkoQuake2BSPTest.swf"><img class="size-full wp-image-434" title="quake2_bsp_proof" src="http://blog.promethe.net/wp-content/uploads/2009/10/quake2_bsp_proof.jpg" alt="quake2_bsp_proof" width="498" height="373" /></a><p class="wp-caption-text">Click on the picture to launch the demo application.</p></div>The application weights 174Ko because the *.BSP file is embed in it. With the map file as an external resource, the application weights only 20Ko! The map is called ''q264_3.bsp" and can be found on Google. It is not an actual Quake 2 map but a fan made map.</p>
<p>Here are some screenshots of the same application loading much more complex maps (those screenshots have been made with the Flash debugger which explains the higher memory consumption) :</p>
<p><div id="attachment_456" class="wp-caption aligncenter" style="width: 510px"><a href="http://blog.promethe.net/wp-content/uploads/2009/10/quake2_actcity2.jpg" rel="shadowbox[post-433];player=img;"><img class="size-full wp-image-456" title="quake2_actcity2" src="http://blog.promethe.net/wp-content/uploads/2009/10/quake2_actcity2.jpg" alt="quake2_actcity2" width="500" height="375" /></a><p class="wp-caption-text">actcity2</p></div>
<div id="attachment_457" class="wp-caption aligncenter" style="width: 510px"><a href="http://blog.promethe.net/wp-content/uploads/2009/10/quake2_aqnitro.jpg" rel="shadowbox[post-433];player=img;"><img class="size-full wp-image-457" title="quake2_aqnitro" src="http://blog.promethe.net/wp-content/uploads/2009/10/quake2_aqnitro.jpg" alt="aqnitro" width="500" height="375" /></a><p class="wp-caption-text">aqnitro</p></div>
<h4>What it does...</h4>
<ul>
<li>load Quake 2's *.BSP files</li>
<li>build the corresponding geometry (vertices, indices and UV data) using Flash 10 native types such as Vector and GraphicsTrianglePath</li>
<li>frustum culling and clipping using bounding boxes and bounding spheres</li>
<li>mouse controlled "free chase" camera (click + drag'n'drop to look around, mouse wheel to zoom in/out)</li>
</ul>
<h4>What's next...</h4>
<ul>
<li>use the embed BSP data to handle z-sorting</li>
<li>use visibility information to display only visible clusters</li>
<li>load WAL textures (Quake 1 and 2 textures file format, already done just have to post it <img src='http://blog.promethe.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )  and use them properly to display the map</li>
<li>load MD2 animated 3D models (again, already done and just have to post it!)</li>
</ul>
<h4>Known issue(s)</h4>
<p>If you zoom enough to place the camera "inside" the map geometry, you will notice a severe framerate drop down. It is very logical since frustum clipping will have to check and eventually clip each polygon of the geometry against the relevant view frustum planes. Because visibility information tells us what is actually visible or not, handling it properly should offer a huge performance boost: instead of having to clip the whole geometry, only the visible areas will be treated.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2009/10/01/load-and-display-quake-2s-maps-in-flash-10/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
