mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-27 06:20:02 +00:00
Restore evicted owners from plans
- A demanded owner missing from the owner cache is restored from its planned tile (resident or prepared-plan store) instead of drafted again - Same restore path as persisted tiles; plans identical
This commit is contained in:
1 parent
0b2a606a25
commit
b4ee500c14
4 files changed
+83
No files matched your search
@@ -28,6 +28,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public final class HydrologyPlanner {
|
||||
@@ -66,6 +67,7 @@ public final class HydrologyPlanner {
|
||||
final HydrologyFeatureSitePlanner featureSites;
|
||||
final HydrologyRegionalPlanner regional;
|
||||
private volatile Predicate<HydrologyTileKey> earlyOwnerScope;
|
||||
private volatile Function<HydrologyTileKey, HydrologyTile> plannedTiles;
|
||||
|
||||
public HydrologyPlanner(long worldSeed, HydrologyPlannerSettings settings, HydrologyTerrainSampler sampler) {
|
||||
this(
|
||||
@@ -255,6 +257,14 @@ public final class HydrologyPlanner {
|
||||
earlyOwnerScope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the plans of tiles already planned are found. An owner draft that left the owner cache is
|
||||
* restored from its tile's plan when a neighbour demands it again, instead of being drafted twice.
|
||||
*/
|
||||
void usePlannedTiles(Function<HydrologyTileKey, HydrologyTile> source) {
|
||||
plannedTiles = source;
|
||||
}
|
||||
|
||||
void clearOwnerDrafts() {
|
||||
resolvedOwners.invalidateAll();
|
||||
regional.clear();
|
||||
@@ -300,6 +310,9 @@ public final class HydrologyPlanner {
|
||||
return local;
|
||||
}
|
||||
CrossTileResolvedOwner cached = resolvedOwners.getIfPresent(key);
|
||||
if (cached == null) {
|
||||
cached = plannedOwner(key);
|
||||
}
|
||||
if (cached != null) {
|
||||
context.remember(key, cached);
|
||||
return cached;
|
||||
@@ -346,6 +359,17 @@ public final class HydrologyPlanner {
|
||||
}
|
||||
}
|
||||
|
||||
private CrossTileResolvedOwner plannedOwner(HydrologyTileKey key) {
|
||||
Function<HydrologyTileKey, HydrologyTile> source = plannedTiles;
|
||||
HydrologyTile tile = source == null ? null : source.apply(key);
|
||||
if (tile == null || tile.resolvedOwner() == null) {
|
||||
return null;
|
||||
}
|
||||
reuseResolvedTile(tile);
|
||||
CrossTileResolvedOwner restored = resolvedOwners.getIfPresent(key);
|
||||
return restored == null ? tile.resolvedOwner() : restored;
|
||||
}
|
||||
|
||||
List<CrossTileResolvedOwner> resolveLowerRankOwners(
|
||||
List<HydrologyTileKey> candidateKeys,
|
||||
CrossTileResolutionContext context,
|
||||
|
||||
@@ -161,6 +161,17 @@ public final class HydrologyTileCache implements AutoCloseable {
|
||||
this.closed = new AtomicBoolean();
|
||||
this.localChunks = ThreadLocal.withInitial(LocalChunks::new);
|
||||
this.neighbourPrefetchEnabled = true;
|
||||
planner.usePlannedTiles(this::plannedTile);
|
||||
}
|
||||
|
||||
/** A tile already planned, resident or in the prepared-plan store, loaded without planning it. */
|
||||
private HydrologyTile plannedTile(HydrologyTileKey key) {
|
||||
HydrologyTile resident = tiles.getIfPresent(key);
|
||||
if (resident != null) {
|
||||
return resident;
|
||||
}
|
||||
PreparedHydrologyTileStore store = persistentStore;
|
||||
return store == null ? null : store.load(key).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user