public override void generate(ErosionOptions?erosionOptions, int time, float waterAmount)
    {
        terrainHeightmap = new Heightmap(width, height);

        for (int x = 0; x < this.width; x++)
        {
            for (int y = 0; y < this.width; y++)
            {
                terrainHeightmap.setHeight(x, y, this.terrainGenerator.GetHeight(x, y));
            }
        }

        enableErosion = erosionOptions.HasValue;
        if (enableErosion)
        {
            this.erosionOptions = erosionOptions.Value;
        }

        applyWaterEffects(time, waterAmount);
        createFinalHeightmaps(waterAmount);
    }
Example #2
0
    /**
     * Generate and create terrain
     */
    void generateTerrain()
    {
        TerrainData groundTerrainData = this.groundTerrain.terrainData;
        TerrainData waterTerrainData  = this.waterTerrain.terrainData;

        setTerrainObjects();

        int res  = (int)(Mathf.Pow(2, this.simulationSize - resolution + 1) + 1f);
        int size = res * 2 * (int)Mathf.Pow(2f, resolution - 1);

        ATerrainGenerator generator = this.getTerrainGenerator(this.terrainGenerator,
                                                               numberFromString(this.generationSeed));
        ATerrainModifier modifier;

        // Which terrain modifier should be used, finite or infinite?
        if (this.useInfiniteModifier)
        {
            modifier = new OptimizedInfiniteModifier(generator);
        }
        else
        {
            modifier = new OptimizedFiniteModifier(generator);
        }

        modifier.setScale(Mathf.Pow(2f, resolution - 1));

        // Instantiate the erosion options if we are going to visualize the erosions
        ErosionOptions?erosionOptions = null;

        if (this.visualizeErosion)
        {
            erosionOptions = new ErosionOptions {
                rainAmount            = rainAmount,
                solubility            = solubility,
                evaporation           = evaporation,
                sedimentCapacity      = sedimentCapacity,
                generations           = generations,
                erosionsPerGeneration = erosionsPerGeneration
            };
        }

        // Start stopwatch to time the process
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        // Generate the heightmap itself
        TerrainMerger terrainMerger = new TerrainMerger(modifier, res, mapSplits);

        terrainMerger.generate(erosionOptions, time - resolution + 1, waterAmount);

        this.groundHeightmap = terrainMerger.getTerrainHeightmap();
        this.waterHeightmap  = terrainMerger.getWaterHeightmap();
        this.erosionMap      = terrainMerger.getErosionHeightmap();
        this.waterflowMap    = terrainMerger.getWaterflowHeightmap();

        this.updateTerrainVisualization();

        // Stop stopwatch and show total processing time.
        sw.Stop();
        float totalTime = (float)Math.Round(sw.ElapsedMilliseconds / 10f) / 100f;
        int   s         = res - 1;

        Debug.Log("Finished in " + totalTime + "s on (" + s + "x" + s + ") with res of " + resolution);
    }