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);
|
||||
effects = new IrisEngineEffects(this);
|
||||
hash32 = new CompletableFuture<>();
|
||||
mantle.hotload();
|
||||
setupMode();
|
||||
getDimension().getEngineScripts().forEach(execution::execute);
|
||||
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.util.collection.KList;
|
||||
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.flag.MantleFlag;
|
||||
import lombok.*;
|
||||
|
||||
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
|
||||
@EqualsAndHashCode(exclude = "engine")
|
||||
@@ -45,8 +47,9 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
private final Mantle mantle;
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final KMap<Integer, KList<MantleComponent>> components;
|
||||
private final AtomicCache<KList<Pair<KList<MantleComponent>, Integer>>> componentsCache = new AtomicCache<>();
|
||||
private final AtomicCache<KSet<MantleFlag>> disabledFlags = new AtomicCache<>();
|
||||
private final KMap<MantleFlag, MantleComponent> registeredComponents = new KMap<>();
|
||||
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 MantleJigsawComponent jigsaw;
|
||||
|
||||
@@ -75,7 +78,7 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<Pair<KList<MantleComponent>, Integer>> getComponents() {
|
||||
public List<Pair<List<MantleComponent>, Integer>> getComponents() {
|
||||
return componentsCache.aquire(() -> {
|
||||
var list = components.keySet()
|
||||
.stream()
|
||||
@@ -86,10 +89,9 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
.mapToInt(MantleComponent::getRadius)
|
||||
.max()
|
||||
.orElse(0);
|
||||
return new Pair<>(components, radius);
|
||||
return new Pair<>(List.copyOf(components), radius);
|
||||
})
|
||||
.collect(Collectors.toCollection(KList::new));
|
||||
|
||||
.toList();
|
||||
|
||||
int radius = 0;
|
||||
for (var pair : list.reversed()) {
|
||||
@@ -102,19 +104,36 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerComponent(MantleComponent c) {
|
||||
c.setEnabled(!getDimension().getDisabledComponents().contains(c.getFlag()));
|
||||
public Map<MantleFlag, MantleComponent> getRegisteredComponents() {
|
||||
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);
|
||||
componentsCache.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<MantleFlag> getComponentFlags() {
|
||||
return components.values()
|
||||
.stream()
|
||||
.flatMap(KList::stream)
|
||||
.map(MantleComponent::getFlag)
|
||||
.collect(KList.collector());
|
||||
return new KList<>(registeredComponents.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
@@ -43,7 +43,10 @@ import com.volmit.iris.util.matter.*;
|
||||
import com.volmit.iris.util.matter.slices.UpdateMatter;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
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 static com.volmit.iris.util.parallel.StreamUtils.forEach;
|
||||
@@ -60,12 +63,19 @@ public interface EngineMantle {
|
||||
|
||||
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();
|
||||
|
||||
void hotload();
|
||||
|
||||
default int getHighest(int x, int z) {
|
||||
return getHighest(x, z, getData());
|
||||
}
|
||||
@@ -185,6 +195,7 @@ public interface EngineMantle {
|
||||
forEach(streamRadius(x, z, radius),
|
||||
pos -> pair.getA()
|
||||
.stream()
|
||||
.filter(MantleComponent::isEnabled)
|
||||
.map(c -> new Pair<>(c, pos)),
|
||||
p -> {
|
||||
MantleComponent c = p.getA();
|
||||
|
||||
@@ -30,5 +30,32 @@ public abstract class IrisMantleComponent implements MantleComponent {
|
||||
private final EngineMantle engineMantle;
|
||||
private final MantleFlag flag;
|
||||
private final int priority;
|
||||
|
||||
private volatile int radius = -1;
|
||||
private final Object lock = new Object();
|
||||
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 hotload();
|
||||
|
||||
@ChunkCoordinates
|
||||
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.mantle.flag.ReservedFlag;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ComponentFlag(ReservedFlag.CARVED)
|
||||
public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
private final int radius = computeRadius();
|
||||
|
||||
public MantleCarvingComponent(EngineMantle engineMantle) {
|
||||
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);
|
||||
}
|
||||
|
||||
private int computeRadius() {
|
||||
protected int computeRadius() {
|
||||
var dimension = getDimension();
|
||||
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.mantle.flag.ReservedFlag;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ComponentFlag(ReservedFlag.FLUID_BODIES)
|
||||
public class MantleFluidBodyComponent extends IrisMantleComponent {
|
||||
private final int radius = computeRadius();
|
||||
|
||||
public MantleFluidBodyComponent(EngineMantle engineMantle) {
|
||||
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);
|
||||
}
|
||||
|
||||
private int computeRadius() {
|
||||
protected int computeRadius() {
|
||||
int max = 0;
|
||||
|
||||
max = Math.max(max, getDimension().getFluidBodies().getMaxRange(getData()));
|
||||
|
||||
@@ -42,8 +42,6 @@ import java.util.List;
|
||||
|
||||
@ComponentFlag(ReservedFlag.JIGSAW)
|
||||
public class MantleJigsawComponent extends IrisMantleComponent {
|
||||
@Getter
|
||||
private final int radius = computeRadius();
|
||||
private final CNG cng;
|
||||
|
||||
public MantleJigsawComponent(EngineMantle engineMantle) {
|
||||
@@ -176,7 +174,7 @@ public class MantleJigsawComponent extends IrisMantleComponent {
|
||||
return getEngineMantle().getEngine().getSeedManager().getJigsaw();
|
||||
}
|
||||
|
||||
private int computeRadius() {
|
||||
protected int computeRadius() {
|
||||
var dimension = getDimension();
|
||||
|
||||
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.NoiseType;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -47,10 +46,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Getter
|
||||
@ComponentFlag(ReservedFlag.OBJECT)
|
||||
public class MantleObjectComponent extends IrisMantleComponent {
|
||||
private final int radius = computeRadius();
|
||||
|
||||
public MantleObjectComponent(EngineMantle engineMantle) {
|
||||
super(engineMantle, ReservedFlag.OBJECT, 1);
|
||||
@@ -157,7 +154,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
return v;
|
||||
}
|
||||
|
||||
private int computeRadius() {
|
||||
protected int computeRadius() {
|
||||
var dimension = getDimension();
|
||||
|
||||
AtomicInteger xg = new AtomicInteger();
|
||||
|
||||
Reference in New Issue
Block a user