mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Studio map: explain how each spot got its region and biome
The hover now carries the pick path: the region pick, the biome list pick and every child level, each with its noise value and the share of the noise every option owns. IrisComplex exposes the pick noise, the pickable biomes and the child slots it already used, so the explanation reads the same inputs the generator does; generation is unchanged (probe signatures match before and after). Hover takes the view, since the path depends on it.
This commit is contained in:
1 parent
4de21dace7
commit
467d42abea
7 files changed
+501
-48
No files matched your search
@@ -179,7 +179,7 @@ public final class StudioBridge implements AutoCloseable {
|
||||
switch (endpoint) {
|
||||
case "world" -> sendJson(exchange, STATUS_OK, worldInfo(get(exchange)));
|
||||
case "tile" -> sendBytes(exchange, "application/octet-stream", tile(get(exchange), query));
|
||||
case "hover" -> sendJson(exchange, STATUS_OK, MapHover.sample(get(exchange).engine(), query.number("x"), query.number("z")));
|
||||
case "hover" -> sendJson(exchange, STATUS_OK, MapHover.sample(get(exchange).engine(), view(query), query.number("x"), query.number("z")));
|
||||
case "entities" -> sendJson(exchange, STATUS_OK, entities(get(exchange)));
|
||||
case "events" -> streamEvents(exchange);
|
||||
case "teleport" -> teleport(exchange, query);
|
||||
@@ -231,9 +231,13 @@ public final class StudioBridge implements AutoCloseable {
|
||||
);
|
||||
}
|
||||
|
||||
private byte[] tile(StudioWorld.Session session, Query query) {
|
||||
MapView view = MapView.byId(query.text("view"))
|
||||
private static MapView view(Query query) {
|
||||
return MapView.byId(query.text("view"))
|
||||
.orElseThrow(() -> new RequestError(STATUS_BAD_REQUEST, "Unknown view: " + query.text("view")));
|
||||
}
|
||||
|
||||
private byte[] tile(StudioWorld.Session session, Query query) {
|
||||
MapView view = view(query);
|
||||
int size = query.whole("size", DEFAULT_TILE_SIZE);
|
||||
double blocksPerPixel = query.number("scale");
|
||||
if (size < 1 || size > LARGEST_TILE_SIZE) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* What the map knows about the column under the cursor.
|
||||
@@ -36,14 +37,15 @@ import java.nio.file.Path;
|
||||
* @param vanillaBiome the platform biome the column gets, such as {@code minecraft:plains}
|
||||
* @param slopeDegrees how steep the terrain is, 0 for flat
|
||||
* @param biomeFile the biome's file within the pack, such as {@code biomes/plains/meadow.json}; null when unknown
|
||||
* @param pickPath how the column got the region and the biome the view shows, region first
|
||||
*/
|
||||
public record MapHover(double worldX, double worldZ, MapLabel biome, MapLabel caveBiome, MapLabel region,
|
||||
String vanillaBiome, double height, double fluidHeight, double slopeDegrees,
|
||||
String biomeFile, String regionFile) {
|
||||
String biomeFile, String regionFile, List<MapPickPath.PickStep> pickPath) {
|
||||
// IrisComplex measures slope as the height change over this many blocks.
|
||||
private static final double SLOPE_STREAM_RANGE_BLOCKS = 3D;
|
||||
|
||||
public static MapHover sample(Engine engine, double worldX, double worldZ) {
|
||||
public static MapHover sample(Engine engine, MapView view, double worldX, double worldZ) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
IrisBiome biome = complex.getBaseBiomeStream().get(worldX, worldZ);
|
||||
IrisBiome caveBiome = complex.getCaveBiomeStream().get(worldX, worldZ);
|
||||
@@ -62,7 +64,8 @@ public record MapHover(double worldX, double worldZ, MapLabel biome, MapLabel ca
|
||||
dimension == null ? 0D : dimension.getFluidHeight(),
|
||||
Math.toDegrees(Math.atan(slope / SLOPE_STREAM_RANGE_BLOCKS)),
|
||||
packPath(engine, biome),
|
||||
packPath(engine, region)
|
||||
packPath(engine, region),
|
||||
MapPickPath.explain(engine, view, worldX, worldZ)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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.object.value.IRare;
|
||||
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.region.IrisRegion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* How a spot got the region and biome a view shows, step by step, read from the same noise the generator picks with:
|
||||
* the region noise, the noise of the region's biome list, then each level of children.
|
||||
*/
|
||||
public final class MapPickPath {
|
||||
private MapPickPath() {
|
||||
}
|
||||
|
||||
public static List<PickStep> explain(Engine engine, MapView view, double x, double z) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
IrisRegion region = complex.getRegionStream().get(x, z);
|
||||
List<PickStep> path = new ArrayList<>();
|
||||
if (region == null) {
|
||||
return path;
|
||||
}
|
||||
path.add(regionStep(engine, region, x, z));
|
||||
switch (view) {
|
||||
case LAND_BIOMES -> addListStep(path, engine, view, region, InferredType.LAND, x, z);
|
||||
case SEA_BIOMES -> addListStep(path, engine, view, region, InferredType.SEA, x, z);
|
||||
case CAVE_BIOMES -> addListStep(path, engine, view, region, InferredType.CAVE, x, z);
|
||||
case BIOMES, REGIONS, HEIGHT -> addBaseBiomeSteps(path, engine, view, region, x, z);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private static PickStep regionStep(Engine engine, IrisRegion region, double x, double z) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
if (complex.getFocusRegion() != null) {
|
||||
return PickStep.chosen(Kind.FOCUS, MapLabel.of(engine, region));
|
||||
}
|
||||
if (complex.getImageMapRuntime().sampleRegion(x, z) != null) {
|
||||
return PickStep.chosen(Kind.IMAGE_MAP, MapLabel.of(engine, region));
|
||||
}
|
||||
List<IrisRegion> regions = engine.getData().getRegionLoader().loadAll(engine.getDimension().getRegions());
|
||||
double noise = complex.getRegionStyleStream().get(x, z);
|
||||
return new PickStep(Kind.REGION, MapLabel.of(engine, region), null, null, noise,
|
||||
rarityBands(regions, candidate -> MapLabel.of(engine, candidate)));
|
||||
}
|
||||
|
||||
// The base biome: the noise picks from the land or sea list the continent noise chose, then children replace it.
|
||||
private static void addBaseBiomeSteps(List<PickStep> path, Engine engine, MapView view, IrisRegion region, double x, double z) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
IrisBiome focus = complex.getFocusBiome();
|
||||
if (focus != null) {
|
||||
path.add(PickStep.chosen(Kind.FOCUS, biomeLabel(engine, view, focus)));
|
||||
addChildSteps(path, engine, view, focus, x, z);
|
||||
return;
|
||||
}
|
||||
IrisBiome mapped = complex.getImageMapRuntime().sampleBiome(x, z);
|
||||
if (mapped != null) {
|
||||
path.add(PickStep.chosen(Kind.IMAGE_MAP, biomeLabel(engine, view, mapped)));
|
||||
return;
|
||||
}
|
||||
IrisBiome picked = addListStep(path, engine, view, region, complex.getBridgeStream().get(x, z), x, z);
|
||||
if (picked != null) {
|
||||
addChildSteps(path, engine, view, picked, x, z);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return the biome the noise picked, or null when the region has no biomes of this type */
|
||||
private static IrisBiome addListStep(List<PickStep> path, Engine engine, MapView view, IrisRegion region,
|
||||
InferredType type, double x, double z) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
List<IrisBiome> options = complex.pickableBiomes(region, type);
|
||||
if (options.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
double noise = complex.biomePickNoise(region, type).get(x, z);
|
||||
IrisBiome picked = IRare.pick(options, noise);
|
||||
path.add(new PickStep(Kind.BIOME, biomeLabel(engine, view, picked), type.name().toLowerCase(Locale.ROOT), null,
|
||||
noise, rarityBands(options, option -> biomeLabel(engine, view, option))));
|
||||
return picked;
|
||||
}
|
||||
|
||||
// A parent that keeps the spot ends the walk: every level below would read the same noise and keep it again.
|
||||
private static void addChildSteps(List<PickStep> path, Engine engine, MapView view, IrisBiome biome, double x, double z) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
IrisBiome parent = biome;
|
||||
for (int level = 0; level < IrisComplex.CHILD_PICK_LEVELS && !parent.getChildren().isEmpty(); level++) {
|
||||
List<IrisBiome> slots = complex.childSlots(parent);
|
||||
if (slots.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
double noise = complex.childNoise(parent).noiseFast2D(x, z);
|
||||
IrisBiome picked = slots.get(slotIndex(noise, slots.size())).withInferredType(parent.getInferredType());
|
||||
boolean kept = sameBiome(picked, parent);
|
||||
path.add(new PickStep(Kind.CHILD, biomeLabel(engine, view, picked), null, kept ? null : parent.getName(),
|
||||
noise, slotBands(slots, option -> biomeLabel(engine, view, option))));
|
||||
if (kept) {
|
||||
return;
|
||||
}
|
||||
parent = picked;
|
||||
}
|
||||
}
|
||||
|
||||
/** The slot the child noise picks, rounded the way {@code CNG.fit2D} rounds. */
|
||||
static int slotIndex(double noise, int slotCount) {
|
||||
if (slotCount == 1) {
|
||||
return 0;
|
||||
}
|
||||
long rounded = Math.round(noise * (slotCount - 1));
|
||||
return (int) Math.clamp(rounded, 0, slotCount - 1);
|
||||
}
|
||||
|
||||
/** Each option's share of the noise, 1 / rarity wide, in the order {@link IRare#pick} walks them. */
|
||||
static <T> List<PickBand> rarityBands(List<T> options, Function<T, MapLabel> label) {
|
||||
double total = options.stream().mapToDouble(option -> 1D / IRare.get(option)).sum();
|
||||
List<PickBand> bands = new ArrayList<>();
|
||||
double from = 0D;
|
||||
for (int index = 0; index < options.size(); index++) {
|
||||
T option = options.get(index);
|
||||
double to = index == options.size() - 1 ? 1D : from + 1D / IRare.get(option) / total;
|
||||
bands.add(new PickBand(label.apply(option), from, to));
|
||||
from = to;
|
||||
}
|
||||
return bands;
|
||||
}
|
||||
|
||||
/** Each slot's share of the child noise, neighbouring slots of one biome joined into one band. */
|
||||
static <T> List<PickBand> slotBands(List<T> slots, Function<T, MapLabel> label) {
|
||||
List<PickBand> bands = new ArrayList<>();
|
||||
int last = slots.size() - 1;
|
||||
for (int index = 0; index <= last; index++) {
|
||||
double from = index == 0 ? 0D : (index - 0.5D) / last;
|
||||
double to = index == last ? 1D : (index + 0.5D) / last;
|
||||
MapLabel option = label.apply(slots.get(index));
|
||||
PickBand previous = bands.isEmpty() ? null : bands.getLast();
|
||||
if (previous != null && previous.option().key().equals(option.key())) {
|
||||
bands.set(bands.size() - 1, new PickBand(option, previous.from(), to));
|
||||
} else {
|
||||
bands.add(new PickBand(option, from, to));
|
||||
}
|
||||
}
|
||||
return bands;
|
||||
}
|
||||
|
||||
private static boolean sameBiome(IrisBiome first, IrisBiome second) {
|
||||
return Objects.equals(first.getLoadKey(), second.getLoadKey());
|
||||
}
|
||||
|
||||
private static MapLabel biomeLabel(Engine engine, MapView view, IrisBiome biome) {
|
||||
return MapLabel.of(engine, biome, view == MapView.REGIONS ? RenderType.BIOME : view.colorType());
|
||||
}
|
||||
|
||||
public enum Kind {
|
||||
/** The region noise picked the region. */
|
||||
REGION,
|
||||
/** The noise of one of the region's biome lists picked the biome. */
|
||||
BIOME,
|
||||
/** The biome's child noise kept it or replaced it with a child. */
|
||||
CHILD,
|
||||
/** The pack's image map set it. */
|
||||
IMAGE_MAP,
|
||||
/** The studio focuses on one region or biome, so nothing was picked. */
|
||||
FOCUS
|
||||
}
|
||||
|
||||
/**
|
||||
* One step on the way to the spot's biome, starting with its region.
|
||||
*
|
||||
* @param list the biome list a {@link Kind#BIOME} step picked from, such as {@code land}
|
||||
* @param replaced the parent a {@link Kind#CHILD} step replaced; null when the parent kept the spot
|
||||
* @param noise the noise value that picked it, 0 to 1; null when nothing was picked
|
||||
* @param bands every option's share of that noise, empty when nothing was picked
|
||||
*/
|
||||
public record PickStep(Kind kind, MapLabel picked, String list, String replaced, Double noise, List<PickBand> bands) {
|
||||
static PickStep chosen(Kind kind, MapLabel picked) {
|
||||
return new PickStep(kind, picked, null, null, null, List.of());
|
||||
}
|
||||
}
|
||||
|
||||
/** One option's share of a noise: the noise picks it from {@code from} up to {@code to}. */
|
||||
public record PickBand(MapLabel option, double from, double to) {
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
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.terrain.IrisGenerator;
|
||||
import art.arcane.iris.engine.object.noise.IrisInterpolator;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
@@ -55,6 +56,7 @@ import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@@ -63,8 +65,8 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(exclude = {"data", "gridBoundsCache", "frozenInterpolators", "frozenGenerators", "inferredBiomeStreams", "imageMapRuntime"})
|
||||
@ToString(exclude = {"data", "gridBoundsCache", "frozenInterpolators", "frozenGenerators", "inferredBiomeStreams", "imageMapRuntime"})
|
||||
@EqualsAndHashCode(exclude = {"data", "gridBoundsCache", "frozenInterpolators", "frozenGenerators", "inferredBiomeStreams", "inferredPickNoiseStreams", "imageMapRuntime"})
|
||||
@ToString(exclude = {"data", "gridBoundsCache", "frozenInterpolators", "frozenGenerators", "inferredBiomeStreams", "inferredPickNoiseStreams", "imageMapRuntime"})
|
||||
public class IrisComplex implements DataProvider {
|
||||
private static final NoiseBounds ZERO_NOISE_BOUNDS = new NoiseBounds(0D, 0D);
|
||||
private static final AtomicLong lastBoundsFailureLog = new AtomicLong(0L);
|
||||
@@ -77,6 +79,10 @@ public class IrisComplex implements DataProvider {
|
||||
IrisGenerator::getLoadKey,
|
||||
Comparator.nullsFirst(Comparator.naturalOrder())
|
||||
);
|
||||
private static final int DEEPEST_CHILD_LEVEL = 3;
|
||||
/** How many levels of children a biome can be replaced through, parent first. */
|
||||
public static final int CHILD_PICK_LEVELS = DEEPEST_CHILD_LEVEL + 1;
|
||||
private static final int CHILD_NOISE_SIGNATURE = 123;
|
||||
private static final InferredType[] INFERRED_BIOME_PREPARATION_ORDER = {
|
||||
InferredType.LAND,
|
||||
InferredType.CAVE,
|
||||
@@ -91,6 +97,8 @@ public class IrisComplex implements DataProvider {
|
||||
private final transient IrisGenerator[][] frozenGenerators;
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final transient Map<IrisRegion, Map<InferredType, ProceduralStream<IrisBiome>>> inferredBiomeStreams;
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final transient Map<IrisRegion, Map<InferredType, ProceduralStream<Double>>> inferredPickNoiseStreams;
|
||||
private RNG rng;
|
||||
private double fluidHeight;
|
||||
private IrisData data;
|
||||
@@ -170,9 +178,14 @@ public class IrisComplex implements DataProvider {
|
||||
}
|
||||
imageMapRuntime.getMappedBiomes().forEach(this::registerGenerators);
|
||||
}
|
||||
inferredPickNoiseStreams = compileInferredBiomeStreams(
|
||||
preparedRegions,
|
||||
(region, inferredType) -> compileInferredPickNoise(engine, region, inferredType)
|
||||
);
|
||||
inferredBiomeStreams = compileInferredBiomeStreams(
|
||||
preparedRegions,
|
||||
(region, inferredType) -> compileInferredBiomeStream(engine, region, inferredType, emptyBiome)
|
||||
(region, inferredType) -> compileInferredBiomeStream(
|
||||
preparedInferredBiomeStream(inferredPickNoiseStreams, region, inferredType), region, inferredType, emptyBiome)
|
||||
);
|
||||
GeneratorGroup[] generatorGroups = freezeGeneratorGroups(generators);
|
||||
int interpolatorCount = generatorGroups.length;
|
||||
@@ -498,49 +511,50 @@ public class IrisComplex implements DataProvider {
|
||||
return preparedInferredBiomeStream(inferredBiomeStreams, region, inferredType);
|
||||
}
|
||||
|
||||
private ProceduralStream<Double> compileInferredPickNoise(Engine engine, IrisRegion region, InferredType inferredType) {
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
return switch (inferredType) {
|
||||
case CAVE -> dimension.getCaveBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.CAVE.ordinal()), getData()).stream()
|
||||
.zoom(dimension.getBiomeZoom())
|
||||
.zoom(region.getCaveBiomeZoom());
|
||||
case LAND -> dimension.getLandBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.LAND.ordinal()), getData()).stream()
|
||||
.zoom(dimension.getBiomeZoom())
|
||||
.zoom(dimension.getLandZoom())
|
||||
.zoom(region.getLandBiomeZoom());
|
||||
case SEA -> dimension.getSeaBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.SEA.ordinal()), getData()).stream()
|
||||
.zoom(dimension.getBiomeZoom())
|
||||
.zoom(dimension.getSeaZoom())
|
||||
.zoom(region.getSeaBiomeZoom());
|
||||
case SHORE -> dimension.getShoreBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.SHORE.ordinal()), getData()).stream()
|
||||
.zoom(dimension.getBiomeZoom())
|
||||
.zoom(region.getShoreBiomeZoom());
|
||||
};
|
||||
}
|
||||
|
||||
private ProceduralStream<IrisBiome> compileInferredBiomeStream(
|
||||
Engine engine,
|
||||
ProceduralStream<Double> pickNoise,
|
||||
IrisRegion region,
|
||||
InferredType inferredType,
|
||||
IrisBiome emptyBiome
|
||||
) {
|
||||
return switch (inferredType) {
|
||||
case CAVE -> engine.getDimension().getCaveBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.CAVE.ordinal()), getData()).stream()
|
||||
.zoom(engine.getDimension().getBiomeZoom())
|
||||
.zoom(region.getCaveBiomeZoom())
|
||||
.selectRarity(loadInferredBiomes(region.getCaveBiomes(), InferredType.CAVE))
|
||||
.onNull(emptyBiome);
|
||||
case LAND -> engine.getDimension().getLandBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.LAND.ordinal()), getData()).stream()
|
||||
.zoom(engine.getDimension().getBiomeZoom())
|
||||
.zoom(engine.getDimension().getLandZoom())
|
||||
.zoom(region.getLandBiomeZoom())
|
||||
.selectRarity(loadInferredBiomes(region.getLandBiomes(), InferredType.LAND));
|
||||
case SEA -> engine.getDimension().getSeaBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.SEA.ordinal()), getData()).stream()
|
||||
.zoom(engine.getDimension().getBiomeZoom())
|
||||
.zoom(engine.getDimension().getSeaZoom())
|
||||
.zoom(region.getSeaBiomeZoom())
|
||||
.selectRarity(loadInferredBiomes(region.getSeaBiomes(), InferredType.SEA));
|
||||
case SHORE -> engine.getDimension().getShoreBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.SHORE.ordinal()), getData()).stream()
|
||||
.zoom(engine.getDimension().getBiomeZoom())
|
||||
.zoom(region.getShoreBiomeZoom())
|
||||
.selectRarity(loadInferredBiomes(region.getShoreBiomes(), InferredType.SHORE));
|
||||
};
|
||||
ProceduralStream<IrisBiome> picked = pickNoise.selectRarity(pickableBiomes(region, inferredType));
|
||||
return inferredType == InferredType.CAVE ? picked.onNull(emptyBiome) : picked;
|
||||
}
|
||||
|
||||
static Map<IrisRegion, Map<InferredType, ProceduralStream<IrisBiome>>> compileInferredBiomeStreams(
|
||||
static <T> Map<IrisRegion, Map<InferredType, T>> compileInferredBiomeStreams(
|
||||
Iterable<IrisRegion> regions,
|
||||
BiFunction<IrisRegion, InferredType, ProceduralStream<IrisBiome>> compiler
|
||||
BiFunction<IrisRegion, InferredType, T> compiler
|
||||
) {
|
||||
IdentityHashMap<IrisRegion, Map<InferredType, ProceduralStream<IrisBiome>>> compiled = new IdentityHashMap<>();
|
||||
IdentityHashMap<IrisRegion, Map<InferredType, T>> compiled = new IdentityHashMap<>();
|
||||
for (IrisRegion region : regions) {
|
||||
if (compiled.containsKey(region)) {
|
||||
continue;
|
||||
}
|
||||
EnumMap<InferredType, ProceduralStream<IrisBiome>> regionStreams = new EnumMap<>(InferredType.class);
|
||||
EnumMap<InferredType, T> regionStreams = new EnumMap<>(InferredType.class);
|
||||
for (InferredType inferredType : INFERRED_BIOME_PREPARATION_ORDER) {
|
||||
regionStreams.put(inferredType, Objects.requireNonNull(compiler.apply(region, inferredType)));
|
||||
}
|
||||
@@ -549,12 +563,12 @@ public class IrisComplex implements DataProvider {
|
||||
return Collections.unmodifiableMap(compiled);
|
||||
}
|
||||
|
||||
static ProceduralStream<IrisBiome> preparedInferredBiomeStream(
|
||||
Map<IrisRegion, Map<InferredType, ProceduralStream<IrisBiome>>> streams,
|
||||
static <T> T preparedInferredBiomeStream(
|
||||
Map<IrisRegion, Map<InferredType, T>> streams,
|
||||
IrisRegion region,
|
||||
InferredType inferredType
|
||||
) {
|
||||
Map<InferredType, ProceduralStream<IrisBiome>> regionStreams = streams.get(region);
|
||||
Map<InferredType, T> regionStreams = streams.get(region);
|
||||
if (regionStreams == null) {
|
||||
String regionKey = region == null || region.getLoadKey() == null || region.getLoadKey().isBlank()
|
||||
? "<unkeyed>"
|
||||
@@ -562,13 +576,45 @@ public class IrisComplex implements DataProvider {
|
||||
throw new IllegalStateException("Inferred-biome streams were not prepared for region '"
|
||||
+ regionKey + "'.");
|
||||
}
|
||||
ProceduralStream<IrisBiome> stream = regionStreams.get(inferredType);
|
||||
T stream = regionStreams.get(inferredType);
|
||||
if (stream == null) {
|
||||
throw new IllegalStateException("Inferred-biome stream was not prepared for type " + inferredType + ".");
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* The noise that picks one of the region's biomes of this type, from 0 to 1; {@link #pickableBiomes} split it by
|
||||
* rarity. The biome streams pick from this very stream.
|
||||
*/
|
||||
public ProceduralStream<Double> biomePickNoise(IrisRegion region, InferredType inferredType) {
|
||||
return preparedInferredBiomeStream(inferredPickNoiseStreams, region, inferredType);
|
||||
}
|
||||
|
||||
/** The region's biomes of this type, in the order their rarities split {@link #biomePickNoise}. */
|
||||
public KList<IrisBiome> pickableBiomes(IrisRegion region, InferredType inferredType) {
|
||||
KList<String> keys = switch (inferredType) {
|
||||
case CAVE -> region.getCaveBiomes();
|
||||
case LAND -> region.getLandBiomes();
|
||||
case SEA -> region.getSeaBiomes();
|
||||
case SHORE -> region.getShoreBiomes();
|
||||
};
|
||||
return loadInferredBiomes(keys, inferredType);
|
||||
}
|
||||
|
||||
/**
|
||||
* The slots a biome's child noise picks from, in noise order: its children and itself, each as often as its rarity
|
||||
* allows. Slot {@code i} of {@code n} is picked where {@link #childNoise} rounds to {@code i / (n - 1)}.
|
||||
*/
|
||||
public List<IrisBiome> childSlots(IrisBiome parent) {
|
||||
return List.of(resolveChildSelectionPlan(parent).mappedBiomes);
|
||||
}
|
||||
|
||||
/** The noise that picks among {@link #childSlots}, read with {@link CNG#noiseFast2D}. */
|
||||
public CNG childNoise(IrisBiome parent) {
|
||||
return parent.getChildrenGenerator(rng, CHILD_NOISE_SIGNATURE, parent.getChildShrinkFactor());
|
||||
}
|
||||
|
||||
private KList<IrisBiome> loadInferredBiomes(KList<String> keys, InferredType type) {
|
||||
KList<IrisBiome> inferred = new KList<>();
|
||||
for (IrisBiome biome : data.getBiomeLoader().loadAll(keys)) {
|
||||
@@ -680,7 +726,7 @@ public class IrisComplex implements DataProvider {
|
||||
return b;
|
||||
}
|
||||
|
||||
return implode(b, x, z, 3);
|
||||
return implode(b, x, z, DEEPEST_CHILD_LEVEL);
|
||||
}
|
||||
|
||||
private IrisBiome implode(IrisBiome b, Double x, Double z, int max) {
|
||||
@@ -692,7 +738,7 @@ public class IrisComplex implements DataProvider {
|
||||
return b;
|
||||
}
|
||||
|
||||
CNG childCell = b.getChildrenGenerator(rng, 123, b.getChildShrinkFactor());
|
||||
CNG childCell = childNoise(b);
|
||||
ChildSelectionPlan childSelectionPlan = resolveChildSelectionPlan(b);
|
||||
IrisBiome biome = childSelectionPlan.select(childCell, x, z).withInferredType(b.getInferredType());
|
||||
return implode(biome, x, z, max - 1);
|
||||
|
||||
@@ -70,6 +70,9 @@ public class StudioBridgeTest {
|
||||
when(complex.getHeightStream()).thenReturn(heights);
|
||||
when(complex.getSlopeStream()).thenReturn(heights);
|
||||
when(complex.getTrueBiomeDerivativeStream()).thenReturn(vanilla);
|
||||
when(complex.getFocusRegion()).thenReturn(region);
|
||||
when(complex.getFocusBiome()).thenReturn(plains);
|
||||
when(plains.getChildren()).thenReturn(new art.arcane.volmlib.util.collection.KList<>());
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.getLoadKey()).thenReturn("overworld");
|
||||
when(dimension.getName()).thenReturn("Overworld");
|
||||
@@ -154,12 +157,22 @@ public class StudioBridgeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theHoverDescribesTheColumn() throws Exception {
|
||||
JsonObject hover = json(get("hover?x=5&z=-3"));
|
||||
public void theHoverDescribesTheColumnAndHowItWasPicked() throws Exception {
|
||||
JsonObject hover = json(get("hover?view=biomes&x=5&z=-3"));
|
||||
|
||||
assertEquals("plains", hover.getAsJsonObject("biome").get("key").getAsString());
|
||||
assertEquals("temperate", hover.getAsJsonObject("region").get("key").getAsString());
|
||||
assertEquals(70D, hover.get("height").getAsDouble(), 0D);
|
||||
JsonObject firstStep = hover.getAsJsonArray("pickPath").get(0).getAsJsonObject();
|
||||
assertEquals("FOCUS", firstStep.get("kind").getAsString());
|
||||
assertEquals("temperate", firstStep.getAsJsonObject("picked").get("key").getAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aHoverNamesItsView() throws Exception {
|
||||
HttpResponse<String> response = http.send(authorized("hover?x=5&z=-3"), HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
assertEquals(400, response.statusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theBiomeViewWalksFromTheRegionThroughItsListToTheChildThatKeptTheSpot() {
|
||||
List<MapPickPath.PickStep> path = MapPickPath.explain(engine, MapView.BIOMES, X, Z);
|
||||
|
||||
assertEquals(List.of(MapPickPath.Kind.REGION, MapPickPath.Kind.BIOME, MapPickPath.Kind.CHILD, MapPickPath.Kind.CHILD),
|
||||
path.stream().map(MapPickPath.PickStep::kind).toList());
|
||||
MapPickPath.PickStep region = path.get(0);
|
||||
assertEquals("dry", region.picked().key());
|
||||
assertEquals(0.9D, region.noise(), 0D);
|
||||
assertBand(region.bands().get(0), "warm", 0D, 0.75D);
|
||||
assertBand(region.bands().get(1), "dry", 0.75D, 1D);
|
||||
assertEquals("land", path.get(1).list());
|
||||
assertEquals("plains", path.get(1).picked().key());
|
||||
assertEquals("meadow", path.get(2).picked().key());
|
||||
assertEquals("Plains", path.get(2).replaced());
|
||||
assertEquals("meadow", path.get(3).picked().key());
|
||||
assertNull("meadow kept the spot", path.get(3).replaced());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aChildStepJoinsNeighbouringSlotsOfOneBiome() {
|
||||
List<MapPickPath.PickBand> bands = MapPickPath.explain(engine, MapView.BIOMES, X, Z).get(2).bands();
|
||||
|
||||
assertEquals(2, bands.size());
|
||||
assertBand(bands.get(0), "meadow", 0D, 0.25D);
|
||||
assertBand(bands.get(1), "plains", 0.25D, 1D);
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anImageMappedRegionWasChosenNotPicked() {
|
||||
IrisImageMapRuntime imageMap = complex.getImageMapRuntime();
|
||||
when(imageMap.sampleRegion(X, Z)).thenReturn(dry);
|
||||
|
||||
MapPickPath.PickStep region = MapPickPath.explain(engine, MapView.REGIONS, X, Z).getFirst();
|
||||
|
||||
assertEquals(MapPickPath.Kind.IMAGE_MAP, region.kind());
|
||||
assertNull(region.noise());
|
||||
assertEquals(List.of(), region.bands());
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
@@ -140,8 +140,11 @@ public class MapTileRendererTest {
|
||||
when(pack.getDataFolder()).thenReturn(new java.io.File("/packs/overworld"));
|
||||
when(engine.getData()).thenReturn(pack);
|
||||
when(desert.getLoadFile()).thenReturn(new java.io.File("/packs/overworld/biomes/desert.json"));
|
||||
when(complex.getFocusRegion()).thenReturn(dry);
|
||||
when(complex.getFocusBiome()).thenReturn(desert);
|
||||
when(desert.getChildren()).thenReturn(new art.arcane.volmlib.util.collection.KList<>());
|
||||
|
||||
MapHover hover = MapHover.sample(engine, 10D, 0D);
|
||||
MapHover hover = MapHover.sample(engine, MapView.BIOMES, 10D, 0D);
|
||||
|
||||
assertEquals("desert", hover.biome().key());
|
||||
assertEquals("cavern", hover.caveBiome().key());
|
||||
@@ -152,6 +155,9 @@ public class MapTileRendererTest {
|
||||
assertEquals(45D, hover.slopeDegrees(), 1e-9);
|
||||
assertEquals("biomes/desert.json", hover.biomeFile());
|
||||
assertNull("a region without a file has no path", hover.regionFile());
|
||||
assertEquals("a studio focused on dry and desert picked neither",
|
||||
List.of(MapPickPath.Kind.FOCUS, MapPickPath.Kind.FOCUS),
|
||||
hover.pickPath().stream().map(MapPickPath.PickStep::kind).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user