9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2026-01-04 15:41:30 +00:00

Compare commits

...

12 Commits

Author SHA1 Message Date
Aidan Aeternum
910220d3ca v+ 2025-01-08 18:22:26 -08:00
Aidan Aeternum
fc05c24e3a Merge pull request #1135 from VolmitSoftware/dev
3.5.3
2025-01-08 18:20:43 -08:00
Julian Krings
e1a7e772cf fix floating objects (#1134) 2025-01-07 22:03:53 +01:00
Aidan Aeternum
3c6411c322 v+ 2025-01-07 11:22:52 -08:00
Aidan Aeternum
628761affa Merge pull request #1130 from VolmitSoftware/dev
3.5.2
2025-01-07 11:21:06 -08:00
Julian Krings
fa7b0f68ff Merge pull request #1129 from VolmitSoftware/feat/deposits
Feat/deposits
2025-01-05 16:25:03 +01:00
Aidan Aeternum
487d0ac237 Merge pull request #1128 from VolmitSoftware/dev
3.5.1
2025-01-04 09:57:30 -08:00
Julian Krings
e79e3fbe45 implement <1 deposit spawn chance 2025-01-04 03:46:08 +01:00
Julian Krings
23a0ab23aa fixes to deposit clump generation and placement 2025-01-04 03:41:55 +01:00
Julian Krings
c78ffab948 fix deposit clump calculation 2025-01-03 00:33:49 +01:00
Julian Krings
d58f497b71 v+ 2025-01-02 23:21:32 +01:00
Julian Krings
3284ab84c5 fix biome&region deposits being placed ^2 2025-01-02 23:15:27 +01:00
20 changed files with 442 additions and 370 deletions

View File

@@ -32,7 +32,7 @@ plugins {
id "de.undercouch.download" version "5.0.1"
}
version '3.5.0-1.19.2-1.21.3'
version '3.5.3-1.19.2-1.21.3'
// ADD YOURSELF AS A NEW LINE IF YOU WANT YOUR OWN BUILD TASK GENERATED
// ======================== WINDOWS =============================

View File

@@ -172,7 +172,7 @@ public class CommandStudio implements DecreeExecutor {
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());

View File

@@ -40,6 +40,7 @@ import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class BoardSVC implements IrisService, BoardProvider {
private final KMap<Player, PlayerBoard> boards = new KMap<>();
@@ -104,11 +105,11 @@ public class BoardSVC implements IrisService, BoardProvider {
@Data
public static class PlayerBoard {
private final Player player;
private final KList<String> lines;
private final CopyOnWriteArrayList<String> lines;
public PlayerBoard(Player player) {
this.player = player;
this.lines = new KList<>();
this.lines = new CopyOnWriteArrayList<>();
update();
}

View File

@@ -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;
@@ -27,23 +27,13 @@ import com.volmit.iris.engine.mantle.components.MantleCarvingComponent;
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")
@@ -51,8 +41,9 @@ import java.util.concurrent.atomic.AtomicInteger;
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;
@@ -60,8 +51,7 @@ public class IrisEngineMantle implements EngineMantle {
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);
@@ -70,9 +60,49 @@ public class IrisEngineMantle implements EngineMantle {
registerComponent(object);
}
@Override
public int getRadius() {
if (components.isEmpty()) return 0;
return getComponents().getFirst().getB();
}
@Override
public int getRealRadius() {
if (components.isEmpty()) return 0;
return getComponents().getLast().getB();
}
@Override
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));
}
return list;
});
}
@Override
public void registerComponent(MantleComponent c) {
components.add(c);
components.computeIfAbsent(c.getPriority(), k -> new KList<>()).add(c);
componentsCache.reset();
}
@Override
@@ -84,243 +114,4 @@ public class IrisEngineMantle implements EngineMantle {
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());
}
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;
}
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;
}
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()));
}
return m;
}
}

View File

@@ -20,10 +20,10 @@ package com.volmit.iris.engine.mantle;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.nms.container.Pair;
import com.volmit.iris.engine.IrisComplex;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineTarget;
import com.volmit.iris.engine.framework.SeedManager;
import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
import com.volmit.iris.engine.object.IObjectPlacer;
@@ -44,7 +44,6 @@ import com.volmit.iris.util.matter.*;
import com.volmit.iris.util.matter.slices.UpdateMatter;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.MultiBurst;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
import java.util.concurrent.TimeUnit;
@@ -59,7 +58,9 @@ public interface EngineMantle extends IObjectPlacer {
int getRadius();
KList<MantleComponent> getComponents();
int getRealRadius();
KList<Pair<KList<MantleComponent>, Integer>> getComponents();
void registerComponent(MantleComponent c);
@@ -187,39 +188,37 @@ public interface EngineMantle extends IObjectPlacer {
return getEngine().burst();
}
default int getRealRadius() {
return (int) Math.ceil(getRadius() / 2D);
}
@ChunkCoordinates
default void generateMatter(int x, int z, boolean multicore, ChunkContext context) {
synchronized (this) {
if (!getEngine().getDimension().isUseMantle()) {
return;
}
if (!getEngine().getDimension().isUseMantle()) {
return;
}
int s = getRealRadius();
BurstExecutor burst = burst().burst(multicore);
MantleWriter writer = getMantle().write(this, x, z, s * 2);
for (int i = -s; i <= s; i++) {
for (int j = -s; j <= s; j++) {
int xx = i + x;
int zz = j + z;
burst.queue(() -> {
IrisContext.touch(getEngine().getContext());
getMantle().raiseFlag(xx, zz, MantleFlag.PLANNED, () -> {
MantleChunk mc = getMantle().getChunk(xx, zz);
try (MantleWriter writer = getMantle().write(this, x, z, getRadius() * 2)) {
var iterator = getComponents().iterator();
while (iterator.hasNext()) {
var pair = iterator.next();
int radius = pair.getB();
boolean last = !iterator.hasNext();
BurstExecutor burst = burst().burst(radius * 2 + 1);
burst.setMulticore(multicore);
for (MantleComponent k : getComponents()) {
generateMantleComponent(writer, xx, zz, k, mc, context);
}
for (int i = -radius; i <= radius; i++) {
for (int j = -radius; j <= radius; j++) {
int xx = x + i;
int zz = z + j;
MantleChunk mc = getMantle().getChunk(xx, zz);
burst.queue(() -> {
IrisContext.touch(getEngine().getContext());
pair.getA().forEach(k -> generateMantleComponent(writer, xx, zz, k, mc, context));
if (last) mc.flag(MantleFlag.PLANNED, true);
});
});
}
}
}
burst.complete();
burst.complete();
}
}
}

View File

@@ -29,4 +29,5 @@ import lombok.ToString;
public abstract class IrisMantleComponent implements MantleComponent {
private final EngineMantle engineMantle;
private final MantleFlag flag;
private final int priority;
}

View File

@@ -26,11 +26,12 @@ import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.mantle.MantleFlag;
import com.volmit.iris.util.parallel.BurstExecutor;
import org.jetbrains.annotations.NotNull;
public interface MantleComponent {
default int getRadius() {
return getEngineMantle().getRealRadius();
}
public interface MantleComponent extends Comparable<MantleComponent> {
int getPriority();
int getRadius();
default IrisData getData() {
return getEngineMantle().getData();
@@ -62,4 +63,9 @@ public interface MantleComponent {
@ChunkCoordinates
void generateLayer(MantleWriter writer, int x, int z, ChunkContext context);
@Override
default int compareTo(@NotNull MantleComponent o) {
return Integer.compare(getPriority(), o.getPriority());
}
}

View File

@@ -35,7 +35,6 @@ import com.volmit.iris.util.mantle.MantleChunk;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.Matter;
import lombok.Data;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
import org.bukkit.util.Vector;
@@ -44,7 +43,7 @@ import java.util.List;
import java.util.Set;
@Data
public class MantleWriter implements IObjectPlacer {
public class MantleWriter implements IObjectPlacer, AutoCloseable {
private final EngineMantle engineMantle;
private final Mantle mantle;
private final KMap<Long, MantleChunk> cachedChunks;
@@ -62,7 +61,7 @@ public class MantleWriter implements IObjectPlacer {
for (int i = -radius; i <= radius; i++) {
for (int j = -radius; j <= radius; j++) {
cachedChunks.put(Cache.key(i + x, j + z), mantle.getChunk(i + x, j + z));
cachedChunks.put(Cache.key(i + x, j + z), mantle.getChunk(i + x, j + z).use());
}
}
}
@@ -633,4 +632,12 @@ public class MantleWriter implements IObjectPlacer {
return cx >= this.x - radius && cx <= this.x + radius
&& cz >= this.z - radius && cz <= this.z + radius;
}
@Override
public void close() {
cachedChunks.values().removeIf(c -> {
c.release();
return true;
});
}
}

View File

@@ -29,10 +29,14 @@ import com.volmit.iris.util.context.ChunkContext;
import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.mantle.MantleFlag;
import com.volmit.iris.util.math.RNG;
import lombok.Getter;
@Getter
public class MantleCarvingComponent extends IrisMantleComponent {
private final int radius = computeRadius();
public MantleCarvingComponent(EngineMantle engineMantle) {
super(engineMantle, MantleFlag.CARVED);
super(engineMantle, MantleFlag.CARVED, 0);
}
@Override
@@ -56,4 +60,21 @@ public class MantleCarvingComponent extends IrisMantleComponent {
private void carve(IrisCarving carving, MantleWriter writer, RNG rng, int cx, int cz) {
carving.doCarving(writer, rng, getEngineMantle().getEngine(), cx << 4, -1, cz << 4);
}
private int computeRadius() {
var dimension = getDimension();
int max = 0;
max = Math.max(max, dimension.getCarving().getMaxRange(getData()));
for (var i : dimension.getAllRegions(this::getData)) {
max = Math.max(max, i.getCarving().getMaxRange(getData()));
}
for (var i : dimension.getAllBiomes(this::getData)) {
max = Math.max(max, i.getCarving().getMaxRange(getData()));
}
return max;
}
}

View File

@@ -29,10 +29,14 @@ import com.volmit.iris.util.context.ChunkContext;
import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.mantle.MantleFlag;
import com.volmit.iris.util.math.RNG;
import lombok.Getter;
@Getter
public class MantleFluidBodyComponent extends IrisMantleComponent {
private final int radius = computeRadius();
public MantleFluidBodyComponent(EngineMantle engineMantle) {
super(engineMantle, MantleFlag.FLUID_BODIES);
super(engineMantle, MantleFlag.FLUID_BODIES, 0);
}
@Override
@@ -56,4 +60,20 @@ public class MantleFluidBodyComponent extends IrisMantleComponent {
private void generate(IrisFluidBodies bodies, MantleWriter writer, RNG rng, int cx, int cz) {
bodies.generate(writer, rng, getEngineMantle().getEngine(), cx << 4, -1, cz << 4);
}
private int computeRadius() {
int max = 0;
max = Math.max(max, getDimension().getFluidBodies().getMaxRange(getData()));
for (IrisRegion i : getDimension().getAllRegions(this::getData)) {
max = Math.max(max, i.getFluidBodies().getMaxRange(getData()));
}
for (IrisBiome i : getDimension().getAllBiomes(this::getData)) {
max = Math.max(max, i.getFluidBodies().getMaxRange(getData()));
}
return max;
}
}

View File

@@ -34,15 +34,18 @@ import com.volmit.iris.util.math.Position2;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.slices.container.JigsawStructuresContainer;
import com.volmit.iris.util.noise.CNG;
import lombok.Getter;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class MantleJigsawComponent extends IrisMantleComponent {
@Getter
private final int radius = computeRadius();
private final CNG cng;
public MantleJigsawComponent(EngineMantle engineMantle) {
super(engineMantle, MantleFlag.JIGSAW);
super(engineMantle, MantleFlag.JIGSAW, 1);
cng = NoiseStyle.STATIC.create(new RNG(jigsaw()));
}
@@ -168,4 +171,29 @@ public class MantleJigsawComponent extends IrisMantleComponent {
private long jigsaw() {
return getEngineMantle().getEngine().getSeedManager().getJigsaw();
}
private int computeRadius() {
var dimension = getDimension();
KSet<String> structures = new KSet<>();
for (var placement : dimension.getJigsawStructures()) {
structures.add(placement.getStructure());
}
for (var region : dimension.getAllRegions(this::getData)) {
for (var placement : region.getJigsawStructures()) {
structures.add(placement.getStructure());
}
}
for (var biome : dimension.getAllBiomes(this::getData)) {
for (var placement : biome.getJigsawStructures()) {
structures.add(placement.getStructure());
}
}
int max = 0;
for (var structure : structures) {
max = Math.max(max, getData().getJigsawStructureLoader().load(structure).getMaxDimension());
}
return max;
}
}

View File

@@ -24,23 +24,35 @@ import com.volmit.iris.engine.mantle.EngineMantle;
import com.volmit.iris.engine.mantle.IrisMantleComponent;
import com.volmit.iris.engine.mantle.MantleWriter;
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.context.ChunkContext;
import com.volmit.iris.util.data.B;
import com.volmit.iris.util.data.IrisBlockData;
import com.volmit.iris.util.documentation.BlockCoordinates;
import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.mantle.MantleFlag;
import com.volmit.iris.util.math.RNG;
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;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
@Getter
public class MantleObjectComponent extends IrisMantleComponent {
private final int radius = computeRadius();
public MantleObjectComponent(EngineMantle engineMantle) {
super(engineMantle, MantleFlag.OBJECT);
super(engineMantle, MantleFlag.OBJECT, 1);
}
@Override
@@ -146,4 +158,112 @@ public class MantleObjectComponent extends IrisMantleComponent {
return v;
}
private int computeRadius() {
var dimension = getDimension();
AtomicInteger xg = new AtomicInteger();
AtomicInteger zg = new AtomicInteger();
KSet<String> objects = new KSet<>();
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
for (var region : dimension.getAllRegions(this::getData)) {
for (var j : region.getObjects()) {
if (j.getScale().canScaleBeyond()) {
scalars.put(j.getScale(), j.getPlace());
} else {
objects.addAll(j.getPlace());
}
}
}
for (var biome : dimension.getAllBiomes(this::getData)) {
for (var j : biome.getObjects()) {
if (j.getScale().canScaleBeyond()) {
scalars.put(j.getScale(), j.getPlace());
} else {
objects.addAll(j.getPlace());
}
}
}
BurstExecutor e = getEngineMantle().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();
}
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
Iris.warn("Object " + i + " has a large size (" + bv + ") and may increase memory usage!");
}
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();
}
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) + ")");
}
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();
return Math.max(xg.get(), zg.get());
}
}

View File

@@ -20,10 +20,7 @@ package com.volmit.iris.engine.modifier;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineAssignedModifier;
import com.volmit.iris.engine.object.IrisBiome;
import com.volmit.iris.engine.object.IrisDepositGenerator;
import com.volmit.iris.engine.object.IrisObject;
import com.volmit.iris.engine.object.IrisRegion;
import com.volmit.iris.engine.object.*;
import com.volmit.iris.util.context.ChunkContext;
import com.volmit.iris.util.data.B;
import com.volmit.iris.util.data.HeightMap;
@@ -45,30 +42,26 @@ public class IrisDepositModifier extends EngineAssignedModifier<BlockData> {
@Override
public void onModify(int x, int z, Hunk<BlockData> output, boolean multicore, ChunkContext context) {
PrecisionStopwatch p = PrecisionStopwatch.start();
generateDeposits(rng, output, Math.floorDiv(x, 16), Math.floorDiv(z, 16), multicore, context);
generateDeposits(output, Math.floorDiv(x, 16), Math.floorDiv(z, 16), multicore, context);
getEngine().getMetrics().getDeposit().put(p.getMilliseconds());
}
public void generateDeposits(RNG rx, Hunk<BlockData> terrain, int x, int z, boolean multicore, ChunkContext context) {
RNG ro = rx.nextParallelRNG(x * x).nextParallelRNG(z * z);
public void generateDeposits(Hunk<BlockData> terrain, int x, int z, boolean multicore, ChunkContext context) {
IrisRegion region = context.getRegion().get(7, 7);
IrisBiome biome = context.getBiome().get(7, 7);
BurstExecutor burst = burst().burst(multicore);
long seed = x * 341873128712L + z * 132897987541L;
for (IrisDepositGenerator k : getDimension().getDeposits()) {
burst.queue(() -> generate(k, terrain, ro, x, z, false, context));
burst.queue(() -> generate(k, terrain, rng.nextParallelRNG(seed), x, z, false, context));
}
for (IrisDepositGenerator k : region.getDeposits()) {
for (int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) {
burst.queue(() -> generate(k, terrain, ro, x, z, false, context));
}
burst.queue(() -> generate(k, terrain, rng.nextParallelRNG(seed), x, z, false, context));
}
for (IrisDepositGenerator k : biome.getDeposits()) {
for (int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) {
burst.queue(() -> generate(k, terrain, ro, x, z, false, context));
}
burst.queue(() -> generate(k, terrain, rng.nextParallelRNG(seed), x, z, false, context));
}
burst.complete();
}
@@ -78,45 +71,48 @@ public class IrisDepositModifier extends EngineAssignedModifier<BlockData> {
}
public void generate(IrisDepositGenerator k, Hunk<BlockData> data, RNG rng, int cx, int cz, boolean safe, HeightMap he, ChunkContext context) {
for (int l = 0; l < rng.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) {
if (k.getSpawnChance() < rng.d())
return;
for (int l = 0; l < rng.i(k.getMinPerChunk(), k.getMaxPerChunk() + 1); l++) {
if (k.getPerClumpSpawnChance() < rng.d())
continue;
IrisObject clump = k.getClump(rng, getData());
int af = (int) Math.floor(clump.getW() / 2D);
int bf = (int) Math.floor(16D - (clump.getW() / 2D));
int dim = clump.getW();
int min = dim / 2;
int max = (int) (16D - dim / 2D);
if (af > bf || af < 0 || bf > 15) {
af = 6;
bf = 9;
if (min > max || min < 0 || max > 15) {
min = 6;
max = 9;
}
af = Math.max(af - 1, 0);
int x = rng.i(af, bf);
int z = rng.i(af, bf);
int x = rng.i(min, max + 1);
int z = rng.i(min, max + 1);
int height = (he != null ? he.getHeight((cx << 4) + x, (cz << 4) + z) : (int) (Math.round(
context.getHeight().get(x, z)
))) - 7;
if (height <= 0) {
return;
}
if (height <= 0)
continue;
int i = Math.max(0, k.getMinHeight());
int minY = Math.max(0, k.getMinHeight());
// TODO: WARNING HEIGHT
int a = Math.min(height, Math.min(getEngine().getHeight(), k.getMaxHeight()));
int maxY = Math.min(height, Math.min(getEngine().getHeight(), k.getMaxHeight()));
if (i >= a) {
return;
}
if (minY >= maxY)
continue;
int h = rng.i(i, a);
int y = rng.i(minY, maxY + 1);
if (h > k.getMaxHeight() || h < k.getMinHeight() || h > height - 2) {
return;
}
if (y > k.getMaxHeight() || y < k.getMinHeight() || y > height - 2)
continue;
for (BlockVector j : clump.getBlocks().keySet()) {
int nx = j.getBlockX() + x;
int ny = j.getBlockY() + h;
int ny = j.getBlockY() + y;
int nz = j.getBlockZ() + z;
if (ny > height || nx > 15 || nx < 0 || ny > getEngine().getHeight() || ny < 0 || nz < 0 || nz > 15) {

View File

@@ -22,13 +22,14 @@ import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.math.BlockPosition;
import com.volmit.iris.util.math.RNG;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.bukkit.block.data.BlockData;
import org.bukkit.util.BlockVector;
@Snippet("deposit")
@Accessors(chain = true)
@@ -69,6 +70,14 @@ public class IrisDepositGenerator {
@MaxNumber(2048)
@Desc("The minimum amount of clumps per chunk")
private int minPerChunk = 0;
@MinNumber(0)
@MaxNumber(1)
@Desc("The change of the deposit spawning in a chunk")
private double spawnChance = 1;
@MinNumber(0)
@MaxNumber(1)
@Desc("The change of the a clump spawning in a chunk")
private double perClumpSpawnChance = 1;
@Required
@ArrayType(min = 1, type = IrisBlockData.class)
@Desc("The palette of blocks to be used in this deposit generator")
@@ -90,35 +99,62 @@ public class IrisDepositGenerator {
return objectsf;
});
return objects.get(rng.i(0, objects.size() - 1));
return objects.get(rng.i(0, objects.size()));
}
public int getMaxDimension() {
return Math.min(11, (int) Math.round(Math.pow(maxSize, 1D / 3D)));
return Math.min(11, (int) Math.ceil(Math.cbrt(maxSize)));
}
private IrisObject generateClumpObject(RNG rngv, IrisData rdata) {
int s = rngv.i(minSize, maxSize);
int dim = Math.min(11, (int) Math.round(Math.pow(maxSize, 1D / 3D)));
int w = dim / 2;
int s = rngv.i(minSize, maxSize + 1);
if (s == 1) {
IrisObject o = new IrisObject(1, 1, 1);
o.getBlocks().put(o.getCenter(), nextBlock(rngv, rdata));
return o;
}
int dim = Math.min(11, (int) Math.ceil(Math.cbrt(s)));
IrisObject o = new IrisObject(dim, dim, dim);
if (s == 1) {
o.getBlocks().put(o.getCenter(), nextBlock(rngv, rdata));
} else {
while (s > 0) {
s--;
BlockVector ang = new BlockVector(rngv.i(-w, w), rngv.i(-w, w), rngv.i(-w, w));
BlockVector pos = o.getCenter().clone().add(ang).toBlockVector();
o.getBlocks().put(pos, nextBlock(rngv, rdata));
int volume = dim * dim * dim;
if (s >= volume) {
int x = 0, y = 0, z = 0;
while (z < dim) {
o.setUnsigned(x++, y, z, nextBlock(rngv, rdata));
if (x == dim) {
x = 0;
y++;
}
if (y == dim) {
y = 0;
z++;
}
}
return o;
}
KSet<BlockPosition> set = new KSet<>();
while (s > 0) {
BlockPosition ang = new BlockPosition(
rngv.i(0, dim),
rngv.i(0, dim),
rngv.i(0, dim)
);
if (!set.add(ang)) continue;
s--;
o.setUnsigned(ang.getX(), ang.getY(), ang.getZ(), nextBlock(rngv, rdata));
}
return o;
}
private BlockData nextBlock(RNG rngv, IrisData rdata) {
return getBlockData(rdata).get(rngv.i(0, getBlockData(rdata).size() - 1));
return getBlockData(rdata).get(rngv.i(0, getBlockData(rdata).size()));
}
public KList<BlockData> getBlockData(IrisData rdata) {

View File

@@ -0,0 +1,7 @@
package com.volmit.iris.util.documentation;
/**
* This Argument is exclusive
*/
public @interface Exclusive {
}

View File

@@ -0,0 +1,7 @@
package com.volmit.iris.util.documentation;
/**
* This Argument is inclusive
*/
public @interface Inclusive {
}

View File

@@ -471,6 +471,12 @@ public class Mantle {
hyperLock.withLong(id, () -> {
TectonicPlate m = loadedRegions.get(id);
if (m != null) {
if (m.inUse()) {
Iris.debug("Tectonic Plate was added to unload while in use " + C.DARK_GREEN + m.getX() + " " + m.getZ());
if (disableClear) toUnload.remove(id);
lastUse.put(id, M.ms());
return;
}
try {
m.write(fileForRegion(dataFolder, id));
loadedRegions.remove(id);

View File

@@ -26,10 +26,12 @@ import com.volmit.iris.util.matter.IrisMatter;
import com.volmit.iris.util.matter.Matter;
import com.volmit.iris.util.matter.MatterSlice;
import lombok.Getter;
import lombok.Synchronized;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicIntegerArray;
import java.util.concurrent.atomic.AtomicReferenceArray;
@@ -44,6 +46,7 @@ public class MantleChunk {
private final int z;
private final AtomicIntegerArray flags;
private final AtomicReferenceArray<Matter> sections;
private final AtomicInteger ref = new AtomicInteger();
/**
* Create a mantle chunk
@@ -101,10 +104,25 @@ public class MantleChunk {
}
}
public boolean inUse() {
return ref.get() > 0;
}
public MantleChunk use() {
ref.incrementAndGet();
return this;
}
public void release() {
ref.decrementAndGet();
}
@Synchronized
public void flag(MantleFlag flag, boolean f) {
flags.set(flag.ordinal(), f ? 1 : 0);
}
@Synchronized
public void raiseFlag(MantleFlag flag, Runnable r) {
if (!isFlagged(flag)) {
flag(flag, true);

View File

@@ -127,6 +127,15 @@ public class TectonicPlate {
}
}
public boolean inUse() {
for (int i = 0; i < chunks.length(); i++) {
MantleChunk chunk = chunks.get(i);
if (chunk != null && chunk.inUse())
return true;
}
return false;
}
/**
* Check if a chunk exists in this plate or not (same as get(x, z) != null)
*
@@ -180,14 +189,10 @@ public class TectonicPlate {
*/
@ChunkCoordinates
public MantleChunk getOrCreate(int x, int z) {
MantleChunk chunk = get(x, z);
if (chunk == null) {
chunk = new MantleChunk(sectionHeight, x & 31, z & 31);
chunks.set(index(x, z), chunk);
}
return chunk;
return chunks.updateAndGet(index(x, z), chunk -> {
if (chunk != null) return chunk;
return new MantleChunk(sectionHeight, x & 31, z & 31);
});
}
@ChunkCoordinates

View File

@@ -18,6 +18,9 @@
package com.volmit.iris.util.math;
import com.volmit.iris.util.documentation.Exclusive;
import com.volmit.iris.util.documentation.Inclusive;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Random;
@@ -89,11 +92,11 @@ public class RNG extends Random {
return d() > percent;
}
public short si(int lowerBound, int upperBound) {
public short si(@Inclusive int lowerBound, @Inclusive int upperBound) {
return (short) (lowerBound + (nextFloat() * ((upperBound - lowerBound) + 1)));
}
public short si(int upperBound) {
public short si(@Inclusive int upperBound) {
return si(0, upperBound);
}
@@ -101,11 +104,11 @@ public class RNG extends Random {
return si(1);
}
public float f(float lowerBound, float upperBound) {
public float f(@Inclusive float lowerBound, @Exclusive float upperBound) {
return lowerBound + (nextFloat() * ((upperBound - lowerBound)));
}
public float f(float upperBound) {
public float f(@Exclusive float upperBound) {
return f(0, upperBound);
}
@@ -113,7 +116,7 @@ public class RNG extends Random {
return f(1);
}
public double d(double lowerBound, double upperBound) {
public double d(@Inclusive double lowerBound, @Exclusive double upperBound) {
if (lowerBound > upperBound) {
return M.lerp(upperBound, lowerBound, nextDouble());
}
@@ -121,7 +124,7 @@ public class RNG extends Random {
return M.lerp(lowerBound, upperBound, nextDouble());
}
public double d(double upperBound) {
public double d(@Exclusive double upperBound) {
return d(0, upperBound);
}
@@ -129,19 +132,19 @@ public class RNG extends Random {
return d(1);
}
public int i(int lowerBound, int upperBound) {
public int i(@Inclusive int lowerBound, @Exclusive int upperBound) {
return (int) Math.floor(d(lowerBound, upperBound));
}
public int i(int upperBound) {
public int i(@Exclusive int upperBound) {
return i(Math.min(upperBound, 0), Math.max(0, upperBound));
}
public long l(long lowerBound, long upperBound) {
public long l(@Inclusive long lowerBound, @Exclusive long upperBound) {
return Math.round(d(lowerBound, upperBound));
}
public long l(long upperBound) {
public long l(@Exclusive long upperBound) {
return l(0, upperBound);
}