mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +00:00
Structures respect rivers
- Add the allowWater structure placement field and recapture the schema digest - Skip surface Iris structures whose piece footprint is more than 10% channel, pond, cascade or waterfall water - Skip surface native placements whose start chunk is more than 10% of that water - Fail closed on a provisional water answer off the server thread - Keep BORE and FORCE_CARVE out of water columns from two blocks below the floor and out of the two-block bank up to the water surface - Run structure pieces and stilts inside a MantleWriter object placement that applies the object water veto unless the placement allows water - Let forced single pieces of allowWater structures enter water like an object's own forcePlace - Apply the object water veto to floating-island object transactions - Share the veto between the destination transaction, MantleWriter and floating transactions - Reset the destination transaction's water flag when an object placement ends
This commit is contained in:
1 parent
cabfca700a
commit
ba0bb1a2c0
20 files changed
+1052
-165
No files matched your search
+22
-3
@@ -35,6 +35,7 @@ import java.util.function.Supplier;
|
||||
import java.util.Objects;
|
||||
import art.arcane.volmlib.util.matter.IrisMatter;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.iris.world.storage.matter.IrisMatterSupport;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -43,14 +44,18 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
private final ObjectContinuationBundle.PlacementKey placementKey;
|
||||
private final KList<BufferedMutation> mutations;
|
||||
private final Map<PositionKey, NativeBlockState> bufferedBlocks;
|
||||
private final boolean entersWater;
|
||||
private ObjectHydrologyVeto waterVeto;
|
||||
private int blockWrites;
|
||||
private BlockPosition canopyPosition;
|
||||
|
||||
FloatingObjectPlacementTransaction(IObjectPlacer delegate, ObjectContinuationBundle.PlacementKey placementKey) {
|
||||
FloatingObjectPlacementTransaction(IObjectPlacer delegate, ObjectContinuationBundle.PlacementKey placementKey,
|
||||
boolean entersWater) {
|
||||
this.delegate = Objects.requireNonNull(delegate);
|
||||
this.placementKey = Objects.requireNonNull(placementKey);
|
||||
this.mutations = new KList<>();
|
||||
this.bufferedBlocks = new HashMap<>();
|
||||
this.entersWater = entersWater;
|
||||
}
|
||||
|
||||
CommitResult commit() {
|
||||
@@ -156,7 +161,7 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, NativeBlockState state) {
|
||||
if (state == null) {
|
||||
if (state == null || waterVeto().keepsBlock(x, y, z, state, entersWater)) {
|
||||
return;
|
||||
}
|
||||
mutations.add(new BlockMutation(x, y, z, state, isCanopy(x, y, z)));
|
||||
@@ -234,7 +239,7 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
|
||||
@Override
|
||||
public <T> void setData(int x, int y, int z, T data) {
|
||||
if (data == null) {
|
||||
if (data == null || keepsWater(x, y, z, data)) {
|
||||
return;
|
||||
}
|
||||
mutations.add(new DataMutation(x, y, z, data, isCanopy(x, y, z)));
|
||||
@@ -244,6 +249,20 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean keepsWater(int x, int y, int z, Object data) {
|
||||
if (data instanceof NativeBlockState state) {
|
||||
return waterVeto().keepsBlock(x, y, z, state, entersWater);
|
||||
}
|
||||
return data instanceof MatterCavern && waterVeto().keeps(x, y, z, false, entersWater);
|
||||
}
|
||||
|
||||
private ObjectHydrologyVeto waterVeto() {
|
||||
if (waterVeto == null) {
|
||||
waterVeto = ObjectHydrologyVeto.of(delegate.getEngine());
|
||||
}
|
||||
return waterVeto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getData(int x, int y, int z, Class<T> type) {
|
||||
for (int i = mutations.size() - 1; i >= 0; i--) {
|
||||
|
||||
@@ -147,51 +147,51 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
+ " is not implemented for structure '" + key + "'");
|
||||
}
|
||||
|
||||
ObjectPlaceMode mode = structure.getPlaceMode();
|
||||
int failedPieces = 0;
|
||||
IrisStructureStiltSettings stilt = placement.getStilt();
|
||||
Long2IntOpenHashMap foundationColumns = stilt == null
|
||||
? null : new Long2IntOpenHashMap();
|
||||
boolean supportNonOccluding = stilt != null && stilt.isSupportNonOccluding();
|
||||
if (placement.isAnchoredUnderground()) {
|
||||
ObjectPlaceMode undergroundMode = (mode == ObjectPlaceMode.ORGANIC_STILT || mode == ObjectPlaceMode.CEILING_HANG)
|
||||
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
|
||||
for (PlacedStructurePiece p : pieces) {
|
||||
if (placeObject(writer, structure, p, undergroundMode, false, rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
} else if (mode == ObjectPlaceMode.STRUCTURE_PIECE || mode == ObjectPlaceMode.FLOATING) {
|
||||
for (PlacedStructurePiece p : pieces) {
|
||||
if (placeObject(writer, structure, p, ObjectPlaceMode.STRUCTURE_PIECE, false, rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
} else if (pieces.size() == 1) {
|
||||
if (placeObject(writer, structure, pieces.getFirst(), mode, true, rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
} else {
|
||||
for (PlacedStructurePiece p : pieces) {
|
||||
if (placeObject(writer, structure, p, ObjectPlaceMode.STRUCTURE_PIECE, false, rng,
|
||||
foundationColumns, supportNonOccluding) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
}
|
||||
int failedPieces = placePieces(writer, placement, structure, pieces, rng);
|
||||
requireAppliedPieces(resolved, cx, cz, failedPieces);
|
||||
if (failedPieces == 0 && stilt != null) {
|
||||
placeFoundation(writer, foundationColumns, stilt, rng, !placement.isAnchoredUnderground());
|
||||
}
|
||||
if (failedPieces == 0) {
|
||||
capture.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int placePieces(MantleWriter writer, IrisStructurePlacement placement, IrisStructure structure,
|
||||
KList<PlacedStructurePiece> pieces, RNG rng) {
|
||||
IrisStructureStiltSettings stilt = placement.getStilt();
|
||||
PieceRun run = new PieceRun(structure, rng, stilt == null ? null : new Long2IntOpenHashMap(),
|
||||
stilt != null && stilt.isSupportNonOccluding(), placement.isAllowWater());
|
||||
ObjectPlaceMode mode = structure.getPlaceMode();
|
||||
int failedPieces = 0;
|
||||
int water = writer.beginObjectPlacement(run.allowWater());
|
||||
try {
|
||||
if (placement.isAnchoredUnderground()) {
|
||||
ObjectPlaceMode undergroundMode = (mode == ObjectPlaceMode.ORGANIC_STILT || mode == ObjectPlaceMode.CEILING_HANG)
|
||||
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
|
||||
for (PlacedStructurePiece p : pieces) {
|
||||
if (placeObject(writer, run, p, undergroundMode, false) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
} else if (pieces.size() == 1 && mode != ObjectPlaceMode.STRUCTURE_PIECE && mode != ObjectPlaceMode.FLOATING) {
|
||||
if (placeObject(writer, run, pieces.getFirst(), mode, true) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
} else {
|
||||
for (PlacedStructurePiece p : pieces) {
|
||||
if (placeObject(writer, run, p, ObjectPlaceMode.STRUCTURE_PIECE, false) == -1) {
|
||||
failedPieces++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (failedPieces == 0 && stilt != null) {
|
||||
placeFoundation(writer, run.foundationColumns(), stilt, rng, !placement.isAnchoredUnderground());
|
||||
}
|
||||
} finally {
|
||||
writer.endObjectPlacement(water);
|
||||
}
|
||||
return failedPieces;
|
||||
}
|
||||
|
||||
private void placeFoundation(MantleWriter writer, Long2IntOpenHashMap columns,
|
||||
IrisStructureStiltSettings settings, RNG rng,
|
||||
boolean surfaceStructure) {
|
||||
@@ -270,8 +270,8 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
+ " assembled piece(s)");
|
||||
}
|
||||
|
||||
private void boreStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
|
||||
IrisStructureTerrain terrain) {
|
||||
void boreStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
|
||||
IrisStructureTerrain terrain) {
|
||||
int[] bounds = computePieceBounds(pieces);
|
||||
if (bounds == null) {
|
||||
return;
|
||||
@@ -291,17 +291,11 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
return;
|
||||
}
|
||||
int mantleOffset = getEngineMantle().getEngine().getMinHeight();
|
||||
for (int bx = minX; bx <= maxX; bx++) {
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
for (int bz = minZ; bz <= maxZ; bz++) {
|
||||
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
|
||||
}
|
||||
}
|
||||
}
|
||||
carveBox(writer, minX, minY, minZ, maxX, maxY, maxZ, mantleOffset);
|
||||
}
|
||||
|
||||
private void forceCarveStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
|
||||
IrisStructureTerrain terrain) {
|
||||
void forceCarveStructure(MantleWriter writer, KList<PlacedStructurePiece> pieces,
|
||||
IrisStructureTerrain terrain) {
|
||||
int[] bounds = computePieceBounds(pieces);
|
||||
if (bounds == null) {
|
||||
return;
|
||||
@@ -344,6 +338,8 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
+ " margin=" + margin + " head=" + head + " floorCut=" + floorCut + " work=" + work);
|
||||
}
|
||||
|
||||
StructureCarveWater water = StructureCarveWater.of(getEngineMantle().getComplex(),
|
||||
footprint.minX(), footprint.minZ(), footprint.maxX(), footprint.maxZ());
|
||||
double sideReachSquared = (double) margin * margin;
|
||||
double downReach = Math.max(1D, floorCut);
|
||||
for (int bz = footprint.minZ(); bz <= footprint.maxZ(); bz++) {
|
||||
@@ -365,6 +361,9 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
int minY = Math.max(worldMin, sourceMinY - floorCut);
|
||||
int maxY = Math.min(worldMax, sourceMaxY + columnUpExtension);
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
if (water.keeps(bx, by - mantleOffset, bz)) {
|
||||
continue;
|
||||
}
|
||||
double normalizedY = StructureCarveEnvelope.normalizedVerticalDistance(
|
||||
by, sourceMinY, sourceMaxY, upReach, downReach);
|
||||
double distanceSquared = normalizedHorizontalDistanceSquared
|
||||
@@ -393,16 +392,19 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
|
||||
private void carveOverboreBox(MantleWriter writer, int[] bounds, int margin, int head, int floorCut,
|
||||
int mantleOffset, int worldMin, int worldMax) {
|
||||
int minX = bounds[0] - margin;
|
||||
int minY = Math.max(worldMin, bounds[1] - floorCut);
|
||||
int minZ = bounds[2] - margin;
|
||||
int maxX = bounds[3] + margin;
|
||||
int maxY = Math.min(worldMax, bounds[4] + head);
|
||||
int maxZ = bounds[5] + margin;
|
||||
carveBox(writer, bounds[0] - margin, Math.max(worldMin, bounds[1] - floorCut), bounds[2] - margin,
|
||||
bounds[3] + margin, Math.min(worldMax, bounds[4] + head), bounds[5] + margin, mantleOffset);
|
||||
}
|
||||
|
||||
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);
|
||||
for (int bx = minX; bx <= maxX; bx++) {
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
for (int bz = minZ; bz <= maxZ; bz++) {
|
||||
writer.setForcedCarve(bx, by - mantleOffset, bz, CARVE_CAVERN);
|
||||
for (int bz = minZ; bz <= maxZ; bz++) {
|
||||
for (int by = minY; by <= maxY; by++) {
|
||||
int mantleY = by - mantleOffset;
|
||||
if (!water.keeps(bx, mantleY, bz)) {
|
||||
writer.setForcedCarve(bx, mantleY, bz, CARVE_CAVERN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -559,27 +561,27 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
return new int[]{minX, minY, minZ, maxX, maxY, maxZ};
|
||||
}
|
||||
|
||||
private int placeObject(MantleWriter writer, IrisStructure structure, PlacedStructurePiece p,
|
||||
ObjectPlaceMode mode, boolean sampledHeight, RNG rng, Long2IntOpenHashMap foundationColumns,
|
||||
boolean supportNonOccluding) {
|
||||
private int placeObject(MantleWriter writer, PieceRun run, PlacedStructurePiece p, ObjectPlaceMode mode,
|
||||
boolean sampledHeight) {
|
||||
IrisObject object = p.getObject();
|
||||
String objectKey = object.getLoadKey();
|
||||
IrisObjectPlacement config = piecePlacement(structure, p, mode);
|
||||
String marker = structurePlacementMarker(structure, p, objectKey);
|
||||
IrisObjectPlacement config = piecePlacement(run.structure(), p, mode, run.allowWater());
|
||||
String marker = structurePlacementMarker(run.structure(), p, objectKey);
|
||||
BiConsumer<BlockPosition, NativeBlockState> listener = (position, state) -> {
|
||||
StructureFoundationPlanner.recordBaseCell(
|
||||
foundationColumns, position.getX(), position.getY(), position.getZ(), state,
|
||||
supportNonOccluding);
|
||||
run.foundationColumns(), position.getX(), position.getY(), position.getZ(), state,
|
||||
run.supportNonOccluding());
|
||||
if (marker != null && shouldWriteStructureMarker(state)) {
|
||||
writer.setData(position.getX(), position.getY(), position.getZ(), marker);
|
||||
}
|
||||
};
|
||||
return sampledHeight
|
||||
? object.place(p.getX(), p.getZ(), writer, config, rng, listener, null, getData())
|
||||
: object.place(p.getX(), p.getY() - getEngineMantle().getEngine().getMinHeight(), p.getZ(), writer, config, rng, listener, null, getData());
|
||||
? object.place(p.getX(), p.getZ(), writer, config, run.rng(), listener, null, getData())
|
||||
: object.place(p.getX(), p.getY() - getEngineMantle().getEngine().getMinHeight(), p.getZ(), writer, config, run.rng(), listener, null, getData());
|
||||
}
|
||||
|
||||
static IrisObjectPlacement piecePlacement(IrisStructure structure, PlacedStructurePiece piece, ObjectPlaceMode mode) {
|
||||
static IrisObjectPlacement piecePlacement(IrisStructure structure, PlacedStructurePiece piece, ObjectPlaceMode mode,
|
||||
boolean allowWater) {
|
||||
IrisObjectPlacement config = structure.createLootPlacement(piece.getObject().getLoadKey());
|
||||
config.setMode(mode);
|
||||
config.setRotation(piece.getRotation());
|
||||
@@ -588,7 +590,7 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
}
|
||||
if (mode != ObjectPlaceMode.STRUCTURE_PIECE && mode != ObjectPlaceMode.FLOATING) {
|
||||
config.setForcePlace(true);
|
||||
config.setForcedByStructure(true);
|
||||
config.setForcedByStructure(!allowWater);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
@@ -713,4 +715,8 @@ public class IrisStructureComponent extends IrisMantleComponent {
|
||||
|
||||
private record ObjectBlockPosition(int x, int y, int z) {
|
||||
}
|
||||
|
||||
private record PieceRun(IrisStructure structure, RNG rng, Long2IntOpenHashMap foundationColumns,
|
||||
boolean supportNonOccluding, boolean allowWater) {
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -217,7 +217,7 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
||||
writer, placements.next(minX >> 4, minZ >> 4));
|
||||
writer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
|
||||
try {
|
||||
int resultY = obj.place(xx, zz, transaction, floatingPlacement, rng, (b, bd) -> {
|
||||
String marker = placementMarker(obj, id);
|
||||
@@ -311,7 +311,8 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
|
||||
int yv = pickTopY + 1 - fp.getLowestSolidKeyY();
|
||||
|
||||
IslandObjectPlacer islandPlacer = IslandObjectPlacer.top(writer, sampleProvider, entry, pickTopY);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(islandPlacer, placements.next(minX >> 4, minZ >> 4));
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
||||
islandPlacer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
|
||||
try {
|
||||
@@ -424,7 +425,8 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
|
||||
int yv = invertedBaseY(pickBottomY, fp, invertedRotation);
|
||||
|
||||
IslandObjectPlacer islandPlacer = IslandObjectPlacer.bottom(writer, sampleProvider, entry, pickBottomY);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(islandPlacer, placements.next(minX >> 4, minZ >> 4));
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
||||
islandPlacer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
|
||||
try {
|
||||
|
||||
@@ -90,6 +90,11 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
@Setter(AccessLevel.NONE)
|
||||
@EqualsAndHashCode.Exclude
|
||||
@ToString.Exclude
|
||||
private final ThreadLocal<ObjectWater> objectWater = new ThreadLocal<>();
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
@EqualsAndHashCode.Exclude
|
||||
@ToString.Exclude
|
||||
private TerrainAccess terrainAccess;
|
||||
|
||||
public MantleWriter(EngineMantle engineMantle, Mantle<Matter> mantle, int x, int z, int radius, boolean multicore) {
|
||||
@@ -215,6 +220,28 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
return capture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int beginObjectPlacement(boolean entersWater) {
|
||||
objectWater.set(new ObjectWater(ObjectHydrologyVeto.of(getEngine()), entersWater));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endObjectPlacement(int checkpoint) {
|
||||
objectWater.remove();
|
||||
}
|
||||
|
||||
private boolean keepsWater(int x, int y, int z, Object value) {
|
||||
ObjectWater water = objectWater.get();
|
||||
if (water == null) {
|
||||
return false;
|
||||
}
|
||||
if (value instanceof NativeBlockState state) {
|
||||
return water.veto().keepsBlock(x, y, z, state, water.entersWater());
|
||||
}
|
||||
return value instanceof MatterCavern && water.veto().keeps(x, y, z, false, water.entersWater());
|
||||
}
|
||||
|
||||
private void recordObjectValue(int x, int y, int z, Class<?> type, Object value) {
|
||||
ObjectPlacementCapture capture = objectPlacementCapture.get();
|
||||
if (capture != null) {
|
||||
@@ -241,7 +268,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
MantleChunk<Matter> chunk = acquireChunk(cx, cz);
|
||||
if (chunk == null) return;
|
||||
|
||||
if (protectsSubterrainPlacement(x, y, z)) {
|
||||
if (protectsSubterrainPlacement(x, y, z) || keepsWater(x, y, z, t)) {
|
||||
return;
|
||||
}
|
||||
synchronized (chunk) {
|
||||
@@ -611,7 +638,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
}
|
||||
|
||||
MantleChunk<Matter> chunk = acquireChunk(x >> 4, z >> 4);
|
||||
if (chunk == null) {
|
||||
if (chunk == null || keepsWater(x, y, z, baseState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1007,6 +1034,9 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
|
||||
naturalOpening ? ALWAYS : NEVER, cavern ? ALWAYS : NEVER) ? (byte) 1 : 0;
|
||||
}
|
||||
|
||||
private record ObjectWater(ObjectHydrologyVeto veto, boolean entersWater) {
|
||||
}
|
||||
|
||||
public final class ObjectPlacementCapture implements AutoCloseable {
|
||||
private final ObjectContinuationBundle.PlacementKey key;
|
||||
private final Long2ObjectOpenHashMap<Matter> fragments = new Long2ObjectOpenHashMap<>();
|
||||
|
||||
+5
-78
@@ -5,10 +5,6 @@ import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.decoration.tree.TreeBlockMaterial;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRasterizer;
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -30,7 +26,6 @@ import java.util.Map;
|
||||
|
||||
final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
private static final Object CLEARED = new Object();
|
||||
private static final int[][] SIDES = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
|
||||
private final MantleWriter writer;
|
||||
private final int destinationChunkX;
|
||||
@@ -45,8 +40,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
private int subterrainY;
|
||||
private int subterrainZ;
|
||||
private boolean subterrainProtects;
|
||||
private boolean hydrologyKnown;
|
||||
private HydrologyRuntime hydrology;
|
||||
private ObjectHydrologyVeto waterVeto;
|
||||
private boolean waterPlacement;
|
||||
|
||||
ObjectDestinationTransaction(MantleWriter writer, int destinationChunkX, int destinationChunkZ) {
|
||||
@@ -86,6 +80,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
|
||||
@Override
|
||||
public void endObjectPlacement(int checkpoint) {
|
||||
waterPlacement = false;
|
||||
if (checkpoint >= 0 && checkpoint < log.size()) {
|
||||
placements.add(new PlacementRange(checkpoint, log.size()));
|
||||
}
|
||||
@@ -417,78 +412,10 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
}
|
||||
|
||||
private boolean hydrologyKeeps(int x, int y, int z, boolean solid, boolean entersWater) {
|
||||
HydrologyRuntime runtime = hydrology();
|
||||
if (runtime == null) {
|
||||
return false;
|
||||
if (waterVeto == null) {
|
||||
waterVeto = ObjectHydrologyVeto.of(getEngine());
|
||||
}
|
||||
ChunkWaterRaster raster = runtime.raster(x >> 4, z >> 4);
|
||||
if (raster.empty()) {
|
||||
return false;
|
||||
}
|
||||
WaterRole role = raster.role(x & 15, z & 15);
|
||||
if (role == WaterRole.INLET && y >= raster.waterHead(x & 15, z & 15) && y <= getEngine().getComplex().naturalTrueHeight(x, z)) {
|
||||
return true;
|
||||
}
|
||||
if (solid && !entersWater && fillsWater(x, y, z)) {
|
||||
return true;
|
||||
}
|
||||
if (role.wet()) {
|
||||
int surface = raster.waterHead(x & 15, z & 15);
|
||||
int fallTop = highestHead(runtime, raster, x, z);
|
||||
if (fallTop > surface && y >= surface && y <= fallTop) {
|
||||
return true;
|
||||
}
|
||||
return !solid && y >= raster.terrainHeight(x & 15, z & 15) && y <= surface;
|
||||
}
|
||||
if (solid || role == WaterRole.NONE) {
|
||||
return false;
|
||||
}
|
||||
int head = Integer.MIN_VALUE;
|
||||
int bed = Integer.MAX_VALUE;
|
||||
for (int[] side : SIDES) {
|
||||
int nx = x + side[0];
|
||||
int nz = z + side[1];
|
||||
ChunkWaterRaster neighbour = neighbour(runtime, raster, x, z, nx, nz);
|
||||
if (neighbour.role(nx & 15, nz & 15).wet()) {
|
||||
head = Math.max(head, neighbour.waterHead(nx & 15, nz & 15));
|
||||
bed = Math.min(bed, neighbour.terrainHeight(nx & 15, nz & 15));
|
||||
}
|
||||
}
|
||||
return y > bed && y <= head;
|
||||
}
|
||||
|
||||
private boolean fillsWater(int x, int y, int z) {
|
||||
IrisComplex complex = getEngine().getComplex();
|
||||
if (!complex.getWaterRoleStream().get(x, z).wet()) {
|
||||
return false;
|
||||
}
|
||||
return y > complex.getRoundedHeighteightStream().get(x, z)
|
||||
&& y <= (int) Math.round(complex.getWaterHeadStream().getDouble(x, z));
|
||||
}
|
||||
|
||||
private static int highestHead(HydrologyRuntime runtime, ChunkWaterRaster raster, int x, int z) {
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (int[] side : SIDES) {
|
||||
int nx = x + side[0];
|
||||
int nz = z + side[1];
|
||||
top = Math.max(top, neighbour(runtime, raster, x, z, nx, nz).waterHead(nx & 15, nz & 15));
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
private static ChunkWaterRaster neighbour(HydrologyRuntime runtime, ChunkWaterRaster raster, int x, int z, int nx, int nz) {
|
||||
return (nx >> 4) == (x >> 4) && (nz >> 4) == (z >> 4) ? raster : runtime.raster(nx >> 4, nz >> 4);
|
||||
}
|
||||
|
||||
private HydrologyRuntime hydrology() {
|
||||
if (!hydrologyKnown) {
|
||||
Engine engine = getEngine();
|
||||
IrisComplex complex = engine == null ? null : engine.getComplex();
|
||||
HydrologyRuntime runtime = complex == null ? null : complex.getHydrologyRuntime();
|
||||
hydrology = runtime != null && runtime.enabled() ? runtime : null;
|
||||
hydrologyKnown = true;
|
||||
}
|
||||
return hydrology;
|
||||
return waterVeto.keeps(x, y, z, solid, entersWater);
|
||||
}
|
||||
|
||||
private boolean protectsSubterrain(int x, int y, int z) {
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
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.volmlib.nativelib.terrain.NativeBlockState;
|
||||
|
||||
final class ObjectHydrologyVeto {
|
||||
private static final int[][] SIDES = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
private static final ObjectHydrologyVeto NONE = new ObjectHydrologyVeto(null, null);
|
||||
|
||||
private final IrisComplex complex;
|
||||
private final HydrologyRuntime runtime;
|
||||
|
||||
private ObjectHydrologyVeto(IrisComplex complex, HydrologyRuntime runtime) {
|
||||
this.complex = complex;
|
||||
this.runtime = runtime;
|
||||
}
|
||||
|
||||
static ObjectHydrologyVeto of(Engine engine) {
|
||||
IrisComplex complex = engine == null ? null : engine.getComplex();
|
||||
HydrologyRuntime runtime = complex == null ? null : complex.getHydrologyRuntime();
|
||||
return runtime != null && runtime.enabled() ? new ObjectHydrologyVeto(complex, runtime) : NONE;
|
||||
}
|
||||
|
||||
boolean keepsBlock(int x, int y, int z, NativeBlockState state, boolean entersWater) {
|
||||
NativeBlockState base = state.isCustom() && state.placementBaseState() != null ? state.placementBaseState() : state;
|
||||
return keeps(x, y, z, base.isSolid(), entersWater);
|
||||
}
|
||||
|
||||
boolean keeps(int x, int y, int z, boolean solid, boolean entersWater) {
|
||||
if (runtime == null) {
|
||||
return false;
|
||||
}
|
||||
ChunkWaterRaster raster = runtime.raster(x >> 4, z >> 4);
|
||||
if (raster.empty()) {
|
||||
return false;
|
||||
}
|
||||
WaterRole role = raster.role(x & 15, z & 15);
|
||||
if (role == WaterRole.INLET && y >= raster.waterHead(x & 15, z & 15) && y <= complex.naturalTrueHeight(x, z)) {
|
||||
return true;
|
||||
}
|
||||
if (solid && !entersWater && fillsWater(x, y, z)) {
|
||||
return true;
|
||||
}
|
||||
if (role.wet()) {
|
||||
int surface = raster.waterHead(x & 15, z & 15);
|
||||
int fallTop = highestHead(raster, x, z);
|
||||
if (fallTop > surface && y >= surface && y <= fallTop) {
|
||||
return true;
|
||||
}
|
||||
return !solid && y >= raster.terrainHeight(x & 15, z & 15) && y <= surface;
|
||||
}
|
||||
if (solid || role == WaterRole.NONE) {
|
||||
return false;
|
||||
}
|
||||
int head = Integer.MIN_VALUE;
|
||||
int bed = Integer.MAX_VALUE;
|
||||
for (int[] side : SIDES) {
|
||||
int nx = x + side[0];
|
||||
int nz = z + side[1];
|
||||
ChunkWaterRaster neighbour = neighbour(raster, x, z, nx, nz);
|
||||
if (neighbour.role(nx & 15, nz & 15).wet()) {
|
||||
head = Math.max(head, neighbour.waterHead(nx & 15, nz & 15));
|
||||
bed = Math.min(bed, neighbour.terrainHeight(nx & 15, nz & 15));
|
||||
}
|
||||
}
|
||||
return y > bed && y <= head;
|
||||
}
|
||||
|
||||
private boolean fillsWater(int x, int y, int z) {
|
||||
if (!complex.getWaterRoleStream().get(x, z).wet()) {
|
||||
return false;
|
||||
}
|
||||
return y > complex.getRoundedHeighteightStream().get(x, z)
|
||||
&& y <= (int) Math.round(complex.getWaterHeadStream().getDouble(x, z));
|
||||
}
|
||||
|
||||
private int highestHead(ChunkWaterRaster raster, int x, int z) {
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (int[] side : SIDES) {
|
||||
int nx = x + side[0];
|
||||
int nz = z + side[1];
|
||||
top = Math.max(top, neighbour(raster, x, z, nx, nz).waterHead(nx & 15, nz & 15));
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
private ChunkWaterRaster neighbour(ChunkWaterRaster raster, int x, int z, int nx, int nz) {
|
||||
return (nx >> 4) == (x >> 4) && (nz >> 4) == (z >> 4) ? raster : runtime.raster(nx >> 4, nz >> 4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
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];
|
||||
}
|
||||
}
|
||||
+5
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -64,6 +65,10 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -590,6 +590,10 @@ 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)) {
|
||||
return null;
|
||||
}
|
||||
if (!allowsResolvedFootprint(engine, placement, structure, pieces)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -130,6 +130,9 @@ public class IrisStructurePlacement {
|
||||
@Description("If false, the placement is skipped when its selected surface or cave column is submerged.")
|
||||
private boolean underwater = false;
|
||||
|
||||
@Description("If true, a surface structure may cover river, stream, pond and lake water, and its pieces and stilts may fill it. If false, a surface placement is skipped when more than 10% of its footprint columns are channel, pond, cascade or waterfall water, and its pieces keep their solid blocks out of the water they touch.")
|
||||
private boolean allowWater = false;
|
||||
|
||||
public IrisStructureTerrain resolvedTerrain() {
|
||||
return terrain == null ? new IrisStructureTerrain() : terrain;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
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