I'm writing a chunk-based voxel engine and I need to gradually load and grow the area around the player.
My chunks are organized in a 3D 'matrix' ('rolling' array with toroidal ('modulo') addressing) representing the visible (rectangular) region of chunks.
The 'matrix' is stored as a 1D array of chunks, each chunk contains its status, the mesh pointer, etc.
I decided to use a simple flood-fill algorithm for determining which chunks to load first after an empty world is created.
But a (non-recursive) flood-fill relies on a queue (for storing the next chunks to process) and performs 8 steps in each direction (with ugly checks, and most of them fail).
Is there a neat space-filling curve for linearizing the 3D 'matrix' which allows to visit chunks in a closest-to-far manner, starting from any given player position inside the cube? The curve should be reasonably simple and quick, and (of course) not 'intersect' already visited elements. Is there anything more efficient (or elegant) than hardcoded 'spiral curve'?
The advantage of using a space-filling curve is that instead of storing an array of chunks to be processed you could store a single value (e.g. the position of the last processed chunk encoded in an int).
(and I have trouble figuring out on paper how to code even the simplest 3D 'cubic spiral' curve.)