Load and display Quake 2′s Maps in Flash 10
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 your own Flash 10 game?
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!
Details, pictures and a demo application right after the jump!
Quake 2's maps file format
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 Binary Space Partitionning 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!
You can find a lot of good documents on the Quake 2 BSP file format. The one hosted on flipcode 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!
The following application is a proof of concept of a Flash powered Quake 2 *.BSP loader :
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.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) :
What it does...
- load Quake 2's *.BSP files
- build the corresponding geometry (vertices, indices and UV data) using Flash 10 native types such as Vector and GraphicsTrianglePath
- frustum culling and clipping using bounding boxes and bounding spheres
- mouse controlled "free chase" camera (click + drag'n'drop to look around, mouse wheel to zoom in/out)
What's next...
- use the embed BSP data to handle z-sorting
- use visibility information to display only visible clusters
- load WAL textures (Quake 1 and 2 textures file format, already done just have to post it
) and use them properly to display the map - load MD2 animated 3D models (again, already done and just have to post it!)
Known issue(s)
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.



October 1st, 2009 - 21:21
Just awesome! Can’t wait for the whole game
October 1st, 2009 - 21:44
The network is your work dude
I’m counting on it…
October 1st, 2009 - 22:14
this kinda inspires me to finish my old stuff, specially now when alternativa has built-in pvs support.
October 4th, 2009 - 18:34
Awesome. Have been toying with the same thing in pre-10 era. (haha @makc
. http://code.google.com/p/paperquake2/
October 5th, 2009 - 00:28
Yes I saw your sources! Makc told me about it on twitter and I’m flattered to see you on my blog
I added a few things since that post such as PVS handling and z-sorting. I’ll post it soon!
October 5th, 2009 - 21:21
Cool! Got PVS working then, but didn’t manage BSP z-sorting. Would be cool if you could post the relevant code
October 5th, 2009 - 23:01
Yes! PVS is working! I’ll post the relevant source code soon. There’s still a lot of work to have the textures and lightmaps set properly though…
October 16th, 2009 - 00:58
Hello from Russia!
Can I quote a post in your blog with the link to you?
October 26th, 2009 - 10:50
Hello from France!
Feel free to do it!
February 2nd, 2010 - 05:01
Nice! I was thinking the same thing about the convenient BSP format when I was trying to find an example for my 3d engine. See http://blog.glowinteractive.com/index.php/2010/01/quake-in-flash-9/