mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-28 03:29:06 +00:00
Prepatch
This commit is contained in:
@@ -54,7 +54,10 @@ import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -405,26 +408,42 @@ public class IrisEngine implements Engine {
|
||||
context.touch();
|
||||
getEngineData().getStatistics().generatedChunk();
|
||||
try {
|
||||
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
Hunk<BlockData> blocks = vblocks.listen((xx, y, zz, t) -> catchBlockUpdates(x + xx, y + getMinHeight(), z + zz, t));
|
||||
getMantle().generateMatter(x >> 4, z >> 4, multicore);
|
||||
|
||||
burst().burst(multicore,
|
||||
() -> getTerrainActuator().actuate(x, z, vblocks, multicore),
|
||||
() -> getBiomeActuator().actuate(x, z, vbiomes, multicore)
|
||||
);
|
||||
burst().burst(multicore,
|
||||
() -> getCaveModifier().modify(x, z, vblocks, multicore),
|
||||
() -> getDecorantActuator().actuate(x, z, blocks, multicore),
|
||||
() -> getRavineModifier().modify(x, z, vblocks, multicore)
|
||||
);
|
||||
if(multicore)
|
||||
{
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
blocks.set(i, 0, j, Material.RED_GLAZED_TERRACOTTA.createBlockData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
getMantle().generateMatter(x >> 4, z >> 4, multicore);
|
||||
|
||||
burst().burst(multicore,
|
||||
() -> getTerrainActuator().actuate(x, z, vblocks, multicore),
|
||||
() -> getBiomeActuator().actuate(x, z, vbiomes, multicore)
|
||||
);
|
||||
burst().burst(multicore,
|
||||
() -> getCaveModifier().modify(x, z, vblocks, multicore),
|
||||
() -> getDecorantActuator().actuate(x, z, blocks, multicore),
|
||||
() -> getRavineModifier().modify(x, z, vblocks, multicore)
|
||||
);
|
||||
|
||||
getPostModifier().modify(x, z, vblocks, multicore);
|
||||
|
||||
burst().burst(multicore,
|
||||
() -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore),
|
||||
() -> getDepositModifier().modify(x, z, vblocks, multicore)
|
||||
);
|
||||
}
|
||||
|
||||
getPostModifier().modify(x, z, vblocks, multicore);
|
||||
|
||||
burst().burst(multicore,
|
||||
() -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore),
|
||||
() -> getDepositModifier().modify(x, z, vblocks, multicore)
|
||||
);
|
||||
|
||||
getMetrics().getTotal().put(p.getMilliseconds());
|
||||
generated.incrementAndGet();
|
||||
|
||||
@@ -18,107 +18,82 @@
|
||||
|
||||
package com.volmit.iris.engine.data.cache;
|
||||
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.scheduling.IrisLock;
|
||||
import com.volmit.iris.Iris;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class AtomicCache<T> {
|
||||
private transient volatile T t;
|
||||
private transient volatile long a;
|
||||
private transient volatile int validations;
|
||||
private final IrisLock check;
|
||||
private final IrisLock time;
|
||||
private final IrisLock write;
|
||||
private final boolean nullSupport;
|
||||
private transient final AtomicReference<T> t;
|
||||
private transient final AtomicBoolean set;
|
||||
private transient final ReentrantLock lock;
|
||||
private transient final boolean nullSupport;
|
||||
|
||||
public AtomicCache() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public AtomicCache(boolean nullSupport) {
|
||||
set = nullSupport ? new AtomicBoolean() : null;
|
||||
t = new AtomicReference<>();
|
||||
lock = new ReentrantLock();
|
||||
this.nullSupport = nullSupport;
|
||||
check = new IrisLock("Check");
|
||||
write = new IrisLock("Write");
|
||||
time = new IrisLock("Time");
|
||||
validations = 0;
|
||||
a = -1;
|
||||
t = null;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
check.lock();
|
||||
write.lock();
|
||||
time.lock();
|
||||
a = -1;
|
||||
t = null;
|
||||
time.unlock();
|
||||
write.unlock();
|
||||
check.unlock();
|
||||
t.set(null);
|
||||
|
||||
if(nullSupport)
|
||||
{
|
||||
set.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
public T aquire(Supplier<T> t) {
|
||||
if (nullSupport) {
|
||||
return aquireNull(t);
|
||||
if(this.t.get() != null)
|
||||
{
|
||||
return this.t.get();
|
||||
}
|
||||
|
||||
if (this.t != null && validations > 1000) {
|
||||
return this.t;
|
||||
else if(nullSupport && set.get())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.t != null && M.ms() - a > 1000) {
|
||||
if (this.t != null) {
|
||||
//noinspection NonAtomicOperationOnVolatileField
|
||||
validations++;
|
||||
lock.lock();
|
||||
|
||||
if(this.t.get() != null)
|
||||
{
|
||||
lock.unlock();
|
||||
return this.t.get();
|
||||
}
|
||||
|
||||
else if(nullSupport && set.get())
|
||||
{
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.t.set(t.get());
|
||||
|
||||
if(nullSupport)
|
||||
{
|
||||
set.set(true);
|
||||
}
|
||||
|
||||
return this.t;
|
||||
}
|
||||
|
||||
check.lock();
|
||||
|
||||
if (this.t == null) {
|
||||
write.lock();
|
||||
this.t = t.get();
|
||||
|
||||
time.lock();
|
||||
|
||||
if (a == -1) {
|
||||
a = M.ms();
|
||||
}
|
||||
|
||||
time.unlock();
|
||||
write.unlock();
|
||||
catch(Throwable e)
|
||||
{
|
||||
Iris.error("Atomic cache failure!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
check.unlock();
|
||||
return this.t;
|
||||
}
|
||||
lock.unlock();
|
||||
|
||||
public T aquireNull(Supplier<T> t) {
|
||||
if (validations > 1000) {
|
||||
return this.t;
|
||||
}
|
||||
|
||||
if (M.ms() - a > 1000) {
|
||||
//noinspection NonAtomicOperationOnVolatileField
|
||||
validations++;
|
||||
return this.t;
|
||||
}
|
||||
|
||||
check.lock();
|
||||
write.lock();
|
||||
this.t = t.get();
|
||||
|
||||
time.lock();
|
||||
|
||||
if (a == -1) {
|
||||
a = M.ms();
|
||||
}
|
||||
|
||||
time.unlock();
|
||||
write.unlock();
|
||||
check.unlock();
|
||||
return this.t;
|
||||
return t.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,8 +198,8 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
private final transient AtomicCache<KMap<String, IrisBiomeGeneratorLink>> genCache = new AtomicCache<>();
|
||||
private final transient AtomicCache<KMap<String, Integer>> genCacheMax = new AtomicCache<>();
|
||||
private final transient AtomicCache<KMap<String, Integer>> genCacheMin = new AtomicCache<>();
|
||||
private final transient AtomicCache<KList<IrisObjectPlacement>> surfaceObjectsCache = new AtomicCache<>(false);
|
||||
private final transient AtomicCache<KList<IrisObjectPlacement>> carveObjectsCache = new AtomicCache<>(false);
|
||||
private final transient AtomicCache<KList<IrisObjectPlacement>> surfaceObjectsCache = new AtomicCache<>();
|
||||
private final transient AtomicCache<KList<IrisObjectPlacement>> carveObjectsCache = new AtomicCache<>();
|
||||
private final transient AtomicCache<Color> cacheColor = new AtomicCache<>();
|
||||
private final transient AtomicCache<Color> cacheColorObjectDensity = new AtomicCache<>();
|
||||
private final transient AtomicCache<Color> cacheColorDecoratorLoad = new AtomicCache<>();
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
||||
import com.volmit.iris.engine.platform.BukkitChunkGenerator;
|
||||
import com.volmit.iris.engine.platform.HeadlessGenerator;
|
||||
@@ -65,8 +66,24 @@ public class HeadlessWorld {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public HeadlessGenerator generate() {
|
||||
return new HeadlessGenerator(this);
|
||||
Engine e = null;
|
||||
|
||||
if(getWorld().tryGetRealWorld())
|
||||
{
|
||||
if(IrisToolbelt.isIrisWorld(getWorld().realWorld()))
|
||||
{
|
||||
e = IrisToolbelt.access(getWorld().realWorld()).getEngine();
|
||||
}
|
||||
}
|
||||
|
||||
if(e != null)
|
||||
{
|
||||
Iris.info("Using Existing Engine " + getWorld().name() + " for Headless Pregeneration.");
|
||||
}
|
||||
|
||||
return e != null ? new HeadlessGenerator(this, e) : new HeadlessGenerator(this);
|
||||
}
|
||||
|
||||
public World load() {
|
||||
@@ -81,7 +98,8 @@ public class HeadlessWorld {
|
||||
}
|
||||
|
||||
public static HeadlessWorld from(World world) {
|
||||
return new HeadlessWorld(world.getName(), IrisToolbelt.access(world).getEngine().getTarget().getDimension(), world.getSeed());
|
||||
return new HeadlessWorld(world.getName(), IrisToolbelt.access(world)
|
||||
.getEngine().getTarget().getDimension(), world.getSeed());
|
||||
}
|
||||
|
||||
public static HeadlessWorld from(String name, String dimension, long seed) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.volmit.iris.util.collection.KList;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -61,6 +62,24 @@ public class IrisWorld {
|
||||
.environment(world.getEnvironment());
|
||||
}
|
||||
|
||||
public boolean tryGetRealWorld()
|
||||
{
|
||||
if(hasRealWorld())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
World w = Bukkit.getWorld(name);
|
||||
|
||||
if(w != null)
|
||||
{
|
||||
realWorld = w;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasRealWorld() {
|
||||
return realWorld != null;
|
||||
}
|
||||
|
||||
@@ -176,6 +176,8 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
|
||||
@Override
|
||||
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
|
||||
|
||||
|
||||
try {
|
||||
if(lastSeed != world.getSeed())
|
||||
{
|
||||
|
||||
@@ -24,16 +24,20 @@ import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||
import com.volmit.iris.core.pregenerator.PregenTask;
|
||||
import com.volmit.iris.engine.IrisEngine;
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.data.chunk.MCATerrainChunk;
|
||||
import com.volmit.iris.engine.data.chunk.TerrainChunk;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineTarget;
|
||||
import com.volmit.iris.engine.framework.WrongEngineBroException;
|
||||
import com.volmit.iris.engine.object.common.HeadlessWorld;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.documentation.RegionCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.nbt.mca.MCAFile;
|
||||
import com.volmit.iris.util.nbt.mca.MCAUtil;
|
||||
import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
@@ -56,12 +60,17 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
private final NBTWorld writer;
|
||||
private final MultiBurst burst;
|
||||
private final Engine engine;
|
||||
private final long rkey = RNG.r.lmax();
|
||||
|
||||
public HeadlessGenerator(HeadlessWorld world) {
|
||||
this(world, new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), world.isStudio()));
|
||||
}
|
||||
|
||||
public HeadlessGenerator(HeadlessWorld world, Engine engine) {
|
||||
this.engine = engine;
|
||||
this.world = world;
|
||||
burst = MultiBurst.burst;
|
||||
writer = new NBTWorld(world.getWorld().worldFolder());
|
||||
engine = new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), isStudio());
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
@@ -79,6 +88,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
getEngine().generate(x * 16, z * 16,
|
||||
Hunk.view((ChunkGenerator.ChunkData) tc), Hunk.view((ChunkGenerator.BiomeGrid) tc),
|
||||
false);
|
||||
chunk.cleanupPalettesAndBlockStates();
|
||||
} catch (Throwable e) {
|
||||
Iris.error("======================================");
|
||||
e.printStackTrace();
|
||||
@@ -102,7 +112,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
@RegionCoordinates
|
||||
public void generateRegion(int x, int z, PregenListener listener) {
|
||||
BurstExecutor e = burst.burst(1024);
|
||||
MCAFile f = writer.getMCA(x, x);
|
||||
MCAFile f = writer.getMCA(x, z);
|
||||
PregenTask.iterateRegion(x, z, (ii, jj) -> e.queue(() -> {
|
||||
if (listener != null) {
|
||||
listener.onChunkGenerating(ii, jj);
|
||||
@@ -132,7 +142,6 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
getEngine().close();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user