/// <summary> /// Returns the tiles as booleans indicating whether they're solid. /// </summary> public bool[,] Generate(BiomeTile[,] biomes, List <Room> rooms, int nThreads, int seed) { //Use a blend between a room's biome and the tile's own biome. BiomeTile[,] oldBiomes = biomes; biomes = new BiomeTile[oldBiomes.GetLength(0), oldBiomes.GetLength(1)]; foreach (Vector2i tilePos in biomes.AllIndices()) { Room r = rooms.FirstOrDefault(_r => _r.Spaces.Contains(tilePos)); if (r == null) { biomes.Set(tilePos, oldBiomes.Get(tilePos)); } else { biomes.Set(tilePos, new BiomeTile(r.Biome, oldBiomes.Get(tilePos), TileVariation)); } } //Turn the room data into a grid of tiles. bool[,] tiles1 = new bool[biomes.GetLength(0), biomes.GetLength(1)]; foreach (Vector2i tilePos in tiles1.AllIndices()) { tiles1.Set(tilePos, !rooms.Any(r => r.Spaces.Contains(tilePos))); } //Create a second copy to ping-pong back and forth between iterations. bool[,] tiles2 = new bool[tiles1.GetLength(0), tiles1.GetLength(1)]; foreach (Vector2i tilePos in tiles2.AllIndices()) { tiles2.Set(tilePos, tiles1.Get(tilePos)); } //Run the cellular automata. for (int i = 0; i < NIterations; ++i) { ThreadedRunner.Run(nThreads, tiles1.GetLength(1), (startI, endI) => RunIteration(startI, endI, biomes, seed, tiles1, tiles2)); //Swap tiles1 and tiles2. bool[,] _tiles1 = tiles1; tiles1 = tiles2; tiles2 = _tiles1; } return(tiles1); }