mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
Seal inlets and headroom
- Seal covered inlet passages with rock where they come within two blocks of a historical chunk - Add inlet headroom bands from the water up to the passage ceiling plus roofClearance to CaveCeilingMask - Join the headroom bands into the carver and orphan sweep protection - Keep subterrain cells out of the headroom bands in carving, the carve resolver and preserveSubterrain - Apply seal guards inside upper-dimension and dimension-stack protected ranges - Add old-chunk seal, headroom mask, carving wiring, subterrain and protected-range tests
This commit is contained in:
1 parent
0ca3a61046
commit
1ae68646b4
14 files changed
+637
-24
No files matched your search
+41
-1
@@ -13,7 +13,8 @@ public final class SeaInletRasterizer {
|
||||
private static final int GRID = CHUNK + 2 * SHELL;
|
||||
static final int NONE = Integer.MIN_VALUE;
|
||||
|
||||
public void write(SeaInlet inlet, int chunkX, int chunkZ, MantleWriter writer, String fluid, String floodedBiome, SubterrainFluid subterrain) {
|
||||
public void write(SeaInlet inlet, int chunkX, int chunkZ, MantleWriter writer, String fluid, String floodedBiome, SubterrainFluid subterrain,
|
||||
HistoricalChunks historical) {
|
||||
if (!touches(inlet, chunkX, chunkZ)) {
|
||||
return;
|
||||
}
|
||||
@@ -26,6 +27,7 @@ public final class SeaInletRasterizer {
|
||||
HydrologyCaveCell dry = new HydrologyCaveCell(HydrologyCaveAction.DRY_AIR, fluid, floodedBiome);
|
||||
HydrologyCaveCell guard = new HydrologyCaveCell(HydrologyCaveAction.SEAL_GUARD, fluid, floodedBiome);
|
||||
int water = inlet.waterLevel();
|
||||
boolean[] historicalAround = historicalAround(chunkX, chunkZ, historical);
|
||||
for (int lz = 0; lz < CHUNK; lz++) {
|
||||
for (int lx = 0; lx < CHUNK; lx++) {
|
||||
int cell = (lz + SHELL) * GRID + lx + SHELL;
|
||||
@@ -40,6 +42,8 @@ public final class SeaInletRasterizer {
|
||||
guard(writer, x, low - SHELL, water, z, guard);
|
||||
} else if (ceilings[cell] == SeaInlet.OPEN) {
|
||||
guard(writer, x, low - SHELL, floor - 1, z, guard);
|
||||
} else if (historicalAround != null && besideHistorical(historicalAround, lx, lz)) {
|
||||
guard(writer, x, low - SHELL, ceilings[cell], z, guard);
|
||||
} else {
|
||||
for (int y = floor + 1; y <= water; y++) {
|
||||
writer.setData(x, y, z, wet);
|
||||
@@ -66,6 +70,12 @@ public final class SeaInletRasterizer {
|
||||
boolean at(int x, int y, int z);
|
||||
}
|
||||
|
||||
public interface HistoricalChunks {
|
||||
HistoricalChunks NONE = (chunkX, chunkZ) -> false;
|
||||
|
||||
boolean at(int chunkX, int chunkZ);
|
||||
}
|
||||
|
||||
public static boolean touches(SeaInlet inlet, int chunkX, int chunkZ) {
|
||||
int[] bounds = bounds(inlet);
|
||||
int minX = chunkX << 4;
|
||||
@@ -182,6 +192,36 @@ public final class SeaInletRasterizer {
|
||||
return roof;
|
||||
}
|
||||
|
||||
private static boolean[] historicalAround(int chunkX, int chunkZ, HistoricalChunks historical) {
|
||||
boolean[] around = null;
|
||||
for (int dz = -1; dz <= 1; dz++) {
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
if ((dx != 0 || dz != 0) && historical.at(chunkX + dx, chunkZ + dz)) {
|
||||
if (around == null) {
|
||||
around = new boolean[9];
|
||||
}
|
||||
around[(dz + 1) * 3 + dx + 1] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return around;
|
||||
}
|
||||
|
||||
private static boolean besideHistorical(boolean[] historicalAround, int lx, int lz) {
|
||||
int fromX = lx < SHELL ? -1 : 0;
|
||||
int toX = lx >= CHUNK - SHELL ? 1 : 0;
|
||||
int fromZ = lz < SHELL ? -1 : 0;
|
||||
int toZ = lz >= CHUNK - SHELL ? 1 : 0;
|
||||
for (int dz = fromZ; dz <= toZ; dz++) {
|
||||
for (int dx = fromX; dx <= toX; dx++) {
|
||||
if (historicalAround[(dz + 1) * 3 + dx + 1]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void guard(MantleWriter writer, int x, int fromY, int toY, int z, HydrologyCaveCell guard) {
|
||||
for (int y = fromY; y <= toY; y++) {
|
||||
if (writer.getDataIfPresent(x, y, z, HydrologyCaveCell.class) == null) {
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
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.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class CaveCeilingMask {
|
||||
static final int CONTAINMENT = 2;
|
||||
static final int ROOF = 2;
|
||||
@@ -53,6 +59,69 @@ public final class CaveCeilingMask {
|
||||
return masked;
|
||||
}
|
||||
|
||||
public static long[] headroom(int chunkX, int chunkZ, HydrologyRuntime runtime, long[] bands) {
|
||||
List<SeaInlet> inlets = runtime.inlets(chunkX, chunkZ);
|
||||
if (inlets.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int roofClearance = runtime.settings().underground().seaInlets().roofClearance();
|
||||
return fillHeadroom(chunkX, chunkZ, inlets, roofClearance, bands) ? bands : null;
|
||||
}
|
||||
|
||||
static boolean fillHeadroom(int chunkX, int chunkZ, List<SeaInlet> inlets, int roofClearance, long[] bands) {
|
||||
if (inlets.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int originX = (chunkX << 4) - CONTAINMENT;
|
||||
int originZ = (chunkZ << 4) - CONTAINMENT;
|
||||
int[] bottoms = new int[FIELD * FIELD];
|
||||
int[] tops = new int[FIELD * FIELD];
|
||||
Arrays.fill(bottoms, Integer.MAX_VALUE);
|
||||
Arrays.fill(tops, Integer.MIN_VALUE);
|
||||
int[] column = new int[2];
|
||||
boolean roofed = false;
|
||||
for (SeaInlet inlet : inlets) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
int fromX = Math.max(originX, bounds[0]);
|
||||
int toX = Math.min(originX + FIELD - 1, bounds[2]);
|
||||
int toZ = Math.min(originZ + FIELD - 1, bounds[3]);
|
||||
for (int z = Math.max(originZ, bounds[1]); z <= toZ; z++) {
|
||||
for (int x = fromX; x <= toX; x++) {
|
||||
if (!SeaInletRasterizer.column(inlet, x, z, column) || column[1] == SeaInlet.OPEN) {
|
||||
continue;
|
||||
}
|
||||
int index = (z - originZ) * FIELD + x - originX;
|
||||
bottoms[index] = Math.min(bottoms[index], inlet.waterLevel() + 1);
|
||||
tops[index] = Math.max(tops[index], column[1] + roofClearance);
|
||||
roofed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!roofed) {
|
||||
return false;
|
||||
}
|
||||
boolean masked = false;
|
||||
for (int lz = 0; lz < CHUNK; lz++) {
|
||||
for (int lx = 0; lx < CHUNK; lx++) {
|
||||
int bottom = Integer.MAX_VALUE;
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (int fz = lz; fz <= lz + CONTAINMENT * 2; fz++) {
|
||||
for (int fx = lx; fx <= lx + CONTAINMENT * 2; fx++) {
|
||||
bottom = Math.min(bottom, bottoms[fz * FIELD + fx]);
|
||||
top = Math.max(top, tops[fz * FIELD + fx]);
|
||||
}
|
||||
}
|
||||
bands[PowerOfTwoCoordinates.packLocal16(lx, lz)] = SurfaceFluidBoundaryPlan.boundary(bottom, top);
|
||||
masked |= bottom <= top;
|
||||
}
|
||||
}
|
||||
return masked;
|
||||
}
|
||||
|
||||
public static boolean masked(int[] ceilings, long[] headroom, int column, int y) {
|
||||
return ceilings != null && y > ceilings[column] || SurfaceFluidBoundaryPlan.protects(headroom, column, y);
|
||||
}
|
||||
|
||||
public static ChunkWaterRaster ready(ChunkWaterRaster raster, int chunkX, int chunkZ) {
|
||||
if (raster.provisional()) {
|
||||
throw new IllegalStateException("The water raster for chunk " + chunkX + "," + chunkZ
|
||||
|
||||
@@ -169,6 +169,10 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
);
|
||||
int[] caveCeilings = CaveCeilingMask.fill(x, z, complex.getHydrologyRuntime()::raster,
|
||||
blendScratch.caveCeilingField, blendScratch.caveCeilings) ? blendScratch.caveCeilings : null;
|
||||
long[] inletHeadroom = CaveCeilingMask.headroom(x, z, complex.getHydrologyRuntime(), blendScratch.inletHeadroom);
|
||||
if (inletHeadroom != null) {
|
||||
SurfaceFluidBoundaryPlan.join(surfaceFluidBoundaries, inletHeadroom);
|
||||
}
|
||||
CaveFluidSupportPlan fluidSupportPlan = new CaveFluidSupportPlan();
|
||||
for (WeightedProfile weightedProfile : weightedProfiles) {
|
||||
carveProfile(weightedProfile, writer, x, z, chunkSurfaceHeights, surfaceFluidBoundaries, caveCeilings, fluidSupportPlan);
|
||||
@@ -190,10 +194,10 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
caveCeilings
|
||||
);
|
||||
}
|
||||
rasterizeSubterrain(writer, x, z, complex, caveCeilings);
|
||||
rasterizeSubterrain(writer, x, z, complex, caveCeilings, inletHeadroom);
|
||||
}
|
||||
|
||||
private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings) {
|
||||
private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings, long[] inletHeadroom) {
|
||||
SubterrainPlanner planner = complex.getSubterrainPlanner();
|
||||
if (planner == null || planner.isEmpty()) {
|
||||
return;
|
||||
@@ -207,7 +211,7 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
if (cell.solid() && !cell.room().reservedSolid()) {
|
||||
return;
|
||||
}
|
||||
if (!cell.solid() && caveCeilings != null && y > caveCeilings[PowerOfTwoCoordinates.packLocal16(x & 15, z & 15)]) {
|
||||
if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, inletHeadroom, PowerOfTwoCoordinates.packLocal16(x & 15, z & 15), y)) {
|
||||
return;
|
||||
}
|
||||
if (cell.solid()) {
|
||||
@@ -763,6 +767,7 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
private final double[] chunkSurfaceHeightSamples = new double[CHUNK_AREA];
|
||||
private final int[] caveCeilingField = new int[CaveCeilingMask.FIELD * CaveCeilingMask.FIELD];
|
||||
private final int[] caveCeilings = new int[CHUNK_AREA];
|
||||
private final long[] inletHeadroom = new long[CHUNK_AREA];
|
||||
private final double[][] neighbourHeights = new double[NEIGHBOURS][CHUNK_AREA];
|
||||
private final Object[][] neighbourObjects = new Object[NEIGHBOURS][CHUNK_AREA];
|
||||
private final long[][] neighbourSubmerged = new long[NEIGHBOURS][4];
|
||||
|
||||
@@ -79,7 +79,7 @@ public final class MantleHydrologyComponent extends IrisMantleComponent {
|
||||
if (!inlets.isEmpty()) {
|
||||
SeaInletRasterizer.SubterrainFluid subterrain = subterrainFluid(writer, complex, chunkX, chunkZ);
|
||||
for (SeaInlet inlet : inlets) {
|
||||
INLETS.write(inlet, chunkX, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, "", subterrain);
|
||||
INLETS.write(inlet, chunkX, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, "", subterrain, complex::isHistoricalChunk);
|
||||
}
|
||||
}
|
||||
generateFalls(writer, complex, runtime, own, chunkX, chunkZ);
|
||||
|
||||
@@ -73,6 +73,17 @@ final class SurfaceFluidBoundaryPlan {
|
||||
}
|
||||
}
|
||||
|
||||
static void join(long[] boundaries, long[] bands) {
|
||||
for (int columnIndex = 0; columnIndex < CHUNK_AREA; columnIndex++) {
|
||||
long band = bands[columnIndex];
|
||||
if (startY(band) > endY(band)) {
|
||||
continue;
|
||||
}
|
||||
long boundary = boundaries[columnIndex];
|
||||
boundaries[columnIndex] = boundary(Math.min(startY(boundary), startY(band)), Math.max(endY(boundary), endY(band)));
|
||||
}
|
||||
}
|
||||
|
||||
static boolean protects(long[] boundaries, int columnIndex, int y) {
|
||||
if (boundaries == null || columnIndex < 0 || columnIndex >= boundaries.length) {
|
||||
return false;
|
||||
|
||||
@@ -164,7 +164,8 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
getEngine().getWorld().minHeight(),
|
||||
resolverState.complex,
|
||||
subterrainPlanner == null ? null : subterrainPlanner.chunkSampler(x, z),
|
||||
subterrain ? caveCeilings(resolverState.complex, x, z) : null
|
||||
subterrain ? caveCeilings(resolverState.complex, x, z) : null,
|
||||
subterrain ? inletHeadroom(resolverState.complex, x, z) : null
|
||||
);
|
||||
CarveResolver carveResolver = new CarveResolver(resolutionContext);
|
||||
terrain.forEachCell(carveResolver::apply);
|
||||
@@ -262,17 +263,18 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
int minimumY = getEngine().getWorld().minHeight();
|
||||
SubterrainSurfaceMaterials materials = subterrainMaterials(planner, blockX >> 4, blockZ >> 4);
|
||||
int[] caveCeilings = caveCeilings(getComplex(), blockX >> 4, blockZ >> 4);
|
||||
long[] inletHeadroom = inletHeadroom(getComplex(), blockX >> 4, blockZ >> 4);
|
||||
MantleChunk<Matter> chunk = getEngine().getMantle().getMantle().useChunk(blockX >> 4, blockZ >> 4);
|
||||
try {
|
||||
preserveSubterrain(planner, materials, caveCeilings, minimumY, blockX, blockZ, output,
|
||||
preserveSubterrain(planner, materials, caveCeilings, inletHeadroom, minimumY, blockX, blockZ, output,
|
||||
(worldX, y, worldZ) -> HydrologyCaveStorage.getIfPresent(chunk, worldX, y, worldZ));
|
||||
} finally {
|
||||
chunk.release();
|
||||
}
|
||||
}
|
||||
|
||||
private void preserveSubterrain(SubterrainPlanner planner, SubterrainSurfaceMaterials materials, int[] caveCeilings, int minimumY,
|
||||
int blockX, int blockZ, Hunk<NativeBlockState> output, HydrologyCells hydrology) {
|
||||
private void preserveSubterrain(SubterrainPlanner planner, SubterrainSurfaceMaterials materials, int[] caveCeilings, long[] inletHeadroom,
|
||||
int minimumY, int blockX, int blockZ, Hunk<NativeBlockState> output, HydrologyCells hydrology) {
|
||||
SubterrainRasterizer.rasterize(planner, blockX >> 4, blockZ >> 4, (worldX, worldY, worldZ, cell) -> {
|
||||
int y = worldY - minimumY;
|
||||
if (y <= 0 || y >= output.getHeight()) {
|
||||
@@ -280,7 +282,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
}
|
||||
int x = worldX & 15;
|
||||
int z = worldZ & 15;
|
||||
if (!cell.solid() && caveCeilings != null && y > caveCeilings[PowerOfTwoCoordinates.packLocal16(x, z)]) {
|
||||
if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, inletHeadroom, PowerOfTwoCoordinates.packLocal16(x, z), y)) {
|
||||
return;
|
||||
}
|
||||
if (hydrology.at(worldX, y, worldZ) != null) {
|
||||
@@ -308,6 +310,10 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
new int[CaveCeilingMask.FIELD * CaveCeilingMask.FIELD], ceilings) ? ceilings : null;
|
||||
}
|
||||
|
||||
private static long[] inletHeadroom(IrisComplex complex, int chunkX, int chunkZ) {
|
||||
return CaveCeilingMask.headroom(chunkX, chunkZ, complex.getHydrologyRuntime(), new long[256]);
|
||||
}
|
||||
|
||||
private void restoreSubterrainSolids(Hunk<NativeBlockState> output, int chunkX, int chunkZ, boolean preserveFloorSupports,
|
||||
HydrologyCells hydrology) {
|
||||
SubterrainPlanner planner = getComplex().getSubterrainPlanner();
|
||||
@@ -481,7 +487,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
CarveOwnership.Owner owner = carveOwner(hydrology, feature,
|
||||
context.terrainColumns() == null ? null : context.terrainColumns()[columnIndex], y);
|
||||
if (owner == CarveOwnership.Owner.SUBTERRAIN) {
|
||||
if (!feature.solid() && context.caveCeilings() != null && y > context.caveCeilings()[columnIndex]) {
|
||||
if (!feature.solid() && CaveCeilingMask.masked(context.caveCeilings(), context.inletHeadroom(), columnIndex, y)) {
|
||||
return;
|
||||
}
|
||||
context.output().setRaw(localX, y, localZ, SubterrainRasterizer.state(feature));
|
||||
@@ -494,6 +500,14 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
return;
|
||||
}
|
||||
|
||||
if (hydrology != null && hydrology.action() == HydrologyCaveAction.SEAL_GUARD) {
|
||||
NativeBlockState unsealed = context.output().getRaw(localX, y, localZ);
|
||||
NativeBlockState sealed = sealGuardState(unsealed, context.chunkContext().getRock().get(localX, localZ));
|
||||
if (sealed != unsealed) {
|
||||
context.output().setRaw(localX, y, localZ, sealed);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (context.upperSurfaceHeights() != null && y >= context.upperSurfaceHeights()[columnIndex]) {
|
||||
return;
|
||||
}
|
||||
@@ -506,13 +520,6 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
return;
|
||||
}
|
||||
NativeBlockState current = context.output().getRaw(localX, y, localZ);
|
||||
if (hydrology != null && hydrology.action() == HydrologyCaveAction.SEAL_GUARD) {
|
||||
NativeBlockState sealed = sealGuardState(current, context.chunkContext().getRock().get(localX, localZ));
|
||||
if (sealed != current) {
|
||||
context.output().setRaw(localX, y, localZ, sealed);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MatterCavern cavern = composeCavern(baseline, hydrology);
|
||||
if (cavern == null || shouldPreserveExistingFluid(cavern, current)) {
|
||||
@@ -570,7 +577,8 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
int minimumY,
|
||||
IrisComplex complex,
|
||||
SubterrainPlanner.ChunkSampler subterrainSampler,
|
||||
int[] caveCeilings
|
||||
int[] caveCeilings,
|
||||
long[] inletHeadroom
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user