Optimizing tiled based alternativa3d map
I’ve recently offered my help to Terry Cavanagh from distractionware with his 7dfps entry. I caught wind of the fact he was using alternativa3d and couldn’t help but poke my nose in and try and offer some tips. A lot of 2d bitmap based games use a tiling type effect to generate maps or levels from an array. With each number specifying a type of texture for that particular block, for example you might see something like this.
var leveldata:Array = [ 0,0,0,0,0, 0,1,1,1,0, 0,1,0,1,0, 0,1,1,1,0, 0,0,0,0,0 ];
If you imagine that 0 is a wall and 1 is a concrete floor your player can walk on, you can see that it begins to take shape. Anyway Terry took this kind of approach in his initial demo, which was obviously just a test but still I thought I would take the time showing the difference of creating an optimized 3d map can do. So first up I had the original demo Terry created, so with some minor changes using the alternativa3d ExportA3D class I exported the current map to a .a3d file and loaded it into blender using my addon. Straight away I could see the huge waste or resources. Each block was a Box primitive or 2 plane primitives for areas where the player can walk. This kind of setup causes unseen faces to be used so more triangles on screen than necessary but it also means that there are 1 or 2 draw calls or DRW per box or plane because each of these uses a surface per box or plane. Adding up in the demo to up to 500 and this can start to impact the fps of the game. One of the first things I did to improve the model was remove any unused or unseen cubes. Next I merged the planes as best I could and set it up so there would be one surface for the entire model finally came up with a mesh that looked like this. After that I simply uvmapped the images and then exported back out a .a3d file and viola. I reduced the triangles from around 2000 down to around 500 and I reduced the draw calls from 400-500 down to 2-3.