mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
One water-head rule
- Add WaterHeads.snap as the single sea-level parity rule for water heads - Route RasterComposer heads through WaterHeads.snap and drop its private level helper - Route PondChannelSettlement heads through WaterHeads.snap and drop its private head helper - Route ChunkFeatures and ReachSegments hasOnlyLevel checks through WaterHeads.snap
This commit is contained in:
1 parent
30c7492679
commit
69416c235c
5 files changed
+32
-30
No files matched your search
@@ -100,17 +100,17 @@ final class ChunkFeatures {
|
||||
|
||||
boolean hasOnlyLevel(int head, int seaLevel) {
|
||||
for (Pond pond : ponds) {
|
||||
if (pond.level() - Math.floorMod(pond.level() - seaLevel, 2) != head) {
|
||||
if (WaterHeads.snap(pond.level(), seaLevel) != head) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (Pond lake : lakes) {
|
||||
if (lake.level() - Math.floorMod(lake.level() - seaLevel, 2) != head) {
|
||||
if (WaterHeads.snap(lake.level(), seaLevel) != head) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (SeaInlet inlet : inlets) {
|
||||
if (inlet.waterLevel() - Math.floorMod(inlet.waterLevel() - seaLevel, 2) != head) {
|
||||
if (WaterHeads.snap(inlet.waterLevel(), seaLevel) != head) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-7
@@ -75,7 +75,7 @@ public final class PondChannelSettlement {
|
||||
BitSet visited = new BitSet(width * (bounds.maxZ() - bounds.minZ() + 1));
|
||||
for (Reach reach : reaches) {
|
||||
for (int segment = 0; segment + 1 < reach.xs().length; segment++) {
|
||||
if (Math.min(head(reach.grade()[segment], seaLevel), head(reach.grade()[segment + 1], seaLevel)) >= head(level, seaLevel)) {
|
||||
if (Math.min(WaterHeads.snap(reach.grade()[segment], seaLevel), WaterHeads.snap(reach.grade()[segment + 1], seaLevel)) >= WaterHeads.snap(level, seaLevel)) {
|
||||
continue;
|
||||
}
|
||||
float radius = Math.max(reach.halfWidth()[segment], reach.halfWidth()[segment + 1]) + 1f;
|
||||
@@ -111,12 +111,8 @@ public final class PondChannelSettlement {
|
||||
if (channel.reach == null) {
|
||||
return level;
|
||||
}
|
||||
int head = head(channel.reach.grade()[channel.point()], seaLevel);
|
||||
return head < head(level, seaLevel) ? head : level;
|
||||
}
|
||||
|
||||
private static int head(int level, int seaLevel) {
|
||||
return level - Math.floorMod(level - seaLevel, 2);
|
||||
int head = WaterHeads.snap(channel.reach.grade()[channel.point()], seaLevel);
|
||||
return head < WaterHeads.snap(level, seaLevel) ? head : level;
|
||||
}
|
||||
|
||||
private record Bounds(int minX, int minZ, int maxX, int maxZ) {
|
||||
|
||||
+15
-19
@@ -87,7 +87,7 @@ final class RasterComposer {
|
||||
int ground = natural[cell];
|
||||
SeaInlet inlet = features.openInletAt(x, z, inletColumn);
|
||||
if (inlet != null) {
|
||||
head[cell] = level(inlet.waterLevel());
|
||||
head[cell] = WaterHeads.snap(inlet.waterLevel(), settings.seaLevel());
|
||||
terrain[cell] = Math.min(Math.min(ground, inletColumn[0]), head[cell] - 1);
|
||||
role[cell] = WaterRole.INLET;
|
||||
feature[cell] = inlet.id();
|
||||
@@ -101,15 +101,15 @@ final class RasterComposer {
|
||||
double variation = BedProfile.variation(settings.seed(), x, z);
|
||||
if (lake >= 0) {
|
||||
Pond water = features.lake(lake);
|
||||
standing(cell, water, trench(ground, level(water.level()), ground, variation, BedProfile.detail(settings.seed(), x, z)));
|
||||
standing(cell, water, trench(ground, WaterHeads.snap(water.level(), settings.seaLevel()), ground, variation, BedProfile.detail(settings.seed(), x, z)));
|
||||
return;
|
||||
}
|
||||
if (pondIndex >= 0) {
|
||||
Pond water = features.pond(pondIndex);
|
||||
pond[cell] = pondIndex;
|
||||
double detail = BedProfile.detail(settings.seed(), x, z);
|
||||
int floor = interior(cell) ? pondFloor(pondIndex, level(water.level()), x, z, ground, variation, detail) : ground;
|
||||
standing(cell, water, trench(floor, level(water.level()), ground, variation, detail));
|
||||
int floor = interior(cell) ? pondFloor(pondIndex, WaterHeads.snap(water.level(), settings.seaLevel()), x, z, ground, variation, detail) : ground;
|
||||
standing(cell, water, trench(floor, WaterHeads.snap(water.level(), settings.seaLevel()), ground, variation, detail));
|
||||
return;
|
||||
}
|
||||
if (cursor.channel.reach != null) {
|
||||
@@ -120,7 +120,7 @@ final class RasterComposer {
|
||||
}
|
||||
|
||||
private void standing(int cell, Pond water, int floor) {
|
||||
head[cell] = level(water.level());
|
||||
head[cell] = WaterHeads.snap(water.level(), settings.seaLevel());
|
||||
terrain[cell] = Math.min(floor, head[cell] - 1);
|
||||
role[cell] = WaterRole.POND;
|
||||
feature[cell] = water.id();
|
||||
@@ -132,14 +132,14 @@ final class RasterComposer {
|
||||
if (hit.reach == null) {
|
||||
return floor;
|
||||
}
|
||||
return Math.min(floor, bed(hit, Math.min(level, level(hit.reach.grade()[hit.point()])), ground, variation, detail));
|
||||
return Math.min(floor, bed(hit, Math.min(level, WaterHeads.snap(hit.reach.grade()[hit.point()], settings.seaLevel())), ground, variation, detail));
|
||||
}
|
||||
|
||||
private void channel(int cell, int x, int z, int ground, double variation) {
|
||||
ReachCursor.Choice hit = cursor.channel;
|
||||
Reach reach = hit.reach;
|
||||
int point = hit.point();
|
||||
head[cell] = level(reach.grade()[point]);
|
||||
head[cell] = WaterHeads.snap(reach.grade()[point], settings.seaLevel());
|
||||
terrain[cell] = bed(hit, head[cell], ground, variation, BedProfile.detail(settings.seed(), x, z));
|
||||
role[cell] = role(reach.style()[point]);
|
||||
feature[cell] = reach.id();
|
||||
@@ -168,7 +168,7 @@ final class RasterComposer {
|
||||
ReachCursor.Choice bank = cursor.bank;
|
||||
if (bank.reach != null) {
|
||||
HydrologyTier bankTier = bank.reach.tier();
|
||||
int surface = level(bank.reach.grade()[bank.point()]);
|
||||
int surface = WaterHeads.snap(bank.reach.grade()[bank.point()], settings.seaLevel());
|
||||
bankEdge = bank.distance - bank.halfWidth();
|
||||
double u = bankEdge / bankTier.bankBand();
|
||||
if (bankTier.bankStyle() != IrisBankStyle.CLIFF && bankTier.bankStyle() != IrisBankStyle.TERRACED) {
|
||||
@@ -192,8 +192,8 @@ final class RasterComposer {
|
||||
}
|
||||
int taper = settings.ponds().shore().taper();
|
||||
boolean tapered = nearPond >= 0 && pondEdge <= taper;
|
||||
if (tapered && ground > level(features.pond(nearPond).level())) {
|
||||
cut = Math.min(cut, taperCut(level(features.pond(nearPond).level()), ground, BedProfile.position(pondEdge / taper, -variation)));
|
||||
if (tapered && ground > WaterHeads.snap(features.pond(nearPond).level(), settings.seaLevel())) {
|
||||
cut = Math.min(cut, taperCut(WaterHeads.snap(features.pond(nearPond).level(), settings.seaLevel()), ground, BedProfile.position(pondEdge / taper, -variation)));
|
||||
}
|
||||
terrain[cell] = raise == Integer.MIN_VALUE ? cut : Math.max(cut, raise);
|
||||
if (bank.reach != null && (!tapered || bankEdge <= pondEdge)) {
|
||||
@@ -267,10 +267,6 @@ final class RasterComposer {
|
||||
return (int) Math.clamp((long) Math.floor(level + rise), level, ground);
|
||||
}
|
||||
|
||||
private int level(int planned) {
|
||||
return planned - Math.floorMod(planned - settings.seaLevel(), 2);
|
||||
}
|
||||
|
||||
private void gradeRiffles() {
|
||||
int surface = Integer.MIN_VALUE;
|
||||
for (int cell = 0; cell < CELLS && surface == Integer.MIN_VALUE; cell++) {
|
||||
@@ -300,18 +296,18 @@ final class RasterComposer {
|
||||
}
|
||||
SeaInlet inlet = features.openInletAt(x, z, inletColumn);
|
||||
if (inlet != null) {
|
||||
return level(inlet.waterLevel());
|
||||
return WaterHeads.snap(inlet.waterLevel(), settings.seaLevel());
|
||||
}
|
||||
int lake = features.lakeCovers(x, z) ? features.lakeAt(x, z, naturalAt(x, z)) : -1;
|
||||
if (lake >= 0) {
|
||||
return level(features.lake(lake).level());
|
||||
return WaterHeads.snap(features.lake(lake).level(), settings.seaLevel());
|
||||
}
|
||||
int pond = features.pondAt(x, z);
|
||||
if (pond >= 0) {
|
||||
return level(features.pond(pond).level());
|
||||
return WaterHeads.snap(features.pond(pond).level(), settings.seaLevel());
|
||||
}
|
||||
features.segments().nearest(x, z, ReachSegments.Scope.CHANNEL, cursor);
|
||||
return cursor.channel.reach == null ? Integer.MIN_VALUE : level(cursor.channel.reach.grade()[cursor.channel.point()]);
|
||||
return cursor.channel.reach == null ? Integer.MIN_VALUE : WaterHeads.snap(cursor.channel.reach.grade()[cursor.channel.point()], settings.seaLevel());
|
||||
}
|
||||
|
||||
private int pondFloor(int index, int level, int x, int z, int ground, double variation, double detail) {
|
||||
@@ -335,7 +331,7 @@ final class RasterComposer {
|
||||
continue;
|
||||
}
|
||||
Pond held = features.pond(index);
|
||||
int level = level(held.level());
|
||||
int level = WaterHeads.snap(held.level(), settings.seaLevel());
|
||||
if (held.damRaise() > 0 && terrain[cell] < level && level + 1 > crest) {
|
||||
crest = level + 1;
|
||||
dam = held.id();
|
||||
|
||||
@@ -59,7 +59,7 @@ final class ReachSegments {
|
||||
int[] grade = reaches[index].grade();
|
||||
int start = grade[segments[index]];
|
||||
int end = grade[segments[index] + 1];
|
||||
if (start - Math.floorMod(start - seaLevel, 2) != head || end - Math.floorMod(end - seaLevel, 2) != head) {
|
||||
if (WaterHeads.snap(start, seaLevel) != head || WaterHeads.snap(end, seaLevel) != head) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package art.arcane.iris.generation.hydrology.raster;
|
||||
|
||||
public final class WaterHeads {
|
||||
private WaterHeads() {
|
||||
}
|
||||
|
||||
public static int snap(int planned, int seaLevel) {
|
||||
return planned - Math.floorMod(planned - seaLevel, 2);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user