Skip to content

Generator

George Aleksandrovich edited this page Aug 15, 2019 · 5 revisions

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.

Generate() method

Here's a general overview of the algorithm.

  1. Load in every Feature we know about (currently a static list, but later we'll have a better solution).
  2. Initialize the starting room (currently a single Tile, but later we'll have a hook for choosing the start).
  3. Pick some ending condition for generation. Right now this condition is just "count to 100", but will be customizable later.
  4. While the ending condition is not met:
    1. Pick the next Feature (using the specified instance of IFeatureSelector).
    2. Pick a position to try to place the selected Feature (using an IPositionSelector).
    3. Compute every possible way the given Feature can be placed at the selected position. A Feature can have multiple external connection points, and there are multiple orientations a Feature can have. This computation does the heavy lifting and finds every way a Feature can be placed, and stores these results in a List<Feature.Configuration>.
    4. Pick one of the valid Configurations (using an IConfigurationSelector).

PlaceTiles() method

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:

  1. Extract the Section at the given position
  2. Find which of the 4 cardinal + 4 diagonal neighbors of the given position are also present in the grid
  3. Combine the Section's Connection information with the physical Connection information. Lookup the corresponding TileType in a table.
  4. Lookup the Tile that corresponds to the given TileType and variant (which is stored in the Section)
  5. Instantiate the GameObject corresponding to the Tile
Clone this wiki locally