Synchronous or Asynchronous Generation
Home -->
Programming Projects -->
Fractal Block Engine -->
Procedural World Generation -->
Synchronous or Asynchronous Generation
When to Generate Chunks Synchronously?
When the system needs to procedurally generate a chunk,
this can be done either synchronously or asynchronously.
In general, we want to generate more chunks asynchronously
(because this is done my multiple threads).
However sometimes we want to generate chunks synchronously
because this may be blocking other tasks.
Here are some guidelines for when we want
chunk generation to be synchronous:
- When the chunk C to be generated contains the player
(or some descendent chunk of C contains the player).
- When the chunk C to be generated is on some level L
but the chunk intersects the
envelope
of level L+1.
See here for the definition of the envelope
of a level.
In this situation, certain chunks on level L+1 cannot be
procedurally generated because they are waiting on
C to be generated.
That is, chunks on level L+1 need to know their
own block types and the block types of adjacent chunks
as input for procedural generation,
but these block types may be for blocks in C
(which has not yet been generated).
This is a problem unique to a fractal game.
A traditional block game does not need to worry about this.
Proto Chunks
See here for the definition of a proto chunk.
When a chunk is first added to the active chunk tree,
it is an empty shell: a proto chunk.
We either populate it synchronously right then,
or we make a request to populate it asynchronously.
Once the system that procedurally generates chunks finishes,
we "populate" the chunk and the chunk is no longer
a proto chunk.
Note that populating a chunk actually requires more than just
procedural world generation.
We also must load all changes that have been made to the chunk
previously from a save file.