void Smooth_Corner(ChunkHeightMap target, ChunkHeightMap MapLB, ChunkHeightMap MapCur, int border)
        {
            Debug.Assert(border < m_World.Section_Width);
            Debug.Assert(border < m_World.Section_Depth);

            int   x, z;
            float y;

            float tx, tz;
            float noise;

            for (x = 0; x < border; ++x)
            {
                for (z = 0; z < border; ++z)
                {
                    tx = (x + 1) / (float)(border);
                    tz = (z + 1) / (float)(border);

                    y = Mathf.Lerp(MapLB[x, z].Height, MapCur[x, z].Height, tx);
                    y = Mathf.Lerp(y, MapCur[x, z].Height, tz);

                    //compute border
                    noise = m_NoiseMaker.Make_2D(target.PivotLB + new Vector2(x, z), m_BorderNoise);

                    target.SetHeight(x, z, (int)y);
                    target.SetLayer(x, z, (noise > 0.5f ? MapCur[x, z].Layer : MapLB[x, z].Layer));
                }
            }
        }
Exemple #2
0
        public void CreateVoxel()
        {
            ChunkHeightMap heightMap = m_Chunk.HeightMap;
            // LayerData layerData = m_Chunk.GetBiome().Layer;

            int BaseAltitude = m_SecInWorld.ToSectionInChunk().Value *m_World.Section_Height;

            m_Voxel.Make(heightMap, BaseAltitude);
        }
        public ChunkHeightMap GetBlendedHeightMap(Vector2Int ChunkInWorld)
        {
            Biome BiomeNow        = m_BiomeMng.GetBiome(ChunkInWorld);
            Biome BiomeLeft       = m_BiomeMng.GetBiome(ChunkInWorld + Vector2Int.left);
            Biome BiomeBottom     = m_BiomeMng.GetBiome(ChunkInWorld + Vector2Int.down);
            Biome BiomeLeftBottom = m_BiomeMng.GetBiome(ChunkInWorld + Vector2Int.down + Vector2Int.left);

            //all biome are the same
            if (BiomeNow == BiomeLeft && BiomeNow == BiomeBottom && BiomeNow == BiomeLeftBottom)
            {
                return(GetHeightMap(ChunkInWorld));
            }

            else
            {
                //Get a cloned Height Map;
                ChunkHeightMap mapBlended = new ChunkHeightMap(GetHeightMap(ChunkInWorld));

                //blend with left heightmap
                if (BiomeNow != BiomeLeft)
                {
                    ChunkHeightMap mapLeft = GetHeightMap(ChunkInWorld + Vector2Int.left);
                    Smooth_X(mapBlended, mapLeft, mapBlended, m_Border);
                }

                //blend with bottom heightmap
                if (BiomeNow != BiomeBottom)
                {
                    ChunkHeightMap mapBottom = GetHeightMap(ChunkInWorld + Vector2Int.down);
                    Smooth_Z(mapBlended, mapBottom, mapBlended, m_Border);
                }


                //blend with Left bottom heightmap
                if (BiomeNow == BiomeLeft && BiomeBottom == BiomeLeftBottom)
                {
                    return(mapBlended);
                }

                else if (BiomeNow == BiomeBottom && BiomeLeft == BiomeLeftBottom)
                {
                    return(mapBlended);
                }
                else
                {
                    ChunkHeightMap mapLeftBottom = GetHeightMap(ChunkInWorld + Vector2Int.left + Vector2Int.down);

                    Smooth_Corner(mapBlended, mapLeftBottom, mapBlended, m_Border);
                }

                return(mapBlended);
            }
        }
        public ChunkHeightMap GetHeightMap(Vector2Int ChunkInWorld)
        {
            if (m_MapCache.TryGetValue(ChunkInWorld, out var _map))
            {
                return(_map);
            }
            else
            {
                _map = new ChunkHeightMap(m_World.Section_Width, m_World.Section_Depth, ChunkInWorld);
                m_MapCache.Put(ChunkInWorld, _map);

                Biome biome = m_BiomeMng.GetBiome(ChunkInWorld);

                _map.GenerateNormal(biome, m_NoiseMaker, m_Octave);

                return(_map);
            }
        }
        void Smooth_Z(ChunkHeightMap target, ChunkHeightMap first, ChunkHeightMap second, int border)
        {
            Debug.Assert(border < m_World.Section_Depth);

            int   x, y, z;
            float noise;

            for (x = 0; x < m_World.Section_Width; ++x)
            {
                for (z = 0; z < border; ++z)
                {
                    //compute height
                    y = (int)Mathf.Lerp(first[x, z].Height, second[x, z].Height, (z + 1) / (float)(border));

                    //compute border
                    noise = m_NoiseMaker.Make_2D(second.PivotLB + new Vector2(x, z), m_BorderNoise);

                    target.SetHeight(x, z, y);
                    target.SetLayer(x, z, (noise > 0.5f ? first[x, z].Layer : second[x, z].Layer));
                }
            }
        }
        public void SetLocation(ChunkInWorld chunkInWorld)
        {
            GSW.RestartTimer();
            //Set Location
            m_ChunkinWorld          = chunkInWorld;
            transform.localPosition = m_ChunkinWorld.ToCoord3D(m_World);

            //Set Name
            transform.name = "Chunk" + "[" + m_ChunkinWorld.Value.x + "]" + "[" + m_ChunkinWorld.Value.y + "]";

            //Compute Unity Position
            m_Coord = chunkInWorld.ToCoord2DInt(m_World);

            //create Height map

            m_HeightMap
                = MonoSingleton <GameSystem> .Instance.WorldMngIns.GetComponent <MapMaker>().GetBlendedHeightMap(m_ChunkinWorld.Value);

            // = MonoSingleton<GameSystem>.Instance.WorldMngIns.GetComponent<BiomeMng>().MakeHeightMap(m_ChunkinWorld.Value);
            //Create Sections
            InitAllSections();

            //StartCoroutine("CreCreateAllSections_Corou");
        }
Exemple #7
0
        public ChunkHeightMap(ChunkHeightMap Other)
        {
            Width        = Other.Width;
            Depth        = Other.Depth;
            ChunkInWorld = Other.ChunkInWorld;
            PivotLB      = new Vector2Int(ChunkInWorld.x * Width, ChunkInWorld.y * Depth);

            m_MapData = new HeightUnit[Width, Depth];


            //Save Max and Min Altitude of This Chunk
            MaxAltitude = Other.MaxAltitude;
            MinAltitude = Other.MinAltitude;

            int i, j;

            for (i = 0; i < Width; ++i)
            {
                for (j = 0; j < Depth; ++j)
                {
                    m_MapData[i, j] = Other[i, j];
                }
            }
        }
        public void Make(ChunkHeightMap heightMap, int BaseAltitude)
        {
            //lock (m_LockObj)
            {
                //init blockType
                int   x, y, z;
                Block TargetBlock;
                //Biome biome;

                for (x = 0; x < m_World.Section_Width; x++)
                {
                    for (y = 0; y < m_World.Section_Height; y++)
                    {
                        for (z = 0; z < m_World.Section_Depth; z++)
                        {
                            TargetBlock = heightMap[x, z].Layer == null
                                ? null : heightMap[x, z].Layer.GetBlock(y + BaseAltitude, heightMap[x, z].Height);

                            m_Voxel[x, y, z] = (TargetBlock == null) ? byte.MinValue : TargetBlock.ID;
                        }
                    }
                }
            }
        }