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.
No comments:
Post a Comment