mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-01 15:36:45 +00:00
precalculate pack hash on engine setup (#1138)
This commit is contained in:
parent
910220d3ca
commit
a09657b4d0
@ -672,10 +672,12 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
metrics.addCustomChart(new DrilldownPie("used_packs", () -> Bukkit.getWorlds().stream()
|
||||
.map(IrisToolbelt::access)
|
||||
.filter(Objects::nonNull)
|
||||
.map(PlatformChunkGenerator::getTarget)
|
||||
.collect(Collectors.toMap(target -> target.getDimension().getLoadKey(), target -> {
|
||||
int version = target.getDimension().getVersion();
|
||||
String checksum = IO.hashRecursive(target.getData().getDataFolder());
|
||||
.map(PlatformChunkGenerator::getEngine)
|
||||
.collect(Collectors.toMap(engine -> engine.getDimension().getLoadKey(), engine -> {
|
||||
var hash32 = engine.getHash32().getNow(null);
|
||||
if (hash32 == null) return Map.of();
|
||||
int version = engine.getDimension().getVersion();
|
||||
String checksum = Long.toHexString(hash32);
|
||||
|
||||
return Map.of("v" + version + " (" + checksum + ")", 1);
|
||||
}, (a, b) -> {
|
||||
|
@ -21,10 +21,10 @@ package com.volmit.iris.engine;
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.ServerConfigurator;
|
||||
import com.volmit.iris.core.events.IrisEngineHotloadEvent;
|
||||
import com.volmit.iris.core.gui.PregeneratorJob;
|
||||
import com.volmit.iris.core.loader.ResourceLoader;
|
||||
import com.volmit.iris.core.nms.container.BlockPos;
|
||||
import com.volmit.iris.core.nms.container.Pair;
|
||||
import com.volmit.iris.core.project.IrisProject;
|
||||
@ -53,7 +53,6 @@ import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@ -63,11 +62,10 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(exclude = "context")
|
||||
@ -92,6 +90,7 @@ public class IrisEngine implements Engine {
|
||||
private final AtomicBoolean cleaning;
|
||||
private final ChronoLatch cleanLatch;
|
||||
private final SeedManager seedManager;
|
||||
private CompletableFuture<Long> hash32;
|
||||
private EngineMode mode;
|
||||
private EngineEffects effects;
|
||||
private EngineExecutionEnvironment execution;
|
||||
@ -174,8 +173,17 @@ public class IrisEngine implements Engine {
|
||||
complex = new IrisComplex(this);
|
||||
execution = new IrisExecutionEnvironment(this);
|
||||
effects = new IrisEngineEffects(this);
|
||||
hash32 = new CompletableFuture<>();
|
||||
setupMode();
|
||||
J.a(this::computeBiomeMaxes);
|
||||
J.a(() -> {
|
||||
File[] roots = getData().getLoaders()
|
||||
.values()
|
||||
.stream()
|
||||
.map(ResourceLoader::getRoot)
|
||||
.toArray(File[]::new);
|
||||
hash32.complete(IO.hashRecursive(roots));
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
Iris.error("FAILED TO SETUP ENGINE!");
|
||||
e.printStackTrace();
|
||||
|
@ -80,6 +80,7 @@ import java.awt.Color;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -611,6 +612,8 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
|
||||
int getGenerated();
|
||||
|
||||
CompletableFuture<Long> getHash32();
|
||||
|
||||
default <T> IrisPosition lookForStreamResult(T find, ProceduralStream<T> stream, Function2<T, T, Boolean> matcher, long timeout) {
|
||||
AtomicInteger checked = new AtomicInteger();
|
||||
AtomicLong time = new AtomicLong(M.ms());
|
||||
|
@ -111,10 +111,12 @@ public class IO {
|
||||
return "¯\\_(ツ)_/¯";
|
||||
}
|
||||
|
||||
public static String hashRecursive(File base) {
|
||||
public static long hashRecursive(File... bases) {
|
||||
LinkedList<File> files = new LinkedList<>();
|
||||
Set<File> processed = new HashSet<>();
|
||||
files.add(base);
|
||||
Arrays.parallelSort(bases, Comparator.comparing(File::getName));
|
||||
files.addAll(Arrays.asList(bases));
|
||||
|
||||
try {
|
||||
CRC32 crc = new CRC32();
|
||||
while (!files.isEmpty()) {
|
||||
@ -141,13 +143,13 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
return Long.toHexString(crc.getValue());
|
||||
return crc.getValue();
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "";
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String hash(File b) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user