/*
 * Copyright 2014 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.core.world.generator.facetProviders;

import org.terasology.math.TeraMath;
import org.terasology.math.geom.Vector2f;
import org.terasology.utilities.procedural.BrownianNoise;
import org.terasology.utilities.procedural.PerlinNoise;
import org.terasology.utilities.procedural.SubSampledNoise;
import org.terasology.world.generation.Border3D;
import org.terasology.world.generation.FacetProvider;
import org.terasology.world.generation.GeneratingRegion;
import org.terasology.world.generation.Produces;
import org.terasology.world.generation.facets.SurfaceHumidityFacet;

/**
 * @author Immortius
 */
@Produces(SurfaceHumidityFacet.class)
public class PerlinHumidityProvider implements FacetProvider {
    private static final int SAMPLE_RATE = 4;

    private SubSampledNoise humidityNoise;

    @Override
    public void setSeed(long seed) {
        humidityNoise = new SubSampledNoise(new BrownianNoise(new PerlinNoise(seed + 6), 8), new Vector2f(0.0005f, 0.0005f), SAMPLE_RATE);
    }

    @Override
    public void process(GeneratingRegion region) {
        Border3D border = region.getBorderForFacet(SurfaceHumidityFacet.class);
        SurfaceHumidityFacet facet = new SurfaceHumidityFacet(region.getRegion(), border);

        float[] noise = humidityNoise.noise(facet.getWorldRegion());
        for (int i = 0; i < noise.length; ++i) {
            noise[i] = TeraMath.clamp((noise[i] * 2.11f + 1f) * 0.5f);
        }
        facet.set(noise);
        region.setRegionFacet(SurfaceHumidityFacet.class, facet);
    }
}

@@ -651,16 +651,62 @@
 iders;%0A%0A
+import org.terasology.entitySystem.Component;%0A
 import o
@@ -776,16 +776,70 @@
 ctor2f;%0A
+import org.terasology.rendering.nui.properties.Range;%0A
 import o
@@ -1092,16 +1092,28 @@
 eration.
+Configurable
 FacetPro
@@ -1305,25 +1305,75 @@
 %0A * 
-@author Immortius
+Defines surface humidity in the range %5B0..1%5D based on random noise.
 %0A */
@@ -1458,16 +1458,28 @@
 lements 
+Configurable
 FacetPro
@@ -1585,191 +1585,177 @@
     
-@Override%0A    public void setSeed(long seed) %7B%0A        humidityNoise = new SubSampledNoise(new BrownianNoise(new PerlinNoise(seed + 6), 8), new Vector2f(0.0005f, 0.0005f), SAMPLE_RATE
+private Configuration config = new Configuration();%0A%0A    private long seed;%0A%0A    @Override%0A    public void setSeed(long seed) %7B%0A        this.seed = seed;%0A        reload(
 );%0A 
@@ -2293,11 +2293,1006 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public String getConfigurationName() %7B%0A        return %22Humidity%22;%0A    %7D%0A%0A    @Override%0A    public Component getConfiguration() %7B%0A        return config;%0A    %7D%0A%0A    @Override%0A    public void setConfiguration(Component configuration) %7B%0A        this.config = (Configuration) configuration;%0A        reload();%0A    %7D%0A%0A    private void reload() %7B%0A        float realScale = config.scale * 0.01f;%0A        Vector2f scale = new Vector2f(realScale, realScale);%0A        BrownianNoise brown = new BrownianNoise(new PerlinNoise(seed + 6), config.octaves);%0A        humidityNoise = new SubSampledNoise(brown, scale, SAMPLE_RATE);%0A    %7D%0A%0A    private static class Configuration implements Component %7B%0A        @Range(min = 0, max = 10.0f, increment = 1f, precision = 0, description = %22The number of noise octaves%22)%0A        private int octaves = 8;%0A%0A        @Range(min = 0.01f, max = 5f, increment = 0.01f, precision = 2, description = %22The noise scale%22)%0A        private float scale = 0.05f;%0A    %7D
 %0A%7D%0A

Make humidity provider configurable