mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-02 02:34:24 +00:00
Refresh recorded cave pools
- Generation history keeps a river revision that moves after recorded river features or cave pools become readable - Studio water tiles reload cave pools when that revision moves instead of the hydrology preview revision - Water tiles at 4 blocks per pixel or closer keep their water state and base colors after completion, counted in the cache weight - The Vision controller re-renders those completed tiles when the river revision moves, after the first retry delay, redrawing only their water - Tests cover the revision counter, completed and coarse tiles through the controller and pools recorded after a raster lands
This commit is contained in:
1 parent
0c59e698cd
commit
81b47a8f9b
10 files changed
+315
-33
No files matched your search
@@ -339,7 +339,8 @@ final class VisionRenderController implements AutoCloseable {
|
||||
tilesInFlight.remove(key);
|
||||
Frame frame = currentFrame;
|
||||
VisibleTile visible = frame == null ? null : frame.tile(key);
|
||||
if (cancelled && visible != null && visible.needsRender(nanoTime.getAsLong(), frame.spec().renderer().previewRevision())) {
|
||||
if (cancelled && visible != null && visible.needsRender(nanoTime.getAsLong(), frame.spec().renderer().previewRevision(),
|
||||
frame.spec().renderer().riverRevision())) {
|
||||
frame.nextCandidate = 0;
|
||||
}
|
||||
}
|
||||
@@ -349,6 +350,7 @@ final class VisionRenderController implements AutoCloseable {
|
||||
boolean cancelled = false;
|
||||
try {
|
||||
long previewRevision = job.renderer().previewRevision();
|
||||
long riverRevision = job.renderer().riverRevision();
|
||||
double tileSpan = TILE_PIXELS * key.blocksPerPixel();
|
||||
MapTileRenderer.TileRender work = job.work();
|
||||
if (work == null) {
|
||||
@@ -364,13 +366,14 @@ final class VisionRenderController implements AutoCloseable {
|
||||
? FIRST_RETRY_NANOS : Math.min(LAST_RETRY_NANOS, previous.retryDelay() * 2L);
|
||||
}
|
||||
long completedAt = nanoTime.getAsLong();
|
||||
boolean retained = work.retainsWater();
|
||||
TileState state = new TileState(tile, provisional, delay, completedAt + delay,
|
||||
completedAt + FIRST_RETRY_NANOS, previewRevision);
|
||||
completedAt + FIRST_RETRY_NANOS, previewRevision, riverRevision, retained);
|
||||
synchronized (this) {
|
||||
if (closed.get()) {
|
||||
return;
|
||||
}
|
||||
cache.put(key, state, provisional ? work : null);
|
||||
cache.put(key, state, provisional || retained ? work : null);
|
||||
if (isWanted(key)) {
|
||||
currentFrame.tile(key).state = state;
|
||||
}
|
||||
@@ -573,9 +576,10 @@ final class VisionRenderController implements AutoCloseable {
|
||||
// Tiles are sorted centre first, and everything before the cursor is drawn or claimed, so each search resumes there.
|
||||
private VisibleTile nextMissing(Set<TileKey> inFlight, boolean advance, long now) {
|
||||
long previewRevision = spec.renderer().previewRevision();
|
||||
long riverRevision = spec.renderer().riverRevision();
|
||||
for (int index = nextCandidate; index < tiles.size(); index++) {
|
||||
VisibleTile tile = tiles.get(index);
|
||||
if (tile.needsRender(now, previewRevision) && !inFlight.contains(tile.key())) {
|
||||
if (tile.needsRender(now, previewRevision, riverRevision) && !inFlight.contains(tile.key())) {
|
||||
if (advance) {
|
||||
nextCandidate = index + 1;
|
||||
}
|
||||
@@ -625,10 +629,16 @@ final class VisionRenderController implements AutoCloseable {
|
||||
return current != null && current.provisional();
|
||||
}
|
||||
|
||||
private boolean needsRender(long now, long previewRevision) {
|
||||
private boolean needsRender(long now, long previewRevision, long riverRevision) {
|
||||
TileState current = state;
|
||||
return current == null || current.provisional() && (now - current.retryAt() >= 0L
|
||||
|| previewRevision != current.previewRevision() && now - current.earliestRetryAt() >= 0L);
|
||||
if (current == null) {
|
||||
return true;
|
||||
}
|
||||
if (current.provisional()) {
|
||||
return now - current.retryAt() >= 0L
|
||||
|| previewRevision != current.previewRevision() && now - current.earliestRetryAt() >= 0L;
|
||||
}
|
||||
return current.retained() && riverRevision != current.riverRevision() && now - current.earliestRetryAt() >= 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,7 +691,7 @@ final class VisionRenderController implements AutoCloseable {
|
||||
}
|
||||
|
||||
private record TileState(MapTile tile, boolean provisional, long retryDelay, long retryAt, long earliestRetryAt,
|
||||
long previewRevision) {
|
||||
long previewRevision, long riverRevision, boolean retained) {
|
||||
}
|
||||
|
||||
private static final class WeightedTileCache {
|
||||
|
||||
@@ -28,6 +28,7 @@ import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.studio.render.IrisRenderer;
|
||||
import art.arcane.iris.studio.render.RenderType;
|
||||
import art.arcane.iris.world.history.GenerationSemanticQueries;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
|
||||
import java.awt.Color;
|
||||
@@ -58,6 +59,7 @@ public final class MapTileRenderer {
|
||||
private static final int NOISE_LOW = rgb(5, 5, 5);
|
||||
private static final int NOISE_HIGH = rgb(255, 255, 255);
|
||||
private static final double DARKEST_PICK_SHADE = 0.3D;
|
||||
private static final double POOL_REFRESH_BLOCKS_PER_PIXEL = 4D;
|
||||
|
||||
private final Engine engine;
|
||||
private final IrisRenderer hydrologyRenderer;
|
||||
@@ -78,6 +80,10 @@ public final class MapTileRenderer {
|
||||
return runtime == null ? 0L : runtime.previewRevision();
|
||||
}
|
||||
|
||||
public long riverRevision() {
|
||||
return GenerationSemanticQueries.recordedRiverRevision(engine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the square of {@code size} pixels whose top left pixel samples the given world position.
|
||||
*
|
||||
@@ -351,6 +357,7 @@ public final class MapTileRenderer {
|
||||
|
||||
public final class TileRender {
|
||||
private final TileRequest request;
|
||||
private final boolean retainsWater;
|
||||
private short[] subjects;
|
||||
private short[] regions;
|
||||
private int[] baseColors;
|
||||
@@ -367,18 +374,22 @@ public final class MapTileRenderer {
|
||||
|
||||
private TileRender(TileRequest request) {
|
||||
this.request = request;
|
||||
boolean drawsWater = request.layer().type() == TileType.RIVER || request.layer().waterOverlay();
|
||||
this.retainsWater = drawsWater && request.blocksPerPixel() <= POOL_REFRESH_BLOCKS_PER_PIXEL;
|
||||
heightsComplete = !request.withHeights() && request.layer().type() != TileType.HEIGHT;
|
||||
waterComplete = request.layer().type() != TileType.RIVER && !request.layer().waterOverlay();
|
||||
waterComplete = !drawsWater;
|
||||
}
|
||||
|
||||
public MapTile render(BooleanSupplier cancelled) {
|
||||
Objects.requireNonNull(cancelled, "cancelled");
|
||||
checkCancelled(cancelled);
|
||||
TileGrid grid = new TileGrid(request.size() + 2, request.startX() - request.blocksPerPixel(),
|
||||
request.startZ() - request.blocksPerPixel(), request.blocksPerPixel(), cancelled);
|
||||
sampleSubjects(grid);
|
||||
sampleBaseColors(grid);
|
||||
sampleTerrain(grid, cancelled);
|
||||
if (!identitiesComplete || !baseComplete || !heightsComplete) {
|
||||
TileGrid grid = new TileGrid(request.size() + 2, request.startX() - request.blocksPerPixel(),
|
||||
request.startZ() - request.blocksPerPixel(), request.blocksPerPixel(), cancelled);
|
||||
sampleSubjects(grid);
|
||||
sampleBaseColors(grid);
|
||||
sampleTerrain(grid, cancelled);
|
||||
}
|
||||
int[] colors = sampleWater(cancelled);
|
||||
checkCancelled(cancelled);
|
||||
complete = baseComplete && heightsComplete && waterComplete;
|
||||
@@ -396,6 +407,10 @@ public final class MapTileRenderer {
|
||||
return complete;
|
||||
}
|
||||
|
||||
public boolean retainsWater() {
|
||||
return retainsWater;
|
||||
}
|
||||
|
||||
public long bytes() {
|
||||
return bytes;
|
||||
}
|
||||
@@ -445,19 +460,21 @@ public final class MapTileRenderer {
|
||||
}
|
||||
|
||||
private int[] sampleWater(BooleanSupplier cancelled) {
|
||||
if (waterComplete) {
|
||||
return finalColors == null ? baseColors : finalColors;
|
||||
}
|
||||
if (water == null) {
|
||||
if (waterComplete) {
|
||||
return finalColors == null ? baseColors : finalColors;
|
||||
}
|
||||
water = hydrologyRenderer.prepareStudioWater(request.startX(), request.startZ(), request.blocksPerPixel(),
|
||||
request.size());
|
||||
}
|
||||
int[] colors = water.render(baseColors, request.layer().waterOverlay(), cancelled);
|
||||
if (baseComplete && water.complete()) {
|
||||
finalColors = colors;
|
||||
baseColors = null;
|
||||
waterComplete = true;
|
||||
water = null;
|
||||
if (!retainsWater) {
|
||||
finalColors = colors;
|
||||
baseColors = null;
|
||||
water = null;
|
||||
}
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
@@ -457,7 +457,6 @@ public final class IrisRenderer {
|
||||
private final double startZ;
|
||||
private final double step;
|
||||
private final int resolution;
|
||||
private final HydrologyRuntime runtime;
|
||||
private final WaterMap map;
|
||||
private boolean complete;
|
||||
private long poolRevision;
|
||||
@@ -467,7 +466,7 @@ public final class IrisRenderer {
|
||||
this.startZ = startZ;
|
||||
this.step = step;
|
||||
this.resolution = resolution;
|
||||
this.runtime = renderer.getComplex().getHydrologyRuntime();
|
||||
HydrologyRuntime runtime = renderer.getComplex().getHydrologyRuntime();
|
||||
this.map = runtime == null || !runtime.enabled() || step > WaterMap.MAX_STEP
|
||||
? null : new WaterMap(runtime, resolution, startX, startZ, step);
|
||||
complete = map == null;
|
||||
@@ -514,7 +513,7 @@ public final class IrisRenderer {
|
||||
}
|
||||
|
||||
private void draw(BooleanSupplier cancelled) {
|
||||
long revision = runtime.previewRevision();
|
||||
long revision = GenerationSemanticQueries.recordedRiverRevision(renderer);
|
||||
boolean advanced = !complete;
|
||||
if (advanced) {
|
||||
map.advance(cancelled);
|
||||
|
||||
@@ -866,6 +866,10 @@ public final class GenerationHistory {
|
||||
return semantics.get(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
public long riverRevision() {
|
||||
return semantics.riverRevision();
|
||||
}
|
||||
|
||||
public synchronized Optional<GenerationSemanticIndex.Match> findRecorded(
|
||||
GenerationSemanticIndex.Query query
|
||||
) {
|
||||
|
||||
@@ -45,6 +45,7 @@ import java.util.Optional;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.function.Predicate;
|
||||
@@ -96,6 +97,7 @@ public final class GenerationSemanticIndex {
|
||||
private final CatalogPublisher catalogPublisher;
|
||||
private final boolean unpublished;
|
||||
private final DeferredDurability durability;
|
||||
private final AtomicLong riverRevision = new AtomicLong();
|
||||
private long regionDecodeCount;
|
||||
private volatile IOException journalFailure;
|
||||
private long appendingRegionKey;
|
||||
@@ -245,6 +247,7 @@ public final class GenerationSemanticIndex {
|
||||
RegionShard baseRegion = loadRegionLocked(regionKey, regionX, regionZ);
|
||||
RegionShard nextRegion = baseRegion;
|
||||
List<ChunkGenerationSemantics> updates = new ArrayList<>(claims.size());
|
||||
boolean water = false;
|
||||
for (Claim pending : claims) {
|
||||
ChunkGenerationSemantics update = pending.update;
|
||||
ChunkGenerationSemantics existing = nextRegion.get(update.chunkX(), update.chunkZ());
|
||||
@@ -261,6 +264,7 @@ public final class GenerationSemanticIndex {
|
||||
}
|
||||
nextRegion = nextRegion.withRecord(merged);
|
||||
updates.add(merged);
|
||||
water |= waterChanged(existing, merged);
|
||||
pending.persisted = true;
|
||||
}
|
||||
if (updates.isEmpty()) {
|
||||
@@ -286,6 +290,9 @@ public final class GenerationSemanticIndex {
|
||||
cacheRegion(regionKey, nextRegion);
|
||||
regionRecordCounts.put(regionKey, nextRegion.recordCount());
|
||||
journalEntries.addTo(regionKey, updates.size());
|
||||
if (water) {
|
||||
riverRevision.incrementAndGet();
|
||||
}
|
||||
for (Claim pending : claims) {
|
||||
pending.completed = true;
|
||||
}
|
||||
@@ -452,6 +459,9 @@ public final class GenerationSemanticIndex {
|
||||
if (existing == null) {
|
||||
regionRecordCounts.addTo(regionKey, 1);
|
||||
}
|
||||
if (waterChanged(existing, merged)) {
|
||||
riverRevision.incrementAndGet();
|
||||
}
|
||||
shardHashes.put(regionKey, shardHash);
|
||||
deleteUnreferencedShard(regionX, regionZ, previousHash, shardHash);
|
||||
return true;
|
||||
@@ -473,6 +483,10 @@ public final class GenerationSemanticIndex {
|
||||
}
|
||||
}
|
||||
|
||||
public long riverRevision() {
|
||||
return riverRevision.get();
|
||||
}
|
||||
|
||||
public int recordCount() {
|
||||
lock.readLock().lock();
|
||||
publicationLock.lock();
|
||||
@@ -1153,6 +1167,10 @@ public final class GenerationSemanticIndex {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean waterChanged(ChunkGenerationSemantics existing, ChunkGenerationSemantics merged) {
|
||||
return existing == null ? !merged.riverFeatures().isEmpty() : !existing.riverFeatures().equals(merged.riverFeatures());
|
||||
}
|
||||
|
||||
private static Set<String> keys(ChunkGenerationSemantics semantics, SemanticKind kind) {
|
||||
return switch (kind) {
|
||||
case SURFACE_BIOME -> semantics.surfaceBiomeKeys();
|
||||
|
||||
@@ -331,6 +331,11 @@ public final class GenerationSemanticQueries {
|
||||
return pools;
|
||||
}
|
||||
|
||||
public static long recordedRiverRevision(Engine engine) {
|
||||
GenerationHistory history = history(Objects.requireNonNull(engine, "engine")).orElse(null);
|
||||
return history == null ? 0L : history.riverRevision();
|
||||
}
|
||||
|
||||
public static boolean allowsActivePrediction(Engine engine, int chunkX, int chunkZ) {
|
||||
Engine requiredEngine = Objects.requireNonNull(engine, "engine");
|
||||
if (!requiredEngine.getComplex().allowsNewGenerationChunk(chunkX, chunkZ)) {
|
||||
|
||||
Reference in new issue
Block a user