Friday, May 23, 2014

More construction optimization

Things are going well for us.
We have most of the 50+ page report on this project written, and the project itself is starting to look good.

We have started trying to figure out the maximums of our different implementations. The most limiting one is that we rely on one mesh per level, and the vertex limit seems to be around 64k vertices per mesh. Our meshes do not currently do rectangular vertex reduction, or any other sort of vertex reduction for that matter, so we decided to do a small optimization before even setting up the mesh: If the algorithm detects a dead area, an area that is a wall and is surrounded by walls, it no longer places anything there. This frees up quite a bit of space in that 64k limit.

Here is a visual aid, the "blank spaces" used to be filled with solid black meshes. In-game they will still get filled with the background solid black:

Saturday, May 10, 2014

Construction Efficiency

Today was a good day, I managed to reduce the time needed to generate a level by a factor of ten.
The old way of generating the levels was this:

    For every point on the map
        Decide what type of point it is by examining its neighbours.
        For all sides the point lacks neighbours:
            add a "Face" to a list, with information about the face type
            and the correct pre-made mesh.
        For all faces in the list:
            Instantiate the pre-made mesh as a GameObject so we have a copy
            Set the UV coordinates based on the face type
            Add the mesh to a CombineInstance used by Mesh.CombineMeshes
            Destroy the GameObject we just created
    Combine all the little meshes to a big one using Mesh.CombineMeshes

The problem with this method is that Instantiating and Destroying GameObjects has a pretty hefty cost, and it creates a lot of garbage. It is a really inefficient way of copying the Mesh component we need.
So now, before the level is generated, we copy the 6 possible meshes using a basic Copy method we wrote, store them, and then copy them again for each face instead of making GameObjects.

Here is a composite picture of part of a level using a few different tilesets Olli drew for us.