mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Native structures respect rivers
- Supply hydrology water to the native structure stages through IrisStructureWater on the Bukkit and modded policies - Carry each native placement's allowWater on its start plan - Judge native placements by the columns their assembled pieces cover in the stage instead of by the start chunk at plan time - Apply the same start rule in the headless probe planner - Move Iris structure footprints and carves onto the shared StructureWaterRules and remove StructureWaterFootprint and StructureCarveWater - Add allowWater to the content-derived placement identity when set, so deduplicated native starts do not depend on list order - Pass dry water to native terrain integrator calls in the adapter tests
This commit is contained in:
1 parent
ba0bb1a2c0
commit
e4efd7800d
22 files changed
+264
-264
No files matched your search
@@ -22,11 +22,14 @@ import art.arcane.volmlib.util.structure.StructureCarvingFootprint;
|
||||
|
||||
import art.arcane.volmlib.util.structure.StructureCarveEnvelope;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterRules;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.cache.Cache;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.structure.placement.IrisStructureLocator;
|
||||
import art.arcane.iris.structure.placement.IrisStructureWater;
|
||||
import art.arcane.iris.structure.placement.PlacedStructurePiece;
|
||||
import art.arcane.iris.structure.placement.StructurePlacementScope;
|
||||
import art.arcane.iris.structure.placement.StructurePlacementMarker;
|
||||
@@ -338,7 +341,7 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
+ " margin=" + margin + " head=" + head + " floorCut=" + floorCut + " work=" + work);
|
||||
}
|
||||
|
||||
StructureCarveWater water = StructureCarveWater.of(getEngineMantle().getComplex(),
|
||||
StructureWaterRules.Carve water = StructureWaterRules.carve(IrisStructureWater.mantle(getEngineMantle().getComplex()),
|
||||
footprint.minX(), footprint.minZ(), footprint.maxX(), footprint.maxZ());
|
||||
double sideReachSquared = (double) margin * margin;
|
||||
double downReach = Math.max(1D, floorCut);
|
||||
@@ -397,7 +400,8 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
}
|
||||
|
||||
private void carveBox(MantleWriter writer, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int mantleOffset) {
|
||||
StructureCarveWater water = StructureCarveWater.of(getEngineMantle().getComplex(), minX, minZ, maxX, maxZ);
|
||||
StructureWaterRules.Carve water = StructureWaterRules.carve(IrisStructureWater.mantle(getEngineMantle().getComplex()),
|
||||
minX, minZ, maxX, maxZ);
|
||||
for (int bx = minX; bx <= maxX; bx++) {
|
||||
for (int bz = minZ; bz <= maxZ; bz++) {
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
|
||||
final class StructureCarveWater {
|
||||
static final int CONTAINMENT = 2;
|
||||
static final int FLOOR = 2;
|
||||
private static final StructureCarveWater NONE = new StructureCarveWater(0, 0, 0, 0, null, null);
|
||||
|
||||
private final int minX;
|
||||
private final int minZ;
|
||||
private final int width;
|
||||
private final int depth;
|
||||
private final int[] floors;
|
||||
private final int[] tops;
|
||||
|
||||
private StructureCarveWater(int minX, int minZ, int width, int depth, int[] floors, int[] tops) {
|
||||
this.minX = minX;
|
||||
this.minZ = minZ;
|
||||
this.width = width;
|
||||
this.depth = depth;
|
||||
this.floors = floors;
|
||||
this.tops = tops;
|
||||
}
|
||||
|
||||
static StructureCarveWater of(IrisComplex complex, int minX, int minZ, int maxX, int maxZ) {
|
||||
if (complex == null || maxX < minX || maxZ < minZ) {
|
||||
return NONE;
|
||||
}
|
||||
int width = maxX - minX + 1;
|
||||
int depth = maxZ - minZ + 1;
|
||||
int sampleWidth = width + CONTAINMENT * 2;
|
||||
int sampleDepth = depth + CONTAINMENT * 2;
|
||||
boolean[] wet = new boolean[sampleWidth * sampleDepth];
|
||||
int[] beds = new int[wet.length];
|
||||
int[] heads = new int[wet.length];
|
||||
ProceduralStream<WaterRole> roles = complex.getWaterRoleStream();
|
||||
long revision = ProvisionalSampling.revision();
|
||||
boolean any = false;
|
||||
for (int sz = 0; sz < sampleDepth; sz++) {
|
||||
int z = minZ - CONTAINMENT + sz;
|
||||
for (int sx = 0; sx < sampleWidth; sx++) {
|
||||
int x = minX - CONTAINMENT + sx;
|
||||
if (!roles.get(x, z).wet()) {
|
||||
continue;
|
||||
}
|
||||
int index = sz * sampleWidth + sx;
|
||||
wet[index] = true;
|
||||
beds[index] = complex.getRoundedHeighteightStream().get(x, z);
|
||||
heads[index] = (int) Math.round(complex.getWaterHeadStream().getDouble(x, z));
|
||||
any = true;
|
||||
}
|
||||
}
|
||||
if (ProvisionalSampling.revision() != revision) {
|
||||
throw new ProvisionalAnswerException("Structure carve over " + minX + "," + minZ + " to " + maxX + "," + maxZ
|
||||
+ " read a provisional water answer; structures only carve around final water.");
|
||||
}
|
||||
if (!any) {
|
||||
return NONE;
|
||||
}
|
||||
int[] floors = new int[width * depth];
|
||||
int[] tops = new int[width * depth];
|
||||
for (int z = 0; z < depth; z++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int floor = Integer.MAX_VALUE;
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (int dz = -CONTAINMENT; dz <= CONTAINMENT; dz++) {
|
||||
for (int dx = -CONTAINMENT; dx <= CONTAINMENT; dx++) {
|
||||
int sample = (z + CONTAINMENT + dz) * sampleWidth + x + CONTAINMENT + dx;
|
||||
if (!wet[sample]) {
|
||||
continue;
|
||||
}
|
||||
floor = Math.min(floor, beds[sample] - FLOOR);
|
||||
top = dx == 0 && dz == 0 ? Integer.MAX_VALUE : Math.max(top, heads[sample]);
|
||||
}
|
||||
}
|
||||
floors[z * width + x] = floor;
|
||||
tops[z * width + x] = top;
|
||||
}
|
||||
}
|
||||
return new StructureCarveWater(minX, minZ, width, depth, floors, tops);
|
||||
}
|
||||
|
||||
boolean keeps(int x, int y, int z) {
|
||||
if (floors == null) {
|
||||
return false;
|
||||
}
|
||||
int localX = x - minX;
|
||||
int localZ = z - minZ;
|
||||
if (localX < 0 || localZ < 0 || localX >= width || localZ >= depth) {
|
||||
return false;
|
||||
}
|
||||
int index = localZ * width + localX;
|
||||
return y >= floors[index] && y <= tops[index];
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import art.arcane.iris.structure.nativegen.NativeStructureStartPlan;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureVolumeIndex;
|
||||
import art.arcane.iris.structure.nativegen.StructureLocateSearch;
|
||||
import art.arcane.iris.structure.placement.IrisStructureLocator;
|
||||
import art.arcane.iris.structure.placement.IrisStructureWater;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockChangeSet;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockPositionPredicate;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -23,6 +24,7 @@ import art.arcane.volmlib.nativelib.terrain.structure.StructurePlacementDecision
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureReferencePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureSeaSurface;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureVolumePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -126,6 +128,11 @@ public final class BukkitStructureStagePolicy implements StructureStagePolicy<
|
||||
return GenerationWritePolicy.seaSurface(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureWater water(Engine context) {
|
||||
return IrisStructureWater.world(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntBinaryOperator worldgenHeight(Engine context, int runtimeMinY, boolean floor) {
|
||||
return (x, z) -> Engine.hostHeight(context, x, z, floor) + runtimeMinY + 1;
|
||||
|
||||
-5
@@ -3,7 +3,6 @@ package art.arcane.iris.structure.nativegen;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.structure.placement.StructurePlacementGrid;
|
||||
import art.arcane.iris.structure.placement.StructurePlacementScope;
|
||||
import art.arcane.iris.structure.placement.StructureWaterFootprint;
|
||||
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.structure.placement.IrisStructureAnchorMode;
|
||||
@@ -65,10 +64,6 @@ public final class NativeStructurePlacementPlanner {
|
||||
if (baseY == null) {
|
||||
return null;
|
||||
}
|
||||
if (!placement.isUnderground()
|
||||
&& !StructureWaterFootprint.admitsChunk(activeEngine, placement, source.getStructure(), chunkX, chunkZ)) {
|
||||
return null;
|
||||
}
|
||||
return new NativeStructureStartPlan(placement, source, chunkX, chunkZ, baseY);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,11 @@ public record NativeStructureStartPlan(
|
||||
return placement.isUnderground();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowWater() {
|
||||
return placement.isAllowWater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replacesSource() {
|
||||
return placement.getNativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
package art.arcane.iris.structure.placement;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureLocateCandidate;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureStagePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterRules;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.StructureLocateLimitException;
|
||||
|
||||
@@ -590,8 +592,8 @@ public final class IrisStructureLocator {
|
||||
"assembled pieces exceed the configured structure or world bounds")) {
|
||||
return null;
|
||||
}
|
||||
if (!placement.isAnchoredUnderground()
|
||||
&& !StructureWaterFootprint.admitsPieces(engine, placement, selectedKey, pieces, cx, cz)) {
|
||||
if (!placement.isAnchoredUnderground() && !placement.isAllowWater()
|
||||
&& !StructureWaterRules.admitsFootprint(IrisStructureWater.mantle(engine.getComplex()), pieceFootprints(pieces))) {
|
||||
return null;
|
||||
}
|
||||
if (!allowsResolvedFootprint(engine, placement, structure, pieces)) {
|
||||
@@ -939,6 +941,14 @@ public final class IrisStructureLocator {
|
||||
);
|
||||
}
|
||||
|
||||
private static List<StructureStagePolicy.Footprint> pieceFootprints(KList<PlacedStructurePiece> pieces) {
|
||||
List<StructureStagePolicy.Footprint> footprints = new ArrayList<>(pieces.size());
|
||||
for (PlacedStructurePiece piece : pieces) {
|
||||
footprints.add(new StructureStagePolicy.Footprint(piece.getMinX(), piece.getMinZ(), piece.getMaxX(), piece.getMaxZ()));
|
||||
}
|
||||
return footprints;
|
||||
}
|
||||
|
||||
private static int saturatedOffset(int coordinate, int offset) {
|
||||
long result = (long) coordinate + offset;
|
||||
return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, result));
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package art.arcane.iris.structure.placement;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterColumn;
|
||||
|
||||
public final class IrisStructureWater implements StructureWater {
|
||||
private final IrisComplex complex;
|
||||
private final int offsetY;
|
||||
|
||||
private IrisStructureWater(IrisComplex complex, int offsetY) {
|
||||
this.complex = complex;
|
||||
this.offsetY = offsetY;
|
||||
}
|
||||
|
||||
public static StructureWater mantle(IrisComplex complex) {
|
||||
return complex == null ? StructureWater.DRY : new IrisStructureWater(complex, 0);
|
||||
}
|
||||
|
||||
public static StructureWater world(Engine engine) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
return complex == null ? StructureWater.DRY : new IrisStructureWater(complex, engine.getMinHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureWaterColumn column(int x, int z) {
|
||||
long revision = ProvisionalSampling.revision();
|
||||
WaterRole role = complex.getWaterRoleStream().get(x, z);
|
||||
StructureWaterColumn column = role.wet()
|
||||
? new StructureWaterColumn(true, river(role),
|
||||
complex.getRoundedHeighteightStream().get(x, z) + offsetY,
|
||||
(int) Math.round(complex.getWaterHeadStream().getDouble(x, z)) + offsetY)
|
||||
: StructureWaterColumn.DRY;
|
||||
if (ProvisionalSampling.revision() != revision && !complex.isPlatformMainThread()) {
|
||||
throw new ProvisionalAnswerException("Structure water at " + x + "," + z
|
||||
+ " read a provisional answer; structures are only placed and carved around final water.");
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
static boolean river(WaterRole role) {
|
||||
return switch (role) {
|
||||
case CHANNEL, POND, CASCADE, WATERFALL -> true;
|
||||
case NONE, BANK, SHORE, POND_SHORE, DAM, MOUTH, INLET -> false;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -159,6 +159,9 @@ public final class StructurePlacementGrid {
|
||||
signature = appendLong(signature, placement.isUnderwater() ? 1L : 0L);
|
||||
signature = appendSources(signature, placement);
|
||||
signature = appendAnchor(signature, placement);
|
||||
if (placement.isAllowWater()) {
|
||||
signature = appendLong(signature, 1L);
|
||||
}
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package art.arcane.iris.structure.placement;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import it.unimi.dsi.fastutil.longs.LongIterator;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
|
||||
public final class StructureWaterFootprint {
|
||||
private static final int MAX_WATER_PERCENT = 10;
|
||||
private static final int CHUNK = 16;
|
||||
|
||||
private StructureWaterFootprint() {
|
||||
}
|
||||
|
||||
public static boolean admitsChunk(Engine engine, IrisStructurePlacement placement, String structureKey,
|
||||
int chunkX, int chunkZ) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
if (placement.isAllowWater() || complex == null) {
|
||||
return true;
|
||||
}
|
||||
ProceduralStream<WaterRole> roles = complex.getWaterRoleStream();
|
||||
long revision = ProvisionalSampling.revision();
|
||||
int water = 0;
|
||||
int minX = chunkX << 4;
|
||||
int minZ = chunkZ << 4;
|
||||
for (int x = minX; x < minX + CHUNK; x++) {
|
||||
for (int z = minZ; z < minZ + CHUNK; z++) {
|
||||
if (coversWater(roles.get(x, z))) {
|
||||
water++;
|
||||
}
|
||||
}
|
||||
}
|
||||
requireFinal(complex, revision, structureKey, chunkX, chunkZ);
|
||||
return admits(water, CHUNK * CHUNK);
|
||||
}
|
||||
|
||||
public static boolean admitsPieces(Engine engine, IrisStructurePlacement placement, String structureKey,
|
||||
KList<PlacedStructurePiece> pieces, int chunkX, int chunkZ) {
|
||||
IrisComplex complex = engine.getComplex();
|
||||
if (placement.isAllowWater() || complex == null) {
|
||||
return true;
|
||||
}
|
||||
LongOpenHashSet columns = new LongOpenHashSet();
|
||||
for (PlacedStructurePiece piece : pieces) {
|
||||
for (int x = piece.getMinX(); x <= piece.getMaxX(); x++) {
|
||||
for (int z = piece.getMinZ(); z <= piece.getMaxZ(); z++) {
|
||||
columns.add(columnKey(x, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
ProceduralStream<WaterRole> roles = complex.getWaterRoleStream();
|
||||
long revision = ProvisionalSampling.revision();
|
||||
int water = 0;
|
||||
LongIterator iterator = columns.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
long column = iterator.nextLong();
|
||||
if (coversWater(roles.get((int) (column >> 32), (int) column))) {
|
||||
water++;
|
||||
}
|
||||
}
|
||||
requireFinal(complex, revision, structureKey, chunkX, chunkZ);
|
||||
return admits(water, columns.size());
|
||||
}
|
||||
|
||||
static boolean coversWater(WaterRole role) {
|
||||
return switch (role) {
|
||||
case CHANNEL, POND, CASCADE, WATERFALL -> true;
|
||||
case NONE, BANK, SHORE, POND_SHORE, DAM, MOUTH, INLET -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean admits(int water, int columns) {
|
||||
return (long) water * 100L <= (long) columns * MAX_WATER_PERCENT;
|
||||
}
|
||||
|
||||
private static void requireFinal(IrisComplex complex, long revision, String structureKey, int chunkX, int chunkZ) {
|
||||
if (ProvisionalSampling.revision() == revision || complex.isPlatformMainThread()) {
|
||||
return;
|
||||
}
|
||||
throw new ProvisionalAnswerException("Structure '" + structureKey + "' starting in chunk " + chunkX + "," + chunkZ
|
||||
+ " read a provisional water answer; structures are only placed from final water.");
|
||||
}
|
||||
|
||||
private static long columnKey(int x, int z) {
|
||||
return ((long) x << 32) | (z & 0xffffffffL);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user