public int landmassTypes;          //  1,2,4,8...

        public TerrainInfo(int globX, int globZ, Terrain ter, Vector3 newPos)
        {
            newPosition = newPos;
            globalX     = globX;
            globalZ     = globZ;
            terrain     = ter;
            string key = globalX.ToString() + "_" + globalZ.ToString();

            landmassTypes = InfiniteTerrain.GetOrAssignLandMassTypes(key);
            SetParameters();
        }
示例#2
0
//
    public static int HasLandmassType(string key, int typeInt)
    {
        int  massType = InfiniteTerrain.GetOrAssignLandMassTypes(key);
        bool is1      = false;

        switch (typeInt)
        {
        case 1:
            if (((massType & 1) > 0))                     // hills
            {
                is1 = true;
            }
            break;

        case 2:
            if (((massType & 2) > 0))                     // mountains
            {
                is1 = true;
            }
            break;

        case 4:
            if (((massType & 4) > 0))                     // ridged mountains
            {
                is1 = true;
            }
            break;

        case 8:
            if (((massType & 8) > 0))                     /// plains
            {
                is1 = true;
            }
            break;
        }

        if (is1 == true)
        {
            return(1);
        }
        else
        {
            return(0);
        }
    }
示例#3
0
    private void FillTerrainPatch()
    {
        int   hRes  = InfiniteTerrain.m_heightMapSize;
        float ratio = (float)InfiniteTerrain.m_landScapeSize / (float)hRes;
        float z0    = (InfiniteLandscape.initialGlobalIndexZ * (InfiniteTerrain.m_heightMapSize - 1)) * ratio;
        float z1    = (InfiniteLandscape.initialGlobalIndexZ * (InfiniteTerrain.m_heightMapSize - 1)) * ratio + hRes * ratio;
        float y0    = 0.0f;
        float y1    = 1.0f;

        bool plainsExist          = false;
        bool hillsExist           = false;
        bool mountainsExist       = false;
        bool ridgedMountainsExist = false;

        string key      = globalTileX.ToString() + "_" + globalTileZ.ToString();
        int    massType = InfiniteTerrain.GetOrAssignLandMassTypes(key);


        if ((massType & 1) > 0)
        {
            hillsExist = true;
        }
        if ((massType & 2) > 0)
        {
            mountainsExist = true;
        }
        if ((massType & 4) > 0)
        {
            ridgedMountainsExist = true;
        }
        if ((massType & 8) > 0)
        {
            plainsExist = true;
        }

        for (int z = h0; z < h1; z++)
        {
            float worldPosZ = (z + globalTileZ * (InfiniteTerrain.m_heightMapSize - 1)) * ratio;
            float hx        = Mathf.Clamp((y1 - y0) / (z1 - z0) * (worldPosZ - z0) + y1, -4, 8);

            for (int x = 0; x < hRes; x++)
            {
                float worldPosX = (x + globalTileX * (InfiniteTerrain.m_heightMapSize - 1)) * ratio;
                float sum       = 0;

                /* // very small hills
                 * if (hillsExist)
                 * {
                 *      //float hills = m_mountainNoise.FractalNoise2D(worldPosX, worldPosZ, 1, 100, 0.02f) + 0.01f; // good small bumpy thing
                 *      // makes "brain" bumps, that look odd from top
                 *      //float hills = -(m_mountainNoiseRidged.FractalNoise2D(worldPosX, worldPosZ, 1, 100, 0.01f)) + 0.005f; // flipped small ridge
                 *      float hills = -(m_mountainNoiseRidged.FractalNoise2D(worldPosX, worldPosZ, 6, 250, 0.015f)); // flipped small ridge
                 *      //hills = 0.2f; // for testing falloff map ignore noise
                 *      hills = BlendLandmass(hills, x, z, key, 1);
                 *      sum += hills;
                 * }
                 */

                // TEST - unnaturally steep transition, otherwise cool

                /*
                 * if (hillsExist)
                 * {
                 *      float hills = -(m_mountainNoiseRidged.FractalNoise2D(worldPosX, worldPosZ, 6, 250, 0.015f)); // flipped small ridge
                 *
                 *      if(hills < testMin ) testMin = hills;
                 *      if (hills > testMax) testMax = hills;
                 *
                 *      // varies somewhere  between -20 and 10 when x 1000
                 *
                 *      if (hills*1000 < 0f)
                 *      {
                 *              hills = -20f/1000f;
                 *      }
                 *      hills = BlendLandmass(hills, x, z, key, 1);
                 *      sum += hills;
                 * }
                 */



                // produces "fjord" like valleys with  plateau tops
                if (hillsExist)
                {
                    float hills = m_mountainNoise.FractalNoise2D(worldPosX, worldPosZ, 1, 500, 1);
                    //if (hills < testMin) testMin = hills;
                    //if (hills > testMax) testMax = hills;

                    hills  = InfiniteTerrain.StaticTestCurve.Evaluate(hills);
                    hills /= 10;
                    hills += 0.01f;                     // to rse it somewhat above sea level

                    // small bumps
                    float hills2 = -(m_mountainNoiseRidged.FractalNoise2D(worldPosX, worldPosZ, 6, 100, 0.002f));                     // flipped small ridge
                    hills += hills2;
                    hills  = BlendLandmass(hills, x, z, key, 1);

                    sum += hills;
                }



                // exiting but unrealistic maze like formation
                // effect depend on the  animation curve

                /*
                 * if (hillsExist)
                 * {
                 *      float hills = m_mountainNoise.FractalNoise2D(worldPosX, worldPosZ, 1, 100, 1);
                 *      if (hills < testMin) testMin = hills;
                 *      if (hills > testMax) testMax = hills;
                 *
                 *      hills = InfiniteTerrain.StaticTestCurve.Evaluate(hills);
                 *
                 *      hills /= 20;
                 *
                 *      hills = BlendLandmass(hills, x, z, key, 1);
                 *
                 *      sum += hills;
                 * }
                 */

                if (mountainsExist)
                {
                    float mountainsPerlin = m_mountainNoise.FractalNoise2D(worldPosX, worldPosZ, 4, 3000, 0.4f);
                    //mountainsPerlin = 0.2f; // for testing falloff map ignore noise
                    mountainsPerlin = BlendLandmass(mountainsPerlin, x, z, key, 2);
                    sum            += mountainsPerlin;
                }

                if (ridgedMountainsExist)
                {
                    float mountainsRidged = m_mountainNoiseRidged.FractalNoise2D(worldPosX, worldPosZ, 4, 3000, 0.2f);
                    //mountainsRidged = 0.2f; // for testing falloff map ignore noise
                    float accentHills = m_mountainNoise.FractalNoise2D(worldPosX, worldPosZ, 1, 100, 0.005f);                     // good small bumpy thing
                    //accentHills = 0f; // for testing falloff map ignore noise
                    mountainsRidged += accentHills;
                    mountainsRidged  = BlendLandmass(mountainsRidged, x, z, key, 4);
                    sum             += mountainsRidged;
                }

                if (plainsExist)
                {
                    float plains = m_mountainNoise.FractalNoise2D(worldPosX, worldPosZ, 4, 9000, 0.1f) + 0.05f; //

                    plains = 0.01f;                                                                             // for testing falloff map ignore noise

                    plains = BlendLandmass(plains, x, z, key, 8);
                    sum   += plains;
                }

                // for debugging textures, create flat surfacce
                //sum = 0.04f;

                float height = (sum) + 0.003f * hx;
                InfiniteTerrain.m_terrainHeights[z, x] = height;
            }
        }

        //Debug.Log( testMin + " - " + testMax );
    }
    protected override void Update()
    {
        base.Update();

        /*
         * //-------Just debugging--------
         * if(updateRound)
         * {
         *      // previous was updateRound
         *      float executionTime = Time.time - StartTime;
         *      //Debug.Log(updatecounter + ": ----------------------------------------> Execution time " + executionTime);
         *      updateRound = false;
         * }
         * updateRound = updateLandscape;
         * StartTime = Time.deltaTime;
         * //--------Just debugging ends -------
         */

        if (updateLandscape == true)
        {
            m_terrainGrid[curCyclicIndexX, curCyclicIndexZ].GetComponent <Collider>().enabled = true;        //Slow operation

            // for displaying data in UI:
            Terrain current = m_terrainGrid[curCyclicIndexX, curCyclicIndexZ];
            //Debug.Log("-------> entering " + current.name);

            terrainName.text = current.name;
            int massType = InfiniteTerrain.GetOrAssignLandMassTypes(current.name);

            hillsValue.text           = (massType & 1) > 0 ? "yes": "no";
            mountainsValue.text       = (massType & 2) > 0 ? "yes": "no";
            ridgedMountainsValue.text = (massType & 4) > 0 ? "yes" : "no";
            plainsValue.text          = (massType & 8) > 0 ? "yes" : "no";

            m_terrainGrid[prevCyclicIndexX, prevCyclicIndexZ].GetComponent <Collider>().enabled = false;

            UpdateTerrainNeighbors();
            UpdateTerrainPositions();
        }

        if (PatchManager.patchQueue.Count != 0)
        {
            terrainIsFlushed = false;
            if (patchIsFilling == false)
            {
                patchToBeFilled = PatchManager.patchQueue.Dequeue();
                StartCoroutine(CountdownForPatch());
            }
            if (patchToBeFilled != null)
            {
                //float execTime = Time.time - oneUpdateTime;

                /*
                 * if(patchToBeFilled is TerrainPatch)
                 * Debug.Log( execTime + "     Executed TerrainPatch...");
                 * if (patchToBeFilled is SplatDetailPatch)
                 * Debug.Log(execTime + "     Executed SplatDetailPatch...");
                 * if (patchToBeFilled is TreePatch)
                 * Debug.Log(execTime + "     Execute TreePatch...");
                 */

                /*
                 * if(execTime > 0.1f)
                 * {
                 * Debug.Log(Time.time +  "------------------> exec time " + execTime);
                 * }
                 */

                //for debugging
                //oneUpdateTime = Time.time;

                patchToBeFilled.ExecutePatch();
                patchToBeFilled = null;
            }
        }
        else if (PatchManager.patchQueue.Count == 0 && terrainIsFlushed == false)
        {
            StartCoroutine(FlushTerrain());
            terrainIsFlushed = true;
        }
    }