mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +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
@@ -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