Пример #1
0
 public void BuildRain(RainMethod pm, Benchmark bench = null)
 {
     Benchmark.Start(bench, "Rain"); // etc
     if (pm == RainMethod.Equal)
     {
         BuildRainByEqual();
     }
     else if (pm == RainMethod.Noise)
     {
         BuildRainByNoise();
     }
     else if (pm == RainMethod.Wind)
     {
         WindSpawn           ws = WindSpawn.TradeLinear;
         WindRainType        rt = WindRainType.HeatBasedContinuous;
         WindEvaporationType et = WindEvaporationType.WaterAndHeat;
         WindTurnType        wt = WindTurnType.TerrainBased;
         BuildRainByWind(1000, ws, rt, et, wt, bench);
         MapUtil.TransformMapMinMax(ref Rain, MapUtil.dNormalize);
     }
     if (bench != null)
     {
         bench.EndBenchmark("Rain");
     }
 }
Пример #2
0
 public void TurnWind(WindTurnType wt, float[,] Elevation, float seaLevel)
 {
     if (wt == WindTurnType.None)
     {
         // do nothing
     }
     else if (wt == WindTurnType.RandomWalk)
     {
         int r = UnityEngine.Random.Range(-1, 1);
         velocity = new Vec(velocity.x, r);
     }
     else if (wt == WindTurnType.TerrainBased)
     {
         if (Elevation[approxMapLoc.x, approxMapLoc.y] > seaLevel)
         {
             velocity.x -= deltaHeight;
             velocity.y -= deltaHeight;
             Vec    lVec    = velocity.GetRotatedVector(-90);
             Vec    rVec    = velocity.GetRotatedVector(90);
             MapLoc lMapLoc = new MapLoc((int)(Math.Max(1, actualMapLoc.x + lVec.x)), (int)Math.Max(1, actualMapLoc.y + lVec.y));
             MapLoc rMapLoc = new MapLoc((int)(Math.Max(1, actualMapLoc.x + rVec.x)), (int)Math.Max(1, actualMapLoc.y + rVec.y));
             try
             {
                 float fDiff = Elevation[lMapLoc.x, lMapLoc.y] - Elevation[rMapLoc.x, rMapLoc.y];
                 velocity.x += lMapLoc.x * fDiff;
                 velocity.y += lMapLoc.y * fDiff;
             }
             catch
             {
                 // ¯\_(ツ)_/¯
             }
         }
     }
 }
Пример #3
0
 private void BuildRainByWindWorkhorse(ref List <Wind> winds, WindSpawn windSpawn, WindRainType rainType, WindEvaporationType evapType, WindTurnType windTurnType)
 {
     //  Combine Winds at the same location
     CombineWinds(ref winds, windSpawn);
     // Add to WindFlow
     foreach (Wind w in winds)
     {
         WindVectorsList[w.approxMapLoc.x, w.approxMapLoc.y].Add(new Vec(w.velocity.x, w.velocity.y));
     }
     //  Move wind in the direction vector
     foreach (Wind w in winds)
     {
         w.Blow(Elevation, Temperature);
     }
     //  If the wind moves off the map, remove it
     RemoveOffWindMaps(ref winds);
     //  Rain
     foreach (Wind w in winds)
     {
         w.Rain(rainType, ref Rain, Elevation, seaLevel);
     }
     // Evaporate
     foreach (Wind w in winds)
     {
         w.Evaporate(evapType, Elevation, Temperature, seaLevel);
     }
     // Turn Wind
     foreach (Wind w in winds)
     {
         w.TurnWind(windTurnType, Elevation, seaLevel);
     }
 }
Пример #4
0
    private void BuildRainByWind(int maxIter, WindSpawn windSpawn, WindRainType rainType, WindEvaporationType evapType, WindTurnType windTurnType, Benchmark bench = null)
    {
        Benchmark.Start(bench, "Wind");
        List <Wind> winds = new List <Wind>();

        for (int x = 0; x < xDim; x++)
        {
            for (int y = 0; y < yDim; y++)
            {
                WindVectorsList[x, y] = new List <Vec>();
                Wind w = new Wind(x, y, Elevation, windSpawn);
                WindVectorsList[x, y].Add(new Vec(w.velocity.x, w.velocity.y));
                winds.Add(w);
            }
        }
        int iter          = 0;
        int numberOfWinds = winds.Count;

        while (iter < maxIter)
        {
            numberOfWinds = winds.Count;
            if (numberOfWinds == 0)
            {
                break;
            }
            else
            {
                BuildRainByWindWorkhorse(ref winds, windSpawn, rainType, evapType, windTurnType);
            }
            iter++;
        }
        MapUtil.TransformMap(ref Rain, MapUtil.dExponentiate, 0.125f);
        TabulateWindflow();
        if (bench != null)
        {
            bench.EndBenchmark("Wind");
        }
    }