Merge remote-tracking branch 'origin/Development' into Development

This commit is contained in:
Vatuu
2022-09-21 01:49:58 +02:00
43 changed files with 10971 additions and 293 deletions

View File

@@ -0,0 +1,27 @@
package com.volmit.iris.util.cache;
import com.volmit.iris.util.data.ChunkCache;
import com.volmit.iris.util.function.Function2;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.Function;
public class ChunkCache2D<T> {
private final AtomicReferenceArray<T> cache;
public ChunkCache2D() {
this.cache = new AtomicReferenceArray<>(256);
}
public T get(int x, int z, Function2<Integer, Integer, T> resolver) {
int key = ((z & 15) * 16) + (x & 15);
T t = cache.get(key);
if(t == null) {
t = resolver.apply(x, z);
cache.set(key, t);
}
return t;
}
}

View File

@@ -0,0 +1,34 @@
package com.volmit.iris.util.cache;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.context.ChunkedDataCache;
import com.volmit.iris.util.data.KCache;
import com.volmit.iris.util.function.Function2;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.scheduling.ChronoLatch;
import it.unimi.dsi.fastutil.longs.Long2LongMaps;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
public class WorldCache2D<T> {
private final KCache<Long, ChunkCache2D<T>> chunks;
private final Function2<Integer, Integer, T> resolver;
public WorldCache2D(Function2<Integer, Integer, T> resolver) {
this.resolver = resolver;
chunks = new KCache<>((x) -> new ChunkCache2D<>(), 1024);
}
public T get(int x, int z) {
ChunkCache2D<T> chunk = chunks.get(Cache.key(x >> 4, z >> 4));
return chunk.get(x, z, resolver);
}
public long getSize() {
return chunks.getSize() * 256L;
}
}

View File

@@ -3,6 +3,7 @@ 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.collection.KMap;
import com.volmit.iris.util.documentation.BlockCoordinates;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.MultiBurst;
@@ -28,6 +29,7 @@ public class ChunkContext {
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);

View File

@@ -1,12 +1,18 @@
package com.volmit.iris.util.context;
import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.documentation.BlockCoordinates;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.stream.ProceduralStream;
import lombok.Data;
import java.util.HashSet;
@Data
public class ChunkedDataCache<T> {
private final int x;
private final int z;
private final KSet<T> uniques;
private final Object[] data;
private final boolean cache;
private final ProceduralStream<T> stream;
@@ -21,6 +27,7 @@ public class ChunkedDataCache<T> {
this.cache = cache;
this.x = x;
this.z = z;
this.uniques = cache ? new KSet<>() : null;
if(cache) {
data = new Object[256];
int i,j;
@@ -29,7 +36,11 @@ public class ChunkedDataCache<T> {
int finalI = i;
for(j = 0; j < 16; j++) {
int finalJ = j;
burst.queue(() -> data[(finalJ * 16) + finalI] = stream.get(x+ finalI, z+ finalJ));
burst.queue(() -> {
T t = stream.get(x+ finalI, z+ finalJ);
data[(finalJ * 16) + finalI] = t;
uniques.add(t);
});
}
}
}

View File

@@ -24,6 +24,10 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.math.RollingSequence;
import java.time.Duration;
import java.time.temporal.TemporalUnit;
import java.util.concurrent.TimeUnit;
public class KCache<K, V> implements MeteredCache {
private final long max;
private CacheLoader<K, V> loader;
@@ -46,7 +50,6 @@ public class KCache<K, V> implements MeteredCache {
return Caffeine
.newBuilder()
.maximumSize(max)
.softValues()
.initialCapacity((int) (max))
.build((k) -> loader == null ? null : loader.load(k));
}

View File

@@ -65,8 +65,7 @@ public class ChunkDataHunkHolder extends AtomicHunk<BlockData> {
for(int k = 0; k < getDepth(); k++) {
BlockData b = super.getRaw(j, i, k);
if(b != null)
{
if(b != null) {
chunk.setBlock(j, i + chunk.getMinHeight(), k, b);
}
}

View File

@@ -18,12 +18,14 @@
package com.volmit.iris.util.hunk.view;
import com.volmit.iris.util.data.B;
import com.volmit.iris.util.hunk.Hunk;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.ChunkData;
@SuppressWarnings("ClassCanBeRecord")
public class ChunkDataHunkView implements Hunk<BlockData> {
private static final BlockData AIR = B.getAir();
private final ChunkData chunk;
public ChunkDataHunkView(ChunkData chunk) {
@@ -54,17 +56,44 @@ public class ChunkDataHunkView implements Hunk<BlockData> {
chunk.setRegion(x1, y1 + chunk.getMinHeight(), z1, x2, y2 + chunk.getMinHeight(), z2, t);
}
public BlockData get(int x, int y, int z) {
return getRaw(x, y, z);
}
public void set(int x, int y, int z, BlockData t) {
setRaw(x, y, z, t);
}
@Override
public void setRaw(int x, int y, int z, BlockData t) {
if(t == null) {
return;
}
chunk.setBlock(x, y + chunk.getMinHeight(), z, t);
try {
chunk.setBlock(x, y + chunk.getMinHeight(), z, t);
}
catch(Throwable ignored)
{
}
}
@Override
public BlockData getRaw(int x, int y, int z) {
return chunk.getBlockData(x, y + chunk.getMinHeight(), z);
try {
return chunk.getBlockData(x, y + chunk.getMinHeight(), z);
}
catch(Throwable e)
{
}
return AIR;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -22,31 +22,7 @@ import com.volmit.iris.util.function.NoiseProvider;
public class Starcast {
public static double starcast(int x, int z, double r, double checks, boolean optimized, NoiseProvider n) {
if(optimized) {
if(checks == 3) return sc3(x, z, r, n);
else if(checks == 5) return sc5(x, z, r, n);
else if(checks == 6) return sc6(x, z, r, n);
else if(checks == 7) return sc7(x, z, r, n);
else if(checks == 9) return sc9(x, z, r, n);
else if(checks == 12) return sc12(x, z, r, n);
else if(checks == 24) return sc24(x, z, r, n);
else if(checks == 32) return sc32(x, z, r, n);
else if(checks == 48) return sc48(x, z, r, n);
else if(checks == 64) return sc64(x, z, r, n);
}
double m = 360D / checks;
double v = 0;
for(int i = 0; i < 360; i += m) {
double sin = Math.sin(Math.toRadians(i));
double cos = Math.cos(Math.toRadians(i));
double cx = x + ((r * cos) - (r * sin));
double cz = z + ((r * sin) + (r * cos));
v += n.noise(cx, cz);
}
return v / checks;
return CompiledStarcast.getStarcast((float)x, (float)z, (float)r, (float)checks, n);
}
public static double starcast(int x, int z, double r, double checks, NoiseProvider n) {

View File

@@ -0,0 +1,31 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.bukkit.block.Biome;
@Data
@AllArgsConstructor
public class MatterBiomeInject {
private final boolean custom;
private final Integer biomeId;
private final Biome biome;
}

View File

@@ -0,0 +1,80 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.matter.MatterCavern;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.block.Biome;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class BiomeInjectMatter extends RawMatter<MatterBiomeInject> {
public BiomeInjectMatter() {
this(1, 1, 1);
}
@Override
public Palette<MatterBiomeInject> getGlobalPalette() {
return null;
}
public BiomeInjectMatter(int width, int height, int depth) {
super(width, height, depth, MatterBiomeInject.class);
}
public static MatterBiomeInject get(Biome biome)
{
return get(false, 0, biome);
}
public static MatterBiomeInject get(int customBiome) {
return get(true, customBiome, null);
}
public static MatterBiomeInject get(boolean custom, int customBiome, Biome biome) {
return new MatterBiomeInject(custom, customBiome, biome);
}
@Override
public void writeNode(MatterBiomeInject b, DataOutputStream dos) throws IOException {
dos.writeBoolean(b.isCustom());
if(b.isCustom()) {
dos.writeShort(b.getBiomeId());
}
else {
dos.writeByte(b.getBiome().ordinal());
}
}
@Override
public MatterBiomeInject readNode(DataInputStream din) throws IOException {
boolean b = din.readBoolean();
int id = b ? din.readShort() : 0;
Biome biome = !b ? Biome.values()[din.readByte()] : Biome.PLAINS;
return new MatterBiomeInject(b, id, biome);
}
}

View File

@@ -25,6 +25,7 @@ import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IRare;
import com.volmit.iris.engine.object.IrisStyledRange;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.context.ChunkContext;
import com.volmit.iris.util.function.Function2;
import com.volmit.iris.util.function.Function3;
import com.volmit.iris.util.function.Function4;
@@ -62,6 +63,7 @@ import com.volmit.iris.util.stream.interpolation.Interpolated;
import com.volmit.iris.util.stream.sources.FunctionStream;
import com.volmit.iris.util.stream.utility.CachedStream2D;
import com.volmit.iris.util.stream.utility.CachedStream3D;
import com.volmit.iris.util.stream.utility.ContextInjectingStream;
import com.volmit.iris.util.stream.utility.NullSafeStream;
import com.volmit.iris.util.stream.utility.ProfiledStream;
import com.volmit.iris.util.stream.utility.SemaphoreStream;
@@ -135,12 +137,18 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
return new AddingStream<>(this, a);
}
default ProceduralStream<T> contextInjecting(Function3<ChunkContext, Integer, Integer, T> contextAccessor) {
//return this;
return new ContextInjectingStream<>(this, contextAccessor);
}
default ProceduralStream<T> add(ProceduralStream<Double> a) {
return add2D((x, z) -> a.get(x, z));
}
default ProceduralStream<T> waste(String name) {
return new WasteDetector<T>(this, name);
return this;
//return new WasteDetector<T>(this, name);
}
default ProceduralStream<T> subtract(ProceduralStream<Double> a) {

View File

@@ -23,6 +23,7 @@ import com.volmit.iris.core.service.PreservationSVC;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.cache.WorldCache2D;
import com.volmit.iris.util.data.KCache;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.hunk.storage.ArrayHunk;
@@ -31,7 +32,7 @@ import com.volmit.iris.util.stream.ProceduralStream;
public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStream<T>, MeteredCache {
private final ProceduralStream<T> stream;
private final KCache<Long, T> cache;
private final WorldCache2D<T> cache;
private final Engine engine;
private boolean chunked = true;
@@ -39,7 +40,7 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
super();
this.stream = stream;
this.engine = engine;
cache = new KCache<>(k -> stream.get(Cache.keyX(k), Cache.keyZ(k)), size);
cache = new WorldCache2D<>(stream::get);
Iris.service(PreservationSVC.class).registerCache(this);
}
@@ -56,7 +57,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));
return cache.get((int) x, (int) z);
}
@Override
@@ -71,12 +72,12 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
@Override
public KCache<?, ?> getRawCache() {
return cache;
return null;
}
@Override
public long getMaxSize() {
return cache.getMaxSize();
return 256 * 32;
}
@Override

View File

@@ -0,0 +1,53 @@
package com.volmit.iris.util.stream.utility;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.context.ChunkContext;
import com.volmit.iris.util.context.IrisContext;
import com.volmit.iris.util.function.Function3;
import com.volmit.iris.util.stream.BasicStream;
import com.volmit.iris.util.stream.ProceduralStream;
import java.util.concurrent.atomic.AtomicInteger;
public class ContextInjectingStream<T> extends BasicStream<T> {
private final Function3<ChunkContext, Integer, Integer, T> contextAccessor;
public ContextInjectingStream(ProceduralStream<T> stream, Function3<ChunkContext, Integer, Integer, T> contextAccessor) {
super(stream);
this.contextAccessor = contextAccessor;
}
@Override
public T get(double x, double z) {
IrisContext context = IrisContext.get();
if(context != null) {
ChunkContext chunkContext = context.getChunkContext();
if(chunkContext != null && (int)x >> 4 == chunkContext.getX() >> 4 && (int)z >> 4 == chunkContext.getZ() >> 4) {
T t = contextAccessor.apply(chunkContext, (int)x&15, (int)z&15);
if(t != null) {
return t;
}
}
}
return getTypedSource().get(x, z);
}
@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);
}
}