mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-01 23:47:21 +00:00
implement priority to static placement component
This commit is contained in:
parent
894de013dd
commit
3a74164627
@ -19,6 +19,7 @@
|
|||||||
package com.volmit.iris.engine.mantle.components;
|
package com.volmit.iris.engine.mantle.components;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||||
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
||||||
@ -39,11 +40,13 @@ 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 com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.util.BlockVector;
|
import org.bukkit.util.BlockVector;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@ -162,99 +165,67 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
|||||||
private int computeRadius() {
|
private int computeRadius() {
|
||||||
var dimension = getDimension();
|
var dimension = getDimension();
|
||||||
|
|
||||||
AtomicInteger xg = new AtomicInteger();
|
|
||||||
AtomicInteger zg = new AtomicInteger();
|
|
||||||
|
|
||||||
KSet<String> objects = new KSet<>();
|
KSet<String> objects = new KSet<>();
|
||||||
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
|
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
|
||||||
for (var region : dimension.getAllRegions(this::getData)) {
|
for (var region : dimension.getAllRegions(this::getData)) {
|
||||||
for (var j : region.getObjects()) {
|
for (var placement : region.getObjects()) {
|
||||||
if (j.getScale().canScaleBeyond()) {
|
if (placement.getScale().canScaleBeyond()) {
|
||||||
scalars.put(j.getScale(), j.getPlace());
|
scalars.put(placement.getScale(), placement.getPlace());
|
||||||
} else {
|
} else {
|
||||||
objects.addAll(j.getPlace());
|
objects.addAll(placement.getPlace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (var biome : dimension.getAllBiomes(this::getData)) {
|
for (var biome : region.getAllBiomes(this::getData)) {
|
||||||
for (var j : biome.getObjects()) {
|
for (var placement : biome.getObjects()) {
|
||||||
if (j.getScale().canScaleBeyond()) {
|
if (placement.getScale().canScaleBeyond()) {
|
||||||
scalars.put(j.getScale(), j.getPlace());
|
scalars.put(placement.getScale(), placement.getPlace());
|
||||||
} else {
|
} else {
|
||||||
objects.addAll(j.getPlace());
|
objects.addAll(placement.getPlace());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BurstExecutor e = getEngineMantle().getTarget().getBurster().burst(objects.size());
|
return computeObjectRadius(objects, scalars, getEngineMantle().getTarget().getBurster(), getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
static int computeObjectRadius(KSet<String> objects, KMap<IrisObjectScale, KList<String>> scalars, MultiBurst burst, IrisData data) {
|
||||||
|
AtomicInteger x = new AtomicInteger();
|
||||||
|
AtomicInteger z = new AtomicInteger();
|
||||||
|
|
||||||
|
BurstExecutor e = burst.burst(objects.size());
|
||||||
KMap<String, BlockVector> sizeCache = new KMap<>();
|
KMap<String, BlockVector> sizeCache = new KMap<>();
|
||||||
for (String i : objects) {
|
for (String loadKey : objects) {
|
||||||
e.queue(() -> {
|
e.queue(() -> {
|
||||||
try {
|
try {
|
||||||
BlockVector bv = sizeCache.computeIfAbsent(i, (k) -> {
|
BlockVector bv = sampleSize(sizeCache, data, loadKey);
|
||||||
try {
|
|
||||||
return IrisObject.sampleSize(getData().getObjectLoader().findFile(i));
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Iris.reportError(ex);
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (bv == null) {
|
|
||||||
throw new RuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
||||||
Iris.warn("Object " + i + " has a large size (" + bv + ") and may increase memory usage!");
|
Iris.warn("Object " + loadKey + " has a large size (" + bv + ") and may increase memory usage!");
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (xg) {
|
x.getAndUpdate(i -> Math.max(bv.getBlockX(), i));
|
||||||
xg.getAndSet(Math.max(bv.getBlockX(), xg.get()));
|
z.getAndUpdate(i -> Math.max(bv.getBlockZ(), i));
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (zg) {
|
|
||||||
zg.getAndSet(Math.max(bv.getBlockZ(), zg.get()));
|
|
||||||
}
|
|
||||||
} catch (Throwable ed) {
|
} catch (Throwable ed) {
|
||||||
Iris.reportError(ed);
|
Iris.reportError(ed);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<IrisObjectScale, KList<String>> entry : scalars.entrySet()) {
|
for (Map.Entry<IrisObjectScale, KList<String>> entry : scalars.entrySet()) {
|
||||||
double ms = entry.getKey().getMaximumScale();
|
double ms = entry.getKey().getMaximumScale();
|
||||||
for (String j : entry.getValue()) {
|
for (String loadKey : entry.getValue()) {
|
||||||
e.queue(() -> {
|
e.queue(() -> {
|
||||||
try {
|
try {
|
||||||
BlockVector bv = sizeCache.computeIfAbsent(j, (k) -> {
|
BlockVector bv = sampleSize(sizeCache, data, loadKey);
|
||||||
try {
|
|
||||||
return IrisObject.sampleSize(getData().getObjectLoader().findFile(j));
|
|
||||||
} catch (IOException ioException) {
|
|
||||||
Iris.reportError(ioException);
|
|
||||||
ioException.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (bv == null) {
|
|
||||||
throw new RuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
||||||
Iris.warn("Object " + j + " has a large size (" + bv + ") and may increase memory usage! (Object scaled up to " + Form.pc(ms, 2) + ")");
|
Iris.warn("Object " + loadKey + " has a large size (" + bv + ") and may increase memory usage! (Object scaled up to " + Form.pc(ms, 2) + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (xg) {
|
x.getAndUpdate(i -> (int) Math.max(Math.ceil(bv.getBlockX() * ms), i));
|
||||||
xg.getAndSet((int) Math.max(Math.ceil(bv.getBlockX() * ms), xg.get()));
|
x.getAndUpdate(i -> (int) Math.max(Math.ceil(bv.getBlockZ() * ms), i));
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (zg) {
|
|
||||||
zg.getAndSet((int) Math.max(Math.ceil(bv.getBlockZ() * ms), zg.get()));
|
|
||||||
}
|
|
||||||
} catch (Throwable ee) {
|
} catch (Throwable ee) {
|
||||||
Iris.reportError(ee);
|
Iris.reportError(ee);
|
||||||
|
|
||||||
@ -264,6 +235,20 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
e.complete();
|
e.complete();
|
||||||
return Math.max(xg.get(), zg.get());
|
return Math.max(x.get(), z.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BlockVector sampleSize(KMap<String, BlockVector> sizeCache, IrisData data, String loadKey) {
|
||||||
|
BlockVector bv = sizeCache.computeIfAbsent(loadKey, (k) -> {
|
||||||
|
try {
|
||||||
|
return IrisObject.sampleSize(data.getObjectLoader().findFile(loadKey));
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
Iris.reportError(ioException);
|
||||||
|
ioException.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
return Objects.requireNonNull(bv, "sampleSize returned a null block vector");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,25 @@ package com.volmit.iris.engine.mantle.components;
|
|||||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||||
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
||||||
import com.volmit.iris.engine.mantle.MantleWriter;
|
import com.volmit.iris.engine.mantle.MantleWriter;
|
||||||
|
import com.volmit.iris.engine.object.IrisObjectScale;
|
||||||
import com.volmit.iris.engine.object.IrisStaticPlacement;
|
import com.volmit.iris.engine.object.IrisStaticPlacement;
|
||||||
import com.volmit.iris.engine.object.NoiseStyle;
|
import com.volmit.iris.engine.object.NoiseStyle;
|
||||||
|
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.context.ChunkContext;
|
import com.volmit.iris.util.context.ChunkContext;
|
||||||
import com.volmit.iris.util.mantle.MantleFlag;
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import com.volmit.iris.util.noise.CNG;
|
import com.volmit.iris.util.noise.CNG;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
public class MantleStaticComponent extends IrisMantleComponent {
|
public class MantleStaticComponent extends IrisMantleComponent {
|
||||||
private final CNG cng;
|
private final CNG cng;
|
||||||
|
@Getter
|
||||||
|
private final int radius = computeRadius();
|
||||||
|
|
||||||
public MantleStaticComponent(EngineMantle engineMantle) {
|
public MantleStaticComponent(EngineMantle engineMantle) {
|
||||||
super(engineMantle, MantleFlag.STATIC);
|
super(engineMantle, MantleFlag.STATIC, 1);
|
||||||
cng = NoiseStyle.STATIC.create(new RNG(seed()));
|
cng = NoiseStyle.STATIC.create(new RNG(seed()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,4 +32,28 @@ public class MantleStaticComponent extends IrisMantleComponent {
|
|||||||
placement.place(writer, rng, getData());
|
placement.place(writer, rng, getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int computeRadius() {
|
||||||
|
var placements = getDimension().getStaticPlacements();
|
||||||
|
|
||||||
|
KSet<String> objects = new KSet<>();
|
||||||
|
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
|
||||||
|
for (var staticPlacement : placements.getObjects()) {
|
||||||
|
var placement = staticPlacement.placement();
|
||||||
|
if (placement.getScale().canScaleBeyond()) {
|
||||||
|
scalars.put(placement.getScale(), placement.getPlace());
|
||||||
|
} else {
|
||||||
|
objects.addAll(placement.getPlace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int jigsaw = placements.getStructures()
|
||||||
|
.stream()
|
||||||
|
.mapToInt(staticPlacement -> staticPlacement.maxDimension(getData()))
|
||||||
|
.max()
|
||||||
|
.orElse(0);
|
||||||
|
int object = MantleObjectComponent.computeObjectRadius(objects, scalars, getEngineMantle().getTarget().getBurster(), getData());
|
||||||
|
|
||||||
|
return Math.max(jigsaw, object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user