- update biome colours

- fix preview map legend info
- added terrain-type display mode
This commit is contained in:
dags- 2020-05-10 10:47:49 +01:00
parent 9786d819b0
commit f4e9e7efe3
4 changed files with 82 additions and 52 deletions

View File

@ -35,6 +35,7 @@ import com.terraforged.core.util.concurrent.ThreadPool;
import com.terraforged.core.util.concurrent.cache.CacheEntry; import com.terraforged.core.util.concurrent.cache.CacheEntry;
import com.terraforged.core.world.GeneratorContext; import com.terraforged.core.world.GeneratorContext;
import com.terraforged.core.world.WorldGeneratorFactory; import com.terraforged.core.world.WorldGeneratorFactory;
import com.terraforged.core.world.heightmap.Levels;
import com.terraforged.core.world.terrain.Terrain; import com.terraforged.core.world.terrain.Terrain;
import com.terraforged.core.world.terrain.Terrains; import com.terraforged.core.world.terrain.Terrains;
import com.terraforged.mod.util.nbt.NBTHelper; import com.terraforged.mod.util.nbt.NBTHelper;
@ -109,6 +110,7 @@ public class Preview extends Button {
RenderSystem.disableRescaleNormal(); RenderSystem.disableRescaleNormal();
updateLegend(mx, my); updateLegend(mx, my);
renderLegend(labels, values, x, y + width, 10, 0xFFFFFF); renderLegend(labels, values, x, y + width, 10, 0xFFFFFF);
} }
@ -130,6 +132,8 @@ public class Preview extends Button {
try { try {
region = task.get(); region = task.get();
render(region); render(region);
} catch (Throwable t) {
t.printStackTrace();
} finally { } finally {
task = null; task = null;
} }
@ -143,8 +147,7 @@ public class Preview extends Button {
} }
RenderMode renderer = previewSettings.mode; RenderMode renderer = previewSettings.mode;
Terrains terrains = Terrains.create(settings); Levels levels = new Levels(settings.generator);
GeneratorContext context = new GeneratorContext(terrains, settings);
int stroke = 2; int stroke = 2;
int width = region.getBlockSize().size; int width = region.getBlockSize().size;
@ -164,8 +167,7 @@ public class Preview extends Button {
if (x < stroke || z < stroke || x >= width - stroke || z >= width - stroke) { if (x < stroke || z < stroke || x >= width - stroke || z >= width - stroke) {
image.setPixelRGBA(x, z, Color.BLACK.getRGB()); image.setPixelRGBA(x, z, Color.BLACK.getRGB());
} else { } else {
Color color = renderer.color(cell, context); image.setPixelRGBA(x, z, renderer.getColor(cell, levels));
image.setPixelRGBA(x, z, RenderMode.rgba(color));
} }
if (z == half) { if (z == half) {
@ -203,19 +205,21 @@ public class Preview extends Button {
.size(FACTOR, 0) .size(FACTOR, 0)
.build(); .build();
return renderer.queue(offsetX, offsetZ, 101 - previewSettings.zoom, true); return renderer.queue(offsetX, offsetZ, 101 - previewSettings.zoom, false);
} }
private void updateLegend(int mx ,int my) { private void updateLegend(int mx ,int my) {
if (region != null) { if (region != null) {
int left = this.x;
int top = this.y;
float size = this.width;
int zoom = (101 - previewSettings.zoom); int zoom = (101 - previewSettings.zoom);
int width = Math.max(1, region.getBlockSize().size * zoom); int width = Math.max(1, region.getBlockSize().size * zoom);
int height = Math.max(1, region.getBlockSize().size * zoom); int height = Math.max(1, region.getBlockSize().size * zoom);
values[0] = width + "x" + height; values[0] = width + "x" + height;
if (mx >= left && mx <= left + size && my >= top && my <= top + size) {
if (mx >= this.x && mx <= this.x + this.width && my >= this.y && my <= this.y + this.height) { float fx = (mx - left) / size;
float fx = (mx - this.x) / (float) this.width; float fz = (my - top) / size;
float fz = (my - this.y) / (float) this.height;
int ix = NoiseUtil.round(fx * region.getBlockSize().size); int ix = NoiseUtil.round(fx * region.getBlockSize().size);
int iz = NoiseUtil.round(fz * region.getBlockSize().size); int iz = NoiseUtil.round(fz * region.getBlockSize().size);
Cell<Terrain> cell = region.getCell(ix, iz); Cell<Terrain> cell = region.getCell(ix, iz);

View File

@ -92,7 +92,7 @@ public class PreviewPage extends BasePage {
update(); update();
} }
protected void update() { public void update() {
preview.update(settings, previewerSettings); preview.update(settings, previewerSettings);
} }

View File

@ -26,7 +26,6 @@
package com.terraforged.mod.gui.preview; package com.terraforged.mod.gui.preview;
import com.terraforged.core.cell.Cell; import com.terraforged.core.cell.Cell;
import com.terraforged.core.world.GeneratorContext;
import com.terraforged.core.world.heightmap.Levels; import com.terraforged.core.world.heightmap.Levels;
import com.terraforged.core.world.terrain.Terrain; import com.terraforged.core.world.terrain.Terrain;
import me.dags.noise.util.NoiseUtil; import me.dags.noise.util.NoiseUtil;
@ -34,50 +33,77 @@ import me.dags.noise.util.NoiseUtil;
import java.awt.*; import java.awt.*;
public enum RenderMode { public enum RenderMode {
BIOME_TYPE, BIOME_TYPE {
TEMPERATURE, @Override
MOISTURE, public int getColor(Cell<Terrain> cell, float scale, float bias) {
BIOME_SHAPE, Color color = cell.biomeType.getColor();
float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]);
return rgba(hsb[0], hsb[1], (hsb[2] * scale) + bias);
}
},
TEMPERATURE {
@Override
public int getColor(Cell<Terrain> cell, float scale, float bias) {
float saturation = 0.7F;
float brightness = 0.8F;
return rgba(step(1 - cell.temperature, 8) * 0.65F, saturation, brightness);
}
},
MOISTURE {
@Override
public int getColor(Cell<Terrain> cell, float scale, float bias) {
float saturation = 0.7F;
float brightness = 0.8F;
return rgba(step(cell.moisture, 8) * 0.65F, saturation, brightness);
}
},
BIOME_SHAPE {
@Override
public int getColor(Cell<Terrain> cell, float scale, float bias) {
float saturation = 0.7F;
float brightness = 0.8F;
return rgba(cell.biome, saturation, brightness);
}
},
TERRAIN_TYPE {
@Override
public int getColor(Cell<Terrain> cell, float scale, float bias) {
float saturation = 0.7F;
float brightness = 0.8F;
return rgba(cell.region, saturation, brightness);
}
},
; ;
public Color color(Cell<Terrain> cell, GeneratorContext context) { public int getColor(Cell<Terrain> cell, Levels levels) {
float baseHeight = Levels.getSeaLevel(context.settings.generator); float baseHeight = levels.water;
if (cell.value < baseHeight) { if (cell.value < baseHeight) {
return new Color(40, 140, 200); return rgba(40, 140, 200);
} }
float bands = 10F; float bands = 10F;
float alpha = 0.2F; float alpha = 0.2F;
float elevation = (cell.value - baseHeight) / (1F - baseHeight); float elevation = (cell.value - baseHeight) / (1F - baseHeight);
int band = NoiseUtil.round(elevation * bands); int band = NoiseUtil.round(elevation * bands);
float scale = 1F - alpha; float scale = 1F - alpha;
float bias = alpha * (band / bands); float bias = alpha * (band / bands);
return getColor(cell, scale, bias);
float saturation = 0.7F;
float brightness = 0.8F;
switch (this) {
case BIOME_SHAPE:
return Color.getHSBColor(cell.biome, saturation, brightness);
case BIOME_TYPE:
Color color = cell.biomeType.getColor();
float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]);
return Color.getHSBColor(hsb[0], hsb[1], (hsb[2] * scale) + bias);
case MOISTURE:
return Color.getHSBColor(step(cell.moisture, 8) * 0.65F, saturation, brightness);
case TEMPERATURE:
return Color.getHSBColor(step(1 - cell.temperature, 8) * 0.65F, saturation, brightness);
default:
return Color.black;
}
} }
public abstract int getColor(Cell<Terrain> cell, float scale, float bias);
private static float step(float value, int steps) { private static float step(float value, int steps) {
return ((float) NoiseUtil.round(value * steps)) / steps; return ((float) NoiseUtil.round(value * steps)) / steps;
} }
public static int rgba(Color color) { public static int rgba(float h, float s, float b) {
return color.getRed() + (color.getGreen() << 8) + (color.getBlue() << 16) + (255 << 24); int argb = Color.HSBtoRGB(h, s, b);
int red = (argb >> 16) & 0xFF;
int green = (argb >> 8) & 0xFF;
int blue = argb & 0xFF;
return rgba(red, green, blue);
}
public static int rgba(int r, int g, int b) {
return r + (g << 8) + (b << 16) + (255 << 24);
} }
} }

View File

@ -1,13 +1,13 @@
#TerraForged BiomeType Hex Colors (do not include hash/pound character) #BiomeType Hex Colors (do not include hash/pound character)
#Fri Jan 10 23:15:10 GMT 2020 #Fri Jan 10 23:15:10 GMT 2020
ALPINE=4b7835 ALPINE=eff2ed
TAIGA=4b7835 TAIGA=4d733b
TEMPERATE_RAINFOREST=3c602b TEMPERATE_RAINFOREST=528c35
TUNDRA=f7fafc TUNDRA=d7dbc8
TROPICAL_RAINFOREST=4aa73a TROPICAL_RAINFOREST=347d3f
SAVANNA=389a38 SAVANNA=88ad3e
GRASSLAND=429545 GRASSLAND=4bb34f
TEMPERATE_FOREST=456938 TEMPERATE_FOREST=5d9948
STEPPE=c3aa61 STEPPE=e0cb89
DESERT=e5d98f DESERT=e6db9c
COLD_STEPPE=a7a374 COLD_STEPPE=c2bb84