예제 #1
0
    public List <bool[, ]> GenerateCellularAutomata(string chunkKey, CubeTemplate template, int smoothIterations, int randomAddition)
    {
        List <bool[, ]> maps = new List <bool[, ]>();

        for (int y = 0; y < WorldManager.dimension * 2; y++)
        {
            maps.Add(new bool[WorldManager.dimension, WorldManager.dimension]);
        }

        if (!template.IsEmpty())
        {
            for (int x = 0; x < maps.Count; x++)
            {
                for (int y = 0; y < maps.Count; y++)
                {
                    maps[y][0, x] = template.left[x, y];
                    maps[y][maps.Count - 1, x] = template.right[x, y];

                    maps[y][x, maps.Count - 1] = template.forward[x, y];
                    maps[y][x, 0] = template.back[x, y];

                    maps[0][x, y] = template.bottom[x, y];
                    maps[maps.Count - 1][x, y] = template.top[x, y];
                }
            }

            randomAddition = (int)(randomAddition * 0.5f);
        }

        //maps = RandomFillMap(maps, chunkKey, WorldManager.dimension, randomAddition);

        for (int i = 0; i < smoothIterations; i++)
        {
            maps = SmoothMap(maps, smoothPercentage);
        }

        return(maps);
    }
예제 #2
0
    public static List <bool[, ]> GenerateChunkFromTexture(string chunkKey, CubeTemplate template)
    {
        List <bool[, ]> maps  = new List <bool[, ]>();
        List <bool[, ]> flags = new List <bool[, ]>();

        for (int y = 0; y < WorldManager.dimension * 2; y++)
        {
            maps.Add(new bool[WorldManager.dimension, WorldManager.dimension]);
            flags.Add(new bool[WorldManager.dimension, WorldManager.dimension]);
        }

        if (!template.IsEmpty())
        {
            for (int x = 0; x < WorldManager.dimension; x++)
            {
                for (int y = 0; y < WorldManager.dimension; y++)
                {
                    if (template.left.GetLength(0) > 1)
                    {
                        maps[y][0, x]  = template.left[x, y];
                        flags[y][0, x] = true;
                    }
                    if (template.right.GetLength(0) > 1)
                    {
                        maps[y][WorldManager.dimension - 1, x]  = template.right[x, y];
                        flags[y][WorldManager.dimension - 1, x] = true;
                    }

                    if (template.forward.GetLength(0) > 1)
                    {
                        maps[y][x, WorldManager.dimension - 1]  = template.forward[x, y];
                        flags[y][x, WorldManager.dimension - 1] = true;
                    }
                    if (template.back.GetLength(0) > 1)
                    {
                        maps[y][x, 0]  = template.back[x, y];
                        flags[y][x, 0] = true;
                    }

                    if (template.bottom.GetLength(0) > 1)
                    {
                        maps[0][x, y]  = template.bottom[x, y];
                        flags[0][x, y] = true;
                    }
                    if (template.top.GetLength(0) > 1)
                    {
                        maps[WorldManager.dimension - 1][x, y]  = template.top[x, y];
                        flags[WorldManager.dimension - 1][x, y] = true;
                    }
                }
            }
        }

        string[] numbers = chunkKey.Split(',');

        Vector3 position = new Vector3(int.Parse(numbers [0]), int.Parse(numbers [1]), int.Parse(numbers [2]));

        for (int y = 0; y < maps.Count - 1; y++)
        {
            for (int x = 0; x < maps [y].GetLength(0); x++)
            {
                for (int z = 0; z < maps [y].GetLength(0); z++)
                {
                    maps [y] [x, z] = HeightMapManager.GetActiveState(x + (int)position.x * WorldManager.dimension, y + (int)position.y * WorldManager.dimension, z + (int)position.z * WorldManager.dimension);
                }
            }
        }

        return(maps);
    }
예제 #3
0
    public static List <bool[, ]> GenerateRecursiveCellularAutomata(string chunkKey, CubeTemplate template, int smoothIterations, int randomAddition)
    {
        List <bool[, ]> maps  = new List <bool[, ]>();
        List <bool[, ]> flags = new List <bool[, ]>();

        for (int y = 0; y < WorldManager.dimension * 2; y++)
        {
            maps.Add(new bool[WorldManager.dimension, WorldManager.dimension]);
            flags.Add(new bool[WorldManager.dimension, WorldManager.dimension]);
        }

        if (!template.IsEmpty())
        {
            for (int x = 0; x < WorldManager.dimension; x++)
            {
                for (int y = 0; y < WorldManager.dimension; y++)
                {
                    if (template.left.GetLength(0) > 1)
                    {
                        maps[y][0, x]  = template.left[x, y];
                        flags[y][0, x] = true;
                    }
                    if (template.right.GetLength(0) > 1)
                    {
                        maps[y][WorldManager.dimension - 1, x]  = template.right[x, y];
                        flags[y][WorldManager.dimension - 1, x] = true;
                    }

                    if (template.forward.GetLength(0) > 1)
                    {
                        maps[y][x, WorldManager.dimension - 1]  = template.forward[x, y];
                        flags[y][x, WorldManager.dimension - 1] = true;
                    }
                    if (template.back.GetLength(0) > 1)
                    {
                        maps[y][x, 0]  = template.back[x, y];
                        flags[y][x, 0] = true;
                    }

                    if (template.bottom.GetLength(0) > 1)
                    {
                        maps[0][x, y]  = template.bottom[x, y];
                        flags[0][x, y] = true;
                    }
                    if (template.top.GetLength(0) > 1)
                    {
                        maps[WorldManager.dimension - 1][x, y]  = template.top[x, y];
                        flags[WorldManager.dimension - 1][x, y] = true;
                    }
                }
            }
        }

        maps = RandomFillMap(maps, flags, chunkKey, randomAddition);

        for (int i = 0; i < 1; i++)
        {
            maps = RecursiveSmoothMap(maps, flags, 0, 0, 0, smoothPercentage);
        }

        return(maps);
    }