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