add climate controls for temperature and moisture ranges

This commit is contained in:
dags- 2020-03-19 09:41:56 +00:00
parent d336a77cef
commit 04a85e8ea0
6 changed files with 138 additions and 10 deletions

View File

@ -0,0 +1,54 @@
package com.terraforged.core.settings;
import com.terraforged.core.util.serialization.annotation.Comment;
import com.terraforged.core.util.serialization.annotation.Range;
import com.terraforged.core.util.serialization.annotation.Serializable;
import me.dags.noise.Module;
import me.dags.noise.Source;
@Serializable
public class ClimateSettings {
public RangeValue moisture = new RangeValue(0, 1F);
public RangeValue temperature = new RangeValue(0, 1F);
@Serializable
public static class RangeValue {
@Range(min = 0F, max = 1F)
@Comment("The lower limit of the range")
public float min;
@Range(min = 0F, max = 1F)
@Comment("The upper limit of the range")
public float max;
public RangeValue() {
this(0, 1);
}
public RangeValue(float min, float max) {
this.min = min;
this.max = max;
}
public float getMin() {
return Math.min(min, max);
}
public float getMax() {
return Math.max(min, max);
}
public Module clamp(Module module) {
float min = getMin();
float max = getMax();
float range = max - min;
if (range == 0) {
return Source.constant(min);
}
return module.scale(range).bias(min);
}
}
}

View File

@ -32,6 +32,8 @@ public class Settings {
public GeneratorSettings generator = new GeneratorSettings();
public ClimateSettings climate = new ClimateSettings();
public RiverSettings rivers = new RiverSettings();
public FilterSettings filters = new FilterSettings();

View File

@ -50,7 +50,7 @@ public class Climate {
private final ClimateModule biomeNoise;
public Climate(GeneratorContext context) {
this.biomeNoise = new ClimateModule(context.seed, context.settings.generator);
this.biomeNoise = new ClimateModule(context.seed, context.settings);
this.treeLine = Source.perlin(context.seed.next(), context.settings.generator.biome.biomeSize * 2, 1)
.scale(0.1).bias(0.4);

View File

@ -26,7 +26,7 @@
package com.terraforged.core.world.climate;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.settings.GeneratorSettings;
import com.terraforged.core.settings.Settings;
import com.terraforged.core.util.Seed;
import com.terraforged.core.world.biome.BiomeType;
import com.terraforged.core.world.terrain.Terrain;
@ -51,8 +51,8 @@ public class ClimateModule {
private final Module moisture;
private final Module temperature;
public ClimateModule(Seed seed, GeneratorSettings settings) {
int biomeSize = settings.biome.biomeSize;
public ClimateModule(Seed seed, Settings settings) {
int biomeSize = settings.generator.biome.biomeSize;
// todo - better solution (reduces the amount that temp/moist grows with biome size)
int tempScaler = biomeSize > 500 ? 8 : 10;
@ -63,23 +63,25 @@ public class ClimateModule {
int temperatureSize = tempScaler * biomeSize;
int moistScale = NoiseUtil.round(moistureSize * biomeFreq);
int tempScale = NoiseUtil.round(temperatureSize * biomeFreq);
int warpScale = settings.biome.biomeWarpScale;
int warpScale = settings.generator.biome.biomeWarpScale;
this.seed = seed.next();
this.edgeClamp = 1F;
this.edgeScale = 1 / edgeClamp;
this.biomeFreq = 1F / biomeSize;
this.warpStrength = settings.biome.biomeWarpStrength;
this.warpStrength = settings.generator.biome.biomeWarpStrength;
this.warpX = Source.perlin(seed.next(), warpScale, 2).bias(-0.5);
this.warpZ = Source.perlin(seed.next(), warpScale, 2).bias(-0.5);
this.moisture = Source.simplex(seed.next(), moistScale, 2)
.clamp(0.15, 0.85).map(0, 1)
Module moisture = Source.simplex(seed.next(), moistScale, 2).clamp(0.15, 0.85).map(0, 1);
this.moisture = settings.climate.moisture.clamp(moisture)
.warp(seed.next(), moistScale / 2, 1, moistScale / 4D)
.warp(seed.next(), moistScale / 6, 2, moistScale / 12D);
Module temperature = Source.sin(tempScale, Source.constant(0.9)).clamp(0.05, 0.95).map(0, 1);
this.temperature = new Compressor(temperature, 0.1F, 0.2F)
Module temperature = Source.sin(tempScale, Source.constant(0.9))
.clamp(0.05, 0.95).map(0, 1);
this.temperature = new Compressor(settings.climate.temperature.clamp(temperature), 0.1F, 0.2F)
.warp(seed.next(), tempScale * 4, 2, tempScale * 4)
.warp(seed.next(), tempScale, 1, tempScale)
.warp(seed.next(), tempScale / 8, 1, tempScale / 8D);

View File

@ -27,6 +27,7 @@ package com.terraforged.mod.gui;
import com.terraforged.mod.gui.element.TerraButton;
import com.terraforged.mod.gui.element.TerraLabel;
import com.terraforged.mod.gui.page.ClimatePage;
import com.terraforged.mod.gui.page.FeaturePage;
import com.terraforged.mod.gui.page.FilterPage;
import com.terraforged.mod.gui.page.GeneratorPage;
@ -60,6 +61,7 @@ public class SettingsScreen extends OverlayScreen {
this.parent = parent;
this.pages = new Page[]{
new GeneratorPage(settings, preview),
new ClimatePage(settings, preview),
new TerrainPage(settings, preview),
new RiverPage(settings, preview),
new FilterPage(settings, preview),

View File

@ -0,0 +1,68 @@
/*
*
* MIT License
*
* Copyright (c) 2020 TerraForged
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.terraforged.mod.gui.page;
import com.terraforged.core.settings.Settings;
import com.terraforged.mod.gui.OverlayScreen;
import com.terraforged.mod.gui.preview.PreviewPage;
import com.terraforged.mod.util.nbt.NBTHelper;
import net.minecraft.nbt.CompoundNBT;
public class ClimatePage extends BasePage {
private final Settings settings;
private final PreviewPage preview;
private final CompoundNBT climateSettings;
public ClimatePage(Settings settings, PreviewPage preview) {
this.settings = settings;
this.preview = preview;
this.climateSettings = NBTHelper.serialize(settings.climate);
}
@Override
public String getTitle() {
return "Climate Settings";
}
@Override
public void save() {
NBTHelper.deserialize(climateSettings, settings.climate);
}
@Override
public void init(OverlayScreen parent) {
Column center = getColumn(0);
center.scrollPane.setScrollAmount(0D);
addElements(0, 0, center, climateSettings, true, center.scrollPane::addButton, this::update);
}
@Override
protected void update() {
super.update();
preview.apply(settings -> NBTHelper.deserialize(climateSettings, settings.climate));
}
}