mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +00:00
Iris Complex
This commit is contained in:
parent
af29b2833f
commit
ed40dc34cf
86
src/main/java/com/volmit/iris/gen/v2/IrisComplex.java
Normal file
86
src/main/java/com/volmit/iris/gen/v2/IrisComplex.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package com.volmit.iris.gen.v2;
|
||||||
|
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
|
||||||
|
import com.volmit.iris.manager.IrisDataManager;
|
||||||
|
import com.volmit.iris.object.InferredType;
|
||||||
|
import com.volmit.iris.object.IrisBiome;
|
||||||
|
import com.volmit.iris.object.IrisDimension;
|
||||||
|
import com.volmit.iris.object.IrisRegion;
|
||||||
|
import com.volmit.iris.object.NoiseStyle;
|
||||||
|
import com.volmit.iris.util.RNG;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class IrisComplex
|
||||||
|
{
|
||||||
|
private ProceduralStream<IrisRegion> regionStream;
|
||||||
|
private ProceduralStream<InferredType> bridgeStream;
|
||||||
|
private ProceduralStream<IrisBiome> landBiomeStream;
|
||||||
|
private ProceduralStream<IrisBiome> seaBiomeStream;
|
||||||
|
private ProceduralStream<IrisBiome> shoreBiomeStream;
|
||||||
|
private ProceduralStream<IrisBiome> baseBiomeStream;
|
||||||
|
|
||||||
|
public IrisComplex()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProceduralStream<IrisBiome> getBiomeStream(InferredType type)
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case CAVE:
|
||||||
|
break;
|
||||||
|
case DEFER:
|
||||||
|
break;
|
||||||
|
case LAKE:
|
||||||
|
break;
|
||||||
|
case LAND:
|
||||||
|
return landBiomeStream;
|
||||||
|
case RIVER:
|
||||||
|
break;
|
||||||
|
case SEA:
|
||||||
|
return seaBiomeStream;
|
||||||
|
case SHORE:
|
||||||
|
return shoreBiomeStream;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flash(long seed, IrisDimension dimension, IrisDataManager data)
|
||||||
|
{
|
||||||
|
RNG rng = new RNG(seed);
|
||||||
|
//@builder
|
||||||
|
regionStream = NoiseStyle.CELLULAR.stream(rng.nextRNG())
|
||||||
|
.zoom(4)
|
||||||
|
.select(dimension.getRegions())
|
||||||
|
.convertCached((s) -> data.getRegionLoader().load(s));
|
||||||
|
landBiomeStream = regionStream.convertCached((r)
|
||||||
|
-> NoiseStyle.CELLULAR.stream(new RNG((long) (seed + 10000 * r.getLandBiomeZoom())))
|
||||||
|
.zoom(r.getLandBiomeZoom())
|
||||||
|
.select(r.getLandBiomes())
|
||||||
|
.convertCached((s) -> data.getBiomeLoader().load(s))
|
||||||
|
).convertAware2D((str, x, z) -> str.get(x, z));
|
||||||
|
seaBiomeStream = regionStream.convertCached((r)
|
||||||
|
-> NoiseStyle.CELLULAR.stream(new RNG((long) (seed + 20000 * r.getSeaBiomeZoom())))
|
||||||
|
.zoom(r.getSeaBiomeZoom())
|
||||||
|
.select(r.getSeaBiomes())
|
||||||
|
.convertCached((s) -> data.getBiomeLoader().load(s))
|
||||||
|
).convertAware2D((str, x, z) -> str.get(x, z));
|
||||||
|
shoreBiomeStream = regionStream.convertCached((r)
|
||||||
|
-> NoiseStyle.CELLULAR.stream(new RNG((long) (seed + 30000 * r.getShoreBiomeZoom())))
|
||||||
|
.zoom(r.getShoreBiomeZoom())
|
||||||
|
.select(r.getShoreBiomes())
|
||||||
|
.convertCached((s) -> data.getBiomeLoader().load(s))
|
||||||
|
).convertAware2D((str, x, z) -> str.get(x, z));
|
||||||
|
bridgeStream = NoiseStyle.CELLULAR.stream(new RNG(seed + 4000))
|
||||||
|
.convert((v) -> v >= dimension.getLandChance() ? InferredType.SEA : InferredType.LAND);
|
||||||
|
baseBiomeStream = bridgeStream.convertAware2D((t, x, z) -> t.equals(InferredType.SEA)
|
||||||
|
? seaBiomeStream.get(x, z) : landBiomeStream.get(x, z));
|
||||||
|
//@done
|
||||||
|
}
|
||||||
|
}
|
34
src/main/java/com/volmit/iris/gen/v2/IrisGenerator.java
Normal file
34
src/main/java/com/volmit/iris/gen/v2/IrisGenerator.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.volmit.iris.gen.v2;
|
||||||
|
|
||||||
|
import org.bukkit.block.Biome;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.Hunk;
|
||||||
|
import com.volmit.iris.manager.IrisDataManager;
|
||||||
|
import com.volmit.iris.object.IrisDimension;
|
||||||
|
import com.volmit.iris.util.RNG;
|
||||||
|
|
||||||
|
public class IrisGenerator
|
||||||
|
{
|
||||||
|
private long seed;
|
||||||
|
private IrisDataManager data;
|
||||||
|
private IrisDimension dimension;
|
||||||
|
private IrisComplex complex;
|
||||||
|
|
||||||
|
public IrisGenerator(long seed, IrisDimension dimension, IrisDataManager data)
|
||||||
|
{
|
||||||
|
this.seed = seed;
|
||||||
|
flash();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flash()
|
||||||
|
{
|
||||||
|
complex.flash(seed, dimension, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generate(int x, int z, Hunk<BlockData> blocks, Hunk<Biome> biomes)
|
||||||
|
{
|
||||||
|
RNG rng = new RNG((((long) x) << 32) | (z & 0xffffffffL));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,8 @@ package com.volmit.iris.gen.v2;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -28,10 +30,10 @@ public class TestGen
|
|||||||
}).convertCached((m) -> m.createBlockData());
|
}).convertCached((m) -> m.createBlockData());
|
||||||
ProceduralStream<Double> terrain = NoiseStyle.CELLULAR.stream(1337)
|
ProceduralStream<Double> terrain = NoiseStyle.CELLULAR.stream(1337)
|
||||||
.fit(1, 32)
|
.fit(1, 32)
|
||||||
.offset(1000, 1000)
|
.zoom(1.75)
|
||||||
.zoom(2.5)
|
.interpolate().bilinear(4)
|
||||||
.interpolate().starcast(8, 9)
|
.into().starcast(4, 9);
|
||||||
.into().bilinear(8);
|
|
||||||
//@done
|
//@done
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -39,7 +41,7 @@ public class TestGen
|
|||||||
{
|
{
|
||||||
ChunkData c = createChunkData(world);
|
ChunkData c = createChunkData(world);
|
||||||
Hunk<BlockData> data = Hunk.view(c);
|
Hunk<BlockData> data = Hunk.view(c);
|
||||||
terrain.fillUp2D(data, x * 16, z * 16, rock);
|
terrain.fill2D(data, x * 16, z * 16, rock);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,10 @@ import java.util.List;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import com.volmit.iris.gen.v2.scaffold.Hunk;
|
import com.volmit.iris.gen.v2.scaffold.Hunk;
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.stream.AwareConversionStream2D;
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.stream.AwareConversionStream3D;
|
||||||
import com.volmit.iris.gen.v2.scaffold.stream.CachedConversionStream;
|
import com.volmit.iris.gen.v2.scaffold.stream.CachedConversionStream;
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.stream.CachedStream2D;
|
||||||
import com.volmit.iris.gen.v2.scaffold.stream.ClampedStream;
|
import com.volmit.iris.gen.v2.scaffold.stream.ClampedStream;
|
||||||
import com.volmit.iris.gen.v2.scaffold.stream.ConversionStream;
|
import com.volmit.iris.gen.v2.scaffold.stream.ConversionStream;
|
||||||
import com.volmit.iris.gen.v2.scaffold.stream.FittedStream;
|
import com.volmit.iris.gen.v2.scaffold.stream.FittedStream;
|
||||||
@ -13,6 +16,8 @@ import com.volmit.iris.gen.v2.scaffold.stream.OffsetStream;
|
|||||||
import com.volmit.iris.gen.v2.scaffold.stream.RoundingStream;
|
import com.volmit.iris.gen.v2.scaffold.stream.RoundingStream;
|
||||||
import com.volmit.iris.gen.v2.scaffold.stream.SelectionStream;
|
import com.volmit.iris.gen.v2.scaffold.stream.SelectionStream;
|
||||||
import com.volmit.iris.gen.v2.scaffold.stream.ZoomStream;
|
import com.volmit.iris.gen.v2.scaffold.stream.ZoomStream;
|
||||||
|
import com.volmit.iris.util.Function3;
|
||||||
|
import com.volmit.iris.util.Function4;
|
||||||
|
|
||||||
public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T>
|
public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T>
|
||||||
{
|
{
|
||||||
@ -21,11 +26,26 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T>
|
|||||||
return new RoundingStream(this);
|
return new RoundingStream(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default ProceduralStream<T> cache2D(int maxSize)
|
||||||
|
{
|
||||||
|
return new CachedStream2D<T>(this, maxSize);
|
||||||
|
}
|
||||||
|
|
||||||
default <V> ProceduralStream<V> convert(Function<T, V> converter)
|
default <V> ProceduralStream<V> convert(Function<T, V> converter)
|
||||||
{
|
{
|
||||||
return new ConversionStream<T, V>(this, converter);
|
return new ConversionStream<T, V>(this, converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default <V> ProceduralStream<V> convertAware2D(Function3<T, Double, Double, V> converter)
|
||||||
|
{
|
||||||
|
return new AwareConversionStream2D<T, V>(this, converter);
|
||||||
|
}
|
||||||
|
|
||||||
|
default <V> ProceduralStream<V> convertAware3D(Function4<T, Double, Double, Double, V> converter)
|
||||||
|
{
|
||||||
|
return new AwareConversionStream3D<T, V>(this, converter);
|
||||||
|
}
|
||||||
|
|
||||||
default <V> ProceduralStream<V> convertCached(Function<T, V> converter)
|
default <V> ProceduralStream<V> convertCached(Function<T, V> converter)
|
||||||
{
|
{
|
||||||
return new CachedConversionStream<T, V>(this, converter);
|
return new CachedConversionStream<T, V>(this, converter);
|
||||||
@ -56,7 +76,7 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T>
|
|||||||
return new ZoomStream<T>(this, all, all, all);
|
return new ZoomStream<T>(this, all, all, all);
|
||||||
}
|
}
|
||||||
|
|
||||||
default <V> ProceduralStream<V> select(V[] types)
|
default <V> ProceduralStream<V> select(@SuppressWarnings("unchecked") V... types)
|
||||||
{
|
{
|
||||||
return new SelectionStream<V>(this, types);
|
return new SelectionStream<V>(this, types);
|
||||||
}
|
}
|
||||||
@ -111,7 +131,46 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default <V> void fillUp2D(Hunk<V> h, double x, double z, ProceduralStream<V> v)
|
default <V> void fillUp3D(Hunk<V> h, double x, int y, double z, V v)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < h.getWidth(); i++)
|
||||||
|
{
|
||||||
|
for(int k = 0; k < h.getDepth(); k++)
|
||||||
|
{
|
||||||
|
|
||||||
|
for(int j = 0; j < h.getHeight(); j++)
|
||||||
|
{
|
||||||
|
double n = getDouble(i + x, j + y, k + z);
|
||||||
|
|
||||||
|
if(n >= 0.5)
|
||||||
|
{
|
||||||
|
h.set(i, j, k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default <V> void fill3D(Hunk<V> h, double x, int y, double z, ProceduralStream<V> v)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < h.getWidth(); i++)
|
||||||
|
{
|
||||||
|
for(int k = 0; k < h.getDepth(); k++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < h.getHeight(); j++)
|
||||||
|
{
|
||||||
|
double n = getDouble(i + x, j + y, k + z);
|
||||||
|
|
||||||
|
if(n >= 0.5)
|
||||||
|
{
|
||||||
|
h.set(i, j, k, v.get(i + x, j + y, k + z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default <V> void fill2D(Hunk<V> h, double x, double z, ProceduralStream<V> v)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < h.getWidth(); i++)
|
for(int i = 0; i < h.getWidth(); i++)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.volmit.iris.gen.v2.scaffold.stream;
|
||||||
|
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
|
||||||
|
import com.volmit.iris.util.Function3;
|
||||||
|
|
||||||
|
public class AwareConversionStream2D<T, V> extends BasicLayer implements ProceduralStream<V>
|
||||||
|
{
|
||||||
|
private final ProceduralStream<T> stream;
|
||||||
|
private final Function3<T, Double, Double, V> converter;
|
||||||
|
|
||||||
|
public AwareConversionStream2D(ProceduralStream<T> stream, Function3<T, Double, Double, V> converter)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.stream = stream;
|
||||||
|
this.converter = converter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double toDouble(V t)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V fromDouble(double d)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V get(double x, double z)
|
||||||
|
{
|
||||||
|
return converter.apply(stream.get(x, z), x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V get(double x, double y, double z)
|
||||||
|
{
|
||||||
|
return converter.apply(stream.get(x, y, z), x, z);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.volmit.iris.gen.v2.scaffold.stream;
|
||||||
|
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
|
||||||
|
import com.volmit.iris.util.Function4;
|
||||||
|
|
||||||
|
public class AwareConversionStream3D<T, V> extends BasicLayer implements ProceduralStream<V>
|
||||||
|
{
|
||||||
|
private final ProceduralStream<T> stream;
|
||||||
|
private final Function4<T, Double, Double, Double, V> converter;
|
||||||
|
|
||||||
|
public AwareConversionStream3D(ProceduralStream<T> stream, Function4<T, Double, Double, Double, V> converter)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.stream = stream;
|
||||||
|
this.converter = converter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double toDouble(V t)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V fromDouble(double d)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V get(double x, double z)
|
||||||
|
{
|
||||||
|
return converter.apply(stream.get(x, z), x, 0D, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V get(double x, double y, double z)
|
||||||
|
{
|
||||||
|
return converter.apply(stream.get(x, y, z), x, y, z);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package com.volmit.iris.gen.v2.scaffold.stream;
|
||||||
|
|
||||||
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
|
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
|
||||||
|
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
|
||||||
|
import com.volmit.iris.util.ChunkPosition;
|
||||||
|
|
||||||
|
public class CachedStream2D<T> extends BasicLayer implements ProceduralStream<T>
|
||||||
|
{
|
||||||
|
private final ProceduralStream<T> stream;
|
||||||
|
private final LoadingCache<ChunkPosition, T> cache;
|
||||||
|
|
||||||
|
public CachedStream2D(ProceduralStream<T> stream, int size)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.stream = stream;
|
||||||
|
cache = Caffeine.newBuilder().maximumSize(size).build((b) -> stream.get(b.getX(), b.getZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double toDouble(T t)
|
||||||
|
{
|
||||||
|
return stream.toDouble(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T fromDouble(double d)
|
||||||
|
{
|
||||||
|
return stream.fromDouble(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T get(double x, double z)
|
||||||
|
{
|
||||||
|
return cache.get(new ChunkPosition((int) x, (int) z));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T get(double x, double y, double z)
|
||||||
|
{
|
||||||
|
return stream.get(x, y, z);
|
||||||
|
}
|
||||||
|
}
|
@ -25,4 +25,14 @@ public class BlockPosition
|
|||||||
{
|
{
|
||||||
return z >> 4;
|
return z >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean is(int x, int z)
|
||||||
|
{
|
||||||
|
return this.x == x && this.z == z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean is(int x, int y, int z)
|
||||||
|
{
|
||||||
|
return this.x == x && this.y == y && this.z == z;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ public class RNG extends Random
|
|||||||
return new RNG(sx + signature);
|
return new RNG(sx + signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public RNG nextRNG()
|
public RNG nextRNG()
|
||||||
{
|
{
|
||||||
return new RNG(nextLong());
|
return new RNG(nextLong());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user