mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Report stopped river searches
- A timed-out hydrology search throws HydrologySearchTimeoutException carrying the nearest feature found so far - nearestRiver answers RiverSearch.Stopped with the nearer of that feature and recorded water, and a message saying a nearer one may exist - Bukkit and modded find river print the stopped message and never teleport on a stopped search - Both commands catch every throwable while delivering a result and log it before telling the player - Modded logs a result that cannot reach the server thread instead of dropping it - The four-argument nearestFeature is removed; tests call the six-argument form
This commit is contained in:
1 parent
474b1e873a
commit
9afd70e69f
11 files changed
+247
-76
No files matched your search
+17
-16
@@ -10,6 +10,7 @@ import art.arcane.iris.generation.hydrology.plan.WindowPlan;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureQuery;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureRef;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologySearchTimeoutException;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
@@ -32,7 +33,6 @@ import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -68,7 +68,7 @@ final class HydrologyFeatureSearch {
|
||||
this.radiusSquared = (long) radius * radius;
|
||||
}
|
||||
|
||||
Optional<HydrologyFeatureRef> nearest(Duration timeout, BooleanSupplier running) throws TimeoutException {
|
||||
Optional<HydrologyFeatureRef> nearest(Duration timeout, BooleanSupplier running) throws HydrologySearchTimeoutException {
|
||||
Objects.requireNonNull(timeout, "timeout");
|
||||
Objects.requireNonNull(running, "running");
|
||||
int rings = Math.ceilDiv(radius, WindowKey.SIZE) + 1;
|
||||
@@ -125,7 +125,7 @@ final class HydrologyFeatureSearch {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void searchLakes(Budget budget) throws TimeoutException {
|
||||
private void searchLakes(Budget budget) throws HydrologySearchTimeoutException {
|
||||
long minX = (long) originX - radius;
|
||||
long minZ = (long) originZ - radius;
|
||||
long maxX = (long) originX + radius;
|
||||
@@ -145,7 +145,7 @@ final class HydrologyFeatureSearch {
|
||||
}
|
||||
}
|
||||
|
||||
private void searchWindows(int rings, Budget budget) throws TimeoutException {
|
||||
private void searchWindows(int rings, Budget budget) throws HydrologySearchTimeoutException {
|
||||
WindowKey origin = WindowKey.containing(originX, originZ);
|
||||
for (int ring = 0; ring <= rings; ring++) {
|
||||
long bound = Math.max(0L, (long) (ring - 2) * WindowKey.SIZE);
|
||||
@@ -162,16 +162,27 @@ final class HydrologyFeatureSearch {
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T await(CompletableFuture<T> plan, Budget budget) throws TimeoutException {
|
||||
private <T> T await(CompletableFuture<T> plan, Budget budget) throws HydrologySearchTimeoutException {
|
||||
CountDownLatch settled = new CountDownLatch(1);
|
||||
plan.whenComplete((value, failure) -> settled.countDown());
|
||||
boolean ready = false;
|
||||
while (!ready) {
|
||||
ready = settle(settled, budget.slice());
|
||||
ready = settle(settled, slice(budget));
|
||||
}
|
||||
return cache.awaitPlan(plan);
|
||||
}
|
||||
|
||||
private long slice(Budget budget) throws HydrologySearchTimeoutException {
|
||||
if (!budget.running().getAsBoolean()) {
|
||||
throw new CancellationException("The hydrology feature search was cancelled.");
|
||||
}
|
||||
long remaining = budget.deadline() - System.nanoTime();
|
||||
if (remaining <= 0L) {
|
||||
throw new HydrologySearchTimeoutException(budget.timeout(), best);
|
||||
}
|
||||
return Math.min(remaining, POLL_NANOS);
|
||||
}
|
||||
|
||||
private static boolean settle(CountDownLatch settled, long nanos) {
|
||||
try {
|
||||
return settled.await(nanos, TimeUnit.NANOSECONDS);
|
||||
@@ -328,15 +339,5 @@ final class HydrologyFeatureSearch {
|
||||
}
|
||||
|
||||
private record Budget(long deadline, Duration timeout, BooleanSupplier running) {
|
||||
private long slice() throws TimeoutException {
|
||||
if (!running.getAsBoolean()) {
|
||||
throw new CancellationException("The hydrology feature search was cancelled.");
|
||||
}
|
||||
long remaining = deadline - System.nanoTime();
|
||||
if (remaining <= 0L) {
|
||||
throw new TimeoutException("The hydrology feature search ran past its " + timeout.toMillis() + " ms limit.");
|
||||
}
|
||||
return Math.min(remaining, POLL_NANOS);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-7
@@ -14,6 +14,7 @@ import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureQuery;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureRef;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologySearchTimeoutException;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChannelFluids;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
@@ -52,7 +53,6 @@ import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Function;
|
||||
@@ -405,14 +405,9 @@ public final class HydrologyRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<HydrologyFeatureRef> nearestFeature(int blockX, int blockZ, HydrologyFeatureQuery query, int radius)
|
||||
throws TimeoutException {
|
||||
return nearestFeature(blockX, blockZ, query, radius, feature -> true, () -> true);
|
||||
}
|
||||
|
||||
public Optional<HydrologyFeatureRef> nearestFeature(int blockX, int blockZ, HydrologyFeatureQuery query, int radius,
|
||||
Predicate<HydrologyFeatureRef> eligible, BooleanSupplier running)
|
||||
throws TimeoutException {
|
||||
throws HydrologySearchTimeoutException {
|
||||
Objects.requireNonNull(query, "query");
|
||||
Objects.requireNonNull(eligible, "eligible");
|
||||
Objects.requireNonNull(running, "running");
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package art.arcane.iris.generation.hydrology.query;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public final class HydrologySearchTimeoutException extends TimeoutException {
|
||||
private final HydrologyFeatureRef nearestSoFar;
|
||||
|
||||
public HydrologySearchTimeoutException(Duration timeout, HydrologyFeatureRef nearestSoFar) {
|
||||
super("The hydrology feature search ran past its " + timeout.toMillis() + " ms limit.");
|
||||
this.nearestSoFar = nearestSoFar;
|
||||
}
|
||||
|
||||
public Optional<HydrologyFeatureRef> nearestSoFar() {
|
||||
return Optional.ofNullable(nearestSoFar);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureQuery;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureRef;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologySearchTimeoutException;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.io.IOException;
|
||||
@@ -27,7 +28,6 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
@@ -218,8 +218,9 @@ public final class GenerationSemanticQueries {
|
||||
RiverResult active;
|
||||
try {
|
||||
active = activeRiver(requiredEngine, history, requiredType, blockX, blockZ, maximumDistance, running);
|
||||
} catch (TimeoutException timedOut) {
|
||||
return recorded != null ? new RiverSearch.Found(recorded) : new RiverSearch.Missing(riverTimeoutMessage(requiredType));
|
||||
} catch (HydrologySearchTimeoutException timedOut) {
|
||||
RiverResult planned = timedOut.nearestSoFar().map(feature -> activeResult(requiredEngine, history, feature)).orElse(null);
|
||||
return stoppedSearch(requiredType, nearer(blockX, blockZ, recorded, planned));
|
||||
}
|
||||
RiverResult nearest = nearer(blockX, blockZ, recorded, active);
|
||||
return nearest == null
|
||||
@@ -273,9 +274,14 @@ public final class GenerationSemanticQueries {
|
||||
return "No " + label(type) + " forms in this dimension: " + reason + ".";
|
||||
}
|
||||
|
||||
private static String riverTimeoutMessage(HydrologyFeatureType type) {
|
||||
return "Stopped searching for the nearest " + label(type) + " after "
|
||||
+ HydrologyRuntime.FEATURE_SEARCH_TIMEOUT.toSeconds() + " seconds.";
|
||||
private static RiverSearch stoppedSearch(HydrologyFeatureType type, RiverResult nearestSoFar) {
|
||||
String stopped = "Stopped searching for the nearest " + label(type) + " after "
|
||||
+ HydrologyRuntime.FEATURE_SEARCH_TIMEOUT.toSeconds() + " seconds";
|
||||
if (nearestSoFar == null) {
|
||||
return new RiverSearch.Stopped(Optional.empty(), stopped + " without finding one.");
|
||||
}
|
||||
return new RiverSearch.Stopped(Optional.of(nearestSoFar), stopped + ". The nearest " + label(type) + " found so far is at "
|
||||
+ nearestSoFar.x() + ", " + nearestSoFar.y() + ", " + nearestSoFar.z() + "; a nearer one may exist.");
|
||||
}
|
||||
|
||||
private static String label(HydrologyFeatureType type) {
|
||||
@@ -381,7 +387,7 @@ public final class GenerationSemanticQueries {
|
||||
int blockZ,
|
||||
int maximumDistance,
|
||||
BooleanSupplier running
|
||||
) throws TimeoutException {
|
||||
) throws HydrologySearchTimeoutException {
|
||||
HydrologyRuntime runtime = engine.getComplex().getHydrologyRuntime();
|
||||
Map<Long, Boolean> eligibleChunks = new HashMap<>();
|
||||
TransitionDisplacementField displacement = engine.getComplex().getTransitionDisplacement();
|
||||
@@ -397,9 +403,10 @@ public final class GenerationSemanticQueries {
|
||||
eligibility,
|
||||
running
|
||||
).orElse(null);
|
||||
if (feature == null) {
|
||||
return null;
|
||||
}
|
||||
return feature == null ? null : activeResult(engine, history, feature);
|
||||
}
|
||||
|
||||
private static RiverResult activeResult(Engine engine, GenerationHistory history, HydrologyFeatureRef feature) {
|
||||
OptionalLong activationId = history == null
|
||||
? OptionalLong.empty()
|
||||
: OptionalLong.of(history.activeActivation().activationId());
|
||||
@@ -470,5 +477,12 @@ public final class GenerationSemanticQueries {
|
||||
Objects.requireNonNull(message, "message");
|
||||
}
|
||||
}
|
||||
|
||||
record Stopped(Optional<RiverResult> nearestSoFar, String message) implements RiverSearch {
|
||||
public Stopped {
|
||||
Objects.requireNonNull(nearestSoFar, "nearestSoFar");
|
||||
Objects.requireNonNull(message, "message");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user