mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-19 15:09:18 +00:00
fix hotloading mantle components
This commit is contained in:
@@ -173,6 +173,7 @@ public class IrisEngine implements Engine {
|
|||||||
execution = EngineEnvironment.create(this);
|
execution = EngineEnvironment.create(this);
|
||||||
effects = new IrisEngineEffects(this);
|
effects = new IrisEngineEffects(this);
|
||||||
hash32 = new CompletableFuture<>();
|
hash32 = new CompletableFuture<>();
|
||||||
|
mantle.hotload();
|
||||||
setupMode();
|
setupMode();
|
||||||
getDimension().getEngineScripts().forEach(execution::execute);
|
getDimension().getEngineScripts().forEach(execution::execute);
|
||||||
J.a(this::computeBiomeMaxes);
|
J.a(this::computeBiomeMaxes);
|
||||||
|
|||||||
@@ -29,13 +29,15 @@ import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
|
|||||||
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.collection.KSet;
|
|
||||||
import com.volmit.iris.util.mantle.Mantle;
|
import com.volmit.iris.util.mantle.Mantle;
|
||||||
import com.volmit.iris.util.mantle.flag.MantleFlag;
|
import com.volmit.iris.util.mantle.flag.MantleFlag;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.stream.Collectors;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(exclude = "engine")
|
@EqualsAndHashCode(exclude = "engine")
|
||||||
@@ -45,8 +47,9 @@ public class IrisEngineMantle implements EngineMantle {
|
|||||||
private final Mantle mantle;
|
private final Mantle mantle;
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private final KMap<Integer, KList<MantleComponent>> components;
|
private final KMap<Integer, KList<MantleComponent>> components;
|
||||||
private final AtomicCache<KList<Pair<KList<MantleComponent>, Integer>>> componentsCache = new AtomicCache<>();
|
private final KMap<MantleFlag, MantleComponent> registeredComponents = new KMap<>();
|
||||||
private final AtomicCache<KSet<MantleFlag>> disabledFlags = new AtomicCache<>();
|
private final AtomicCache<List<Pair<List<MantleComponent>, Integer>>> componentsCache = new AtomicCache<>();
|
||||||
|
private final AtomicCache<Set<MantleFlag>> disabledFlags = new AtomicCache<>();
|
||||||
private final MantleObjectComponent object;
|
private final MantleObjectComponent object;
|
||||||
private final MantleJigsawComponent jigsaw;
|
private final MantleJigsawComponent jigsaw;
|
||||||
|
|
||||||
@@ -75,7 +78,7 @@ public class IrisEngineMantle implements EngineMantle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KList<Pair<KList<MantleComponent>, Integer>> getComponents() {
|
public List<Pair<List<MantleComponent>, Integer>> getComponents() {
|
||||||
return componentsCache.aquire(() -> {
|
return componentsCache.aquire(() -> {
|
||||||
var list = components.keySet()
|
var list = components.keySet()
|
||||||
.stream()
|
.stream()
|
||||||
@@ -86,10 +89,9 @@ public class IrisEngineMantle implements EngineMantle {
|
|||||||
.mapToInt(MantleComponent::getRadius)
|
.mapToInt(MantleComponent::getRadius)
|
||||||
.max()
|
.max()
|
||||||
.orElse(0);
|
.orElse(0);
|
||||||
return new Pair<>(components, radius);
|
return new Pair<>(List.copyOf(components), radius);
|
||||||
})
|
})
|
||||||
.collect(Collectors.toCollection(KList::new));
|
.toList();
|
||||||
|
|
||||||
|
|
||||||
int radius = 0;
|
int radius = 0;
|
||||||
for (var pair : list.reversed()) {
|
for (var pair : list.reversed()) {
|
||||||
@@ -102,19 +104,36 @@ public class IrisEngineMantle implements EngineMantle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerComponent(MantleComponent c) {
|
public Map<MantleFlag, MantleComponent> getRegisteredComponents() {
|
||||||
c.setEnabled(!getDimension().getDisabledComponents().contains(c.getFlag()));
|
return Collections.unmodifiableMap(registeredComponents);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean registerComponent(MantleComponent c) {
|
||||||
|
if (registeredComponents.putIfAbsent(c.getFlag(), c) != null) return false;
|
||||||
|
c.setEnabled(!getDisabledFlags().contains(c.getFlag()));
|
||||||
components.computeIfAbsent(c.getPriority(), k -> new KList<>()).add(c);
|
components.computeIfAbsent(c.getPriority(), k -> new KList<>()).add(c);
|
||||||
componentsCache.reset();
|
componentsCache.reset();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KList<MantleFlag> getComponentFlags() {
|
public KList<MantleFlag> getComponentFlags() {
|
||||||
return components.values()
|
return new KList<>(registeredComponents.keySet());
|
||||||
.stream()
|
}
|
||||||
.flatMap(KList::stream)
|
|
||||||
.map(MantleComponent::getFlag)
|
@Override
|
||||||
.collect(KList.collector());
|
public void hotload() {
|
||||||
|
disabledFlags.reset();
|
||||||
|
for (var component : registeredComponents.values()) {
|
||||||
|
component.hotload();
|
||||||
|
component.setEnabled(!getDisabledFlags().contains(component.getFlag()));
|
||||||
|
}
|
||||||
|
componentsCache.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<MantleFlag> getDisabledFlags() {
|
||||||
|
return disabledFlags.aquire(() -> Set.copyOf(getDimension().getDisabledComponents()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ import com.volmit.iris.util.matter.*;
|
|||||||
import com.volmit.iris.util.matter.slices.UpdateMatter;
|
import com.volmit.iris.util.matter.slices.UpdateMatter;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.jetbrains.annotations.UnmodifiableView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static com.volmit.iris.util.parallel.StreamUtils.forEach;
|
import static com.volmit.iris.util.parallel.StreamUtils.forEach;
|
||||||
@@ -60,12 +63,19 @@ public interface EngineMantle {
|
|||||||
|
|
||||||
int getRealRadius();
|
int getRealRadius();
|
||||||
|
|
||||||
KList<Pair<KList<MantleComponent>, Integer>> getComponents();
|
@UnmodifiableView
|
||||||
|
List<Pair<List<MantleComponent>, Integer>> getComponents();
|
||||||
|
|
||||||
void registerComponent(MantleComponent c);
|
@UnmodifiableView
|
||||||
|
Map<MantleFlag, MantleComponent> getRegisteredComponents();
|
||||||
|
|
||||||
|
boolean registerComponent(MantleComponent c);
|
||||||
|
|
||||||
|
@UnmodifiableView
|
||||||
KList<MantleFlag> getComponentFlags();
|
KList<MantleFlag> getComponentFlags();
|
||||||
|
|
||||||
|
void hotload();
|
||||||
|
|
||||||
default int getHighest(int x, int z) {
|
default int getHighest(int x, int z) {
|
||||||
return getHighest(x, z, getData());
|
return getHighest(x, z, getData());
|
||||||
}
|
}
|
||||||
@@ -185,6 +195,7 @@ public interface EngineMantle {
|
|||||||
forEach(streamRadius(x, z, radius),
|
forEach(streamRadius(x, z, radius),
|
||||||
pos -> pair.getA()
|
pos -> pair.getA()
|
||||||
.stream()
|
.stream()
|
||||||
|
.filter(MantleComponent::isEnabled)
|
||||||
.map(c -> new Pair<>(c, pos)),
|
.map(c -> new Pair<>(c, pos)),
|
||||||
p -> {
|
p -> {
|
||||||
MantleComponent c = p.getA();
|
MantleComponent c = p.getA();
|
||||||
|
|||||||
@@ -30,5 +30,32 @@ public abstract class IrisMantleComponent implements MantleComponent {
|
|||||||
private final EngineMantle engineMantle;
|
private final EngineMantle engineMantle;
|
||||||
private final MantleFlag flag;
|
private final MantleFlag flag;
|
||||||
private final int priority;
|
private final int priority;
|
||||||
|
|
||||||
|
private volatile int radius = -1;
|
||||||
|
private final Object lock = new Object();
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
|
|
||||||
|
protected abstract int computeRadius();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hotload() {
|
||||||
|
synchronized (lock) {
|
||||||
|
radius = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int getRadius() {
|
||||||
|
int r = radius;
|
||||||
|
if(r != -1) return r;
|
||||||
|
|
||||||
|
synchronized (lock) {
|
||||||
|
if((r = radius) != -1) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = computeRadius();
|
||||||
|
if(r < 0) r = 0;
|
||||||
|
return radius = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ public interface MantleComponent extends Comparable<MantleComponent> {
|
|||||||
|
|
||||||
void setEnabled(boolean b);
|
void setEnabled(boolean b);
|
||||||
|
|
||||||
|
void hotload();
|
||||||
|
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
void generateLayer(MantleWriter writer, int x, int z, ChunkContext context);
|
void generateLayer(MantleWriter writer, int x, int z, ChunkContext context);
|
||||||
|
|
||||||
|
|||||||
@@ -30,13 +30,9 @@ import com.volmit.iris.util.context.ChunkContext;
|
|||||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
import com.volmit.iris.util.mantle.flag.ReservedFlag;
|
import com.volmit.iris.util.mantle.flag.ReservedFlag;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@ComponentFlag(ReservedFlag.CARVED)
|
@ComponentFlag(ReservedFlag.CARVED)
|
||||||
public class MantleCarvingComponent extends IrisMantleComponent {
|
public class MantleCarvingComponent extends IrisMantleComponent {
|
||||||
private final int radius = computeRadius();
|
|
||||||
|
|
||||||
public MantleCarvingComponent(EngineMantle engineMantle) {
|
public MantleCarvingComponent(EngineMantle engineMantle) {
|
||||||
super(engineMantle, ReservedFlag.CARVED, 0);
|
super(engineMantle, ReservedFlag.CARVED, 0);
|
||||||
}
|
}
|
||||||
@@ -63,7 +59,7 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
|||||||
carving.doCarving(writer, rng, getEngineMantle().getEngine(), cx << 4, -1, cz << 4, 0);
|
carving.doCarving(writer, rng, getEngineMantle().getEngine(), cx << 4, -1, cz << 4, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int computeRadius() {
|
protected int computeRadius() {
|
||||||
var dimension = getDimension();
|
var dimension = getDimension();
|
||||||
int max = 0;
|
int max = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -30,13 +30,9 @@ import com.volmit.iris.util.context.ChunkContext;
|
|||||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
import com.volmit.iris.util.mantle.flag.ReservedFlag;
|
import com.volmit.iris.util.mantle.flag.ReservedFlag;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@ComponentFlag(ReservedFlag.FLUID_BODIES)
|
@ComponentFlag(ReservedFlag.FLUID_BODIES)
|
||||||
public class MantleFluidBodyComponent extends IrisMantleComponent {
|
public class MantleFluidBodyComponent extends IrisMantleComponent {
|
||||||
private final int radius = computeRadius();
|
|
||||||
|
|
||||||
public MantleFluidBodyComponent(EngineMantle engineMantle) {
|
public MantleFluidBodyComponent(EngineMantle engineMantle) {
|
||||||
super(engineMantle, ReservedFlag.FLUID_BODIES, 0);
|
super(engineMantle, ReservedFlag.FLUID_BODIES, 0);
|
||||||
}
|
}
|
||||||
@@ -63,7 +59,7 @@ public class MantleFluidBodyComponent extends IrisMantleComponent {
|
|||||||
bodies.generate(writer, rng, getEngineMantle().getEngine(), cx << 4, -1, cz << 4);
|
bodies.generate(writer, rng, getEngineMantle().getEngine(), cx << 4, -1, cz << 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int computeRadius() {
|
protected int computeRadius() {
|
||||||
int max = 0;
|
int max = 0;
|
||||||
|
|
||||||
max = Math.max(max, getDimension().getFluidBodies().getMaxRange(getData()));
|
max = Math.max(max, getDimension().getFluidBodies().getMaxRange(getData()));
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ import java.util.List;
|
|||||||
|
|
||||||
@ComponentFlag(ReservedFlag.JIGSAW)
|
@ComponentFlag(ReservedFlag.JIGSAW)
|
||||||
public class MantleJigsawComponent extends IrisMantleComponent {
|
public class MantleJigsawComponent extends IrisMantleComponent {
|
||||||
@Getter
|
|
||||||
private final int radius = computeRadius();
|
|
||||||
private final CNG cng;
|
private final CNG cng;
|
||||||
|
|
||||||
public MantleJigsawComponent(EngineMantle engineMantle) {
|
public MantleJigsawComponent(EngineMantle engineMantle) {
|
||||||
@@ -176,7 +174,7 @@ public class MantleJigsawComponent extends IrisMantleComponent {
|
|||||||
return getEngineMantle().getEngine().getSeedManager().getJigsaw();
|
return getEngineMantle().getEngine().getSeedManager().getJigsaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int computeRadius() {
|
protected int computeRadius() {
|
||||||
var dimension = getDimension();
|
var dimension = getDimension();
|
||||||
|
|
||||||
KSet<String> structures = new KSet<>();
|
KSet<String> structures = new KSet<>();
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import com.volmit.iris.util.matter.MatterStructurePOI;
|
|||||||
import com.volmit.iris.util.noise.CNG;
|
import com.volmit.iris.util.noise.CNG;
|
||||||
import com.volmit.iris.util.noise.NoiseType;
|
import com.volmit.iris.util.noise.NoiseType;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.util.BlockVector;
|
import org.bukkit.util.BlockVector;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -47,10 +46,8 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@ComponentFlag(ReservedFlag.OBJECT)
|
@ComponentFlag(ReservedFlag.OBJECT)
|
||||||
public class MantleObjectComponent extends IrisMantleComponent {
|
public class MantleObjectComponent extends IrisMantleComponent {
|
||||||
private final int radius = computeRadius();
|
|
||||||
|
|
||||||
public MantleObjectComponent(EngineMantle engineMantle) {
|
public MantleObjectComponent(EngineMantle engineMantle) {
|
||||||
super(engineMantle, ReservedFlag.OBJECT, 1);
|
super(engineMantle, ReservedFlag.OBJECT, 1);
|
||||||
@@ -157,7 +154,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int computeRadius() {
|
protected int computeRadius() {
|
||||||
var dimension = getDimension();
|
var dimension = getDimension();
|
||||||
|
|
||||||
AtomicInteger xg = new AtomicInteger();
|
AtomicInteger xg = new AtomicInteger();
|
||||||
|
|||||||
Reference in New Issue
Block a user