Skip to content

Commit

Permalink
Merge pull request #1135 from VolmitSoftware/dev
Browse files Browse the repository at this point in the history
3.5.3
  • Loading branch information
AvianAeternum authored Jan 9, 2025
2 parents 3c6411c + e1a7e77 commit fc05c24
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void regen(
KList<Runnable> js = new KList<>();
BurstExecutor b = MultiBurst.burst.burst();
b.setMulticore(false);
int rad = engine.getMantle().getRealRadius();
int rad = engine.getMantle().getRadius();
for (int i = -(radius + rad); i <= radius + rad; i++) {
for (int j = -(radius + rad); j <= radius + rad; j++) {
engine.getMantle().getMantle().deleteChunk(i + cx.getX(), j + cx.getZ());
Expand Down
301 changes: 46 additions & 255 deletions core/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.volmit.iris.engine;

import com.volmit.iris.Iris;
import com.volmit.iris.core.nms.container.Pair;
import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.mantle.EngineMantle;
Expand All @@ -27,41 +27,31 @@
import com.volmit.iris.engine.mantle.components.MantleFluidBodyComponent;
import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
import com.volmit.iris.engine.object.*;
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.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.parallel.BurstExecutor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.bukkit.util.BlockVector;
import lombok.*;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

@Data
@EqualsAndHashCode(exclude = "engine")
@ToString(exclude = "engine")
public class IrisEngineMantle implements EngineMantle {
private final Engine engine;
private final Mantle mantle;
private final KList<MantleComponent> components;
private final int radius;
@Getter(AccessLevel.NONE)
private final KMap<Integer, KList<MantleComponent>> components;
private final AtomicCache<KList<Pair<KList<MantleComponent>, Integer>>> componentsCache = new AtomicCache<>();
private final AtomicCache<Integer> radCache = new AtomicCache<>();
private final MantleObjectComponent object;
private final MantleJigsawComponent jigsaw;

public IrisEngineMantle(Engine engine) {
this.engine = engine;
this.mantle = new Mantle(new File(engine.getWorld().worldFolder(), "mantle"), engine.getTarget().getHeight());
radius = radCache.aquire(this::computeParallaxSize);
components = new KList<>();
components = new KMap<>();
registerComponent(new MantleCarvingComponent(this));
registerComponent(new MantleFluidBodyComponent(this));
jigsaw = new MantleJigsawComponent(this);
Expand All @@ -71,256 +61,57 @@ public IrisEngineMantle(Engine engine) {
}

@Override
public void registerComponent(MantleComponent c) {
components.add(c);
public int getRadius() {
if (components.isEmpty()) return 0;
return getComponents().getFirst().getB();
}

@Override
public MantleJigsawComponent getJigsawComponent() {
return jigsaw;
public int getRealRadius() {
if (components.isEmpty()) return 0;
return getComponents().getLast().getB();
}

@Override
public MantleObjectComponent getObjectComponent() {
return object;
}

private KList<IrisRegion> getAllRegions() {
KList<IrisRegion> r = new KList<>();

for (String i : getEngine().getDimension().getRegions()) {
r.add(getEngine().getData().getRegionLoader().load(i));
}

return r;
}

private KList<IrisBiome> getAllBiomes() {
KList<IrisBiome> r = new KList<>();

for (IrisRegion i : getAllRegions()) {
r.addAll(i.getAllBiomes(getEngine()));
}

return r;
}

private void warn(String ob, BlockVector bv) {
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
Iris.warn("Object " + ob + " has a large size (" + bv + ") and may increase memory usage!");
}
}

private void warnScaled(String ob, BlockVector bv, double ms) {
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
Iris.warn("Object " + ob + " has a large size (" + bv + ") and may increase memory usage! (Object scaled up to " + Form.pc(ms, 2) + ")");
}
}

private int computeParallaxSize() {
Iris.verbose("Calculating the Parallax Size in Parallel");
AtomicInteger xg = new AtomicInteger(0);
AtomicInteger zg = new AtomicInteger();
xg.set(0);
zg.set(0);
int jig = 0;
KSet<String> objects = new KSet<>();
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
int x = xg.get();
int z = zg.get();

if (getEngine().getDimension().isUseMantle()) {
KList<IrisRegion> r = getAllRegions();
KList<IrisBiome> b = getAllBiomes();

for (IrisBiome i : b) {
for (IrisObjectPlacement j : i.getObjects()) {
if (j.getScale().canScaleBeyond()) {
scalars.put(j.getScale(), j.getPlace());
} else {
objects.addAll(j.getPlace());
}
}

for (IrisJigsawStructurePlacement j : i.getJigsawStructures()) {
jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension());
}
}

for (IrisRegion i : r) {
for (IrisObjectPlacement j : i.getObjects()) {
if (j.getScale().canScaleBeyond()) {
scalars.put(j.getScale(), j.getPlace());
} else {
objects.addAll(j.getPlace());
}
}

for (IrisJigsawStructurePlacement j : i.getJigsawStructures()) {
jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension());
}
}

for (IrisJigsawStructurePlacement j : getEngine().getDimension().getJigsawStructures()) {
jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension());
public KList<Pair<KList<MantleComponent>, Integer>> getComponents() {
return componentsCache.aquire(() -> {
var list = components.keySet()
.stream()
.sorted()
.map(components::get)
.map(components -> {
int radius = components.stream()
.mapToInt(MantleComponent::getRadius)
.max()
.orElse(0);
return new Pair<>(components, radius);
})
.collect(Collectors.toCollection(KList::new));


int radius = 0;
for (var pair : list.reversed()) {
radius += pair.getB();
pair.setB(Math.ceilDiv(radius, 16));
}

if (getEngine().getDimension().getStronghold() != null) {
try {
jig = Math.max(jig, getData().getJigsawStructureLoader().load(getEngine().getDimension().getStronghold()).getMaxDimension());
} catch (Throwable e) {
Iris.reportError(e);
e.printStackTrace();
}
}

Iris.verbose("Checking sizes for " + Form.f(objects.size()) + " referenced objects.");
BurstExecutor e = getEngine().getTarget().getBurster().burst(objects.size());
KMap<String, BlockVector> sizeCache = new KMap<>();
for (String i : objects) {
e.queue(() -> {
try {
BlockVector bv = sizeCache.computeIfAbsent(i, (k) -> {
try {
return IrisObject.sampleSize(getData().getObjectLoader().findFile(i));
} catch (IOException ex) {
Iris.reportError(ex);
ex.printStackTrace();
}

return null;
});

if (bv == null) {
throw new RuntimeException();
}

warn(i, bv);

synchronized (xg) {
xg.getAndSet(Math.max(bv.getBlockX(), xg.get()));
}

synchronized (zg) {
zg.getAndSet(Math.max(bv.getBlockZ(), zg.get()));
}
} catch (Throwable ed) {
Iris.reportError(ed);

}
});
}

for (Map.Entry<IrisObjectScale, KList<String>> entry : scalars.entrySet()) {
double ms = entry.getKey().getMaximumScale();
for (String j : entry.getValue()) {
e.queue(() -> {
try {
BlockVector bv = sizeCache.computeIfAbsent(j, (k) -> {
try {
return IrisObject.sampleSize(getData().getObjectLoader().findFile(j));
} catch (IOException ioException) {
Iris.reportError(ioException);
ioException.printStackTrace();
}

return null;
});

if (bv == null) {
throw new RuntimeException();
}

warnScaled(j, bv, ms);

synchronized (xg) {
xg.getAndSet((int) Math.max(Math.ceil(bv.getBlockX() * ms), xg.get()));
}

synchronized (zg) {
zg.getAndSet((int) Math.max(Math.ceil(bv.getBlockZ() * ms), zg.get()));
}
} catch (Throwable ee) {
Iris.reportError(ee);

}
});
}
}

e.complete();

x = xg.get();
z = zg.get();

for (IrisDepositGenerator i : getEngine().getDimension().getDeposits()) {
int max = i.getMaxDimension();
x = Math.max(max, x);
z = Math.max(max, z);
}

for (IrisRegion v : r) {
for (IrisDepositGenerator i : v.getDeposits()) {
int max = i.getMaxDimension();
x = Math.max(max, x);
z = Math.max(max, z);
}
}

for (IrisBiome v : b) {
for (IrisDepositGenerator i : v.getDeposits()) {
int max = i.getMaxDimension();
x = Math.max(max, x);
z = Math.max(max, z);
}
}
} else {
return 0;
}

x = Math.max(z, x);
int u = x;
int c = Math.max(computeCarvingRange(), computeBodyRange());
x = Math.max(jig, x);
x = Math.max(x, c);
x = (Math.max(x, 16) + 16) >> 4;
x = x % 2 == 0 ? x + 1 : x;
Iris.info("Mantle Size: " + x + " Chunks");
Iris.info(" Object Mantle Size: " + u + " (" + ((Math.max(u, 16) + 16) >> 4) + ")");
Iris.info(" Jigsaw Mantle Size: " + jig + " (" + ((Math.max(jig, 16) + 16) >> 4) + ")");
Iris.info(" Carving Mantle Size: " + c + " (" + ((Math.max(c, 16) + 16) >> 4) + ")");
return x;
return list;
});
}

private int computeBodyRange() {
int m = 0;

m = Math.max(m, getDimension().getFluidBodies().getMaxRange(getData()));

for (IrisRegion i : getDimension().getAllRegions(getEngine())) {
m = Math.max(m, i.getFluidBodies().getMaxRange(getData()));
}

for (IrisBiome i : getDimension().getAllBiomes(getEngine())) {
m = Math.max(m, i.getFluidBodies().getMaxRange(getData()));
}

return m;
@Override
public void registerComponent(MantleComponent c) {
components.computeIfAbsent(c.getPriority(), k -> new KList<>()).add(c);
componentsCache.reset();
}

private int computeCarvingRange() {
int m = 0;

m = Math.max(m, getDimension().getCarving().getMaxRange(getData()));

for (IrisRegion i : getDimension().getAllRegions(getEngine())) {
m = Math.max(m, i.getCarving().getMaxRange(getData()));
}

for (IrisBiome i : getDimension().getAllBiomes(getEngine())) {
m = Math.max(m, i.getCarving().getMaxRange(getData()));
}
@Override
public MantleJigsawComponent getJigsawComponent() {
return jigsaw;
}

return m;
@Override
public MantleObjectComponent getObjectComponent() {
return object;
}
}
Loading

0 comments on commit fc05c24

Please sign in to comment.