コード例 #1
0
        void CreateStrata()
        {
            OctaveNoise n = new OctaveNoise(8, rnd);

            CurrentState = "Creating strata";
            int hMapIndex = 0, maxY = Height - 1, mapIndex = 0;
            // Try to bulk fill bottom of the map if possible
            int minStoneY = CreateStrataFast();

            for (int z = 0; z < Length; z++)
            {
                for (int x = 0; x < Width; x++)
                {
                    int dirtThickness = (int)(n.Compute(x, z) / 24 - 4);
                    int dirtHeight    = heightmap[hMapIndex++];
                    int stoneHeight   = dirtHeight + dirtThickness;

                    stoneHeight = Math.Min(stoneHeight, maxY);
                    dirtHeight  = Math.Min(dirtHeight, maxY);

                    mapIndex = minStoneY * oneY + z * Width + x;
                    for (int y = minStoneY; y <= stoneHeight; y++)
                    {
                        blocks[mapIndex] = Block.Stone; mapIndex += oneY;
                    }

                    stoneHeight = Math.Max(stoneHeight, 0);
                    mapIndex    = (stoneHeight + 1) * oneY + z * Width + x;
                    for (int y = stoneHeight + 1; y <= dirtHeight; y++)
                    {
                        blocks[mapIndex] = Block.Dirt; mapIndex += oneY;
                    }
                }
            }
        }
コード例 #2
0
        void CreateHeightmap()
        {
            Noise n1 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            Noise n2 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            Noise n3    = new OctaveNoise(6, rnd);
            int   index = 0;

            short[] hMap = new short[width * length];
            CurrentState = "Building heightmap";

            for (int z = 0; z < length; z++)
            {
                CurrentProgress = (float)z / length;
                for (int x = 0; x < width; x++)
                {
                    double hLow  = n1.Compute(x * 1.3f, z * 1.3f) / 6 - 4;
                    double hHigh = n2.Compute(x * 1.3f, z * 1.3f) / 5 + 6;

                    double height = n3.Compute(x, z) > 0 ? hLow : Math.Max(hLow, hHigh);
                    height *= 0.5;
                    if (height < 0)
                    {
                        height *= 0.8f;
                    }
                    hMap[index++] = (short)(height + waterLevel);
                }
            }
            heightmap = hMap;
        }
コード例 #3
0
        void CreateSurfaceLayer()
        {
            OctaveNoise n1 = new OctaveNoise(8, rnd), n2 = new OctaveNoise(8, rnd);

            CurrentState = "Creating surface";
            // TODO: update heightmap

            int hMapIndex = 0;

            for (int z = 0; z < Length; z++)
            {
                CurrentProgress = (float)z / Length;
                for (int x = 0; x < Width; x++)
                {
                    int y = heightmap[hMapIndex++];
                    if (y < 0 || y >= Height)
                    {
                        continue;
                    }

                    int     index      = (y * Length + z) * Width + x;
                    BlockID blockAbove = y >= (Height - 1) ? Block.Air : blocks[index + oneY];
                    if (blockAbove == Block.Water && (n2.Compute(x, z) > 12))
                    {
                        blocks[index] = Block.Gravel;
                    }
                    else if (blockAbove == Block.Air)
                    {
                        blocks[index] = (y <= waterLevel && (n1.Compute(x, z) > 8)) ? Block.Sand : Block.Grass;
                    }
                }
            }
        }
コード例 #4
0
        public void GenerateChunk(int chunkX, int chunkZ)
        {
            chunkSeed = (chunkX * chunkXMul) ^ (chunkZ * chunkZMul) ^ Seed;
            CombinedNoise n1 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            CombinedNoise n2 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            OctaveNoise n3 = new OctaveNoise(6, rnd);

            if (heightmap == null)
            {
                heightmap = new short[Width * Length];
            }

            CreateChunkHeightmap(chunkX, chunkZ, n1, n2, n3);

            OctaveNoise n4 = new OctaveNoise(8, rnd);

            CreateChunkStrata(chunkX, chunkZ, n4);

            OctaveNoise n5 = new OctaveNoise(8, rnd);
            OctaveNoise n6 = new OctaveNoise(8, rnd);

            CreateChunkSurfaceLayer(chunkX, chunkZ, n5, n6);
        }
コード例 #5
0
        void CreateSurfaceLayer()
        {
            Noise n1 = new OctaveNoise(8, rnd), n2 = new OctaveNoise(8, rnd);

            CurrentState = "Creating surface";
            // TODO: update heightmap

            int hMapIndex = 0;

            for (int z = 0; z < length; z++)
            {
                CurrentProgress = (float)z / length;
                for (int x = 0; x < width; x++)
                {
                    bool sand   = n1.Compute(x, z) > 8;
                    bool gravel = n2.Compute(x, z) > 12;
                    int  y      = heightmap[hMapIndex++];
                    if (y >= height)
                    {
                        continue;
                    }

                    int  index      = (y * length + z) * width + x;
                    byte blockAbove = y >= (height - 1) ? Block.Air : blocks[index + oneY];
                    if (blockAbove == Block.Water && gravel)
                    {
                        blocks[index] = Block.Gravel;
                    }
                    else if (blockAbove == Block.Air)
                    {
                        blocks[index] = (y <= waterLevel && sand) ? Block.Sand : Block.Grass;
                    }
                }
            }
        }
コード例 #6
0
        void CreateChunkSurfaceLayer(int chunkX, int chunkZ, OctaveNoise n1, OctaveNoise n2)
        {
            CurrentState = "Creating surface";
            // TODO: update heightmap
            int offsetX = (chunkX * 16);
            int offsetZ = (chunkZ * 16);

            for (int z = 0; z < 16; z++)
            {
                int zCur = z + offsetZ;
                CurrentProgress = (float)z / Length;
                for (int x = 0; x < 16; x++)
                {
                    int xCur      = x + offsetX;
                    int hMapIndex = zCur * Width + xCur;
                    int y         = heightmap[hMapIndex];
                    if (y < 0 || y >= Height)
                    {
                        continue;
                    }

                    int      index      = (y * Length + zCur) * Width + xCur;
                    BlockRaw blockAbove = y >= (Height - 1) ? Block.Air : blocks[index + oneY];
                    if (blockAbove == Block.Water && (n2.Compute(xCur, zCur) > 12))
                    {
                        blocks[index] = Block.Gravel;
                    }
                    else if (blockAbove == Block.Air)
                    {
                        blocks[index] = (y <= waterLevel && (n1.Compute(xCur, zCur) > 8)) ? Block.Sand : Block.Grass;
                    }
                }
            }
        }
コード例 #7
0
        /* ========================= */
        /* ===== OLD FUNCTIONS ===== */
        /* ========================= */

        void CreateHeightmap()
        {
            CombinedNoise n1 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            CombinedNoise n2 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            OctaveNoise n3    = new OctaveNoise(6, rnd);
            int         index = 0;

            short[] hMap = new short[Width * Length];
            CurrentState = "Building heightmap";

            for (int z = 0; z < Length; z++)
            {
                CurrentProgress = (float)z / Length;
                for (int x = 0; x < Width; x++)
                {
                    double hLow = n1.Compute(x * 1.3f, z * 1.3f) / 6 - 4, height = hLow;
                    double hHigh = n2.Compute(x * 1.3f, z * 1.3f) / 5 + 6;

                    if (n3.Compute(x, z) <= 0)
                    {
                        height = Math.Max(hLow, hHigh);
                    }

                    /*if (x == 135 && z == 138) {
                     *      double nose = n3.Compute(x, z) / 8;
                     *      Console.WriteLine(nose.ToString());
                     * }*/

                    height *= 0.5;
                    if (height < 0)
                    {
                        height *= 0.8f;
                    }

                    double erode = n3.Compute(x, z);

                    //if (n3.Compute(x, z) > 3.0 && hHigh < hLow) {
                    if (erode / 8 <= hLow && Closer(hLow, hHigh, erode / 4) == hLow && erode >= 0)
                    {
                        //if (n3.Compute(x * 1.3, z * 1.3) / 6 < -0.5 || n3.Compute(x * 1.3, z * 1.3) / 6 > 1.5) {
                        if ((short)height % 2 != 0 && (short)height > 0)
                        {
                            height -= 1;
                        }
                    }

                    short adjHeight = (short)(height + waterLevel);
                    minHeight     = adjHeight < minHeight ? adjHeight : minHeight;
                    hMap[index++] = adjHeight;
                }
            }
            heightmap = hMap;
        }
コード例 #8
0
        public override BlockRaw[] Generate()
        {
            game.World.seed = this.Seed;
            oneY            = Width * Length;
            waterLevel      = Height / 2;
            blocks          = new BlockRaw[Width * Height * Length];
            rnd             = new JavaRandom(Seed);
            rnd2            = new JavaRandom(Seed);
            chunkXMul       = rnd2.nextLong();
            chunkZMul       = rnd2.nextLong();
            minHeight       = Height;

            n1 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            n2 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            n3 = new OctaveNoise(6, rnd);

            n4 = new OctaveNoise(8, rnd);

            n5 = new OctaveNoise(8, rnd);
            n6 = new OctaveNoise(8, rnd);

            for (int z = 0; z < Length / 16; z++)
            {
                for (int x = 0; x < Width / 16; x++)
                {
                    GenerateChunk(x, z);
                }
            }

            /*for (int z = 0; z < (Length + Length % 16) / 16; z++)
             *      for (int x = 0; x < (Width + Width % 16) / 16; x++) {
             *      chunkSeed = Seed + (x * chunkXMul) + (z * chunkZMul);
             *      if (heightmap == null) heightmap = new short[Width * Length];
             *      CreateChunkHeightmap(x, z, n1, n2, n3);
             * }
             *
             * CreateHeightmap();
             * CreateStrata();
             * CarveCaves();
             * CarveOreVeins(0.9f, "coal ore", Block.CoalOre);
             * CarveOreVeins(0.7f, "iron ore", Block.IronOre);
             * CarveOreVeins(0.5f, "gold ore", Block.GoldOre);
             *
             * FloodFillWaterBorders();
             * FloodFillWater();
             * FloodFillLava();
             *
             * CreateSurfaceLayer();
             * PlantFlowers();
             * PlantMushrooms();
             * PlantTrees();*/
            return(blocks);
        }
コード例 #9
0
        void CreateStrata()
        {
            Noise n = new OctaveNoise(8, rnd);

            CurrentState = "Creating strata";

            int hMapIndex = 0;

            for (int z = 0; z < length; z++)
            {
                CurrentProgress = (float)z / length;
                for (int x = 0; x < width; x++)
                {
                    int dirtThickness = (int)(n.Compute(x, z) / 24 - 4);
                    int dirtHeight    = heightmap[hMapIndex++];

                    int stoneHeight = dirtHeight + dirtThickness;
                    int mapIndex    = z * width + x;

                    blocks[mapIndex] = (byte)Block.Lava;
                    mapIndex        += oneY;
                    for (int y = 1; y < height; y++)
                    {
                        byte type = 0;
                        if (y <= stoneHeight)
                        {
                            type = (byte)Block.Stone;
                        }
                        else if (y <= dirtHeight)
                        {
                            type = (byte)Block.Dirt;
                        }

                        blocks[mapIndex] = type;
                        mapIndex        += oneY;
                    }
                }
            }
        }
コード例 #10
0
        void CreateChunkStrata(int chunkX, int chunkZ, OctaveNoise n)
        {
            CurrentState = "Creating strata";
            int hMapIndex = 0, maxY = Height - 1, mapIndex = 0;
            // Try to bulk fill bottom of the map if possible
            int minStoneY = CreateChunkStrataFast(chunkX, chunkZ);
            int offsetX   = (chunkX * 16);
            int offsetZ   = (chunkZ * 16);

            for (int z = 0; z < 16; z++)
            {
                int zCur = z + offsetZ;
                CurrentProgress = (float)z / Length;
                for (int x = 0; x < 16; x++)
                {
                    int xCur          = x + offsetX;
                    int index         = zCur * Width + xCur;
                    int dirtThickness = (int)(n.Compute(x, z) / 24 - 4);
                    int dirtHeight    = heightmap[index];
                    int stoneHeight   = dirtHeight + dirtThickness;

                    stoneHeight = Math.Min(stoneHeight, maxY);
                    dirtHeight  = Math.Min(dirtHeight, maxY);

                    mapIndex = minStoneY * oneY + zCur * Width + xCur;
                    for (int y = minStoneY; y <= stoneHeight; y++)
                    {
                        blocks[mapIndex] = Block.Stone; mapIndex += oneY;
                    }

                    stoneHeight = Math.Max(stoneHeight, 0);
                    mapIndex    = (stoneHeight + 1) * oneY + zCur * Width + xCur;
                    for (int y = stoneHeight + 1; y <= dirtHeight; y++)
                    {
                        blocks[mapIndex] = Block.Dirt; mapIndex += oneY;
                    }
                }
            }
        }
コード例 #11
0
        void CreateHeightmap()
        {
            CombinedNoise n1 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            CombinedNoise n2 = new CombinedNoise(
                new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
            OctaveNoise n3    = new OctaveNoise(6, rnd);
            int         index = 0;

            short[] hMap = new short[Width * Length];
            CurrentState = "Building heightmap";

            for (int z = 0; z < Length; z++)
            {
                CurrentProgress = (float)z / Length;
                for (int x = 0; x < Width; x++)
                {
                    double hLow = n1.Compute(x * 1.3f, z * 1.3f) / 6 - 4, height = hLow;

                    if (n3.Compute(x, z) <= 0)
                    {
                        double hHigh = n2.Compute(x * 1.3f, z * 1.3f) / 5 + 6;
                        height = Math.Max(hLow, hHigh);
                    }

                    height *= 0.5;
                    if (height < 0)
                    {
                        height *= 0.8f;
                    }

                    short adjHeight = (short)(height + waterLevel);
                    minHeight     = adjHeight < minHeight ? adjHeight : minHeight;
                    hMap[index++] = adjHeight;
                }
            }
            heightmap = hMap;
        }
コード例 #12
0
ファイル: Noise.cs プロジェクト: takaaptech/MCGalaxy
 public CombinedNoise(OctaveNoise noise1, OctaveNoise noise2)
 {
     this.noise1 = noise1;
     this.noise2 = noise2;
 }
コード例 #13
0
        void CreateSurfaceLayer()
        {
            Noise n1 = new OctaveNoise( 8, rnd ), n2 = new OctaveNoise( 8, rnd );
            CurrentState = "Creating surface";
            // TODO: update heightmap

            int hMapIndex = 0;
            for( int z = 0; z < length; z++ ) {
                CurrentProgress = (float)z / length;
                for( int x = 0; x < width; x++ ) {
                    bool sand = n1.Compute( x, z ) > 8;
                    bool gravel = n2.Compute( x, z ) > 12;
                    int y = heightmap[hMapIndex++];
                    if( y >= height ) continue;

                    int index = (y * length + z) * width + x;
                    byte blockAbove = y >= (height - 1) ? (byte)0 : blocks[index + oneY];
                    if( blockAbove == (byte)Block.Water && gravel ) {
                        blocks[index] = (byte)Block.Gravel;
                    } else if( blockAbove == 0 ) {
                        blocks[index] = (y <= waterLevel && sand) ?
                            (byte)Block.Sand : (byte)Block.Grass;
                    }
                }
            }
        }
コード例 #14
0
        void CreateStrata()
        {
            Noise n = new OctaveNoise( 8, rnd );
            CurrentState = "Creating strata";

            int hMapIndex = 0;
            for( int z = 0; z < length; z++ ) {
                CurrentProgress = (float)z / length;
                for( int x = 0; x < width; x++ ) {
                    int dirtThickness = (int)(n.Compute( x, z ) / 24 - 4);
                    int dirtHeight = heightmap[hMapIndex++];

                    int stoneHeight = dirtHeight + dirtThickness;
                    int mapIndex = z * width + x;

                    blocks[mapIndex] = (byte)Block.Lava;
                    mapIndex += oneY;
                    for( int y = 1; y < height; y++ ) {
                        byte type = 0;
                        if( y <= stoneHeight ) type = (byte)Block.Stone;
                        else if( y <= dirtHeight ) type = (byte)Block.Dirt;

                        blocks[mapIndex] = type;
                        mapIndex += oneY;
                    }
                }
            }
        }
コード例 #15
0
        void CreateHeightmap()
        {
            Noise n1 = new CombinedNoise(
                new OctaveNoise( 8, rnd ), new OctaveNoise( 8, rnd ) );
            Noise n2 = new CombinedNoise(
                new OctaveNoise( 8, rnd ), new OctaveNoise( 8, rnd ) );
            Noise n3 = new OctaveNoise( 6, rnd );
            int index = 0;
            short[] hMap = new short[width * length];
            CurrentState = "Building heightmap";

            for( int z = 0; z < length; z++ ) {
                CurrentProgress = (float)z / length;
                for( int x = 0; x < width; x++ ) {
                    double hLow = n1.Compute( x * 1.3f, z * 1.3f ) / 6 - 4;
                    double hHigh = n2.Compute( x * 1.3f, z * 1.3f ) / 5 + 6;

                    double height = n3.Compute( x, z ) > 0 ? hLow : Math.Max( hLow, hHigh );
                    height *= 0.5;
                    if( height < 0 ) height *= 0.8f;
                    hMap[index++] = (short)(height + waterLevel);
                }
            }
            heightmap = hMap;
        }
コード例 #16
0
        void CreateChunkHeightmap(int chunkX, int chunkZ, CombinedNoise n1, CombinedNoise n2, OctaveNoise n3)
        {
            /*CombinedNoise n1 = new CombinedNoise(
             *      new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
             * CombinedNoise n2 = new CombinedNoise(
             *      new OctaveNoise(8, rnd), new OctaveNoise(8, rnd));
             * OctaveNoise n3 = new OctaveNoise(6, rnd);*/
            int index = 0;
            //short[] hMap = new short[16 * 16];
            int offsetX = (chunkX * 16);
            int offsetZ = (chunkZ * 16);

            CurrentState = "Building heightmap";

            for (int z = 0; z < 16; z++)
            {
                int zCur = z + offsetZ;
                CurrentProgress = (float)z / Length;
                for (int x = 0; x < 16; x++)
                {
                    int xCur = x + offsetX;
                    if (xCur >= Width || zCur >= Length)
                    {
                        break;
                    }
                    double hLow = n1.Compute(xCur * 1.3f, zCur * 1.3f) / 6 - 4, height = hLow;

                    if (n3.Compute(xCur, zCur) <= 0)
                    {
                        double hHigh = n2.Compute(xCur * 1.3f, zCur * 1.3f) / 5 + 6;
                        height = Math.Max(hLow, hHigh);
                    }

                    height *= 0.5;
                    if (height < 0)
                    {
                        height *= 0.8f;
                    }

                    short adjHeight = (short)(height + waterLevel);
                    minHeight        = adjHeight < minHeight ? adjHeight : minHeight;
                    index            = zCur * Width + xCur;
                    heightmap[index] = adjHeight;
                }
            }
            //heightmap = hMap;
        }