Skip to main content

Snowflake Performance Tuning

·165 words·1 min

Sweet. So the benchmark I measured yesterday was about 2.5-2.6 seconds to process 30 steps. With just a couple changes I got that down to 0.7-0.8 seconds.

First, I stopped recreating arrays in each of thousands of calls to get the directions to adjacent hexagons.

Second, I iterated over every hex and stored its is_receptive() result in a boolean array. This eliminated multiple calls to that method which is pretty expensive because it often has to visit a hexagon’s neighbours as well.

Unfortunately, that’s still not fast enough for my game idea. Might be a good excuse to learn about compute shaders..?

Some people have implemented this algorithm on Shadertoy. Here’s a nice one by soudfv: https://www.shadertoy.com/view/7t3XDr

Maybe I could run the shader and every few frames I could pull the pixels from the shader for use in the game mechanics. I can also add seeds to the texture when the player clicks the mouse or the player character plants the seed or whatever.