-
Notifications
You must be signed in to change notification settings - Fork 1
Generator
The Generator is the primary entry point for Labrys dungeon generation. Generator is a singleton Monobehavior, which runs the main Generate()
method when the Start()
method is called by Unity. After that, PlaceTiles()
is called, which resolves the Section
objects generated in Generate()
into physical GameObject
s represented by Tile
s.
Here's a general overview of the algorithm.
- Load in every
Feature
we know about (currently a static list, but later we'll have a better solution). - Initialize the starting room (currently a single
Tile
, but later we'll have a hook for choosing the start). - Pick some ending condition for generation. Right now this condition is just "count to 100", but will be customizable later.
- While the ending condition is not met:
- Pick the next
Feature
(using the specified instance ofIFeatureSelector
). - Pick a position to try to place the selected
Feature
(using anIPositionSelector
). - Compute every possible way the given
Feature
can be placed at the selected position. AFeature
can have multiple external connection points, and there are multiple orientations aFeature
can have. This computation does the heavy lifting and finds every way aFeature
can be placed, and stores these results in aList<Feature.Configuration>
. - Pick one of the valid
Configuration
s (using anIConfigurationSelector
).
- Pick the next
At this point, we have a Grid
that contains some Section
s. Each Section
has information about which connections to restrict, but it has no knowledge about which connections are actually present. PlaceTiles()
collects neighbor information for each Section
in the Grid
, and then computes which physical Tile
should be placed at the corresponding position.
Here is the summary of this algorithm.
For each occupied position in the grid:
- Extract the
Section
at the given position - Find which of the 4 cardinal + 4 diagonal neighbors of the given position are also present in the grid
- Combine the
Section
'sConnection
information with the physicalConnection
information. Lookup the correspondingTileType
in a table. - Lookup the
Tile
that corresponds to the givenTileType
and variant (which is stored in theSection
) - Instantiate the GameObject corresponding to the
Tile