-
Notifications
You must be signed in to change notification settings - Fork 0
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 GameObjects represented by Tiles.
Here's a general overview of the algorithm.
- Load in every
Featurewe 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
Featurecan be placed at the selected position. AFeaturecan have multiple external connection points, and there are multiple orientations aFeaturecan have. This computation does the heavy lifting and finds every way aFeaturecan be placed, and stores these results in aList<Feature.Configuration>. - Pick one of the valid
Configurations (using anIConfigurationSelector).
- Pick the next
At this point, we have a Grid that contains some Sections. 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
Sectionat 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'sConnectioninformation with the physicalConnectioninformation. Lookup the correspondingTileTypein a table. - Lookup the
Tilethat corresponds to the givenTileTypeand variant (which is stored in theSection) - Instantiate the GameObject corresponding to the
Tile