Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add temperature and humidity values to biome #8

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
1 change: 0 additions & 1 deletion src/main/java/org/terasology/core/world/CoreBiome.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ public String getDisplayName() {
public String toString() {
return this.displayName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ public void process(GeneratingRegion region) {
float hum = temp * humidityFacet.get(pos);
float height = heightFacet.get(pos);

if (height <= seaLevel) {
if (height <= seaLevel || hum >= .85) { // TODO: remove hum qualifier here and for ocean?
biomeFacet.set(pos, CoreBiome.OCEAN);
} else if (height <= seaLevel + 2) {
} else if (height <= seaLevel + 2 || hum >= .8) {
biomeFacet.set(pos, CoreBiome.BEACH);
} else if (temp >= 0.5f && hum < 0.3f) {
} else if (hum <= 0.15f) {
biomeFacet.set(pos, CoreBiome.DESERT);
} else if (hum >= 0.3f && hum <= 0.6f && temp >= 0.5f) {
} else if (hum <= 0.6f && temp >= 0.20f) {
biomeFacet.set(pos, CoreBiome.PLAINS);
} else if (temp <= 0.3f && hum > 0.5f) {
} else if (hum >= .55f && temp <= 0.05f) {
biomeFacet.set(pos, CoreBiome.SNOW);
} else if (hum >= 0.2f && hum <= 0.6f && temp < 0.5f) {
} else if (hum <= .45f && temp <= .15f) {
biomeFacet.set(pos, CoreBiome.MOUNTAINS);
} else {
biomeFacet.set(pos, CoreBiome.FOREST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import org.terasology.entitySystem.Component;
import org.terasology.math.TeraMath;
import org.terasology.math.geom.BaseVector2i;
import org.terasology.math.geom.Rect2i;
import org.terasology.math.geom.Vector2f;
import org.terasology.nui.properties.Range;
import org.terasology.utilities.procedural.BrownianNoise;
Expand Down Expand Up @@ -63,11 +65,13 @@ 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);
Rect2i processRegion = facet.getWorldRegion();
for (BaseVector2i position : processRegion.contents()) {
// clamp to reasonable values (between 0 and 1, since it's relative humidity), just in case
float noiseAdjusted = TeraMath.clamp(humidityNoise.noise(position.x(), position.y()) + .6f, 0f, 1f);
facet.setWorld(position, noiseAdjusted);
}
facet.set(noise);

region.setRegionFacet(SurfaceHumidityFacet.class, facet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package org.terasology.core.world.generator.facetProviders;

import org.terasology.math.TeraMath;
import org.terasology.math.geom.BaseVector2i;
import org.terasology.math.geom.Rect2i;
import org.terasology.math.geom.Vector2f;
import org.terasology.utilities.procedural.BrownianNoise;
import org.terasology.utilities.procedural.SimplexNoise;
Expand All @@ -30,6 +32,7 @@
@Produces(SurfaceTemperatureFacet.class)
public class SimplexSurfaceTemperatureProvider implements FacetProvider {
private static final int SAMPLE_RATE = 4;
private static final float TEMPERATURE_BASE = .25f;

private SubSampledNoise temperatureNoise;

Expand All @@ -41,13 +44,17 @@ public void setSeed(long seed) {
@Override
public void process(GeneratingRegion region) {
SurfaceTemperatureFacet facet = new SurfaceTemperatureFacet(region.getRegion(), region.getBorderForFacet(SurfaceTemperatureFacet.class));
float[] noise = this.temperatureNoise.noise(facet.getWorldRegion());
Rect2i processRegion = facet.getWorldRegion();

for (int i = 0; i < noise.length; ++i) {
noise[i] = TeraMath.clamp((noise[i] * 2.11f + 1f) * 0.5f);
for (BaseVector2i position : processRegion.contents()) {
// modify initial noise to make it closer to temperature base
float noiseAdjusted = this.temperatureNoise.noise(position.x(), position.y()) / 5 + TEMPERATURE_BASE;

// clamp to more reasonable base values, where each value is a Celsuis temperature / 100
noiseAdjusted = TeraMath.clamp(noiseAdjusted, -.45f, .45f);
facet.setWorld(position, noiseAdjusted);
}

facet.set(noise);
region.setRegionFacet(SurfaceTemperatureFacet.class, facet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@
import org.terasology.world.block.BlockManager;
import org.terasology.world.chunks.ChunkConstants;
import org.terasology.world.chunks.CoreChunk;
import org.terasology.world.chunks.blockdata.ExtraBlockDataManager;
import org.terasology.world.chunks.blockdata.ExtraDataSystem;
import org.terasology.world.chunks.blockdata.RegisterExtraData;
import org.terasology.world.generation.Region;
import org.terasology.world.generation.WorldRasterizer;
import org.terasology.world.generation.facets.DensityFacet;
import org.terasology.world.generation.facets.SeaLevelFacet;
import org.terasology.world.generation.facets.SurfaceDepthFacet;
import org.terasology.world.generation.facets.SurfaceHeightFacet;
import org.terasology.world.generation.facets.SurfaceHumidityFacet;
import org.terasology.world.generation.facets.SurfaceTemperatureFacet;

@ExtraDataSystem
public class SolidRasterizer implements WorldRasterizer {

private Block water;
Expand All @@ -44,6 +50,7 @@ public class SolidRasterizer implements WorldRasterizer {
private Block snow;
private Block dirt;
private BiomeRegistry biomeRegistry;
private ExtraBlockDataManager extraBlockDataManager;

@Override
public void initialize() {
Expand All @@ -56,17 +63,25 @@ public void initialize() {
grass = blockManager.getBlock("CoreAssets:Grass");
snow = blockManager.getBlock("CoreAssets:Snow");
dirt = blockManager.getBlock("CoreAssets:Dirt");

extraBlockDataManager = CoreRegistry.get(ExtraBlockDataManager.class);
}

@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
int temperatureSlot = extraBlockDataManager.getSlotNumber("climateConditions.temperature");
int humiditySlot = extraBlockDataManager.getSlotNumber("climateConditions.humidity");

DensityFacet solidityFacet = chunkRegion.getFacet(DensityFacet.class);
SurfaceHeightFacet surfaceFacet = chunkRegion.getFacet(SurfaceHeightFacet.class);
SurfaceDepthFacet surfaceDepthFacet = chunkRegion.getFacet(SurfaceDepthFacet.class);
BiomeFacet biomeFacet = chunkRegion.getFacet(BiomeFacet.class);
SeaLevelFacet seaLevelFacet = chunkRegion.getFacet(SeaLevelFacet.class);
int seaLevel = seaLevelFacet.getSeaLevel();

SurfaceHumidityFacet surfaceHumidityFacet = chunkRegion.getFacet(SurfaceHumidityFacet.class);
SurfaceTemperatureFacet surfaceTemperatureFacet = chunkRegion.getFacet(SurfaceTemperatureFacet.class);

Vector2i pos2d = new Vector2i();
for (Vector3i pos : ChunkConstants.CHUNK_REGION) {
pos2d.set(pos.x, pos.z);
Expand Down Expand Up @@ -99,6 +114,11 @@ public void generateChunk(CoreChunk chunk, Region chunkRegion) {
// }
}
}

// extra data has to be an int, so multiply by 1000, convert to int, and
// then convert to float/divide by 1000 once using the block data
chunk.setExtraData(temperatureSlot, pos.x, pos.y, pos.z, (int) (surfaceTemperatureFacet.get(pos.x, pos.z) * 1000));
chunk.setExtraData(humiditySlot, pos.x, pos.y, pos.z, (int) (surfaceHumidityFacet.get(pos.x, pos.z) * 1000));
}
}

Expand Down Expand Up @@ -154,4 +174,13 @@ private Block getSurfaceBlock(int depth, int height,
}
return dirt;
}

@RegisterExtraData(name="climateConditions.humidity", bitSize=16)
public static boolean humidityByBlock(Block block) {
return true;
}
@RegisterExtraData(name="climateConditions.temperature", bitSize=16)
public static boolean temperatureByBlock(Block block) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import org.terasology.core.world.generator.facetProviders.DefaultFloraProvider;
import org.terasology.core.world.generator.facetProviders.DefaultTreeProvider;
import org.terasology.core.world.generator.facetProviders.FlatSurfaceHeightProvider;
import org.terasology.core.world.generator.facetProviders.PerlinHumidityProvider;
import org.terasology.core.world.generator.facetProviders.PerlinSurfaceTemperatureProvider;
import org.terasology.core.world.generator.facetProviders.SeaLevelProvider;
import org.terasology.core.world.generator.facetProviders.SimplexHumidityProvider;
import org.terasology.core.world.generator.facetProviders.SimplexSurfaceTemperatureProvider;
import org.terasology.core.world.generator.facetProviders.SurfaceToDensityProvider;
import org.terasology.core.world.generator.rasterizers.FloraRasterizer;
import org.terasology.core.world.generator.rasterizers.SolidRasterizer;
Expand Down Expand Up @@ -49,8 +49,8 @@ protected WorldBuilder createWorld() {
.addProvider(new SeaLevelProvider(32))
// height of 40 so that it is far enough from sea level so that it doesnt just create beachfront
.addProvider(new FlatSurfaceHeightProvider(40))
.addProvider(new PerlinHumidityProvider())
.addProvider(new PerlinSurfaceTemperatureProvider())
.addProvider(new SimplexSurfaceTemperatureProvider())
.addProvider(new SimplexHumidityProvider())
.addProvider(new BiomeProvider())
.addProvider(new SurfaceToDensityProvider())
.addProvider(new DefaultFloraProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import org.terasology.core.world.generator.facetProviders.DefaultFloraProvider;
import org.terasology.core.world.generator.facetProviders.DefaultTreeProvider;
import org.terasology.core.world.generator.facetProviders.HeightMapSurfaceHeightProvider;
import org.terasology.core.world.generator.facetProviders.PerlinHumidityProvider;
import org.terasology.core.world.generator.facetProviders.PerlinSurfaceTemperatureProvider;
import org.terasology.core.world.generator.facetProviders.SeaLevelProvider;
import org.terasology.core.world.generator.facetProviders.SimplexHumidityProvider;
import org.terasology.core.world.generator.facetProviders.SimplexSurfaceTemperatureProvider;
import org.terasology.core.world.generator.facetProviders.SurfaceToDensityProvider;
import org.terasology.core.world.generator.rasterizers.FloraRasterizer;
import org.terasology.core.world.generator.rasterizers.SolidRasterizer;
Expand Down Expand Up @@ -51,8 +51,8 @@ protected WorldBuilder createWorld() {
.setSeaLevel(16)
.addProvider(new SeaLevelProvider(16))
.addProvider(new HeightMapSurfaceHeightProvider())
.addProvider(new PerlinHumidityProvider())
.addProvider(new PerlinSurfaceTemperatureProvider())
.addProvider(new SimplexSurfaceTemperatureProvider())
.addProvider(new SimplexHumidityProvider())
.addProvider(new BiomeProvider())
.addProvider(new SurfaceToDensityProvider())
.addProvider(new DefaultFloraProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import org.terasology.core.world.generator.facetProviders.BiomeProvider;
import org.terasology.core.world.generator.facetProviders.DefaultFloraProvider;
import org.terasology.core.world.generator.facetProviders.DefaultTreeProvider;
import org.terasology.core.world.generator.facetProviders.PlateauProvider;
import org.terasology.core.world.generator.facetProviders.PerlinBaseSurfaceProvider;
import org.terasology.core.world.generator.facetProviders.PerlinHillsAndMountainsProvider;
import org.terasology.core.world.generator.facetProviders.PerlinHumidityProvider;
import org.terasology.core.world.generator.facetProviders.PerlinOceanProvider;
import org.terasology.core.world.generator.facetProviders.PerlinRiverProvider;
import org.terasology.core.world.generator.facetProviders.PerlinSurfaceTemperatureProvider;
import org.terasology.core.world.generator.facetProviders.PlateauProvider;
import org.terasology.core.world.generator.facetProviders.SeaLevelProvider;
import org.terasology.core.world.generator.facetProviders.SimplexHumidityProvider;
import org.terasology.core.world.generator.facetProviders.SimplexSurfaceTemperatureProvider;
import org.terasology.core.world.generator.facetProviders.SurfaceToDensityProvider;
import org.terasology.core.world.generator.rasterizers.FloraRasterizer;
import org.terasology.core.world.generator.rasterizers.SolidRasterizer;
Expand Down Expand Up @@ -68,12 +68,12 @@ protected WorldBuilder createWorld() {
return new WorldBuilder(worldGeneratorPluginLibrary)
.setSeaLevel(seaLevel)
.addProvider(new SeaLevelProvider(seaLevel))
.addProvider(new PerlinHumidityProvider())
.addProvider(new PerlinSurfaceTemperatureProvider())
.addProvider(new PerlinBaseSurfaceProvider())
.addProvider(new PerlinRiverProvider())
.addProvider(new PerlinOceanProvider())
.addProvider(new PerlinHillsAndMountainsProvider())
.addProvider(new SimplexSurfaceTemperatureProvider())
.addProvider(new SimplexHumidityProvider())
.addProvider(new BiomeProvider())
.addProvider(new SurfaceToDensityProvider())
.addProvider(new DefaultFloraProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import org.terasology.core.world.generator.facetProviders.DefaultFloraProvider;
import org.terasology.core.world.generator.facetProviders.DefaultTreeProvider;
import org.terasology.core.world.generator.facetProviders.PlateauProvider;
import org.terasology.core.world.generator.facetProviders.SeaLevelProvider;
import org.terasology.core.world.generator.facetProviders.SimplexBaseSurfaceProvider;
import org.terasology.core.world.generator.facetProviders.SimplexHillsAndMountainsProvider;
import org.terasology.core.world.generator.facetProviders.SimplexHumidityProvider;
import org.terasology.core.world.generator.facetProviders.SimplexOceanProvider;
import org.terasology.core.world.generator.facetProviders.SimplexRiverProvider;
import org.terasology.core.world.generator.facetProviders.SimplexSurfaceTemperatureProvider;
import org.terasology.core.world.generator.facetProviders.SeaLevelProvider;
import org.terasology.core.world.generator.facetProviders.SurfaceToDensityProvider;
import org.terasology.core.world.generator.rasterizers.FloraRasterizer;
import org.terasology.core.world.generator.rasterizers.SolidRasterizer;
Expand Down