mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Rank studio water features
- Plan-mode pond and lake masks keep the strongest feature per pixel instead of overwriting channels and falls - Water map ranks come from an explicit switch per feature type, with ponds above lakes - Studio water tiles redraw recorded cave pools when the hydrology preview revision changes - Tests cover channels over ponds, ponds over lakes and cave pool refresh on a completed tile
This commit is contained in:
1 parent
c0169d6dcd
commit
0c59e698cd
5 files changed
+185
-32
No files matched your search
@@ -457,15 +457,17 @@ public final class IrisRenderer {
|
||||
private final double startZ;
|
||||
private final double step;
|
||||
private final int resolution;
|
||||
private final HydrologyRuntime runtime;
|
||||
private final WaterMap map;
|
||||
private boolean complete;
|
||||
private long poolRevision;
|
||||
|
||||
private WaterTile(double startX, double startZ, double step, int resolution) {
|
||||
this.startX = startX;
|
||||
this.startZ = startZ;
|
||||
this.step = step;
|
||||
this.resolution = resolution;
|
||||
HydrologyRuntime runtime = renderer.getComplex().getHydrologyRuntime();
|
||||
this.runtime = renderer.getComplex().getHydrologyRuntime();
|
||||
this.map = runtime == null || !runtime.enabled() || step > WaterMap.MAX_STEP
|
||||
? null : new WaterMap(runtime, resolution, startX, startZ, step);
|
||||
complete = map == null;
|
||||
@@ -477,13 +479,8 @@ public final class IrisRenderer {
|
||||
if (composite && (base == null || base.length != resolution * resolution)) {
|
||||
throw new IllegalArgumentException("Water overlay requires matching base pixels");
|
||||
}
|
||||
if (!complete) {
|
||||
map.advance(cancelled);
|
||||
map.drawCavePools(GenerationSemanticQueries.recordedCavePools(renderer,
|
||||
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)));
|
||||
complete = !map.provisional();
|
||||
if (map != null) {
|
||||
draw(cancelled);
|
||||
}
|
||||
int[] colors = composite ? base.clone() : new int[resolution * resolution];
|
||||
if (!composite) {
|
||||
@@ -515,6 +512,23 @@ public final class IrisRenderer {
|
||||
public long bytes() {
|
||||
return map == null ? 0L : map.bytes();
|
||||
}
|
||||
|
||||
private void draw(BooleanSupplier cancelled) {
|
||||
long revision = runtime.previewRevision();
|
||||
boolean advanced = !complete;
|
||||
if (advanced) {
|
||||
map.advance(cancelled);
|
||||
complete = !map.provisional();
|
||||
}
|
||||
if (!advanced && revision == poolRevision) {
|
||||
return;
|
||||
}
|
||||
map.drawCavePools(GenerationSemanticQueries.recordedCavePools(renderer,
|
||||
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)));
|
||||
poolRevision = revision;
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
|
||||
@@ -24,12 +24,8 @@ import java.util.function.BooleanSupplier;
|
||||
final class WaterMap {
|
||||
static final double RASTER_STEP = 2D;
|
||||
static final double MAX_STEP = 16D;
|
||||
static final List<HydrologyFeatureType> DRAWN = List.of(HydrologyFeatureType.WATERFALL, HydrologyFeatureType.CASCADE,
|
||||
HydrologyFeatureType.MOUTH, HydrologyFeatureType.MAJOR_RIVER, HydrologyFeatureType.RIVER, HydrologyFeatureType.STREAM,
|
||||
HydrologyFeatureType.SEA_INLET, HydrologyFeatureType.LAKE, HydrologyFeatureType.POND, HydrologyFeatureType.DAM,
|
||||
HydrologyFeatureType.CAVE_POOL);
|
||||
static final List<HydrologyFeatureType> DRAWN = drawn();
|
||||
private static final int DRY = Integer.MAX_VALUE;
|
||||
private static final int[] RANK = ranks();
|
||||
|
||||
private final HydrologyRuntime runtime;
|
||||
private final int resolution;
|
||||
@@ -280,7 +276,7 @@ final class WaterMap {
|
||||
int lastX = Math.min(resolution - 1, (int) Math.floor((centreX + half - 1 - startX) / step));
|
||||
for (int pixelZ = firstZ; pixelZ <= lastZ; pixelZ++) {
|
||||
for (int pixelX = firstX; pixelX <= lastX; pixelX++) {
|
||||
ranks[pixelZ * resolution + pixelX] = RANK[type.ordinal()];
|
||||
stamp(pixelX, pixelZ, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -296,7 +292,7 @@ final class WaterMap {
|
||||
return;
|
||||
}
|
||||
int index = pixelZ * resolution + pixelX;
|
||||
int rank = RANK[type.ordinal()];
|
||||
int rank = rank(type);
|
||||
if (rank < ranks[index]) {
|
||||
ranks[index] = rank;
|
||||
}
|
||||
@@ -308,12 +304,31 @@ final class WaterMap {
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] ranks() {
|
||||
int[] ranks = new int[HydrologyFeatureType.values().length];
|
||||
Arrays.fill(ranks, DRY);
|
||||
for (int index = 0; index < DRAWN.size(); index++) {
|
||||
ranks[DRAWN.get(index).ordinal()] = index;
|
||||
private static int rank(HydrologyFeatureType type) {
|
||||
return switch (type) {
|
||||
case WATERFALL -> 0;
|
||||
case CASCADE -> 1;
|
||||
case MOUTH -> 2;
|
||||
case MAJOR_RIVER -> 3;
|
||||
case RIVER -> 4;
|
||||
case STREAM -> 5;
|
||||
case SEA_INLET -> 6;
|
||||
case POND -> 7;
|
||||
case LAKE -> 8;
|
||||
case DAM -> 9;
|
||||
case CAVE_POOL -> 10;
|
||||
};
|
||||
}
|
||||
|
||||
private static List<HydrologyFeatureType> drawn() {
|
||||
HydrologyFeatureType[] drawn = new HydrologyFeatureType[HydrologyFeatureType.values().length];
|
||||
for (HydrologyFeatureType type : HydrologyFeatureType.values()) {
|
||||
int rank = rank(type);
|
||||
if (drawn[rank] != null) {
|
||||
throw new IllegalStateException("Water map ranks " + drawn[rank] + " and " + type + " equally");
|
||||
}
|
||||
drawn[rank] = type;
|
||||
}
|
||||
return ranks;
|
||||
return List.of(drawn);
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,8 @@ public class IrisRendererRiverTest {
|
||||
assertEquals("cave pools sit under everything else", HydrologyFeatureType.CAVE_POOL, drawn.getLast());
|
||||
assertTrue(drawn.containsAll(List.of(HydrologyFeatureType.STREAM, HydrologyFeatureType.RIVER, HydrologyFeatureType.MAJOR_RIVER,
|
||||
HydrologyFeatureType.LAKE, HydrologyFeatureType.POND, HydrologyFeatureType.DAM, HydrologyFeatureType.SEA_INLET)));
|
||||
assertTrue(drawn.indexOf(HydrologyFeatureType.LAKE) < drawn.indexOf(HydrologyFeatureType.POND));
|
||||
assertTrue(drawn.indexOf(HydrologyFeatureType.STREAM) < drawn.indexOf(HydrologyFeatureType.POND));
|
||||
assertTrue(drawn.indexOf(HydrologyFeatureType.POND) < drawn.indexOf(HydrologyFeatureType.LAKE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,21 +196,15 @@ public class IrisRendererRiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void standingWaterCoversChannelsInBothDrawModes() throws Exception {
|
||||
public void standingWaterCoversChannelsInRasters() throws Exception {
|
||||
HydrologySettings settings = FakeHydrology.settings(SEA_LEVEL);
|
||||
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))) {
|
||||
Engine engine = engine(hydrology.runtime);
|
||||
BufferedImage image = settled(engine(hydrology.runtime), 2D * PIXELS, PIXELS, RenderType.RIVER);
|
||||
|
||||
for (int step : new int[]{2, 4}) {
|
||||
BufferedImage image = settled(engine, (double) step * PIXELS, PIXELS, RenderType.RIVER);
|
||||
|
||||
assertEquals("pond over the channel at " + step + " b/px", IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.POND),
|
||||
image.getRGB(POND_X / step, POND_Z / step));
|
||||
assertEquals("channel outside the pond at " + step + " b/px",
|
||||
IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.STREAM), image.getRGB(8 / step, POND_Z / step));
|
||||
}
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.POND), image.getRGB(POND_X / 2, POND_Z / 2));
|
||||
assertEquals(IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.STREAM), image.getRGB(4, POND_Z / 2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package art.arcane.iris.studio.render;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyPlanPreview;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.world.history.ChunkGenerationSemantics;
|
||||
import art.arcane.iris.world.history.GenerationHistory;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisRendererTest {
|
||||
private static final int PIXELS = 32;
|
||||
private static final double STEP = 4D;
|
||||
|
||||
@Test
|
||||
public void cavePoolsRefreshOnRevision() {
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
AtomicLong revision = new AtomicLong(7L);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.planPreview(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(HydrologyPlanPreview.EMPTY);
|
||||
when(runtime.previewRevision()).thenAnswer(invocation -> revision.get());
|
||||
AtomicBoolean recorded = new AtomicBoolean();
|
||||
IrisEngine engine = engine(runtime, recorded);
|
||||
IrisRenderer.WaterTile tile = new IrisRenderer(engine).prepareStudioWater(0D, 0D, STEP, PIXELS);
|
||||
int pool = IrisRenderer.hydrologyFeatureColor(HydrologyFeatureType.CAVE_POOL) & 0xFFFFFF;
|
||||
int index = (24 / (int) STEP) * PIXELS + 20 / (int) STEP;
|
||||
|
||||
int[] before = tile.render(null, false, () -> false);
|
||||
assertTrue(tile.complete());
|
||||
assertNotEquals(pool, before[index]);
|
||||
|
||||
recorded.set(true);
|
||||
int[] sameRevision = tile.render(null, false, () -> false);
|
||||
assertNotEquals("a completed tile keeps its pools until the plan revision moves", pool, sameRevision[index]);
|
||||
|
||||
revision.incrementAndGet();
|
||||
int[] refreshed = tile.render(null, false, () -> false);
|
||||
assertEquals(pool, refreshed[index]);
|
||||
}
|
||||
|
||||
private static IrisEngine engine(HydrologyRuntime runtime, AtomicBoolean recorded) {
|
||||
IrisEngine engine = mock(IrisEngine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
GenerationHistory history = mock(GenerationHistory.class);
|
||||
GenerationHistoryRuntimeRouter router = mock(GenerationHistoryRuntimeRouter.class);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(router.history()).thenReturn(history);
|
||||
ChunkGenerationSemantics pool = ChunkGenerationSemantics.builder(1, 1, 1L)
|
||||
.addRiverFeature("water", HydrologyFeatureType.CAVE_POOL, 7L, 20, 12, 24).build();
|
||||
when(history.semantics(anyInt(), anyInt())).thenReturn(Optional.empty());
|
||||
when(history.semantics(1, 1)).thenAnswer(invocation -> recorded.get() ? Optional.of(pool) : Optional.empty());
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package art.arcane.iris.studio.render;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyPlanPreview;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.testsupport.WaterScene;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class WaterMapTest {
|
||||
private static final int PIXELS = 32;
|
||||
private static final double MID_STEP = 4D;
|
||||
private static final int LEVEL = 62;
|
||||
private static final int POND_X = 30;
|
||||
private static final int POND_Z = 30;
|
||||
|
||||
@Test
|
||||
public void channelsDrawOverPondsAtMidZoom() {
|
||||
HydrologyTier tier = WaterScene.stream();
|
||||
Reach across = WaterScene.line(1L, tier, 4, POND_Z, 60, POND_Z, (x, z) -> LEVEL);
|
||||
Reach fall = WaterScene.line(2L, tier, POND_X, 10, POND_X, 50, (x, z) -> z < POND_Z ? LEVEL + 8 : LEVEL);
|
||||
Pond pond = WaterScene.pond(3L, LEVEL, POND_X, POND_Z, 10);
|
||||
|
||||
WaterMap map = draw(List.of(across, fall), List.of(pond), List.of());
|
||||
|
||||
assertEquals("the fall where both channels cross the pond", HydrologyFeatureType.WATERFALL, map.at(7, 7));
|
||||
assertEquals("the channel across the pond", HydrologyFeatureType.STREAM, map.at(6, 7));
|
||||
assertEquals("the channel below the fall", HydrologyFeatureType.STREAM, map.at(7, 9));
|
||||
assertEquals("open pond water", HydrologyFeatureType.POND, map.at(9, 9));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pondsDrawOverLakesAtMidZoom() {
|
||||
Pond pond = WaterScene.pond(4L, LEVEL, POND_X, POND_Z, 10);
|
||||
Pond lake = WaterScene.pond(5L, LEVEL, 44, POND_Z, 12);
|
||||
|
||||
WaterMap map = draw(List.of(), List.of(pond), List.of(lake));
|
||||
|
||||
assertEquals("pond and lake share the pixel", HydrologyFeatureType.POND, map.at(9, 7));
|
||||
assertEquals("open lake water", HydrologyFeatureType.LAKE, map.at(13, 7));
|
||||
}
|
||||
|
||||
private static WaterMap draw(List<Reach> reaches, List<Pond> ponds, List<Pond> lakes) {
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user