mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-06 15:56:27 +00:00
Fixes
This commit is contained in:
51
src/main/java/com/volmit/iris/util/context/ChunkContext.java
Normal file
51
src/main/java/com/volmit/iris/util/context/ChunkContext.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.volmit.iris.util.context;
|
||||
|
||||
import com.volmit.iris.engine.IrisComplex;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisRegion;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import lombok.Data;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
@Data
|
||||
public class ChunkContext {
|
||||
private final int x;
|
||||
private final int z;
|
||||
private ChunkedDataCache<Double> height;
|
||||
private ChunkedDataCache<IrisBiome> biome;
|
||||
private ChunkedDataCache<IrisBiome> cave;
|
||||
private ChunkedDataCache<BlockData> rock;
|
||||
private ChunkedDataCache<BlockData> fluid;
|
||||
private ChunkedDataCache<IrisRegion> region;
|
||||
|
||||
@BlockCoordinates
|
||||
public ChunkContext(int x, int z, IrisComplex c) {
|
||||
this(x, z, c, true);
|
||||
}
|
||||
@BlockCoordinates
|
||||
public ChunkContext(int x, int z, IrisComplex c, boolean cache) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
if(cache) {
|
||||
BurstExecutor b = MultiBurst.burst.burst();
|
||||
height = new ChunkedDataCache<>(b, c.getHeightStream(), x, z);
|
||||
biome = new ChunkedDataCache<>(b, c.getTrueBiomeStream(), x, z);
|
||||
cave = new ChunkedDataCache<>(b, c.getCaveBiomeStream(), x, z);
|
||||
rock = new ChunkedDataCache<>(b, c.getRockStream(), x, z);
|
||||
fluid = new ChunkedDataCache<>(b, c.getFluidStream(), x, z);
|
||||
region = new ChunkedDataCache<>(b, c.getRegionStream(), x, z);
|
||||
b.complete();
|
||||
}
|
||||
|
||||
else {
|
||||
height = new ChunkedDataCache<>(null, c.getHeightStream(), x, z, false);
|
||||
biome = new ChunkedDataCache<>(null, c.getTrueBiomeStream(), x, z, false);
|
||||
cave = new ChunkedDataCache<>(null, c.getCaveBiomeStream(), x, z, false);
|
||||
rock = new ChunkedDataCache<>(null, c.getRockStream(), x, z, false);
|
||||
fluid = new ChunkedDataCache<>(null, c.getFluidStream(), x, z, false);
|
||||
region = new ChunkedDataCache<>(null, c.getRegionStream(), x, z, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.volmit.iris.util.context;
|
||||
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
|
||||
public class ChunkedDataCache<T> {
|
||||
private final int x;
|
||||
private final int z;
|
||||
private final Object[] data;
|
||||
private final boolean cache;
|
||||
private final ProceduralStream<T> stream;
|
||||
|
||||
@BlockCoordinates
|
||||
public ChunkedDataCache(BurstExecutor burst, ProceduralStream<T> stream, int x, int z) {
|
||||
this(burst, stream, x, z, true);
|
||||
}
|
||||
@BlockCoordinates
|
||||
public ChunkedDataCache(BurstExecutor burst, ProceduralStream<T> stream, int x, int z, boolean cache) {
|
||||
this.stream = stream;
|
||||
this.cache = cache;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
if(cache) {
|
||||
data = new Object[256];
|
||||
int i,j;
|
||||
|
||||
for(i = 0; i < 16; i++) {
|
||||
int finalI = i;
|
||||
for(j = 0; j < 16; j++) {
|
||||
int finalJ = j;
|
||||
burst.queue(() -> data[(finalJ * 16) + finalI] = stream.get(x+ finalI, z+ finalJ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
data = new Object[0];
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@BlockCoordinates
|
||||
public T get(int x, int z) {
|
||||
if(!cache) {
|
||||
return stream.get(this.x + x, this.z + z);
|
||||
}
|
||||
|
||||
T t = (T) data[(z * 16) + x];
|
||||
return t == null ? stream.get(this.x + x, this.z + z) : t;
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,26 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class IrisContext {
|
||||
private static final KMap<Thread, IrisContext> context = new KMap<>();
|
||||
private static ChronoLatch cl = new ChronoLatch(60000);
|
||||
private final Engine engine;
|
||||
private ChunkContext chunkContext;
|
||||
|
||||
public IrisContext(Engine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
public static IrisContext getOr(Engine engine) {
|
||||
IrisContext c = get();
|
||||
|
||||
if(c == null) {
|
||||
c = new IrisContext(engine);
|
||||
touch(c);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public static IrisContext get() {
|
||||
return context.get(Thread.currentThread());
|
||||
|
||||
@@ -30,6 +30,9 @@ import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.function.Function4;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.GridLock;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.stream.arithmetic.AddingStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.ClampedStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.CoordinateBitShiftLeftStream;
|
||||
@@ -63,9 +66,11 @@ import com.volmit.iris.util.stream.utility.NullSafeStream;
|
||||
import com.volmit.iris.util.stream.utility.ProfiledStream;
|
||||
import com.volmit.iris.util.stream.utility.SemaphoreStream;
|
||||
import com.volmit.iris.util.stream.utility.SynchronizedStream;
|
||||
import com.volmit.iris.util.stream.utility.WasteDetector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@@ -111,7 +116,7 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
|
||||
}
|
||||
|
||||
default ProceduralStream<T> profile() {
|
||||
return profile(10);
|
||||
return profile(256);
|
||||
}
|
||||
|
||||
default ProceduralStream<T> profile(int memory) {
|
||||
@@ -134,6 +139,10 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
|
||||
return add2D((x, z) -> a.get(x, z));
|
||||
}
|
||||
|
||||
default ProceduralStream<T> waste(String name) {
|
||||
return new WasteDetector<T>(this, name);
|
||||
}
|
||||
|
||||
default ProceduralStream<T> subtract(ProceduralStream<Double> a) {
|
||||
return subtract2D((x, z) -> a.get(x, z));
|
||||
}
|
||||
@@ -406,6 +415,48 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
|
||||
}, Interpolated.DOUBLE);
|
||||
}
|
||||
|
||||
default Hunk<T> fastFill2DParallel(int x, int z) {
|
||||
Hunk<T> hunk = Hunk.newAtomicHunk(16, 16, 1);
|
||||
BurstExecutor e = MultiBurst.burst.burst(256);
|
||||
int i,j;
|
||||
|
||||
for(i = 0; i < 16; i++) {
|
||||
for(j = 0; j < 16; j++) {
|
||||
int fi = i;
|
||||
int fj = j;
|
||||
e.queue(() -> hunk.setRaw(fi, fj, 0, get(x+ fi, z+ fj)));
|
||||
}
|
||||
}
|
||||
|
||||
e.complete();
|
||||
return hunk;
|
||||
}
|
||||
|
||||
default void fastFill2DParallel(Hunk<T> hunk, BurstExecutor e, int x, int z) {
|
||||
int i,j;
|
||||
|
||||
for(i = 0; i < 16; i++) {
|
||||
for(j = 0; j < 16; j++) {
|
||||
int fi = i;
|
||||
int fj = j;
|
||||
e.queue(() -> hunk.setRaw(fi, fj, 0, get(x+ fi, z+ fj)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default Hunk<T> fastFill2D(int x, int z) {
|
||||
Hunk<T> hunk = Hunk.newArrayHunk(16, 16, 1);
|
||||
int i,j;
|
||||
|
||||
for(i = 0; i < 16; i++) {
|
||||
for(j = 0; j < 16; j++) {
|
||||
hunk.setRaw(i, j, 0, get(x+ i, z+ j));
|
||||
}
|
||||
}
|
||||
|
||||
return hunk;
|
||||
}
|
||||
|
||||
default ProceduralStream<T> fit(double inMin, double inMax, double min, double max) {
|
||||
return new FittedStream<T>(this, inMin, inMax, min, max);
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
|
||||
|
||||
@Override
|
||||
public T get(double x, double z) {
|
||||
//return stream.get(x, z);
|
||||
return cache.get(Cache.key((int) x, (int) z));
|
||||
}
|
||||
|
||||
|
||||
@@ -34,11 +34,13 @@ public class ProfiledStream<T> extends BasicStream<T> {
|
||||
public static final AtomicInteger ids = new AtomicInteger();
|
||||
private final int id;
|
||||
private final RollingSequence metrics;
|
||||
public static final KList<ProfiledStream<?>> profiles = new KList<>();
|
||||
|
||||
public ProfiledStream(ProceduralStream<T> stream, int memory) {
|
||||
super(stream);
|
||||
this.metrics = new RollingSequence(memory);
|
||||
this.id = ids.getAndAdd(1);
|
||||
profiles.add(this);
|
||||
}
|
||||
|
||||
public static void print(Consumer<String> printer, ProceduralStream<?> stream) {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.volmit.iris.util.stream.utility;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class WasteDetector<T> extends BasicStream<T> {
|
||||
public static final boolean checking = false;
|
||||
private static final KMap<String, Integer> allAccesses = new KMap<>();
|
||||
private static final KMap<String, List<Throwable>> allThrows = new KMap<>();
|
||||
private final AtomicInteger accesses;
|
||||
private final String name;
|
||||
|
||||
public WasteDetector(ProceduralStream<T> stream, String name) {
|
||||
super(stream);
|
||||
this.name = name;
|
||||
accesses = new AtomicInteger(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(double x, double z) {
|
||||
if(checking)
|
||||
{
|
||||
if(x == 7 && z == 7) {
|
||||
// AHHHAAA!
|
||||
allAccesses.compute(name, (k, v) -> v == null ? 1 : v + 1);
|
||||
try {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
catch(RuntimeException e) {
|
||||
allThrows.computeIfAbsent(name, (k) -> new KList<>()).add(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return getTypedSource().get(x, z);
|
||||
}
|
||||
|
||||
public static void printAll() {
|
||||
if(checking)
|
||||
{
|
||||
Iris.warn("=========================================================");
|
||||
for(String i : allAccesses.sortKNumber().reverse()) {
|
||||
Iris.warn(i + ": " + allAccesses.get(i) + " Time(s)");
|
||||
}
|
||||
Iris.warn("=========================================================");
|
||||
for(String i : allAccesses.sortKNumber().reverse()) {
|
||||
Iris.warn("======== "+ i + " ========");
|
||||
for(Throwable j : allThrows.get(i)) {
|
||||
j.printStackTrace();
|
||||
}
|
||||
Iris.warn("---------------------------------------------------------");
|
||||
}
|
||||
Iris.warn("=========================================================");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(double x, double y, double z) {
|
||||
return getTypedSource().get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double toDouble(T t) {
|
||||
return getTypedSource().toDouble(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T fromDouble(double d) {
|
||||
return getTypedSource().fromDouble(d);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user