mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Remove studio render paths
- Drop IrisRenderer.renderStudio, renderStudioBase and refineStudioBiome with their adaptive, height and river atlases - Drop RenderType.RIVER and the test-only WaterMap.draw - Port the river renderer tests to the live WaterTile path - Use a settled WaterTile as the map overlay test oracle
This commit is contained in:
1 parent
490016b56a
commit
6cbe4b2c09
9 files changed
+115
-661
No files matched your search
@@ -39,7 +39,7 @@ final class IrisBiomeColorRenderer {
|
||||
|
||||
static Color getColor(IrisBiome biome, Engine engine, RenderType type) {
|
||||
switch (type) {
|
||||
case BIOME, HEIGHT, CAVE_LAND, REGION, BIOME_SEA, BIOME_LAND, RIVER -> {
|
||||
case BIOME, HEIGHT, CAVE_LAND, REGION, BIOME_SEA, BIOME_LAND -> {
|
||||
return biome.getCacheColor().aquire(() -> {
|
||||
if (biome.getColor() == null) {
|
||||
RandomColor randomColor = new RandomColor(biome.getName().hashCode());
|
||||
|
||||
@@ -88,64 +88,6 @@ public final class IrisRenderer {
|
||||
int resolution,
|
||||
RenderType currentType,
|
||||
BooleanSupplier cancelled
|
||||
) {
|
||||
return render(sx, sz, size, resolution, currentType, cancelled, false, false);
|
||||
}
|
||||
|
||||
public BufferedImage renderStudio(
|
||||
double sx,
|
||||
double sz,
|
||||
double size,
|
||||
int resolution,
|
||||
RenderType currentType,
|
||||
BooleanSupplier cancelled
|
||||
) {
|
||||
return render(sx, sz, size, resolution, currentType, cancelled, true, true);
|
||||
}
|
||||
|
||||
public BufferedImage renderStudioBase(
|
||||
double sx,
|
||||
double sz,
|
||||
double size,
|
||||
int resolution,
|
||||
RenderType currentType,
|
||||
BooleanSupplier cancelled
|
||||
) {
|
||||
return render(sx, sz, size, resolution, currentType, cancelled, true, false);
|
||||
}
|
||||
|
||||
public BufferedImage refineStudioBiome(
|
||||
double sx,
|
||||
double sz,
|
||||
double size,
|
||||
BufferedImage base,
|
||||
BooleanSupplier cancelled
|
||||
) {
|
||||
Objects.requireNonNull(base, "base");
|
||||
Objects.requireNonNull(cancelled, "cancelled");
|
||||
checkCancelled(cancelled);
|
||||
if (!Double.isFinite(sx) || !Double.isFinite(sz) || !Double.isFinite(size) || size <= 0D
|
||||
|| base.getWidth() != base.getHeight()) {
|
||||
throw new IllegalArgumentException("Vision biome refinement requires finite coordinates and a square base image");
|
||||
}
|
||||
int resolution = base.getWidth();
|
||||
BufferedImage image = new BufferedImage(resolution, resolution, BufferedImage.TYPE_INT_RGB);
|
||||
base.copyData(image.getRaster());
|
||||
int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
|
||||
renderRiverAtlas(pixels, resolution, sx, sz, size / resolution, renderer, cancelled, true);
|
||||
checkCancelled(cancelled);
|
||||
return image;
|
||||
}
|
||||
|
||||
private BufferedImage render(
|
||||
double sx,
|
||||
double sz,
|
||||
double size,
|
||||
int resolution,
|
||||
RenderType currentType,
|
||||
BooleanSupplier cancelled,
|
||||
boolean studio,
|
||||
boolean riverOverlay
|
||||
) {
|
||||
if (!Double.isFinite(sx) || !Double.isFinite(sz) || !Double.isFinite(size) || size <= 0D) {
|
||||
throw new IllegalArgumentException("Vision render coordinates and size must be finite");
|
||||
@@ -160,23 +102,7 @@ public final class IrisRenderer {
|
||||
BufferedImage image = new BufferedImage(resolution, resolution, BufferedImage.TYPE_INT_RGB);
|
||||
int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
|
||||
double step = size / resolution;
|
||||
if (studio && currentType == RenderType.HEIGHT) {
|
||||
renderHeightAtlas(pixels, resolution, sx, sz, step, renderer, cancelled);
|
||||
return image;
|
||||
}
|
||||
if (currentType == RenderType.RIVER) {
|
||||
Arrays.fill(pixels, NO_RIVER);
|
||||
renderRiverAtlas(pixels, resolution, sx, sz, step, renderer, cancelled, false);
|
||||
return image;
|
||||
}
|
||||
PixelShader shader = shader(currentType, studio);
|
||||
if (studio && adaptiveStudioType(currentType)) {
|
||||
renderAdaptiveAtlas(pixels, resolution, sx, sz, step, shader, cancelled);
|
||||
if (currentType == RenderType.BIOME && riverOverlay) {
|
||||
renderRiverAtlas(pixels, resolution, sx, sz, step, renderer, cancelled, true);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
PixelShader shader = shader(currentType);
|
||||
int groupSize = sampleGroup(step, resolution);
|
||||
|
||||
for (int groupZ = 0; groupZ < resolution; groupZ += groupSize) {
|
||||
@@ -248,118 +174,19 @@ public final class IrisRenderer {
|
||||
return Math.max(1, Math.min(resolution, (int) Math.floor(16D / absoluteStep)));
|
||||
}
|
||||
|
||||
private PixelShader shader(RenderType currentType, boolean studio) {
|
||||
private PixelShader shader(RenderType currentType) {
|
||||
IrisComplex complex = renderer.getComplex();
|
||||
return switch (currentType) {
|
||||
case BIOME, DECORATOR_LOAD, OBJECT_LOAD, LAYER_LOAD -> biomeShader(
|
||||
studio ? complex.getBaseBiomeStream() : complex.getTrueBiomeStream(), currentType);
|
||||
case BIOME, DECORATOR_LOAD, OBJECT_LOAD, LAYER_LOAD -> biomeShader(complex.getTrueBiomeStream(), currentType);
|
||||
case BIOME_LAND -> biomeShader(complex.getLandBiomeStream(), currentType);
|
||||
case BIOME_SEA -> biomeShader(complex.getSeaBiomeStream(), currentType);
|
||||
case REGION -> regionShader(complex, currentType);
|
||||
case CAVE_LAND -> biomeShader(complex.getCaveBiomeStream(), currentType);
|
||||
case HEIGHT -> heightShader(studio ? complex.getNaturalHeightStream() : complex.getHeightStream());
|
||||
case RIVER -> throw new IllegalArgumentException("River maps render from the water raster atlas, not a pixel shader");
|
||||
case CONTINENT -> studio
|
||||
? continentShader(complex.getBaseBiomeStream())
|
||||
: this::continentColor;
|
||||
case HEIGHT -> heightShader(complex.getHeightStream());
|
||||
case CONTINENT -> this::continentColor;
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean adaptiveStudioType(RenderType type) {
|
||||
return switch (type) {
|
||||
case BIOME, DECORATOR_LOAD, OBJECT_LOAD, LAYER_LOAD, BIOME_LAND, BIOME_SEA, REGION, CAVE_LAND,
|
||||
CONTINENT -> true;
|
||||
case HEIGHT, RIVER -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private static void renderAdaptiveAtlas(
|
||||
int[] pixels,
|
||||
int resolution,
|
||||
double startX,
|
||||
double startZ,
|
||||
double step,
|
||||
PixelShader shader,
|
||||
BooleanSupplier cancelled
|
||||
) {
|
||||
int maximumPixels = Math.max(1, Math.min(16, (int) Math.floor(64D / step)));
|
||||
int blockPixels = Integer.highestOneBit(maximumPixels);
|
||||
AdaptiveSampler sampler = new AdaptiveSampler(pixels, resolution, startX, startZ, step, shader, cancelled);
|
||||
for (int pixelZ = 0; pixelZ < resolution; pixelZ += blockPixels) {
|
||||
int height = Math.min(blockPixels, resolution - pixelZ);
|
||||
for (int pixelX = 0; pixelX < resolution; pixelX += blockPixels) {
|
||||
sampler.render(pixelX, pixelZ, Math.min(blockPixels, resolution - pixelX), height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void renderHeightAtlas(
|
||||
int[] pixels,
|
||||
int resolution,
|
||||
double startX,
|
||||
double startZ,
|
||||
double step,
|
||||
Engine engine,
|
||||
BooleanSupplier cancelled
|
||||
) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
double fluidHeight = dimension == null ? 0D : dimension.getFluidHeight();
|
||||
int maximumPixels = Math.max(1, Math.min(16, (int) Math.floor(64D / step)));
|
||||
int blockPixels = Integer.highestOneBit(maximumPixels);
|
||||
HeightSampler sampler = new HeightSampler(
|
||||
pixels,
|
||||
resolution,
|
||||
startX,
|
||||
startZ,
|
||||
step,
|
||||
complex.getNaturalHeightStream(),
|
||||
engine.getHeight(),
|
||||
fluidHeight,
|
||||
cancelled
|
||||
);
|
||||
for (int pixelZ = 0; pixelZ < resolution; pixelZ += blockPixels) {
|
||||
int height = Math.min(blockPixels, resolution - pixelZ);
|
||||
for (int pixelX = 0; pixelX < resolution; pixelX += blockPixels) {
|
||||
sampler.render(pixelX, pixelZ, Math.min(blockPixels, resolution - pixelX), height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void renderRiverAtlas(
|
||||
int[] pixels,
|
||||
int resolution,
|
||||
double startX,
|
||||
double startZ,
|
||||
double step,
|
||||
Engine engine,
|
||||
BooleanSupplier cancelled,
|
||||
boolean composite
|
||||
) {
|
||||
HydrologyRuntime runtime = engine.getComplex().getHydrologyRuntime();
|
||||
if (runtime == null || !runtime.enabled() || step > WaterMap.MAX_STEP) {
|
||||
return;
|
||||
}
|
||||
WaterMap map = WaterMap.draw(runtime, resolution, startX, startZ, step, cancelled);
|
||||
map.drawCavePools(GenerationSemanticQueries.recordedCavePools(engine, Math.floorDiv((int) Math.floor(startX), 16),
|
||||
Math.floorDiv((int) Math.floor(startZ), 16), Math.floorDiv((int) Math.ceil(startX + resolution * step) - 1, 16),
|
||||
Math.floorDiv((int) Math.ceil(startZ + resolution * step) - 1, 16)));
|
||||
for (int pixelZ = 0; pixelZ < resolution; pixelZ++) {
|
||||
for (int pixelX = 0; pixelX < resolution; pixelX++) {
|
||||
HydrologyFeatureType type = map.at(pixelX, pixelZ);
|
||||
if (type == null) {
|
||||
continue;
|
||||
}
|
||||
int index = pixelZ * resolution + pixelX;
|
||||
int color = hydrologyFeatureColor(type);
|
||||
pixels[index] = composite ? blend(pixels[index], color, RIVER_OVERLAY) : color;
|
||||
}
|
||||
}
|
||||
if (map.provisional()) {
|
||||
ProvisionalSampling.mark();
|
||||
}
|
||||
}
|
||||
|
||||
private PixelShader biomeShader(ProceduralStream<IrisBiome> stream, RenderType currentType) {
|
||||
IdentityHashMap<IrisBiome, Integer> colors = new IdentityHashMap<>();
|
||||
return (double x, double z) -> {
|
||||
@@ -403,19 +230,6 @@ public final class IrisRenderer {
|
||||
return continentColor(biome);
|
||||
}
|
||||
|
||||
private PixelShader continentShader(ProceduralStream<IrisBiome> stream) {
|
||||
IdentityHashMap<IrisBiome, Integer> colors = new IdentityHashMap<>();
|
||||
return (double x, double z) -> {
|
||||
IrisBiome biome = stream.get(x, z);
|
||||
Integer color = colors.get(biome);
|
||||
if (color == null) {
|
||||
color = continentColor(biome);
|
||||
colors.put(biome, color);
|
||||
}
|
||||
return color;
|
||||
};
|
||||
}
|
||||
|
||||
private int continentColor(IrisBiome biome) {
|
||||
if (biome == null) {
|
||||
return GREEN;
|
||||
@@ -534,254 +348,4 @@ public final class IrisRenderer {
|
||||
private interface PixelShader {
|
||||
int color(double x, double z);
|
||||
}
|
||||
|
||||
private static final class AdaptiveSampler {
|
||||
private final int[] pixels;
|
||||
private final boolean[] sampled;
|
||||
private final int resolution;
|
||||
private final double startX;
|
||||
private final double startZ;
|
||||
private final double step;
|
||||
private final PixelShader shader;
|
||||
private final BooleanSupplier cancelled;
|
||||
|
||||
private AdaptiveSampler(
|
||||
int[] pixels,
|
||||
int resolution,
|
||||
double startX,
|
||||
double startZ,
|
||||
double step,
|
||||
PixelShader shader,
|
||||
BooleanSupplier cancelled
|
||||
) {
|
||||
this.pixels = pixels;
|
||||
this.sampled = new boolean[pixels.length];
|
||||
this.resolution = resolution;
|
||||
this.startX = startX;
|
||||
this.startZ = startZ;
|
||||
this.step = step;
|
||||
this.shader = shader;
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
private void render(int pixelX, int pixelZ, int width, int height) {
|
||||
checkCancelled(cancelled);
|
||||
if (width == 1 && height == 1) {
|
||||
sample(pixelX, pixelZ);
|
||||
return;
|
||||
}
|
||||
int maximumX = pixelX + width - 1;
|
||||
int maximumZ = pixelZ + height - 1;
|
||||
int centerX = pixelX + width / 2;
|
||||
int centerZ = pixelZ + height / 2;
|
||||
int color = sample(pixelX, pixelZ);
|
||||
if (sample(maximumX, pixelZ) == color
|
||||
&& sample(pixelX, maximumZ) == color
|
||||
&& sample(maximumX, maximumZ) == color
|
||||
&& sample(centerX, centerZ) == color) {
|
||||
fill(pixelX, pixelZ, width, height, color);
|
||||
return;
|
||||
}
|
||||
int leftWidth = Math.max(1, width / 2);
|
||||
int rightWidth = width - leftWidth;
|
||||
int topHeight = Math.max(1, height / 2);
|
||||
int bottomHeight = height - topHeight;
|
||||
render(pixelX, pixelZ, leftWidth, topHeight);
|
||||
if (rightWidth > 0) {
|
||||
render(pixelX + leftWidth, pixelZ, rightWidth, topHeight);
|
||||
}
|
||||
if (bottomHeight > 0) {
|
||||
render(pixelX, pixelZ + topHeight, leftWidth, bottomHeight);
|
||||
if (rightWidth > 0) {
|
||||
render(pixelX + leftWidth, pixelZ + topHeight, rightWidth, bottomHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int sample(int pixelX, int pixelZ) {
|
||||
int index = pixelZ * resolution + pixelX;
|
||||
if (!sampled[index]) {
|
||||
pixels[index] = shader.color(startX + pixelX * step, startZ + pixelZ * step);
|
||||
sampled[index] = true;
|
||||
}
|
||||
return pixels[index];
|
||||
}
|
||||
|
||||
private void fill(int pixelX, int pixelZ, int width, int height, int color) {
|
||||
for (int row = pixelZ; row < pixelZ + height; row++) {
|
||||
int start = row * resolution + pixelX;
|
||||
Arrays.fill(pixels, start, start + width, color);
|
||||
Arrays.fill(sampled, start, start + width, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class HeightSampler {
|
||||
private static final double MAXIMUM_INTERPOLATION_ERROR = 1.5D;
|
||||
|
||||
private final int[] pixels;
|
||||
private final double[] heights;
|
||||
private final boolean[] sampled;
|
||||
private final int resolution;
|
||||
private final double startX;
|
||||
private final double startZ;
|
||||
private final double step;
|
||||
private final ProceduralStream<Double> stream;
|
||||
private final double maximumHeight;
|
||||
private final double fluidHeight;
|
||||
private final BooleanSupplier cancelled;
|
||||
|
||||
private HeightSampler(
|
||||
int[] pixels,
|
||||
int resolution,
|
||||
double startX,
|
||||
double startZ,
|
||||
double step,
|
||||
ProceduralStream<Double> stream,
|
||||
double maximumHeight,
|
||||
double fluidHeight,
|
||||
BooleanSupplier cancelled
|
||||
) {
|
||||
this.pixels = pixels;
|
||||
this.heights = new double[pixels.length];
|
||||
this.sampled = new boolean[pixels.length];
|
||||
this.resolution = resolution;
|
||||
this.startX = startX;
|
||||
this.startZ = startZ;
|
||||
this.step = step;
|
||||
this.stream = stream;
|
||||
this.maximumHeight = maximumHeight;
|
||||
this.fluidHeight = fluidHeight;
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
private void render(int pixelX, int pixelZ, int width, int height) {
|
||||
checkCancelled(cancelled);
|
||||
if (width == 1 && height == 1) {
|
||||
pixels[pixelZ * resolution + pixelX] = heightColor(
|
||||
sample(pixelX, pixelZ), maximumHeight, fluidHeight);
|
||||
return;
|
||||
}
|
||||
int maximumX = pixelX + width - 1;
|
||||
int maximumZ = pixelZ + height - 1;
|
||||
int centerX = pixelX + width / 2;
|
||||
int centerZ = pixelZ + height / 2;
|
||||
double topLeft = sample(pixelX, pixelZ);
|
||||
double topRight = sample(maximumX, pixelZ);
|
||||
double bottomLeft = sample(pixelX, maximumZ);
|
||||
double bottomRight = sample(maximumX, maximumZ);
|
||||
if (matchesPlane(pixelX, pixelZ, width, height, topLeft, topRight, bottomLeft, bottomRight,
|
||||
centerX, pixelZ)
|
||||
&& matchesPlane(pixelX, pixelZ, width, height, topLeft, topRight, bottomLeft, bottomRight,
|
||||
pixelX, centerZ)
|
||||
&& matchesPlane(pixelX, pixelZ, width, height, topLeft, topRight, bottomLeft, bottomRight,
|
||||
maximumX, centerZ)
|
||||
&& matchesPlane(pixelX, pixelZ, width, height, topLeft, topRight, bottomLeft, bottomRight,
|
||||
centerX, maximumZ)
|
||||
&& matchesPlane(pixelX, pixelZ, width, height, topLeft, topRight, bottomLeft, bottomRight,
|
||||
centerX, centerZ)) {
|
||||
fillPlane(pixelX, pixelZ, width, height, topLeft, topRight, bottomLeft, bottomRight);
|
||||
return;
|
||||
}
|
||||
int leftWidth = Math.max(1, width / 2);
|
||||
int rightWidth = width - leftWidth;
|
||||
int topHeight = Math.max(1, height / 2);
|
||||
int bottomHeight = height - topHeight;
|
||||
render(pixelX, pixelZ, leftWidth, topHeight);
|
||||
if (rightWidth > 0) {
|
||||
render(pixelX + leftWidth, pixelZ, rightWidth, topHeight);
|
||||
}
|
||||
if (bottomHeight > 0) {
|
||||
render(pixelX, pixelZ + topHeight, leftWidth, bottomHeight);
|
||||
if (rightWidth > 0) {
|
||||
render(pixelX + leftWidth, pixelZ + topHeight, rightWidth, bottomHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchesPlane(
|
||||
int pixelX,
|
||||
int pixelZ,
|
||||
int width,
|
||||
int height,
|
||||
double topLeft,
|
||||
double topRight,
|
||||
double bottomLeft,
|
||||
double bottomRight,
|
||||
int sampleX,
|
||||
int sampleZ
|
||||
) {
|
||||
double predicted = interpolate(
|
||||
pixelX,
|
||||
pixelZ,
|
||||
width,
|
||||
height,
|
||||
topLeft,
|
||||
topRight,
|
||||
bottomLeft,
|
||||
bottomRight,
|
||||
sampleX,
|
||||
sampleZ
|
||||
);
|
||||
return Math.abs(sample(sampleX, sampleZ) - predicted) <= MAXIMUM_INTERPOLATION_ERROR;
|
||||
}
|
||||
|
||||
private void fillPlane(
|
||||
int pixelX,
|
||||
int pixelZ,
|
||||
int width,
|
||||
int height,
|
||||
double topLeft,
|
||||
double topRight,
|
||||
double bottomLeft,
|
||||
double bottomRight
|
||||
) {
|
||||
for (int row = pixelZ; row < pixelZ + height; row++) {
|
||||
int offset = row * resolution;
|
||||
for (int column = pixelX; column < pixelX + width; column++) {
|
||||
double value = interpolate(
|
||||
pixelX,
|
||||
pixelZ,
|
||||
width,
|
||||
height,
|
||||
topLeft,
|
||||
topRight,
|
||||
bottomLeft,
|
||||
bottomRight,
|
||||
column,
|
||||
row
|
||||
);
|
||||
pixels[offset + column] = heightColor(value, maximumHeight, fluidHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double sample(int pixelX, int pixelZ) {
|
||||
int index = pixelZ * resolution + pixelX;
|
||||
if (!sampled[index]) {
|
||||
heights[index] = stream.getDouble(startX + pixelX * step, startZ + pixelZ * step);
|
||||
sampled[index] = true;
|
||||
}
|
||||
return heights[index];
|
||||
}
|
||||
|
||||
private static double interpolate(
|
||||
int pixelX,
|
||||
int pixelZ,
|
||||
int width,
|
||||
int height,
|
||||
double topLeft,
|
||||
double topRight,
|
||||
double bottomLeft,
|
||||
double bottomRight,
|
||||
int sampleX,
|
||||
int sampleZ
|
||||
) {
|
||||
double x = width <= 1 ? 0D : (sampleX - pixelX) / (double) (width - 1);
|
||||
double z = height <= 1 ? 0D : (sampleZ - pixelZ) / (double) (height - 1);
|
||||
double top = topLeft + (topRight - topLeft) * x;
|
||||
double bottom = bottomLeft + (bottomRight - bottomLeft) * x;
|
||||
return top + (bottom - top) * z;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,5 +19,5 @@
|
||||
package art.arcane.iris.studio.render;
|
||||
|
||||
public enum RenderType {
|
||||
BIOME, BIOME_LAND, BIOME_SEA, REGION, CAVE_LAND, RIVER, HEIGHT, OBJECT_LOAD, DECORATOR_LOAD, CONTINENT, LAYER_LOAD
|
||||
BIOME, BIOME_LAND, BIOME_SEA, REGION, CAVE_LAND, HEIGHT, OBJECT_LOAD, DECORATOR_LOAD, CONTINENT, LAYER_LOAD
|
||||
}
|
||||
@@ -53,12 +53,6 @@ final class WaterMap {
|
||||
provisional = true;
|
||||
}
|
||||
|
||||
static WaterMap draw(HydrologyRuntime runtime, int resolution, double startX, double startZ, double step, BooleanSupplier cancelled) {
|
||||
WaterMap map = new WaterMap(runtime, resolution, startX, startZ, step);
|
||||
map.advance(cancelled);
|
||||
return map;
|
||||
}
|
||||
|
||||
void advance(BooleanSupplier cancelled) {
|
||||
if (!provisional) {
|
||||
return;
|
||||
|
||||
@@ -23,7 +23,7 @@ import art.arcane.volmlib.util.stream.interpolation.Interpolated;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -39,9 +39,9 @@ public class MapHydrologyTest {
|
||||
Engine engine = engine(water.runtime, biome());
|
||||
MapTileRenderer renderer = new MapTileRenderer(engine);
|
||||
MapTile tile = settled(renderer, MapLayer.of(TileType.BIOME));
|
||||
BufferedImage expected = new IrisRenderer(engine).renderStudio(0, 0, 64, 64, RenderType.BIOME, () -> false);
|
||||
assertNotEquals(new Color(0x738249).getRGB(), expected.getRGB(16, 16));
|
||||
assertEquals(expected.getRGB(16, 16), tile.image(MapStyle.PLAIN).getRGB(16, 16));
|
||||
int expected = 0xFF000000 | overlaid(engine, 0x738249)[16 * 64 + 16];
|
||||
assertNotEquals(new Color(0x738249).getRGB(), expected);
|
||||
assertEquals(expected, tile.image(MapStyle.PLAIN).getRGB(16, 16));
|
||||
MapTile dry = settled(renderer, MapLayer.biomes(PickDisplay.PICKS, false));
|
||||
assertEquals(new Color(0x738249).getRGB(), dry.image(MapStyle.PLAIN).getRGB(16, 16));
|
||||
assertNotEquals(MapLayer.biomes(PickDisplay.PICKS, true), MapLayer.biomes(PickDisplay.PICKS, false));
|
||||
@@ -105,6 +105,21 @@ public class MapHydrologyTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] overlaid(Engine engine, int biomeColor) throws Exception {
|
||||
IrisRenderer.WaterTile water = new IrisRenderer(engine).prepareStudioWater(0D, 0D, 1D, 64);
|
||||
int[] base = new int[64 * 64];
|
||||
Arrays.fill(base, biomeColor);
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10L);
|
||||
while (true) {
|
||||
int[] colors = water.render(base, true, () -> false);
|
||||
if (water.complete()) {
|
||||
return colors;
|
||||
}
|
||||
assertTrue("water never settled", System.nanoTime() < deadline);
|
||||
Thread.sleep(10L);
|
||||
}
|
||||
}
|
||||
|
||||
private static IrisBiome biome() {
|
||||
IrisBiome biome = new IrisBiome();
|
||||
biome.setColor("#738249");
|
||||
|
||||
+3
-109
@@ -2,24 +2,16 @@ package art.arcane.iris.studio.render;
|
||||
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -71,117 +63,19 @@ public class IrisRendererPerformanceContractTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioHeightUsesNaturalTerrainWhileProtocolRenderRemainsExact() {
|
||||
public void heightRenderSamplesTheExactHeightStream() {
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> natural = mock(ProceduralStream.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> exact = mock(ProceduralStream.class);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getHeight()).thenReturn(320);
|
||||
when(complex.getNaturalHeightStream()).thenReturn(natural);
|
||||
when(complex.getHeightStream()).thenReturn(exact);
|
||||
when(natural.getDouble(0D, 0D)).thenReturn(80D);
|
||||
when(exact.getDouble(0D, 0D)).thenReturn(96D);
|
||||
IrisRenderer renderer = new IrisRenderer(engine);
|
||||
|
||||
renderer.renderStudio(0D, 0D, 1D, 1, RenderType.HEIGHT, () -> false);
|
||||
|
||||
verify(natural).getDouble(0D, 0D);
|
||||
verifyNoInteractions(exact);
|
||||
|
||||
renderer.render(0D, 0D, 1D, 1, RenderType.HEIGHT);
|
||||
new IrisRenderer(engine).render(0D, 0D, 1D, 1, RenderType.HEIGHT);
|
||||
|
||||
verify(exact).getDouble(0D, 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioBiomeAndContinentAvoidRiverAdjustedEngineLookups() {
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<IrisBiome> base = mock(ProceduralStream.class);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.getBaseBiomeStream()).thenReturn(base);
|
||||
when(base.get(0D, 0D)).thenReturn(biome);
|
||||
when(biome.getColor(engine, RenderType.BIOME)).thenReturn(Color.GREEN);
|
||||
when(biome.getGenerators()).thenReturn(new KList<>());
|
||||
IrisRenderer renderer = new IrisRenderer(engine);
|
||||
|
||||
renderer.renderStudio(0D, 0D, 1D, 1, RenderType.BIOME, () -> false);
|
||||
renderer.renderStudio(0D, 0D, 1D, 1, RenderType.CONTINENT, () -> false);
|
||||
|
||||
verify(base, times(2)).get(0D, 0D);
|
||||
verify(engine, never()).getBiome(anyInt(), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uniformStudioBiomePagesUseAdaptiveDomainSampling() {
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<IrisBiome> base = mock(ProceduralStream.class);
|
||||
AtomicInteger samples = new AtomicInteger();
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.getBaseBiomeStream()).thenReturn(base);
|
||||
when(base.get(org.mockito.ArgumentMatchers.anyDouble(), org.mockito.ArgumentMatchers.anyDouble()))
|
||||
.thenAnswer(invocation -> {
|
||||
samples.incrementAndGet();
|
||||
return biome;
|
||||
});
|
||||
when(biome.getColor(engine, RenderType.BIOME)).thenReturn(Color.GREEN);
|
||||
|
||||
new IrisRenderer(engine).renderStudio(0D, 0D, 256D, 64, RenderType.BIOME, () -> false);
|
||||
|
||||
assertTrue(samples.get() < 128);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioBiomeBaseDoesNotEnterHydrologyPlanning() {
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<IrisBiome> base = mock(ProceduralStream.class);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.getBaseBiomeStream()).thenReturn(base);
|
||||
when(base.get(org.mockito.ArgumentMatchers.anyDouble(), org.mockito.ArgumentMatchers.anyDouble()))
|
||||
.thenReturn(biome);
|
||||
when(biome.getColor(engine, RenderType.BIOME)).thenReturn(Color.GREEN);
|
||||
|
||||
BufferedImage image = new IrisRenderer(engine).renderStudioBase(
|
||||
0D, 0D, 256D, 64, RenderType.BIOME, () -> false);
|
||||
|
||||
assertEquals(Color.GREEN.getRGB(), image.getRGB(0, 0));
|
||||
assertEquals(Color.GREEN.getRGB(), image.getRGB(63, 63));
|
||||
verify(complex, never()).getHydrologyRuntime();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void planarStudioHeightPagesInterpolateWithoutPerPixelEngineSampling() {
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> natural = mock(ProceduralStream.class);
|
||||
AtomicInteger samples = new AtomicInteger();
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getHeight()).thenReturn(320);
|
||||
when(complex.getNaturalHeightStream()).thenReturn(natural);
|
||||
when(natural.getDouble(org.mockito.ArgumentMatchers.anyDouble(), org.mockito.ArgumentMatchers.anyDouble()))
|
||||
.thenAnswer(invocation -> {
|
||||
samples.incrementAndGet();
|
||||
double x = invocation.getArgument(0);
|
||||
double z = invocation.getArgument(1);
|
||||
return 80D + x * 0.05D + z * 0.025D;
|
||||
});
|
||||
|
||||
BufferedImage image = new IrisRenderer(engine).renderStudio(
|
||||
0D, 0D, 256D, 64, RenderType.HEIGHT, () -> false);
|
||||
|
||||
assertTrue(samples.get() < 256);
|
||||
assertNotEquals(image.getRGB(0, 0), image.getRGB(63, 63));
|
||||
verify(complex, never()).getNaturalHeightStream();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.studio.render;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyPlanPreview;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
@@ -18,11 +17,10 @@ import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.testsupport.FakeHydrology;
|
||||
import art.arcane.iris.testsupport.WaterScene;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -33,7 +31,6 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -44,7 +41,8 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisRendererRiverTest {
|
||||
private static final int SEA_LEVEL = 40;
|
||||
private static final int NO_RIVER = new Color(28, 31, 38).getRGB();
|
||||
private static final int NO_RIVER = new Color(28, 31, 38).getRGB() & 0xFFFFFF;
|
||||
private static final int GREEN = Color.GREEN.getRGB() & 0xFFFFFF;
|
||||
private static final int PIXELS = 64;
|
||||
private static final long SETTLE_SECONDS = 10L;
|
||||
private static final int POND_X = 30;
|
||||
@@ -59,7 +57,7 @@ public class IrisRendererRiverTest {
|
||||
public void everyFeatureTypeHasItsOwnColor() {
|
||||
Set<Integer> colors = new HashSet<>();
|
||||
for (HydrologyFeatureType type : HydrologyFeatureType.values()) {
|
||||
assertTrue(type.name(), colors.add(IrisRenderer.hydrologyFeatureColor(type)));
|
||||
assertTrue(type.name(), colors.add(water(type)));
|
||||
}
|
||||
assertFalse(colors.contains(NO_RIVER));
|
||||
}
|
||||
@@ -83,16 +81,16 @@ public class IrisRendererRiverTest {
|
||||
hydrology.hold();
|
||||
long before = ProvisionalSampling.revision();
|
||||
|
||||
BufferedImage provisional = new IrisRenderer(engine).renderStudio(0D, 0D, 64D, 64, RenderType.RIVER, () -> false);
|
||||
int[] provisional = new IrisRenderer(engine).prepareStudioWater(0D, 0D, 1D, 64).render(null, false, () -> false);
|
||||
|
||||
assertNotEquals(before, ProvisionalSampling.revision());
|
||||
assertEquals(NO_RIVER, provisional.getRGB(16, 16));
|
||||
assertEquals(NO_RIVER, at(provisional, 64, 16, 16));
|
||||
hydrology.release();
|
||||
|
||||
BufferedImage planned = settled(engine, 64D, 64, RenderType.RIVER);
|
||||
int[] planned = settled(engine, 64D, 64);
|
||||
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.POND), planned.getRGB(16, 16));
|
||||
assertEquals(NO_RIVER, planned.getRGB(48, 48));
|
||||
assertEquals(water(HydrologyFeatureType.POND), at(planned, 64, 16, 16));
|
||||
assertEquals(NO_RIVER, at(planned, 64, 48, 48));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,21 +104,21 @@ public class IrisRendererRiverTest {
|
||||
when(runtime.rasterPreview(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.PROVISIONAL);
|
||||
IrisRenderer renderer = new IrisRenderer(engine(runtime));
|
||||
|
||||
BufferedImage overview = renderer.renderStudio(0D, 0D, 256D, 64, RenderType.RIVER, () -> false);
|
||||
int water = IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.POND);
|
||||
assertEquals(water, overview.getRGB(4, 4));
|
||||
int[] overview = renderer.prepareStudioWater(0D, 0D, 4D, 64).render(null, false, () -> false);
|
||||
int water = water(HydrologyFeatureType.POND);
|
||||
assertEquals(water, at(overview, 64, 4, 4));
|
||||
|
||||
for (int step : new int[]{2, 1}) {
|
||||
long before = ProvisionalSampling.revision();
|
||||
BufferedImage detailed = renderer.renderStudio(0D, 0D, step * 64D, 64, RenderType.RIVER, () -> false);
|
||||
assertEquals(water, detailed.getRGB(16 / step, 16 / step));
|
||||
int[] detailed = renderer.prepareStudioWater(0D, 0D, step, 64).render(null, false, () -> false);
|
||||
assertEquals(water, at(detailed, 64, 16 / step, 16 / step));
|
||||
assertNotEquals(before, ProvisionalSampling.revision());
|
||||
}
|
||||
|
||||
when(runtime.rasterPreview(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.EMPTY);
|
||||
long before = ProvisionalSampling.revision();
|
||||
BufferedImage settled = renderer.renderStudio(0D, 0D, 64D, 64, RenderType.RIVER, () -> false);
|
||||
assertEquals(NO_RIVER, settled.getRGB(16, 16));
|
||||
int[] settled = renderer.prepareStudioWater(0D, 0D, 1D, 64).render(null, false, () -> false);
|
||||
assertEquals(NO_RIVER, at(settled, 64, 16, 16));
|
||||
assertEquals(before, ProvisionalSampling.revision());
|
||||
}
|
||||
|
||||
@@ -129,12 +127,10 @@ public class IrisRendererRiverTest {
|
||||
HydrologySettings settings = FakeHydrology.settings(SEA_LEVEL);
|
||||
Reach brook = WaterScene.line(11L, settings.tiers().getFirst(), 2, 40, 29, 40, (x, z) -> 62);
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 60, SEA_LEVEL, List.of(brook), List.of())) {
|
||||
Engine engine = engine(hydrology.runtime);
|
||||
int[] colors = settled(engine(hydrology.runtime), 32D, 32D, 32, null);
|
||||
|
||||
BufferedImage image = settled(engine, 32D, 32D, 32, RenderType.RIVER);
|
||||
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.STREAM), image.getRGB(16, 8));
|
||||
assertEquals(NO_RIVER, image.getRGB(16, 0));
|
||||
assertEquals(water(HydrologyFeatureType.STREAM), at(colors, 32, 16, 8));
|
||||
assertEquals(NO_RIVER, at(colors, 32, 16, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +139,7 @@ public class IrisRendererRiverTest {
|
||||
try (FakeHydrology hydrology = scene()) {
|
||||
HydrologyRuntime runtime = spy(hydrology.runtime);
|
||||
|
||||
assertScene(settled(engine(runtime), 2D * PIXELS, PIXELS, RenderType.RIVER), 2);
|
||||
assertScene(settled(engine(runtime), 2D * PIXELS, PIXELS), 2);
|
||||
verify(runtime, atLeastOnce()).rasterPreview(anyInt(), anyInt());
|
||||
verify(runtime, never()).rasterSnapshot(anyInt(), anyInt());
|
||||
}
|
||||
@@ -154,7 +150,7 @@ public class IrisRendererRiverTest {
|
||||
try (FakeHydrology hydrology = scene()) {
|
||||
HydrologyRuntime runtime = spy(hydrology.runtime);
|
||||
|
||||
assertScene(settled(engine(runtime), 4D * PIXELS, PIXELS, RenderType.RIVER), 4);
|
||||
assertScene(settled(engine(runtime), 4D * PIXELS, PIXELS), 4);
|
||||
assertNoRasters(runtime);
|
||||
}
|
||||
}
|
||||
@@ -164,7 +160,7 @@ public class IrisRendererRiverTest {
|
||||
try (FakeHydrology hydrology = scene()) {
|
||||
HydrologyRuntime runtime = spy(hydrology.runtime);
|
||||
|
||||
assertScene(settled(engine(runtime), 16D * PIXELS, PIXELS, RenderType.RIVER), 16);
|
||||
assertScene(settled(engine(runtime), 16D * PIXELS, PIXELS), 16);
|
||||
assertNoRasters(runtime);
|
||||
}
|
||||
}
|
||||
@@ -188,9 +184,9 @@ public class IrisRendererRiverTest {
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 90, SEA_LEVEL, List.of(), List.of(), List.of(),
|
||||
List.of(inlet))) {
|
||||
HydrologyRuntime runtime = spy(hydrology.runtime);
|
||||
BufferedImage plan = settled(engine(runtime), 16D * PIXELS, PIXELS, RenderType.RIVER);
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.SEA_INLET), plan.getRGB(200 / 16, 200 / 16));
|
||||
assertEquals(NO_RIVER, plan.getRGB(200 / 16, 400 / 16));
|
||||
int[] plan = settled(engine(runtime), 16D * PIXELS, PIXELS);
|
||||
assertEquals(water(HydrologyFeatureType.SEA_INLET), at(plan, PIXELS, 200 / 16, 200 / 16));
|
||||
assertEquals(NO_RIVER, at(plan, PIXELS, 200 / 16, 400 / 16));
|
||||
assertNoRasters(runtime);
|
||||
}
|
||||
}
|
||||
@@ -201,22 +197,20 @@ public class IrisRendererRiverTest {
|
||||
Reach through = WaterScene.line(31L, settings.tiers().getFirst(), 4, POND_Z, 60, POND_Z, (x, z) -> 62);
|
||||
Pond pond = WaterScene.pond(32L, 62, POND_X, POND_Z, 10);
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 60, SEA_LEVEL, List.of(through), List.of(pond))) {
|
||||
BufferedImage image = settled(engine(hydrology.runtime), 2D * PIXELS, PIXELS, RenderType.RIVER);
|
||||
int[] colors = settled(engine(hydrology.runtime), 2D * PIXELS, PIXELS);
|
||||
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.POND), image.getRGB(POND_X / 2, POND_Z / 2));
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.STREAM), image.getRGB(4, POND_Z / 2));
|
||||
assertEquals(water(HydrologyFeatureType.POND), at(colors, PIXELS, POND_X / 2, POND_Z / 2));
|
||||
assertEquals(water(HydrologyFeatureType.STREAM), at(colors, PIXELS, 4, POND_Z / 2));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zoomedOutPixelsKeepTheStrongestWaterInTheirFootprint() throws Exception {
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 60, SEA_LEVEL, 63)) {
|
||||
Engine engine = engine(hydrology.runtime);
|
||||
int[] colors = settled(engine(hydrology.runtime), 32D, 2);
|
||||
|
||||
BufferedImage image = settled(engine, 32D, 2, RenderType.RIVER);
|
||||
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.POND), image.getRGB(0, 0));
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.POND), image.getRGB(1, 1));
|
||||
assertEquals(water(HydrologyFeatureType.POND), at(colors, 2, 0, 0));
|
||||
assertEquals(water(HydrologyFeatureType.POND), at(colors, 2, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,11 +229,11 @@ public class IrisRendererRiverTest {
|
||||
when(history.semantics(1, 1)).thenReturn(Optional.of(ChunkGenerationSemantics.builder(1, 1, 1L)
|
||||
.addRiverFeature("water", HydrologyFeatureType.CAVE_POOL, 7L, 20, 12, 24).build()));
|
||||
|
||||
BufferedImage image = settled(engine, 64D, 32, RenderType.RIVER);
|
||||
int[] colors = settled(engine, 64D, 32);
|
||||
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.CAVE_POOL), image.getRGB(10, 12));
|
||||
assertEquals(NO_RIVER, image.getRGB(20, 20));
|
||||
assertEquals(NO_RIVER, image.getRGB(10, 13));
|
||||
assertEquals(water(HydrologyFeatureType.CAVE_POOL), at(colors, 32, 10, 12));
|
||||
assertEquals(NO_RIVER, at(colors, 32, 20, 20));
|
||||
assertEquals(NO_RIVER, at(colors, 32, 10, 13));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,9 +243,9 @@ public class IrisRendererRiverTest {
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
long before = ProvisionalSampling.revision();
|
||||
|
||||
BufferedImage image = new IrisRenderer(engine(runtime)).renderStudio(0D, 0D, 2048D, 64, RenderType.RIVER, () -> false);
|
||||
int[] colors = new IrisRenderer(engine(runtime)).prepareStudioWater(0D, 0D, 32D, 64).render(null, false, () -> false);
|
||||
|
||||
assertEquals(NO_RIVER, image.getRGB(0, 0));
|
||||
assertEquals(NO_RIVER, at(colors, 64, 0, 0));
|
||||
assertEquals(before, ProvisionalSampling.revision());
|
||||
verify(runtime, never()).planPreview(anyInt(), anyInt(), anyInt(), anyInt());
|
||||
assertNoRasters(runtime);
|
||||
@@ -261,54 +255,35 @@ public class IrisRendererRiverTest {
|
||||
public void disabledHydrologyLeavesTheRiverMapEmpty() {
|
||||
long before = ProvisionalSampling.revision();
|
||||
|
||||
BufferedImage image = new IrisRenderer(engine(FakeHydrology.disabled())).renderStudio(0D, 0D, 32D, 32, RenderType.RIVER,
|
||||
() -> false);
|
||||
int[] colors = new IrisRenderer(engine(FakeHydrology.disabled())).prepareStudioWater(0D, 0D, 1D, 32)
|
||||
.render(null, false, () -> false);
|
||||
|
||||
assertEquals(NO_RIVER, image.getRGB(16, 16));
|
||||
assertEquals(NO_RIVER, at(colors, 32, 16, 16));
|
||||
assertEquals(before, ProvisionalSampling.revision());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeRefinementCompositesThePlannedWaterOverTheBase() throws Exception {
|
||||
public void compositeTilesBlendThePlannedWaterOverTheBase() throws Exception {
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 60, SEA_LEVEL, 63)) {
|
||||
Engine engine = engine(hydrology.runtime);
|
||||
greenBiomes(engine);
|
||||
settled(engine, 64D, 64, RenderType.RIVER);
|
||||
IrisRenderer renderer = new IrisRenderer(engine);
|
||||
BufferedImage preview = renderer.renderStudioBase(0D, 0D, 64D, 64, RenderType.BIOME, () -> false);
|
||||
int[] composite = settled(engine(hydrology.runtime), 64D, 64, green(64));
|
||||
|
||||
BufferedImage refined = renderer.refineStudioBiome(0D, 0D, 64D, preview, () -> false);
|
||||
BufferedImage complete = renderer.renderStudio(0D, 0D, 64D, 64, RenderType.BIOME, () -> false);
|
||||
|
||||
assertEquals(Color.GREEN.getRGB(), preview.getRGB(16, 16));
|
||||
assertNotEquals(preview.getRGB(16, 16), refined.getRGB(16, 16));
|
||||
assertEquals(Color.GREEN.getRGB(), refined.getRGB(48, 48));
|
||||
assertEquals(complete.getRGB(16, 16), refined.getRGB(16, 16));
|
||||
assertNotEquals(GREEN, at(composite, 64, 16, 16));
|
||||
assertNotEquals(water(HydrologyFeatureType.POND), at(composite, 64, 16, 16));
|
||||
assertEquals(GREEN, at(composite, 64, 48, 48));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioBiomeViewShowsWaterAtItsDefaultZoomWithoutRasters() throws Exception {
|
||||
public void compositeTilesShowWaterAtTheDefaultZoomWithoutRasters() throws Exception {
|
||||
try (FakeHydrology hydrology = scene()) {
|
||||
HydrologyRuntime runtime = spy(hydrology.runtime);
|
||||
Engine engine = engine(runtime);
|
||||
greenBiomes(engine);
|
||||
IrisRenderer renderer = new IrisRenderer(engine);
|
||||
BufferedImage preview = renderer.renderStudioBase(0D, 0D, 4D * PIXELS, PIXELS, RenderType.BIOME, () -> false);
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(SETTLE_SECONDS);
|
||||
BufferedImage refined;
|
||||
long revision;
|
||||
do {
|
||||
assertTrue("The studio water never settled", System.nanoTime() < deadline);
|
||||
Thread.sleep(10L);
|
||||
revision = ProvisionalSampling.revision();
|
||||
refined = renderer.refineStudioBiome(0D, 0D, 4D * PIXELS, preview, () -> false);
|
||||
} while (ProvisionalSampling.revision() != revision);
|
||||
|
||||
assertNotEquals(Color.GREEN.getRGB(), refined.getRGB(POND_X / 4, POND_Z / 4));
|
||||
assertNotEquals(Color.GREEN.getRGB(), refined.getRGB(LAKE_X / 4, LAKE_Z / 4));
|
||||
assertNotEquals(Color.GREEN.getRGB(), refined.getRGB(STREAM_X / 4, STREAM_Z / 4));
|
||||
assertEquals(Color.GREEN.getRGB(), refined.getRGB(DRY / 4, DRY / 4));
|
||||
int[] composite = settled(engine(runtime), 4D * PIXELS, PIXELS, green(PIXELS));
|
||||
|
||||
assertNotEquals(GREEN, at(composite, PIXELS, POND_X / 4, POND_Z / 4));
|
||||
assertNotEquals(GREEN, at(composite, PIXELS, LAKE_X / 4, LAKE_Z / 4));
|
||||
assertNotEquals(GREEN, at(composite, PIXELS, STREAM_X / 4, STREAM_Z / 4));
|
||||
assertEquals(GREEN, at(composite, PIXELS, DRY / 4, DRY / 4));
|
||||
assertNoRasters(runtime);
|
||||
}
|
||||
}
|
||||
@@ -321,11 +296,11 @@ public class IrisRendererRiverTest {
|
||||
return new FakeHydrology(() -> false, (x, z) -> 60, SEA_LEVEL, List.of(brook), List.of(pond), List.of(lake));
|
||||
}
|
||||
|
||||
private static void assertScene(BufferedImage image, int step) {
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.POND), image.getRGB(POND_X / step, POND_Z / step));
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.LAKE), image.getRGB(LAKE_X / step, LAKE_Z / step));
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.STREAM), image.getRGB(STREAM_X / step, STREAM_Z / step));
|
||||
assertEquals(NO_RIVER, image.getRGB(DRY / step, DRY / step));
|
||||
private static void assertScene(int[] colors, int step) {
|
||||
assertEquals(water(HydrologyFeatureType.POND), at(colors, PIXELS, POND_X / step, POND_Z / step));
|
||||
assertEquals(water(HydrologyFeatureType.LAKE), at(colors, PIXELS, LAKE_X / step, LAKE_Z / step));
|
||||
assertEquals(water(HydrologyFeatureType.STREAM), at(colors, PIXELS, STREAM_X / step, STREAM_Z / step));
|
||||
assertEquals(NO_RIVER, at(colors, PIXELS, DRY / step, DRY / step));
|
||||
}
|
||||
|
||||
private static void assertNoRasters(HydrologyRuntime runtime) {
|
||||
@@ -334,28 +309,36 @@ public class IrisRendererRiverTest {
|
||||
verify(runtime, never()).raster(anyInt(), anyInt());
|
||||
}
|
||||
|
||||
private static void greenBiomes(Engine engine) {
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<IrisBiome> base = mock(ProceduralStream.class);
|
||||
when(engine.getComplex().getBaseBiomeStream()).thenReturn(base);
|
||||
when(base.get(anyDouble(), anyDouble())).thenReturn(biome);
|
||||
when(biome.getColor(engine, RenderType.BIOME)).thenReturn(Color.GREEN);
|
||||
private static int water(HydrologyFeatureType type) {
|
||||
return IrisRenderer.hydrologyFeatureColor(type) & 0xFFFFFF;
|
||||
}
|
||||
|
||||
private static BufferedImage settled(Engine engine, double span, int pixels, RenderType type) throws InterruptedException {
|
||||
return settled(engine, 0D, span, pixels, type);
|
||||
private static int at(int[] colors, int pixels, int x, int z) {
|
||||
return colors[z * pixels + x];
|
||||
}
|
||||
|
||||
private static BufferedImage settled(Engine engine, double startZ, double span, int pixels, RenderType type)
|
||||
throws InterruptedException {
|
||||
IrisRenderer renderer = new IrisRenderer(engine);
|
||||
private static int[] green(int pixels) {
|
||||
int[] base = new int[pixels * pixels];
|
||||
Arrays.fill(base, GREEN);
|
||||
return base;
|
||||
}
|
||||
|
||||
private static int[] settled(Engine engine, double span, int pixels) throws InterruptedException {
|
||||
return settled(engine, 0D, span, pixels, null);
|
||||
}
|
||||
|
||||
private static int[] settled(Engine engine, double span, int pixels, int[] base) throws InterruptedException {
|
||||
return settled(engine, 0D, span, pixels, base);
|
||||
}
|
||||
|
||||
private static int[] settled(Engine engine, double startZ, double span, int pixels, int[] base) throws InterruptedException {
|
||||
IrisRenderer.WaterTile tile = new IrisRenderer(engine).prepareStudioWater(0D, startZ, span / pixels, pixels);
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(SETTLE_SECONDS);
|
||||
while (true) {
|
||||
long revision = ProvisionalSampling.revision();
|
||||
BufferedImage image = renderer.renderStudio(0D, startZ, span, pixels, type, () -> false);
|
||||
int[] colors = tile.render(base, base != null, () -> false);
|
||||
if (ProvisionalSampling.revision() == revision) {
|
||||
return image;
|
||||
return colors;
|
||||
}
|
||||
assertTrue("The water map never settled", System.nanoTime() < deadline);
|
||||
Thread.sleep(10L);
|
||||
|
||||
@@ -34,7 +34,8 @@ public class WaterMapProgressTest {
|
||||
.thenReturn(new HydrologyPlanPreview(List.of(reach), List.of(), List.of(), List.of(), true));
|
||||
when(runtime.rasterPreview(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.EMPTY);
|
||||
|
||||
WaterMap map = WaterMap.draw(runtime, 32, 0D, 0D, 1D, () -> false);
|
||||
WaterMap map = new WaterMap(runtime, 32, 0D, 0D, 1D);
|
||||
map.advance(() -> false);
|
||||
|
||||
assertFalse(map.provisional());
|
||||
verifyNoInteractions(reach);
|
||||
@@ -84,7 +85,8 @@ public class WaterMapProgressTest {
|
||||
assertTrue(map.provisional());
|
||||
map.advance(() -> false);
|
||||
assertFalse(map.provisional());
|
||||
WaterMap expected = WaterMap.draw(runtime, 32, -16.5D, -16.5D, 0.5D, () -> false);
|
||||
WaterMap expected = new WaterMap(runtime, 32, -16.5D, -16.5D, 0.5D);
|
||||
expected.advance(() -> false);
|
||||
for (int z = 0; z < 32; z++) {
|
||||
for (int x = 0; x < 32; x++) {
|
||||
assertEquals(expected.at(x, z), map.at(x, z));
|
||||
|
||||
@@ -55,6 +55,8 @@ public class WaterMapTest {
|
||||
when(runtime.planPreview(anyInt(), anyInt(), anyInt(), anyInt()))
|
||||
.thenReturn(new HydrologyPlanPreview(reaches, ponds, lakes, List.of(), true));
|
||||
when(runtime.channelType(any(HydrologyTier.class))).thenReturn(HydrologyFeatureType.STREAM);
|
||||
return WaterMap.draw(runtime, PIXELS, 0D, 0D, MID_STEP, () -> false);
|
||||
WaterMap map = new WaterMap(runtime, PIXELS, 0D, 0D, MID_STEP);
|
||||
map.advance(() -> false);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user