Esempio n. 1
0
        private bool CanSeeTheSky(int x, int y, int z, IChunk c)
        {
            int by;

            for (by = y; _blockHelper.Opacity(c.GetType(x, by, z)) == 0 && by < 128; ++by)
            {
                ;
            }

            return(by == 128);
        }
 public void SetNeighbor(FaceDirection direction, IChunk chunk)
 {
     Neighbors[direction] = chunk;
     Dirty = true;
     if (chunk?.Neighbors == null)
     {
         return;
     }
     try
     {
         chunk.Neighbors[General.FlipDirection(direction)] = this; //TODO WHAT THE F**K! F**K THREADS
     }
     catch (Exception e)
     {
         Debug.LogError($"NPE: {chunk?.GetType()} {chunk?.ChunkId}");
     }
 }
Esempio n. 3
0
        private bool CanSeeTheSky(int x, int y, int z, IChunk c)
        {
            int by;
            for (by = y; _blockHelper.Opacity(c.GetType(x, by, z)) == 0 && by < 128; ++by) ;

            return by == 128;
        }
Esempio n. 4
0
        private void GenerateFlora(IChunk c, int x, int z)
        {
            BIOME_TYPE biome = CalcBiomeType(x, z);
            for (int bx = 0; bx < 16; ++bx)
            {
                int worldX = bx + x * 16;
                for (int bz = 0; bz < 16; ++bz)
                {
                    int worldZ = bz + z * 16;
                    for (int by = 64; by < 128; ++by)
                    {
                        int worldY = by;
                        //int index = bx << 11 | bz << 7 | by + 1;

                        if (c.GetType(bx, by, bz) == BlockData.Blocks.Grass && c.GetType(bx, by + 1, bz) == (byte)BlockData.Blocks.Air)
                        {
                            double grassDens = CalcGrassDensity(worldX, worldZ);
                            if (grassDens > 0.0)
                            {
                                // Generate high grass.
                                double rand = _FastRandom.standNormalDistrDouble();
                                if (rand > -0.2 && rand < 0.2)
                                {
                                    c.SetType(bx, by + 1, bz, BlockData.Blocks.TallGrass, false);
                                    c.SetData(bx, by + 1, bz, 1, false);
                                }


                                //Generate flowers.
                                if (_FastRandom.standNormalDistrDouble() < -2)
                                {
                                    if (_FastRandom.randomBoolean())
                                        c.SetType(bx, by + 1, bz, BlockData.Blocks.Rose, false);
                                    else
                                        c.SetType(bx, by + 1, bz, BlockData.Blocks.Yellow_Flower, false);
                                }
                            }

                            if (by < 110 && bx % 4 == 0 && bz % 4 == 0)
                            {
                                double forestDens = CalcForestDensity(worldX, worldZ);

                                if (forestDens > 0.005)
                                {
                                    int randX = bx + _FastRandom.randomInt() % 12 + 4;
                                    int randZ = bz + _FastRandom.randomInt() % 12 + 4;

                                    if (randX < 3)
                                        randX = 3;
                                    else if (randX > 12)
                                        randX = 12;

                                    if (randZ < 3)
                                        randZ = 3;
                                    else if (randZ > 15)
                                        randZ = 12;

                                    if (c.GetType(randX, by, randZ) == BlockData.Blocks.Grass)
                                        GenerateTree(c, randX, by, randZ);
                                    
                                    else if (biome == BIOME_TYPE.DESERT && c.GetType(randX, by, randZ) == BlockData.Blocks.Sand)
                                        GenerateCactus(c, randX, by, randZ);
                                    
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        private void GenerateTerrain(IChunk c, int x, int z)
        {           
            double[, ,] density = new double[17, 129, 17];

            // Build the density map with lower resolution, 4*4*16 instead of 16*16*128
            for (int bx = 0; bx <= 16; bx += 4)
            {
                int worldX = bx + (x * 16);
                for (int bz = 0; bz <= 16; bz += 4)
                {
                    BIOME_TYPE type = CalcBiomeType(x, z);
                    int worldZ = bz + (z * 16);
                    for (int by = 0; by <= 128; by += 8)
                    {
                        density[bx, by, bz] = CalcDensity(worldX, by, worldZ, type);
                    }
                }
            }

            triLerpDensityMap(density);

            for (int bx = 0; bx < 16; bx++)
            {
                int worldX = bx + (x * 16);
                for (int bz = 0; bz < 16; bz++)
                {
                    int worldZ = bz + (z * 16);
                    int firstBlockHeight = -1;

                    BIOME_TYPE type = CalcBiomeType(worldX, worldZ);
                    for (int by = 127; by >= 0; --by)
                    {
                        //int index = bx << 11 | bz << 7 | by;
                        if (by == 0) // First bedrock Layer
                            c.SetType(bx, by, bz, BlockData.Blocks.Bedrock, false);

                        else if (by > 0 && by < 5 && _FastRandom.randomDouble() > 0.3) // Randomly put blocks of the remaining 4 layers of bedrock
                            c.SetType(bx, by, bz, BlockData.Blocks.Bedrock, false);

                        else if (by <= 55)
                            c.SetType(bx, by, bz, BlockData.Blocks.Stone, false);
                        else
                        {
                            if (by > 55 && by < 64)
                            {
                                c.SetType(bx, by, bz, BlockData.Blocks.Still_Water, false);
                                if (by == 63 && type == BIOME_TYPE.SNOW)
                                {
                                    c.SetBiomeColumn(bx, bz, (byte)BIOME_TYPE.SNOW);
                                    c.SetType(bx, by, bz, BlockData.Blocks.Ice, false);
                                }
                            }

                            double dens = density[bx, by, bz];

                            if (dens >= 0.009 && dens <= 0.02)
                            {
                                // Some block was set...
                                if (firstBlockHeight == -1)
                                    firstBlockHeight = by;

                                GenerateOuterLayer(bx, by, bz, firstBlockHeight, type, c);
                            }
                            else if (dens > 0.02)
                            {
                                // Some block was set...
                                if (firstBlockHeight == -1)
                                    firstBlockHeight = by;

                                if (CalcCaveDensity(worldX, by, worldZ) > -0.6)
                                    GenerateInnerLayer(bx, by, bz, type, c);
                            }
                            else
                                firstBlockHeight = -1;
                        }

                        if (c.GetType(bx, by, bz) == BlockData.Blocks.Stone)
                            GenerateResource(bx, by, bz, c);
                    }
                }
            }
        }
Esempio n. 6
0
 static void VerifyWriteToThrow(IChunk chunk) =>
 throw new IOException($"Did not write all bytes: {chunk.GetType().FullName}");
Esempio n. 7
0
        private void GenerateFlora(IChunk c, int x, int z)
        {
            BIOME_TYPE biome = CalcBiomeType(x, z);

            for (int bx = 0; bx < 16; ++bx)
            {
                int worldX = bx + x * 16;
                for (int bz = 0; bz < 16; ++bz)
                {
                    int worldZ = bz + z * 16;
                    for (int by = 64; by < 128; ++by)
                    {
                        int worldY = by;
                        //int index = bx << 11 | bz << 7 | by + 1;

                        if (c.GetType(bx, by, bz) == BlockData.Blocks.Grass && c.GetType(bx, by + 1, bz) == (byte)BlockData.Blocks.Air)
                        {
                            double grassDens = CalcGrassDensity(worldX, worldZ);
                            if (grassDens > 0.0)
                            {
                                // Generate high grass.
                                double rand = _FastRandom.standNormalDistrDouble();
                                if (rand > -0.2 && rand < 0.2)
                                {
                                    c.SetType(bx, by + 1, bz, BlockData.Blocks.TallGrass, false);
                                    c.SetData(bx, by + 1, bz, 1, false);
                                }


                                //Generate flowers.
                                if (_FastRandom.standNormalDistrDouble() < -2)
                                {
                                    if (_FastRandom.randomBoolean())
                                    {
                                        c.SetType(bx, by + 1, bz, BlockData.Blocks.Rose, false);
                                    }
                                    else
                                    {
                                        c.SetType(bx, by + 1, bz, BlockData.Blocks.Yellow_Flower, false);
                                    }
                                }
                            }

                            if (by < 110 && bx % 4 == 0 && bz % 4 == 0)
                            {
                                double forestDens = CalcForestDensity(worldX, worldZ);

                                if (forestDens > 0.005)
                                {
                                    int randX = bx + _FastRandom.randomInt() % 12 + 4;
                                    int randZ = bz + _FastRandom.randomInt() % 12 + 4;

                                    if (randX < 3)
                                    {
                                        randX = 3;
                                    }
                                    else if (randX > 12)
                                    {
                                        randX = 12;
                                    }

                                    if (randZ < 3)
                                    {
                                        randZ = 3;
                                    }
                                    else if (randZ > 15)
                                    {
                                        randZ = 12;
                                    }

                                    if (c.GetType(randX, by, randZ) == BlockData.Blocks.Grass)
                                    {
                                        GenerateTree(c, randX, by, randZ);
                                    }

                                    else if (biome == BIOME_TYPE.DESERT && c.GetType(randX, by, randZ) == BlockData.Blocks.Sand)
                                    {
                                        GenerateCactus(c, randX, by, randZ);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        private void GenerateTerrain(IChunk c, int x, int z)
        {
            double[, ,] density = new double[17, 129, 17];

            // Build the density map with lower resolution, 4*4*16 instead of 16*16*128
            for (int bx = 0; bx <= 16; bx += 4)
            {
                int worldX = bx + (x * 16);
                for (int bz = 0; bz <= 16; bz += 4)
                {
                    BIOME_TYPE type   = CalcBiomeType(x, z);
                    int        worldZ = bz + (z * 16);
                    for (int by = 0; by <= 128; by += 8)
                    {
                        density[bx, by, bz] = CalcDensity(worldX, by, worldZ, type);
                    }
                }
            }

            triLerpDensityMap(density);

            for (int bx = 0; bx < 16; bx++)
            {
                int worldX = bx + (x * 16);
                for (int bz = 0; bz < 16; bz++)
                {
                    int worldZ           = bz + (z * 16);
                    int firstBlockHeight = -1;

                    BIOME_TYPE type = CalcBiomeType(worldX, worldZ);
                    for (int by = 127; by >= 0; --by)
                    {
                        //int index = bx << 11 | bz << 7 | by;
                        if (by == 0) // First bedrock Layer
                        {
                            c.SetType(bx, by, bz, BlockData.Blocks.Bedrock, false);
                        }

                        else if (by > 0 && by < 5 && _FastRandom.randomDouble() > 0.3) // Randomly put blocks of the remaining 4 layers of bedrock
                        {
                            c.SetType(bx, by, bz, BlockData.Blocks.Bedrock, false);
                        }

                        else if (by <= 55)
                        {
                            c.SetType(bx, by, bz, BlockData.Blocks.Stone, false);
                        }
                        else
                        {
                            if (by > 55 && by < 64)
                            {
                                c.SetType(bx, by, bz, BlockData.Blocks.Still_Water, false);
                                if (by == 63 && type == BIOME_TYPE.SNOW)
                                {
                                    c.SetBiomeColumn(bx, bz, (byte)BIOME_TYPE.SNOW);
                                    c.SetType(bx, by, bz, BlockData.Blocks.Ice, false);
                                }
                            }

                            double dens = density[bx, by, bz];

                            if (dens >= 0.009 && dens <= 0.02)
                            {
                                // Some block was set...
                                if (firstBlockHeight == -1)
                                {
                                    firstBlockHeight = by;
                                }

                                GenerateOuterLayer(bx, by, bz, firstBlockHeight, type, c);
                            }
                            else if (dens > 0.02)
                            {
                                // Some block was set...
                                if (firstBlockHeight == -1)
                                {
                                    firstBlockHeight = by;
                                }

                                if (CalcCaveDensity(worldX, by, worldZ) > -0.6)
                                {
                                    GenerateInnerLayer(bx, by, bz, type, c);
                                }
                            }
                            else
                            {
                                firstBlockHeight = -1;
                            }
                        }

                        if (c.GetType(bx, by, bz) == BlockData.Blocks.Stone)
                        {
                            GenerateResource(bx, by, bz, c);
                        }
                    }
                }
            }
        }