Spellcaster Studios

Make it happen…

Optimization: failed!

Today I spent my evening trying to optimize the map generation (when the player lands on a planet) and the area generation (when the player changes areas).

The map generation takes about 15 seconds on a normal map (this can be a bit more or less, but this is a good average), which is very long. The problem is that most of this time is unavoidable…

Doing some profiling on it yielded the following results:

T(setup)=5 ms
T(base_generation)=373 ms
T(blurring)=1566 ms
T(normalize_heights)=18 ms
T(rock_spawns_normal)=3 ms
T(caves)=0 ms
T(water)=11224 ms
T(trees)=8 ms
T(process_heightmap)=921 ms
T(special_process)=0 ms
T(pirate_lairs)=0 ms
T(temples)=0 ms
T(camps)=0 ms
Total(build_heightmap)=14121 ms

As you can see, most of the time is generating the water courses, and that part is already quite optimized… It’s something that takes time to do well… Reducing that time would have a significant impact on the rivers and lakes… I might be able to do something more on the pathfinder I use to create the river, but I don’t believe I’ll be able to get that time down much…

Then we have the area generation… This one takes currently about 600 ms on average, 95% of it in generating the navigation mesh, and I already squeezed that one as much as I can (most of the code belongs to Recast, the library I use for navigation mesh generation).

So I have about 200 ms shaved on the map generation to show for my efforts tonight, which is kind of sucky…

I think I’ll be able to multithread the map generation, so the player won’t be waiting 15 seconds do be able to land on a planet… I’ve already separated the code with that in mind, so except for some sync points where I create the flow map texture, I should be able to run it in a separate thread that gets launched as soon as the player goes into hyperspace to a new planet… Between the hyperspace travel, and running to the lander, that’s at least 10 seconds of time I can hide, and the rest I can hide on a “in the atmosphere” cutscene.

Next step in the polish is to grab the lava worlds and see what can be done there with the water algorithm, glows and maybe some fire jets on the lava pools… A “fire snow” like effect to simulate ash in the atmosphere might be also interesting.

I’m also guessing I’ll find some bugs (I always do when I revisit planets), and this is one of the planets where a new camera algorithm/occlusion handling would be useful, so I expect about a week of fun… Disappointed smile

Now listening to “Viva Hades” by “Mono Inc.”

Comment