mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Studio map: inspect noise picks and preview one region
The picks route measures, for the area in view, how each region or biome noise spreads over the bands that pick its options, against how much ground each option gets. Tiles can carry the noise that settled each spot's pick, and the regions view can preview one region across the whole map with the surface biomes it would place there. Preview tiles take their heights from the shading lattice, so they draw as fast as biome tiles. Only coastline pixels can then disagree with the hover's exact biome: 0.25% of spots at 1-2 blocks/px, 2.3% at 8. The bridge serialises nulls so the studio can tell "none" from "not sent".
This commit is contained in:
1 parent
467d42abea
commit
13c0705d44
17 files changed
+1123
-195
No files matched your search
@@ -166,6 +166,8 @@ public class StudioBridgeTest {
|
||||
JsonObject firstStep = hover.getAsJsonArray("pickPath").get(0).getAsJsonObject();
|
||||
assertEquals("FOCUS", firstStep.get("kind").getAsString());
|
||||
assertEquals("temperate", firstStep.getAsJsonObject("picked").get("key").getAsString());
|
||||
assertTrue("nothing picked the focused region, which the studio reads as a null noise",
|
||||
firstStep.has("noise") && firstStep.get("noise").isJsonNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,6 +177,17 @@ public class StudioBridgeTest {
|
||||
assertEquals(400, response.statusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyTheRegionViewPreviewsARegionAndOnlyOneTheWorldPrepared() throws Exception {
|
||||
assertEquals(400, get("hover?view=biomes&preview=temperate&x=0&z=0").statusCode());
|
||||
assertEquals(400, get("hover?view=regions&preview=nowhere&x=0&z=0").statusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theHeightViewHasNoPicksToInspect() throws Exception {
|
||||
assertEquals(400, get("picks?view=height&minX=0&minZ=0&maxX=10&maxZ=10").statusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aWorldWithoutAnEngineIsUnavailableUntilItHasOneAgain() throws Exception {
|
||||
Engine engine = running.getAndSet(null);
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package art.arcane.iris.core.studio.map;
|
||||
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class MapPickInspectionTest {
|
||||
private static final MapPickInspection.Area AREA = new MapPickInspection.Area(-100D, -100D, 100D, 100D);
|
||||
private static final long SPOTS = (long) MapPickInspection.SAMPLES_PER_SIDE * MapPickInspection.SAMPLES_PER_SIDE;
|
||||
|
||||
private final PickedWorld world = new PickedWorld();
|
||||
|
||||
@Test
|
||||
public void theRegionViewMeasuresTheRegionNoiseAgainstEachRegionsShare() {
|
||||
MapPickInspection.Inspection inspection = measure(MapLayer.of(MapView.REGIONS));
|
||||
|
||||
MapPickInspection.Section section = inspection.sections().getFirst();
|
||||
assertNull("the regions themselves are picked, not one region's biomes", section.region());
|
||||
MapPickInspection.Spread regions = section.spreads().getFirst();
|
||||
assertEquals(SPOTS, regions.samples());
|
||||
assertEquals("every spot reads 0.9", SPOTS, regions.histogram()[45]);
|
||||
assertRow(regions.rows().get(0), "warm", 0.75D, 0D);
|
||||
assertRow(regions.rows().get(1), "dry", 0.25D, 1D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theBiomeViewMeasuresEachRegionsListAndEveryChildNoiseItsSpotsReach() {
|
||||
MapPickInspection.Inspection inspection = measure(MapLayer.of(MapView.BIOMES));
|
||||
|
||||
assertEquals(1, inspection.sections().size());
|
||||
MapPickInspection.Section dry = inspection.sections().getFirst();
|
||||
assertEquals("dry", dry.region().key());
|
||||
assertEquals(1D, dry.share(), 0D);
|
||||
assertEquals("plains, forest, meadow and glade", 4, dry.biomeCount());
|
||||
assertEquals(List.of("Land biome noise", "Plains child noise", "Meadow child noise"),
|
||||
dry.spreads().stream().map(MapPickInspection.Spread::title).toList());
|
||||
assertRow(dry.spreads().get(0).rows().get(0), "plains", 0.5D, 1D);
|
||||
MapPickInspection.Spread plainsChildren = dry.spreads().get(1);
|
||||
assertEquals("meadow's slot and plains' two slots are two bands", 2, plainsChildren.rows().size());
|
||||
assertRow(plainsChildren.rows().get(0), "meadow", 0.25D, 1D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPreviewMeasuresThePreviewedRegionsListsEverywhere() {
|
||||
IrisComplex complex = world.complex;
|
||||
var landBiomes = complex.pickableBiomes(world.dry, InferredType.LAND);
|
||||
var landNoise = complex.biomePickNoise(world.dry, InferredType.LAND);
|
||||
var landPicks = complex.biomePicks(world.dry, InferredType.LAND);
|
||||
when(complex.surfacePickAsIfIn(eq(world.warm), anyDouble(), anyDouble()))
|
||||
.thenReturn(new IrisComplex.BiomePick(world.meadow, InferredType.LAND));
|
||||
when(complex.pickableBiomes(world.warm, InferredType.LAND)).thenReturn(landBiomes);
|
||||
when(complex.biomePickNoise(world.warm, InferredType.LAND)).thenReturn(landNoise);
|
||||
when(complex.biomePicks(world.warm, InferredType.LAND)).thenReturn(landPicks);
|
||||
|
||||
MapPickInspection.Section section = measure(MapLayer.preview(world.warm)).sections().getFirst();
|
||||
|
||||
assertEquals("warm", section.region().key());
|
||||
assertEquals(SPOTS, section.spreads().getFirst().samples());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theHeightViewHasNoPicks() {
|
||||
assertThrows(IllegalArgumentException.class, () -> measure(MapLayer.of(MapView.HEIGHT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anAreaNeedsItsSecondCornerBeyondItsFirst() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new MapPickInspection.Area(0D, 0D, 0D, 10D));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theBiomeNoiseSettlesAtTheLastChildPick() {
|
||||
TileGrid grid = new TileGrid(2, 0D, 0D, 1D, () -> false);
|
||||
|
||||
float[] noise = MapPickNoise.sample(world.engine, MapLayer.of(MapView.BIOMES), grid);
|
||||
|
||||
assertEquals("meadow kept the spot at 0.8", 0.8F, noise[3], 1e-6F);
|
||||
}
|
||||
|
||||
private MapPickInspection.Inspection measure(MapLayer layer) {
|
||||
return MapPickInspection.measure(world.engine, layer, AREA);
|
||||
}
|
||||
|
||||
private static void assertRow(MapPickInspection.Row row, String key, double weight, double inView) {
|
||||
assertEquals(key, row.option().key());
|
||||
assertEquals(weight, row.weight(), 1e-9);
|
||||
assertEquals(inView, row.inView(), 1e-9);
|
||||
}
|
||||
}
|
||||
@@ -1,84 +1,27 @@
|
||||
package art.arcane.iris.core.studio.map;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.render.RenderType;
|
||||
import art.arcane.iris.engine.image.IrisImageMapRuntime;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class MapPickPathTest {
|
||||
private static final double X = 12D;
|
||||
private static final double Z = -7D;
|
||||
|
||||
private final Engine engine = mock(Engine.class);
|
||||
private final IrisComplex complex = mock(IrisComplex.class);
|
||||
private final IrisBiome plains = biome("plains", "Plains", 1);
|
||||
private final IrisBiome forest = biome("forest", "Forest", 1);
|
||||
private final IrisBiome meadow = biome("meadow", "Meadow", 1);
|
||||
private final IrisBiome glade = biome("glade", "Glade", 1);
|
||||
private IrisRegion dry;
|
||||
|
||||
/**
|
||||
* A dry region (rarity 3, so the last quarter of the region noise) picked at 0.9; its land list picks plains at 0.2;
|
||||
* plains' child noise at 0.1 rounds to its first slot, meadow; meadow's at 0.8 rounds to its last slot, itself.
|
||||
*/
|
||||
@Before
|
||||
public void pickTheWayDown() {
|
||||
IrisRegion warm = region("warm", "Warm", 1);
|
||||
dry = region("dry", "Dry", 3);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.getRegions()).thenReturn(new KList<>(List.of("warm", "dry")));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
IrisData data = mock(IrisData.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
|
||||
when(regionLoader.loadAll(any(KList.class))).thenReturn(new KList<>(List.of(warm, dry)));
|
||||
when(data.getRegionLoader()).thenReturn(regionLoader);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
IrisImageMapRuntime noImageMap = mock(IrisImageMapRuntime.class);
|
||||
when(complex.getImageMapRuntime()).thenReturn(noImageMap);
|
||||
|
||||
ProceduralStream<IrisRegion> regions = stream(dry);
|
||||
ProceduralStream<Double> regionNoise = stream(0.9D);
|
||||
ProceduralStream<InferredType> continents = stream(InferredType.LAND);
|
||||
ProceduralStream<Double> landNoise = stream(0.2D);
|
||||
when(complex.getRegionStream()).thenReturn(regions);
|
||||
when(complex.getRegionStyleStream()).thenReturn(regionNoise);
|
||||
when(complex.getBridgeStream()).thenReturn(continents);
|
||||
when(complex.pickableBiomes(dry, InferredType.LAND)).thenReturn(new KList<>(List.of(plains, forest)));
|
||||
when(complex.biomePickNoise(dry, InferredType.LAND)).thenReturn(landNoise);
|
||||
children(plains, List.of(meadow, plains, plains), 0.1D);
|
||||
children(meadow, List.of(glade, meadow), 0.8D);
|
||||
}
|
||||
private final PickedWorld world = new PickedWorld();
|
||||
|
||||
@Test
|
||||
public void theBiomeViewWalksFromTheRegionThroughItsListToTheChildThatKeptTheSpot() {
|
||||
List<MapPickPath.PickStep> path = MapPickPath.explain(engine, MapView.BIOMES, X, Z);
|
||||
List<MapPickPath.PickStep> path = explain(MapLayer.of(MapView.BIOMES));
|
||||
|
||||
assertEquals(List.of(MapPickPath.Kind.REGION, MapPickPath.Kind.BIOME, MapPickPath.Kind.CHILD, MapPickPath.Kind.CHILD),
|
||||
path.stream().map(MapPickPath.PickStep::kind).toList());
|
||||
kinds(path));
|
||||
MapPickPath.PickStep region = path.get(0);
|
||||
assertEquals("dry", region.picked().key());
|
||||
assertEquals(0.9D, region.noise(), 0D);
|
||||
@@ -94,7 +37,7 @@ public class MapPickPathTest {
|
||||
|
||||
@Test
|
||||
public void aChildStepJoinsNeighbouringSlotsOfOneBiome() {
|
||||
List<MapPickPath.PickBand> bands = MapPickPath.explain(engine, MapView.BIOMES, X, Z).get(2).bands();
|
||||
List<MapPickPath.PickBand> bands = explain(MapLayer.of(MapView.BIOMES)).get(2).bands();
|
||||
|
||||
assertEquals(2, bands.size());
|
||||
assertBand(bands.get(0), "meadow", 0D, 0.25D);
|
||||
@@ -103,17 +46,14 @@ public class MapPickPathTest {
|
||||
|
||||
@Test
|
||||
public void theLandViewStopsAtTheListPickBecauseItsStreamHasNoChildren() {
|
||||
List<MapPickPath.PickStep> path = MapPickPath.explain(engine, MapView.LAND_BIOMES, X, Z);
|
||||
|
||||
assertEquals(List.of(MapPickPath.Kind.REGION, MapPickPath.Kind.BIOME), path.stream().map(MapPickPath.PickStep::kind).toList());
|
||||
assertEquals(List.of(MapPickPath.Kind.REGION, MapPickPath.Kind.BIOME), kinds(explain(MapLayer.of(MapView.LAND_BIOMES))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anImageMappedRegionWasChosenNotPicked() {
|
||||
IrisImageMapRuntime imageMap = complex.getImageMapRuntime();
|
||||
when(imageMap.sampleRegion(X, Z)).thenReturn(dry);
|
||||
when(world.imageMap.sampleRegion(X, Z)).thenReturn(world.dry);
|
||||
|
||||
MapPickPath.PickStep region = MapPickPath.explain(engine, MapView.REGIONS, X, Z).getFirst();
|
||||
MapPickPath.PickStep region = explain(MapLayer.of(MapView.REGIONS)).getFirst();
|
||||
|
||||
assertEquals(MapPickPath.Kind.IMAGE_MAP, region.kind());
|
||||
assertNull(region.noise());
|
||||
@@ -121,52 +61,36 @@ public class MapPickPathTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void slotsRoundTheWayTheChildNoiseDoes() {
|
||||
assertEquals(0, MapPickPath.slotIndex(0.24D, 3));
|
||||
assertEquals(1, MapPickPath.slotIndex(0.26D, 3));
|
||||
assertEquals(2, MapPickPath.slotIndex(1.4D, 3));
|
||||
assertEquals(0, MapPickPath.slotIndex(0.9D, 1));
|
||||
public void aPreviewedRegionOwnsTheSpotAndPicksFromTheListItsSurfaceNeeds() {
|
||||
when(world.complex.surfacePickAsIfIn(world.dry, X, Z)).thenReturn(new IrisComplex.BiomePick(world.meadow, InferredType.LAND));
|
||||
|
||||
List<MapPickPath.PickStep> path = explain(MapLayer.preview(world.dry));
|
||||
|
||||
assertEquals(List.of(MapPickPath.Kind.PREVIEW, MapPickPath.Kind.BIOME, MapPickPath.Kind.CHILD, MapPickPath.Kind.CHILD),
|
||||
kinds(path));
|
||||
assertEquals("dry", path.get(0).picked().key());
|
||||
assertEquals("land", path.get(1).list());
|
||||
}
|
||||
|
||||
private static void assertBand(MapPickPath.PickBand band, String key, double from, double to) {
|
||||
@Test
|
||||
public void slotsRoundTheWayTheChildNoiseDoes() {
|
||||
assertEquals(0, ChildPicks.slotIndex(0.24D, 3));
|
||||
assertEquals(1, ChildPicks.slotIndex(0.26D, 3));
|
||||
assertEquals(2, ChildPicks.slotIndex(1.4D, 3));
|
||||
assertEquals(0, ChildPicks.slotIndex(0.9D, 1));
|
||||
}
|
||||
|
||||
private List<MapPickPath.PickStep> explain(MapLayer layer) {
|
||||
return MapPickPath.explain(world.engine, layer, X, Z);
|
||||
}
|
||||
|
||||
private static List<MapPickPath.Kind> kinds(List<MapPickPath.PickStep> path) {
|
||||
return path.stream().map(MapPickPath.PickStep::kind).toList();
|
||||
}
|
||||
|
||||
static void assertBand(MapPickPath.PickBand band, String key, double from, double to) {
|
||||
assertEquals(key, band.option().key());
|
||||
assertEquals(from, band.from(), 1e-9);
|
||||
assertEquals(to, band.to(), 1e-9);
|
||||
}
|
||||
|
||||
private void children(IrisBiome parent, List<IrisBiome> slots, double noise) {
|
||||
when(parent.getChildren()).thenReturn(new KList<>(List.of("child")));
|
||||
when(complex.childSlots(parent)).thenReturn(slots);
|
||||
CNG childNoise = mock(CNG.class);
|
||||
when(childNoise.noiseFast2D(X, Z)).thenReturn(noise);
|
||||
when(complex.childNoise(parent)).thenReturn(childNoise);
|
||||
}
|
||||
|
||||
private IrisBiome biome(String key, String name, int rarity) {
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
when(biome.getLoadKey()).thenReturn(key);
|
||||
when(biome.getName()).thenReturn(name);
|
||||
when(biome.getRarity()).thenReturn(rarity);
|
||||
when(biome.getChildren()).thenReturn(new KList<>());
|
||||
when(biome.getInferredType()).thenReturn(InferredType.LAND);
|
||||
when(biome.withInferredType(any(InferredType.class))).thenReturn(biome);
|
||||
when(biome.getColor(eq(engine), any(RenderType.class))).thenReturn(Color.GREEN);
|
||||
return biome;
|
||||
}
|
||||
|
||||
private IrisRegion region(String key, String name, int rarity) {
|
||||
IrisRegion region = mock(IrisRegion.class);
|
||||
when(region.getLoadKey()).thenReturn(key);
|
||||
when(region.getName()).thenReturn(name);
|
||||
when(region.getRarity()).thenReturn(rarity);
|
||||
when(region.getColor(complex, RenderType.REGION)).thenReturn(Color.ORANGE);
|
||||
return region;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> ProceduralStream<T> stream(T value) {
|
||||
ProceduralStream<T> stream = mock(ProceduralStream.class);
|
||||
when(stream.get(anyDouble(), anyDouble())).thenReturn(value);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package art.arcane.iris.core.studio.map;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.render.RenderType;
|
||||
import art.arcane.iris.engine.image.IrisImageMapRuntime;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
@@ -14,6 +16,7 @@ import org.junit.Test;
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.function.DoubleBinaryOperator;
|
||||
|
||||
@@ -121,7 +124,7 @@ public class MapTileRendererTest {
|
||||
Engine untouched = mock(Engine.class);
|
||||
|
||||
assertThrows(CancellationException.class,
|
||||
() -> new MapTileRenderer(untouched).render(MapView.BIOMES, 0D, 0D, 1D, SIZE, false, () -> true));
|
||||
() -> new MapTileRenderer(untouched).render(MapLayer.of(MapView.BIOMES), 0D, 0D, 1D, SIZE, Set.of(), () -> true));
|
||||
verifyNoInteractions(untouched);
|
||||
}
|
||||
|
||||
@@ -144,7 +147,7 @@ public class MapTileRendererTest {
|
||||
when(complex.getFocusBiome()).thenReturn(desert);
|
||||
when(desert.getChildren()).thenReturn(new art.arcane.volmlib.util.collection.KList<>());
|
||||
|
||||
MapHover hover = MapHover.sample(engine, MapView.BIOMES, 10D, 0D);
|
||||
MapHover hover = MapHover.sample(engine, MapLayer.of(MapView.BIOMES), 10D, 0D);
|
||||
|
||||
assertEquals("desert", hover.biome().key());
|
||||
assertEquals("cavern", hover.caveBiome().key());
|
||||
@@ -168,8 +171,45 @@ public class MapTileRendererTest {
|
||||
assertEquals(Optional.empty(), MapView.byId("nothing"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRegionPreviewLabelsTheBiomesThatRegionWouldPlaceAndOwnsEverySpot() {
|
||||
heights((x, z) -> 70D);
|
||||
when(complex.surfacePickAsIfIn(org.mockito.ArgumentMatchers.eq(dry), anyDouble(), anyDouble(), anyDouble()))
|
||||
.thenAnswer(call -> new IrisComplex.BiomePick((double) call.getArgument(1) < 0 ? cavern : desert, InferredType.LAND));
|
||||
|
||||
MapTile tile = new MapTileRenderer(engine).render(MapLayer.preview(dry), -4D, 0D, 1D, SIZE, Set.of(), () -> false);
|
||||
|
||||
assertEquals(MapLabel.Kind.BIOME, tile.subjectKind());
|
||||
assertEquals("cavern", tile.subjectAt(0, 0).key());
|
||||
assertEquals("desert", tile.subjectAt(4, 0).key());
|
||||
assertEquals("dry", tile.regionAt(0, 0).key());
|
||||
assertEquals("dry", tile.regionAt(7, 7).key());
|
||||
assertNull("heights only when asked", tile.heights());
|
||||
org.mockito.Mockito.verify(complex, org.mockito.Mockito.atLeastOnce())
|
||||
.surfacePickAsIfIn(org.mockito.ArgumentMatchers.eq(dry), anyDouble(), anyDouble(), org.mockito.AdditionalMatchers.eq(70D, 1e-4D));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theRegionViewCarriesTheRegionNoiseOnlyWhenAsked() {
|
||||
IrisImageMapRuntime imageMaps = mock(IrisImageMapRuntime.class);
|
||||
when(complex.getImageMapRuntime()).thenReturn(imageMaps);
|
||||
ProceduralStream<Double> regionNoise = stream((x, z) -> (x + 10D) / 100D);
|
||||
when(complex.getRegionStyleStream()).thenReturn(regionNoise);
|
||||
|
||||
MapTile plain = render(MapView.REGIONS, 0D, 0D, 1D, false);
|
||||
MapTile withNoise = new MapTileRenderer(engine).render(MapLayer.of(MapView.REGIONS), 0D, 0D, 1D, SIZE,
|
||||
Set.of(MapTile.Extra.PICK_NOISE), () -> false);
|
||||
MapTile caves = new MapTileRenderer(engine).render(MapLayer.of(MapView.CAVE_BIOMES), 0D, 0D, 1D, SIZE,
|
||||
Set.of(MapTile.Extra.PICK_NOISE), () -> false);
|
||||
|
||||
assertNull(plain.pickNoise());
|
||||
assertEquals(0.13F, withNoise.pickNoise()[withNoise.gridIndex(3, 5)], 1e-6F);
|
||||
assertNull("no noise picks the cave biome layer here", caves.pickNoise());
|
||||
}
|
||||
|
||||
private MapTile render(MapView view, double startX, double startZ, double blocksPerPixel, boolean withHeights) {
|
||||
return new MapTileRenderer(engine).render(view, startX, startZ, blocksPerPixel, SIZE, withHeights, () -> false);
|
||||
Set<MapTile.Extra> extras = withHeights ? Set.of(MapTile.Extra.HEIGHTS) : Set.of();
|
||||
return new MapTileRenderer(engine).render(MapLayer.of(view), startX, startZ, blocksPerPixel, SIZE, extras, () -> false);
|
||||
}
|
||||
|
||||
private void heights(DoubleBinaryOperator height) {
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package art.arcane.iris.core.studio.map;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.render.RenderType;
|
||||
import art.arcane.iris.engine.image.IrisImageMapRuntime;
|
||||
import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* A world that picks the same way at every spot: a dry region (rarity 3, so the last quarter of the region noise)
|
||||
* picked at 0.9; its land list picks plains at 0.2; plains' child noise at 0.1 rounds to its first slot, meadow;
|
||||
* meadow's at 0.8 rounds to its last slot, itself.
|
||||
*/
|
||||
final class PickedWorld {
|
||||
final Engine engine = mock(Engine.class);
|
||||
final IrisComplex complex = mock(IrisComplex.class);
|
||||
final IrisBiome plains = biome("plains", "Plains", 1);
|
||||
final IrisBiome forest = biome("forest", "Forest", 1);
|
||||
final IrisBiome meadow = biome("meadow", "Meadow", 1);
|
||||
final IrisBiome glade = biome("glade", "Glade", 1);
|
||||
final IrisRegion warm = region("warm", "Warm", 1);
|
||||
final IrisRegion dry = region("dry", "Dry", 3);
|
||||
final IrisImageMapRuntime imageMap = mock(IrisImageMapRuntime.class);
|
||||
|
||||
PickedWorld() {
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.getRegions()).thenReturn(new KList<>(List.of("warm", "dry")));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
IrisData data = mock(IrisData.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
|
||||
when(regionLoader.loadAll(any(KList.class))).thenReturn(new KList<>(List.of(warm, dry)));
|
||||
when(data.getRegionLoader()).thenReturn(regionLoader);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(complex.getImageMapRuntime()).thenReturn(imageMap);
|
||||
|
||||
ProceduralStream<IrisRegion> regions = stream(dry);
|
||||
ProceduralStream<Double> regionNoise = stream(0.9D);
|
||||
ProceduralStream<InferredType> continents = stream(InferredType.LAND);
|
||||
ProceduralStream<Double> landNoise = stream(0.2D);
|
||||
ProceduralStream<IrisBiome> landPicks = stream(plains);
|
||||
when(complex.getRegionStream()).thenReturn(regions);
|
||||
when(complex.getRegionStyleStream()).thenReturn(regionNoise);
|
||||
when(complex.getBridgeStream()).thenReturn(continents);
|
||||
when(complex.pickableBiomes(dry, InferredType.LAND)).thenReturn(new KList<>(List.of(plains, forest)));
|
||||
when(complex.biomePickNoise(dry, InferredType.LAND)).thenReturn(landNoise);
|
||||
when(complex.biomePicks(dry, InferredType.LAND)).thenReturn(landPicks);
|
||||
children(plains, List.of(meadow, plains, plains), 0.1D);
|
||||
children(meadow, List.of(glade, meadow), 0.8D);
|
||||
}
|
||||
|
||||
private void children(IrisBiome parent, List<IrisBiome> slots, double noise) {
|
||||
when(parent.getChildren()).thenReturn(new KList<>(List.of("child")));
|
||||
when(complex.childSlots(parent)).thenReturn(slots);
|
||||
CNG childNoise = mock(CNG.class);
|
||||
when(childNoise.noiseFast2D(anyDouble(), anyDouble())).thenReturn(noise);
|
||||
when(complex.childNoise(parent)).thenReturn(childNoise);
|
||||
}
|
||||
|
||||
private IrisBiome biome(String key, String name, int rarity) {
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
when(biome.getLoadKey()).thenReturn(key);
|
||||
when(biome.getName()).thenReturn(name);
|
||||
when(biome.getRarity()).thenReturn(rarity);
|
||||
when(biome.getChildren()).thenReturn(new KList<>());
|
||||
when(biome.getInferredType()).thenReturn(InferredType.LAND);
|
||||
when(biome.withInferredType(any(InferredType.class))).thenReturn(biome);
|
||||
when(biome.getColor(eq(engine), any(RenderType.class))).thenReturn(Color.GREEN);
|
||||
return biome;
|
||||
}
|
||||
|
||||
private IrisRegion region(String key, String name, int rarity) {
|
||||
IrisRegion region = mock(IrisRegion.class);
|
||||
when(region.getLoadKey()).thenReturn(key);
|
||||
when(region.getName()).thenReturn(name);
|
||||
when(region.getRarity()).thenReturn(rarity);
|
||||
when(region.getColor(complex, RenderType.REGION)).thenReturn(Color.ORANGE);
|
||||
return region;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> ProceduralStream<T> stream(T value) {
|
||||
ProceduralStream<T> stream = mock(ProceduralStream.class);
|
||||
when(stream.get(anyDouble(), anyDouble())).thenReturn(value);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user