Esempio n. 1
0
        public BiomeTile[,] Generate(int sizeX, int sizeY, int nThreads, int seed)
        {
            BiomeTile[,] tiles = new BiomeTile[sizeX, sizeY];

            Func <Vector3, float, float> sampler = (pos, scale) =>
                                                   NoiseAlgos3D.LinearNoise(pos * scale);

            float seedF = (float)seed;

            ThreadedRunner.Run(nThreads, sizeY,
                               (startY, endY) =>
            {
                for (int y = startY; y <= endY; ++y)
                {
                    float yF = (float)y;
                    for (int x = 0; x < sizeX; ++x)
                    {
                        float xF = (float)x;

                        tiles[x, y] = new BiomeTile();
                        tiles[x, y].CaveSmoothness = Noise.Sample(new Vector3(xF, yF, seedF),
                                                                  sampler);
                    }
                }
            });

            return(tiles);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
 public Room(BiomeTile biome, RectI bounds)
 {
     Biome          = biome;
     OriginalBounds = bounds;
 }
Esempio n. 4
0
 public BiomeTile(BiomeTile a, BiomeTile b, float t)
 {
     CaveSmoothness = Mathf.Lerp(a.CaveSmoothness, b.CaveSmoothness, t);
 }