9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-29 20:19:06 +00:00
This commit is contained in:
Daniel Mills
2020-08-16 13:18:02 -04:00
parent d89371a279
commit 2407c3f2f8
35 changed files with 1531 additions and 505 deletions

View File

@@ -1,6 +1,7 @@
package com.volmit.iris.gen;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
@@ -12,6 +13,7 @@ import org.bukkit.entity.Player;
import com.volmit.iris.Iris;
import com.volmit.iris.IrisContext;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.gen.atomics.AtomicRegionData;
import com.volmit.iris.noise.CNG;
import com.volmit.iris.object.IrisBiome;
@@ -189,18 +191,29 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon
@Override
public void onHotloaded()
{
if(!IrisSettings.get().hotloading)
{
return;
}
if(!isHotloadable())
{
Iris.warn("Hotload skipped (During Chunk Gen). Retrying.");
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, this::onHotloaded);
return;
}
CNG.creates = 0;
getData().dump();
getCache().drop();
Iris.proj.updateWorkspace(getWorkspaceFile());
onHotload();
}
private File getWorkspaceFile()
{
return new File(getDimension().getLoadFile().getParent(), getDimension().getLoadKey() + ".code-workspace");
}
public long guessMemoryUsage()
{
long bytes = 1024 * 1024 * (8 + (getThreads() / 3));
@@ -215,6 +228,7 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon
bytes += i.guessMemoryUsage();
}
bytes += getCache().getSize() * 65;
bytes += parallaxMap.getLoadedChunks().size() * 256 * 4 * 460;
bytes += ceilingParallaxMap.getLoadedChunks().size() * 256 * 4 * 460;
bytes += getSliverBuffer() * 220;

View File

@@ -33,7 +33,8 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator implements IObjectPlacer {
public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator implements IObjectPlacer
{
protected KMap<ChunkPosition, AtomicSliver> sliverCache;
protected AtomicWorldData parallaxMap;
protected KMap<ChunkPosition, AtomicSliver> ceilingSliverCache;
@@ -43,7 +44,8 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
private IrisLock lockq = new IrisLock("ParallaxQueueLock");
private int sliverBuffer;
public ParallaxChunkGenerator(String dimensionName, int threads) {
public ParallaxChunkGenerator(String dimensionName, int threads)
{
super(dimensionName, threads);
sliverCache = new KMap<>();
ceilingSliverCache = new KMap<>();
@@ -51,41 +53,49 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
masterLock = new MasterLock();
}
public void onInit(World world, RNG rng) {
public void onInit(World world, RNG rng)
{
super.onInit(world, rng);
parallaxMap = new AtomicWorldData(world, "floor");
ceilingParallaxMap = new AtomicWorldData(world, "ceiling");
}
protected KMap<ChunkPosition, AtomicSliver> getSliverCache() {
protected KMap<ChunkPosition, AtomicSliver> getSliverCache()
{
return getDimension().isInverted() ? ceilingSliverCache : sliverCache;
}
protected void onClose() {
protected void onClose()
{
super.onClose();
try {
try
{
parallaxMap.unloadAll(true);
ceilingParallaxMap.unloadAll(true);
}
catch (IOException e) {
catch(IOException e)
{
e.printStackTrace();
}
}
@Override
public int getHighest(int x, int z) {
public int getHighest(int x, int z)
{
return getHighest(x, z, false);
}
@Override
public int getHighest(int x, int z, boolean ignoreFluid) {
int h = (int) Math
.round(ignoreFluid ? getTerrainHeight(x, z) : getTerrainWaterHeight(x, z));
public int getHighest(int x, int z, boolean ignoreFluid)
{
int h = (int) Math.round(ignoreFluid ? getTerrainHeight(x, z) : getTerrainWaterHeight(x, z));
if (getDimension().isCarving() && h >= getDimension().getCarvingMin()) {
while (getGlCarve().isCarved(x, h, z)) {
if(getDimension().isCarving() && h >= getDimension().getCarvingMin())
{
while(getGlCarve().isCarved(x, h, z))
{
h--;
}
@@ -96,24 +106,28 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
}
@Override
public void set(int x, int y, int z, BlockData d) {
public void set(int x, int y, int z, BlockData d)
{
getMasterLock().lock((x >> 4) + "." + (z >> 4));
getParallaxSliver(x, z).set(y, d);
getMasterLock().unlock((x >> 4) + "." + (z >> 4));
}
@Override
public BlockData get(int x, int y, int z) {
public BlockData get(int x, int y, int z)
{
BlockData b = sampleSliver(x, z).getBlock().get(y);
return b == null ? AIR : b;
}
@Override
public boolean isSolid(int x, int y, int z) {
public boolean isSolid(int x, int y, int z)
{
return get(x, y, z).getMaterial().isSolid();
}
public AtomicSliver getParallaxSliver(int wx, int wz) {
public AtomicSliver getParallaxSliver(int wx, int wz)
{
getMasterLock().lock("gpc");
getMasterLock().lock((wx >> 4) + "." + (wz >> 4));
AtomicSliverMap map = getParallaxChunk(wx >> 4, wz >> 4);
@@ -124,24 +138,30 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
return sliver;
}
public boolean isParallaxGenerated(int x, int z) {
public boolean isParallaxGenerated(int x, int z)
{
return getParallaxChunk(x, z).isParallaxGenerated();
}
public boolean isWorldGenerated(int x, int z) {
public boolean isWorldGenerated(int x, int z)
{
return getParallaxChunk(x, z).isWorldGenerated();
}
public AtomicWorldData getParallaxMap() {
public AtomicWorldData getParallaxMap()
{
return getDimension().isInverted() ? ceilingParallaxMap : parallaxMap;
}
public AtomicSliverMap getParallaxChunk(int x, int z) {
try {
public AtomicSliverMap getParallaxChunk(int x, int z)
{
try
{
return getParallaxMap().loadChunk(x, z);
}
catch (IOException e) {
catch(IOException e)
{
fail(e);
}
@@ -149,16 +169,18 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
}
@Override
protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height,
BiomeMap biomeMap) {
if (getSliverCache().size() > 20000) {
protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap)
{
if(getSliverCache().size() > 20000)
{
getSliverCache().clear();
}
super.onPostGenerate(random, x, z, data, grid, height, biomeMap);
PrecisionStopwatch p = PrecisionStopwatch.start();
if (getDimension().isPlaceObjects()) {
if(getDimension().isPlaceObjects())
{
onGenerateParallax(random, x, z);
getParallaxChunk(x, z).inject(data);
setSliverBuffer(getSliverCache().size());
@@ -173,50 +195,58 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
getData().getObjectLoader().clean();
}
public IrisStructureResult getStructure(int x, int y, int z) {
public IrisStructureResult getStructure(int x, int y, int z)
{
IrisBiome b = sampleTrueBiome(x, z).getBiome();
IrisRegion r = sampleRegion(x, z);
RNG ro = getMasterRandom().nextParallelRNG(496888 + (x >> 4) + (z >> 4));
int h = (int) Math.round(getTerrainHeight(x, z));
KList<IrisStructurePlacement> p = new KList<>();
for (IrisStructurePlacement i : r.getStructures()) {
if (i.getHeight() > -1) {
if (y >= i.getHeight() && y <= i.getHeight()
+ (i.getStructure(this).getGridHeight() * i.getStructure(this).getMaxLayers())) {
for(IrisStructurePlacement i : r.getStructures())
{
if(i.getHeight() > -1)
{
if(y >= i.getHeight() && y <= i.getHeight() + (i.getStructure(this).getGridHeight() * i.getStructure(this).getMaxLayers()))
{
p.add(i);
}
}
else if (y >= h && y <= i.getStructure(this).getGridHeight() + h) {
else if(y >= h && y <= i.getStructure(this).getGridHeight() + h)
{
p.add(i);
}
}
for (IrisStructurePlacement i : b.getStructures()) {
if (i.getHeight() > -1) {
if (y >= i.getHeight() && y <= i.getHeight()
+ (i.getStructure(this).getGridHeight() * i.getStructure(this).getMaxLayers())) {
for(IrisStructurePlacement i : b.getStructures())
{
if(i.getHeight() > -1)
{
if(y >= i.getHeight() && y <= i.getHeight() + (i.getStructure(this).getGridHeight() * i.getStructure(this).getMaxLayers()))
{
p.add(i);
}
}
else if (y >= h && y <= i.getStructure(this).getGridHeight() + h) {
else if(y >= h && y <= i.getStructure(this).getGridHeight() + h)
{
p.add(i);
}
}
for (IrisStructurePlacement i : p) {
if (!i.hasStructure(ro, x, y, z)) {
for(IrisStructurePlacement i : p)
{
if(!i.hasStructure(ro, x, y, z))
{
continue;
}
int hv = (i.getHeight() == -1 ? 0 : i.getHeight())
+ (Math.floorDiv(y, i.getStructure(this).getGridHeight()) * i.getStructure(this).getGridHeight());
TileResult tile = i.getStructure(this).getTile(ro, Math.floorDiv(i.gridSize(this), x) * i.gridSize(this),
hv, Math.floorDiv(i.gridSize(this), z) * i.gridSize(this));
int hv = (i.getHeight() == -1 ? 0 : i.getHeight()) + (Math.floorDiv(y, i.getStructure(this).getGridHeight()) * i.getStructure(this).getGridHeight());
TileResult tile = i.getStructure(this).getTile(ro, Math.floorDiv(i.gridSize(this), x) * i.gridSize(this), hv, Math.floorDiv(i.gridSize(this), z) * i.gridSize(this));
if (tile != null && tile.getTile() != null) {
if(tile != null && tile.getTile() != null)
{
return new IrisStructureResult(tile.getTile(), i.getStructure(this));
}
}
@@ -224,52 +254,58 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
return null;
}
protected void onGenerateParallax(RNG random, int x, int z) {
protected void onGenerateParallax(RNG random, int x, int z)
{
String key = "par." + x + "." + "z";
ChunkPosition rad = getDimension().getParallaxSize(this);
KList<NastyRunnable> q = new KList<>();
for (int ii = x - (rad.getX() / 2); ii <= x + (rad.getX() / 2); ii++) {
for(int ii = x - (rad.getX() / 2); ii <= x + (rad.getX() / 2); ii++)
{
int i = ii;
for (int jj = z - (rad.getZ() / 2); jj <= z + (rad.getZ() / 2); jj++) {
for(int jj = z - (rad.getZ() / 2); jj <= z + (rad.getZ() / 2); jj++)
{
int j = jj;
if (isParallaxGenerated(ii, jj)) {
if(isParallaxGenerated(ii, jj))
{
continue;
}
if (isWorldGenerated(ii, jj)) {
if(isWorldGenerated(ii, jj))
{
continue;
}
getAccelerant().queue(key, () -> {
getAccelerant().queue(key, () ->
{
IrisBiome b = sampleTrueBiome((i * 16) + 7, (j * 16) + 7).getBiome();
RNG ro = getMasterRandom().nextParallelRNG(496888 + i + j);
int g = 1;
searching: for (IrisBiomeMutation k : getDimension().getMutations()) {
for (int l = 0; l < k.getChecks(); l++) {
IrisBiome sa = sampleTrueBiome(
((i * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius()),
((j * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius())).getBiome();
IrisBiome sb = sampleTrueBiome(
((i * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius()),
((j * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius())).getBiome();
searching: for(IrisBiomeMutation k : getDimension().getMutations())
{
for(int l = 0; l < k.getChecks(); l++)
{
IrisBiome sa = sampleTrueBiome(((i * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius()), ((j * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius())).getBiome();
IrisBiome sb = sampleTrueBiome(((i * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius()), ((j * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius())).getBiome();
if (sa.getLoadKey().equals(sb.getLoadKey())) {
if(sa.getLoadKey().equals(sb.getLoadKey()))
{
continue;
}
if (k.getRealSideA(this).contains(sa.getLoadKey())
&& k.getRealSideB(this).contains(sb.getLoadKey())) {
for (IrisObjectPlacement m : k.getObjects()) {
if(k.getRealSideA(this).contains(sa.getLoadKey()) && k.getRealSideB(this).contains(sb.getLoadKey()))
{
for(IrisObjectPlacement m : k.getObjects())
{
int gg = g++;
lockq.lock();
q.add(() -> {
placeObject(m, i, j, random.nextParallelRNG(
(34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1569962));
q.add(() ->
{
placeObject(m, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1569962));
});
lockq.unlock();
}
@@ -281,52 +317,61 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
IrisRegion r = sampleRegion((i * 16) + 7, (j * 16) + 7);
for (IrisStructurePlacement k : r.getStructures()) {
for(IrisStructurePlacement k : r.getStructures())
{
lockq.lock();
q.add(() -> {
q.add(() ->
{
k.place(this, random.nextParallelRNG(2228), i, j);
});
lockq.unlock();
}
for (IrisStructurePlacement k : b.getStructures()) {
for(IrisStructurePlacement k : b.getStructures())
{
lockq.lock();
q.add(() -> {
q.add(() ->
{
k.place(this, random.nextParallelRNG(-22228), i, j);
});
lockq.unlock();
}
for (IrisObjectPlacement k : b.getObjects()) {
for(IrisObjectPlacement k : b.getObjects())
{
int gg = g++;
lockq.lock();
q.add(() -> {
placeObject(k, i, j, random
.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 3569222));
q.add(() ->
{
placeObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 3569222));
});
lockq.unlock();
}
if (getDimension().isCaves()) {
if(getDimension().isCaves())
{
int bx = (i * 16) + ro.nextInt(16);
int bz = (j * 16) + ro.nextInt(16);
IrisBiome biome = sampleCaveBiome(bx, bz).getBiome();
if (biome == null) {
if(biome == null)
{
return;
}
if (biome.getObjects().isEmpty()) {
if(biome.getObjects().isEmpty())
{
return;
}
for (IrisObjectPlacement k : biome.getObjects()) {
for(IrisObjectPlacement k : biome.getObjects())
{
int gg = g++;
lockq.lock();
q.add(() -> {
placeCaveObject(k, i, j, random
.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1869322));
q.add(() ->
{
placeCaveObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1869322));
});
lockq.unlock();
}
@@ -340,7 +385,8 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
getAccelerant().waitFor(key);
lockq.lock();
for (NastyRunnable i : q) {
for(NastyRunnable i : q)
{
getAccelerant().queue(key + "-obj", i);
}
lockq.unlock();
@@ -348,34 +394,39 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
getAccelerant().waitFor(key + "-obj");
}
public void placeObject(IrisObjectPlacement o, int x, int z, RNG rng) {
for (int i = 0; i < o.getTriesForChunk(rng); i++) {
public void placeObject(IrisObjectPlacement o, int x, int z, RNG rng)
{
for(int i = 0; i < o.getTriesForChunk(rng); i++)
{
rng = rng.nextParallelRNG((i * 3 + 8) - 23040);
o.getSchematic(this, rng).place((x * 16) + rng.nextInt(16), (z * 16) + rng.nextInt(16), this, o, rng);
}
}
public void placeCaveObject(IrisObjectPlacement o, int x, int z, RNG rng) {
for (int i = 0; i < o.getTriesForChunk(rng); i++) {
public void placeCaveObject(IrisObjectPlacement o, int x, int z, RNG rng)
{
for(int i = 0; i < o.getTriesForChunk(rng); i++)
{
rng = rng.nextParallelRNG((i * 3 + 8) - 23040);
int xx = (x * 16) + rng.nextInt(16);
int zz = (z * 16) + rng.nextInt(16);
KList<CaveResult> res = getCaves(xx, zz);
if (res.isEmpty()) {
if(res.isEmpty())
{
continue;
}
o.getSchematic(this, rng).place(xx,
res.get(rng.nextParallelRNG(29345 * (i + 234)).nextInt(res.size())).getFloor() + 2, zz, this, o,
rng);
o.getSchematic(this, rng).place(xx, res.get(rng.nextParallelRNG(29345 * (i + 234)).nextInt(res.size())).getFloor() + 2, zz, this, o, rng);
}
}
public AtomicSliver sampleSliver(int x, int z) {
public AtomicSliver sampleSliver(int x, int z)
{
ChunkPosition key = new ChunkPosition(x, z);
if (getSliverCache().containsKey(key)) {
if(getSliverCache().containsKey(key))
{
return getSliverCache().get(key);
}
@@ -387,7 +438,8 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
}
@Override
public boolean isPreventingDecay() {
public boolean isPreventingDecay()
{
return getDimension().isPreventLeafDecay();
}
}

View File

@@ -17,7 +17,8 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public abstract class ParallelChunkGenerator extends BiomeChunkGenerator {
public abstract class ParallelChunkGenerator extends BiomeChunkGenerator
{
private GroupedExecutor accelerant;
private int threads;
protected int cacheX;
@@ -25,7 +26,8 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator {
private IrisLock genlock;
protected boolean cachingAllowed;
public ParallelChunkGenerator(String dimensionName, int threads) {
public ParallelChunkGenerator(String dimensionName, int threads)
{
super(dimensionName);
cacheX = 0;
cacheZ = 0;
@@ -34,35 +36,37 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator {
cachingAllowed = false;
}
public void changeThreadCount(int tc) {
public void changeThreadCount(int tc)
{
threads = tc;
GroupedExecutor e = accelerant;
accelerant = new GroupedExecutor(threads, Thread.NORM_PRIORITY, "Iris Generator - " + world.getName());
Iris.executors.add(accelerant);
if (e != null) {
if(e != null)
{
e.close();
}
}
protected abstract void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver,
BiomeMap biomeMap, boolean sampled);
protected abstract void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, boolean sampled);
protected void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver,
BiomeMap biomeMap) {
protected void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap)
{
onGenerateColumn(cx, cz, wx, wz, x, z, sliver, biomeMap, false);
}
protected abstract int onSampleColumnHeight(int cx, int cz, int wx, int wz, int x, int z);
protected abstract void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height,
BiomeMap biomeMap);
protected abstract void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap);
protected int sampleHeight(int x, int z) {
protected int sampleHeight(int x, int z)
{
return onSampleColumnHeight(x >> 4, z >> 4, x, z, x & 15, z & 15);
}
protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) {
protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid)
{
genlock.lock();
cacheX = x;
cacheZ = z;
@@ -74,16 +78,19 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator {
BiomeMap biomeMap = new BiomeMap();
int ii, jj;
for (ii = 0; ii < 16; ii++) {
for(ii = 0; ii < 16; ii++)
{
int i = ii;
int wx = (x * 16) + i;
for (jj = 0; jj < 16; jj++) {
for(jj = 0; jj < 16; jj++)
{
int j = jj;
int wz = (z * 16) + j;
AtomicSliver sliver = map.getSliver(i, j);
accelerant.queue(key, () -> {
accelerant.queue(key, () ->
{
onGenerateColumn(x, z, wx, wz, i, j, sliver, biomeMap);
});
}
@@ -97,18 +104,21 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator {
genlock.unlock();
}
protected void onClose() {
protected void onClose()
{
accelerant.close();
Iris.executors.remove(accelerant);
}
public void onInit(World world, RNG rng) {
public void onInit(World world, RNG rng)
{
super.onInit(world, rng);
changeThreadCount(threads);
}
@Override
public boolean isParallelCapable() {
public boolean isParallelCapable()
{
return false;
}
}

View File

@@ -2,6 +2,7 @@ package com.volmit.iris.gen;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.Bisected.Half;
import org.bukkit.block.data.BlockData;
@@ -29,36 +30,42 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
{
private long lastUpdateRequest = M.ms();
private long lastChunkLoad = M.ms();
private GenLayerCave glCave;
private GenLayerCarve glCarve;
private RNG rockRandom;
public TerrainChunkGenerator(String dimensionName, int threads) {
public TerrainChunkGenerator(String dimensionName, int threads)
{
super(dimensionName, threads);
}
public void onInit(World world, RNG rng) {
public void onInit(World world, RNG rng)
{
super.onInit(world, rng);
rockRandom = getMasterRandom().nextParallelRNG(2858678);
glCave = new GenLayerCave(this, rng.nextParallelRNG(238948));
glCarve = new GenLayerCarve(this, rng.nextParallelRNG(968346576));
}
public KList<CaveResult> getCaves(int x, int z) {
public KList<CaveResult> getCaves(int x, int z)
{
return glCave.genCaves(x, z, x & 15, z & 15, null);
}
@Override
protected void onGenerateColumn(int cx, int cz, int rx, int rz, int x, int z, AtomicSliver sliver,
BiomeMap biomeMap, boolean sampled) {
if (x > 15 || x < 0 || z > 15 || z < 0) {
protected void onGenerateColumn(int cx, int cz, int rx, int rz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, boolean sampled)
{
if(x > 15 || x < 0 || z > 15 || z < 0)
{
throw new RuntimeException("Invalid OnGenerate call: x:" + x + " z:" + z);
}
try {
try
{
int highestPlaced = 0;
BlockData block;
@@ -75,27 +82,29 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
BiomeResult biomeResult = sampleTrueBiome(rx, rz, noise);
IrisBiome biome = biomeResult.getBiome();
if (biome == null) {
if(biome == null)
{
throw new RuntimeException("Null Biome!");
}
KList<BlockData> layers = biome.generateLayers(rx, rz, masterRandom, height, height - getFluidHeight());
KList<BlockData> seaLayers = biome.isSea()
? biome.generateSeaLayers(rx, rz, masterRandom, fluidHeight - height)
: new KList<>();
KList<BlockData> seaLayers = biome.isSea() ? biome.generateSeaLayers(rx, rz, masterRandom, fluidHeight - height) : new KList<>();
boolean caverning = false;
KList<Integer> cavernHeights = new KList<>();
int lastCavernHeight = -1;
boolean bxx = false;
// From Height to Bedrock
for (int k = Math.max(height, fluidHeight); k >= 0; k--) {
for(int k = Math.max(height, fluidHeight); k >= 0; k--)
{
boolean cavernSurface = false;
// Bedrock
if (k == 0) {
if (biomeMap != null) {
if(k == 0)
{
if(biomeMap != null)
{
sliver.set(k, biome.getDerivative());
biomeMap.setBiome(x, z, biome);
}
sliver.set(k, BEDROCK);
@@ -103,10 +112,11 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
}
// Carving
if (carvable && glCarve.isCarved(rx, k, rz)) {
if (biomeMap != null) {
if(carvable && glCarve.isCarved(rx, k, rz))
{
if(biomeMap != null)
{
sliver.set(k, biome.getDerivative());
biomeMap.setBiome(x, z, biome);
}
sliver.set(k, CAVE_AIR);
@@ -114,7 +124,8 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
continue;
}
else if (carvable && caverning) {
else if(carvable && caverning)
{
lastCavernHeight = k;
cavernSurface = true;
cavernHeights.add(k);
@@ -124,24 +135,35 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
boolean underwater = k > height && k <= fluidHeight;
// Set Biome
if (biomeMap != null) {
if(!bxx && biomeMap != null)
{
bxx = true;
sliver.set(k, biome.getGroundBiome(masterRandom, rz, k, rx));
biomeMap.setBiome(x, z, biome);
for(int kv = Math.max(height, fluidHeight); kv < Math.min(Math.max(height, fluidHeight) + 16, 255); kv++)
{
Biome skyBiome = biome.getSkyBiome(masterRandom, rz, kv, rx);
sliver.set(kv, biome.getDerivative());
sliver.set(k, skyBiome);
}
}
// Set Sea Material (water/lava)
if (underwater) {
block = seaLayers.hasIndex(fluidHeight - k) ? layers.get(depth)
: getDimension().getFluid(rockRandom, wx, k, wz);
if(underwater)
{
block = seaLayers.hasIndex(fluidHeight - k) ? layers.get(depth) : getDimension().getFluid(rockRandom, wx, k, wz);
}
// Set Surface Material for cavern layer surfaces
else if (layers.hasIndex(lastCavernHeight - k)) {
else if(layers.hasIndex(lastCavernHeight - k))
{
block = layers.get(lastCavernHeight - k);
}
// Set Surface Material for true surface
else {
else
{
block = layers.hasIndex(depth) ? layers.get(depth) : getDimension().getRock(rockRandom, wx, k, wz);
depth++;
}
@@ -151,13 +173,14 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
highestPlaced = Math.max(highestPlaced, k);
// Decorate underwater surface
if (!cavernSurface && (k == height && block.getMaterial().isSolid() && k < fluidHeight)) {
if(!cavernSurface && (k == height && B.isSolid(block.getMaterial()) && k < fluidHeight))
{
decorateUnderwater(biome, sliver, wx, k, wz, rx, rz, block);
}
// Decorate Cavern surfaces, but not the true surface
if ((carvable && cavernSurface) && !(k == Math.max(height, fluidHeight) && block.getMaterial().isSolid()
&& k < 255 && k >= fluidHeight)) {
if((carvable && cavernSurface) && !(k == Math.max(height, fluidHeight) && block.getMaterial().isSolid() && k < 255 && k >= fluidHeight))
{
decorateLand(biome, sliver, wx, k, wz, rx, rz, block);
}
}
@@ -167,31 +190,36 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
IrisBiome caveBiome = glBiome.generateData(InferredType.CAVE, wx, wz, rx, rz, region).getBiome();
// Decorate Cave Biome Height Sections
if (caveBiome != null) {
for (CaveResult i : caveResults) {
for (int j = i.getFloor(); j <= i.getCeiling(); j++) {
if(caveBiome != null)
{
for(CaveResult i : caveResults)
{
for(int j = i.getFloor(); j <= i.getCeiling(); j++)
{
sliver.set(j, caveBiome);
sliver.set(j, caveBiome.getGroundBiome(masterRandom, rz, j, rx));
}
KList<BlockData> floor = caveBiome.generateLayers(wx, wz, rockRandom, i.getFloor() - 2,
i.getFloor() - 2);
KList<BlockData> ceiling = caveBiome.generateLayers(wx + 256, wz + 256, rockRandom,
height - i.getCeiling() - 2, height - i.getCeiling() - 2);
KList<BlockData> floor = caveBiome.generateLayers(wx, wz, rockRandom, i.getFloor() - 2, i.getFloor() - 2);
KList<BlockData> ceiling = caveBiome.generateLayers(wx + 256, wz + 256, rockRandom, height - i.getCeiling() - 2, height - i.getCeiling() - 2);
BlockData blockc = null;
for (int j = 0; j < floor.size(); j++) {
if (j == 0) {
for(int j = 0; j < floor.size(); j++)
{
if(j == 0)
{
blockc = floor.get(j);
}
sliver.set(i.getFloor() - j, floor.get(j));
}
for (int j = ceiling.size() - 1; j > 0; j--) {
for(int j = ceiling.size() - 1; j > 0; j--)
{
sliver.set(i.getCeiling() + j, ceiling.get(j));
}
if (blockc != null && !sliver.isSolid(i.getFloor() + 1)) {
if(blockc != null && !sliver.isSolid(i.getFloor() + 1))
{
decorateCave(caveBiome, sliver, wx, i.getFloor(), wz, rx, rz, blockc);
}
}
@@ -200,76 +228,91 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
block = sliver.get(Math.max(height, fluidHeight));
// Decorate True Surface
if (block.getMaterial().isSolid()) {
if(block.getMaterial().isSolid())
{
decorateLand(biome, sliver, wx, Math.max(height, fluidHeight), wz, rx, rz, block);
}
}
catch (Throwable e) {
catch(Throwable e)
{
fail(e);
}
}
@Override
protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) {
protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid)
{
super.onGenerate(random, x, z, data, grid);
RNG ro = random.nextParallelRNG((x * x * x) - z);
IrisRegion region = sampleRegion((x * 16) + 7, (z * 16) + 7);
IrisBiome biome = sampleTrueBiome((x * 16) + 7, (z * 16) + 7).getBiome();
for (IrisDepositGenerator k : getDimension().getDeposits()) {
for(IrisDepositGenerator k : getDimension().getDeposits())
{
k.generate(data, ro, this);
}
for (IrisDepositGenerator k : region.getDeposits()) {
for (int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) {
for(IrisDepositGenerator k : region.getDeposits())
{
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate(data, ro, this);
}
}
for (IrisDepositGenerator k : biome.getDeposits()) {
for (int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) {
for(IrisDepositGenerator k : biome.getDeposits())
{
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate(data, ro, this);
}
}
}
private void decorateLand(IrisBiome biome, AtomicSliver sliver, double wx, int k, double wz, int rx, int rz,
BlockData block) {
if (!getDimension().isDecorate()) {
private void decorateLand(IrisBiome biome, AtomicSliver sliver, double wx, int k, double wz, int rx, int rz, BlockData block)
{
if(!getDimension().isDecorate())
{
return;
}
int j = 0;
for (IrisBiomeDecorator i : biome.getDecorators()) {
if (i.getPartOf().equals(DecorationPart.SHORE_LINE) && (!touchesSea(rx, rz) || k != getFluidHeight())) {
for(IrisBiomeDecorator i : biome.getDecorators())
{
if(i.getPartOf().equals(DecorationPart.SHORE_LINE) && (!touchesSea(rx, rz) || k != getFluidHeight()))
{
continue;
}
BlockData d = i.getBlockData(getMasterRandom()
.nextParallelRNG((int) (38888 + biome.getRarity() + biome.getName().length() + j++)), rx, rz);
BlockData d = i.getBlockData(getMasterRandom().nextParallelRNG((int) (38888 + biome.getRarity() + biome.getName().length() + j++)), rx, rz);
if (d != null) {
if (!B.canPlaceOnto(d.getMaterial(), block.getMaterial())) {
if(d != null)
{
if(!B.canPlaceOnto(d.getMaterial(), block.getMaterial()))
{
continue;
}
if (d.getMaterial().equals(Material.CACTUS)) {
if (!block.getMaterial().equals(Material.SAND) && !block.getMaterial().equals(Material.RED_SAND)) {
if(d.getMaterial().equals(Material.CACTUS))
{
if(!block.getMaterial().equals(Material.SAND) && !block.getMaterial().equals(Material.RED_SAND))
{
sliver.set(k, B.getBlockData("RED_SAND"));
}
}
if (d.getMaterial().equals(Material.WHEAT) || d.getMaterial().equals(Material.CARROTS)
|| d.getMaterial().equals(Material.POTATOES) || d.getMaterial().equals(Material.MELON_STEM)
|| d.getMaterial().equals(Material.PUMPKIN_STEM)) {
if (!block.getMaterial().equals(Material.FARMLAND)) {
if(d.getMaterial().equals(Material.WHEAT) || d.getMaterial().equals(Material.CARROTS) || d.getMaterial().equals(Material.POTATOES) || d.getMaterial().equals(Material.MELON_STEM) || d.getMaterial().equals(Material.PUMPKIN_STEM))
{
if(!block.getMaterial().equals(Material.FARMLAND))
{
sliver.set(k, B.getBlockData("FARMLAND"));
}
}
if (d instanceof Bisected && k < 254) {
if(d instanceof Bisected && k < 254)
{
Bisected t = ((Bisected) d.clone());
t.setHalf(Half.TOP);
Bisected b = ((Bisected) d.clone());
@@ -278,17 +321,19 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
sliver.set(k + 2, t);
}
else {
int stack = i.getHeight(getMasterRandom().nextParallelRNG(
(int) (39456 + (10000 * i.getChance()) + i.getStackMax() + i.getStackMin() + i.getZoom())),
rx, rz);
else
{
int stack = i.getHeight(getMasterRandom().nextParallelRNG((int) (39456 + (10000 * i.getChance()) + i.getStackMax() + i.getStackMin() + i.getZoom())), rx, rz);
if (stack == 1) {
if(stack == 1)
{
sliver.set(k + 1, d);
}
else if (k < 255 - stack) {
for (int l = 0; l < stack; l++) {
else if(k < 255 - stack)
{
for(int l = 0; l < stack; l++)
{
sliver.set(k + l + 1, d);
}
}
@@ -299,31 +344,36 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
}
}
private void decorateCave(IrisBiome biome, AtomicSliver sliver, double wx, int k, double wz, int rx, int rz,
BlockData block) {
if (!getDimension().isDecorate()) {
private void decorateCave(IrisBiome biome, AtomicSliver sliver, double wx, int k, double wz, int rx, int rz, BlockData block)
{
if(!getDimension().isDecorate())
{
return;
}
int j = 0;
for (IrisBiomeDecorator i : biome.getDecorators()) {
BlockData d = i.getBlockData(
getMasterRandom().nextParallelRNG(2333877 + biome.getRarity() + biome.getName().length() + +j++),
rx, rz);
for(IrisBiomeDecorator i : biome.getDecorators())
{
BlockData d = i.getBlockData(getMasterRandom().nextParallelRNG(2333877 + biome.getRarity() + biome.getName().length() + +j++), rx, rz);
if (d != null) {
if (!B.canPlaceOnto(d.getMaterial(), block.getMaterial())) {
if(d != null)
{
if(!B.canPlaceOnto(d.getMaterial(), block.getMaterial()))
{
continue;
}
if (d.getMaterial().equals(Material.CACTUS)) {
if (!block.getMaterial().equals(Material.SAND) && !block.getMaterial().equals(Material.RED_SAND)) {
if(d.getMaterial().equals(Material.CACTUS))
{
if(!block.getMaterial().equals(Material.SAND) && !block.getMaterial().equals(Material.RED_SAND))
{
sliver.set(k, B.getBlockData("SAND"));
}
}
if (d instanceof Bisected && k < 254) {
if(d instanceof Bisected && k < 254)
{
Bisected t = ((Bisected) d.clone());
t.setHalf(Half.TOP);
Bisected b = ((Bisected) d.clone());
@@ -332,17 +382,21 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
sliver.set(k + 2, t);
}
else {
int stack = i.getHeight(getMasterRandom()
.nextParallelRNG((int) (39456 + (1000 * i.getChance()) + i.getZoom() * 10)), rx, rz);
else
{
int stack = i.getHeight(getMasterRandom().nextParallelRNG((int) (39456 + (1000 * i.getChance()) + i.getZoom() * 10)), rx, rz);
if (stack == 1) {
if(stack == 1)
{
sliver.set(k + 1, d);
}
else if (k < 255 - stack) {
for (int l = 0; l < stack; l++) {
if (sliver.isSolid(k + l + 1)) {
else if(k < 255 - stack)
{
for(int l = 0; l < stack; l++)
{
if(sliver.isSolid(k + l + 1))
{
break;
}
@@ -356,35 +410,38 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
}
}
private void decorateUnderwater(IrisBiome biome, AtomicSliver sliver, double wx, int y, double wz, int rx, int rz,
BlockData block) {
if (!getDimension().isDecorate()) {
private void decorateUnderwater(IrisBiome biome, AtomicSliver sliver, double wx, int y, double wz, int rx, int rz, BlockData block)
{
if(!getDimension().isDecorate())
{
return;
}
int j = 0;
for (IrisBiomeDecorator i : biome.getDecorators()) {
if (biome.getInferredType().equals(InferredType.SHORE)) {
for(IrisBiomeDecorator i : biome.getDecorators())
{
if(biome.getInferredType().equals(InferredType.SHORE))
{
continue;
}
BlockData d = i.getBlockData(
getMasterRandom().nextParallelRNG(2555 + biome.getRarity() + biome.getName().length() + j++), rx,
rz);
BlockData d = i.getBlockData(getMasterRandom().nextParallelRNG(2555 + biome.getRarity() + biome.getName().length() + j++), rx, rz);
if (d != null) {
int stack = i.getHeight(getMasterRandom().nextParallelRNG((int) (239456 + i.getStackMax()
+ i.getStackMin() + i.getVerticalZoom() + i.getZoom() + i.getBlockData().size() + j)), rx, rz);
if(d != null)
{
int stack = i.getHeight(getMasterRandom().nextParallelRNG((int) (239456 + i.getStackMax() + i.getStackMin() + i.getVerticalZoom() + i.getZoom() + i.getBlockData().size() + j)), rx, rz);
if (stack == 1) {
if(stack == 1)
{
sliver.set(i.getPartOf().equals(DecorationPart.SEA_SURFACE) ? (getFluidHeight() + 1) : (y + 1), d);
}
else if (y < getFluidHeight() - stack) {
for (int l = 0; l < stack; l++) {
sliver.set(i.getPartOf().equals(DecorationPart.SEA_SURFACE) ? (getFluidHeight() + 1 + l)
: (y + l + 1), d);
else if(y < getFluidHeight() - stack)
{
for(int l = 0; l < stack; l++)
{
sliver.set(i.getPartOf().equals(DecorationPart.SEA_SURFACE) ? (getFluidHeight() + 1 + l) : (y + l + 1), d);
}
}
@@ -394,22 +451,23 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
}
@Override
protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height,
BiomeMap biomeMap) {
protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap)
{
onPreParallaxPostGenerate(random, x, z, data, grid, height, biomeMap);
}
protected void onPreParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height,
BiomeMap biomeMap) {
protected void onPreParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap)
{
}
protected void onPostParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid,
HeightMap height, BiomeMap biomeMap) {
protected void onPostParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap)
{
}
private double getNoiseHeight(int rx, int rz) {
private double getNoiseHeight(int rx, int rz)
{
double wx = getZoomed(rx);
double wz = getZoomed(rz);
double h = getBiomeHeight(wx, wz, rx, rz);
@@ -417,8 +475,10 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
return h;
}
public BiomeResult sampleTrueBiomeBase(int x, int z, int height) {
if (!getDimension().getFocus().equals("")) {
public BiomeResult sampleTrueBiomeBase(int x, int z, int height)
{
if(!getDimension().getFocus().equals(""))
{
return focus();
}
@@ -428,42 +488,51 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
double sh = region.getShoreHeight(wx, wz);
IrisBiome current = sampleBiome(x, z).getBiome();
if (current.isShore() && height > sh) {
if(current.isShore() && height > sh)
{
return glBiome.generateData(InferredType.LAND, wx, wz, x, z, region);
}
if (current.isShore() || current.isLand() && height <= getDimension().getFluidHeight()) {
if(current.isShore() || current.isLand() && height <= getDimension().getFluidHeight())
{
return glBiome.generateData(InferredType.SEA, wx, wz, x, z, region);
}
if (current.isSea() && height > getDimension().getFluidHeight()) {
if(current.isSea() && height > getDimension().getFluidHeight())
{
return glBiome.generateData(InferredType.LAND, wx, wz, x, z, region);
}
if (height <= getDimension().getFluidHeight()) {
if(height <= getDimension().getFluidHeight())
{
return glBiome.generateData(InferredType.SEA, wx, wz, x, z, region);
}
if (height <= getDimension().getFluidHeight() + sh) {
if(height <= getDimension().getFluidHeight() + sh)
{
return glBiome.generateData(InferredType.SHORE, wx, wz, x, z, region);
}
return glBiome.generateRegionData(wx, wz, x, z, region);
}
public BiomeResult sampleCaveBiome(int x, int z) {
public BiomeResult sampleCaveBiome(int x, int z)
{
double wx = getModifiedX(x, z);
double wz = getModifiedZ(x, z);
return glBiome.generateData(InferredType.CAVE, wx, wz, x, z, sampleRegion(x, z));
}
public BiomeResult sampleTrueBiome(int x, int y, int z) {
if (y < getTerrainHeight(x, z)) {
public BiomeResult sampleTrueBiome(int x, int y, int z)
{
if(y < getTerrainHeight(x, z))
{
double wx = getModifiedX(x, z);
double wz = getModifiedZ(x, z);
BiomeResult r = glBiome.generateData(InferredType.CAVE, wx, wz, x, z, sampleRegion(x, z));
if (r.getBiome() != null) {
if(r.getBiome() != null)
{
return r;
}
}
@@ -471,21 +540,26 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
return sampleTrueBiome(x, z);
}
public BiomeResult sampleTrueBiome(int x, int z) {
public BiomeResult sampleTrueBiome(int x, int z)
{
return sampleTrueBiome(x, z, getTerrainHeight(x, z));
}
@Override
public IrisRegion sampleRegion(int x, int z) {
public IrisRegion sampleRegion(int x, int z)
{
return getCache().getRegion(x, z, () -> super.sampleRegion(x, z));
}
public BiomeResult sampleTrueBiome(int x, int z, double noise) {
if (!getDimension().getFocus().equals("")) {
public BiomeResult sampleTrueBiome(int x, int z, double noise)
{
if(!getDimension().getFocus().equals(""))
{
return focus();
}
return getCache().getBiome(x, z, () -> {
return getCache().getBiome(x, z, () ->
{
double wx = getModifiedX(x, z);
double wz = getModifiedZ(x, z);
IrisRegion region = sampleRegion(x, z);
@@ -494,7 +568,8 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
BiomeResult res = sampleTrueBiomeBase(x, z, height);
IrisBiome current = res.getBiome();
if (current.isSea() && height > getDimension().getFluidHeight() - sh) {
if(current.isSea() && height > getDimension().getFluidHeight() - sh)
{
return glBiome.generateData(InferredType.SHORE, wx, wz, x, z, region);
}
@@ -503,32 +578,38 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
}
@Override
protected int onSampleColumnHeight(int cx, int cz, int rx, int rz, int x, int z) {
protected int onSampleColumnHeight(int cx, int cz, int rx, int rz, int x, int z)
{
return (int) Math.round(getTerrainHeight(rx, rz));
}
private boolean touchesSea(int rx, int rz) {
return isFluidAtHeight(rx + 1, rz) || isFluidAtHeight(rx - 1, rz) || isFluidAtHeight(rx, rz - 1)
|| isFluidAtHeight(rx, rz + 1);
private boolean touchesSea(int rx, int rz)
{
return isFluidAtHeight(rx + 1, rz) || isFluidAtHeight(rx - 1, rz) || isFluidAtHeight(rx, rz - 1) || isFluidAtHeight(rx, rz + 1);
}
public boolean isUnderwater(int x, int z) {
public boolean isUnderwater(int x, int z)
{
return isFluidAtHeight(x, z);
}
public boolean isFluidAtHeight(int x, int z) {
public boolean isFluidAtHeight(int x, int z)
{
return Math.round(getTerrainHeight(x, z)) < getFluidHeight();
}
public int getFluidHeight() {
public int getFluidHeight()
{
return getDimension().getFluidHeight();
}
public double getTerrainHeight(int x, int z) {
public double getTerrainHeight(int x, int z)
{
return getCache().getHeight(x, z, () -> getNoiseHeight(x, z) + getFluidHeight());
}
public double getTerrainWaterHeight(int x, int z) {
public double getTerrainWaterHeight(int x, int z)
{
return Math.max(getTerrainHeight(x, z), getFluidHeight());
}
}

View File

@@ -3,11 +3,13 @@ package com.volmit.iris.gen.atomics;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.BiomeResult;
import com.volmit.iris.util.KMap;
public class AtomicMulticache {
public class AtomicMulticache
{
private final AtomicInteger x;
private final AtomicInteger z;
private final KMap<Long, Double> height;
@@ -18,7 +20,8 @@ public class AtomicMulticache {
private int w = 0;
private int m = 0;
public AtomicMulticache() {
public AtomicMulticache()
{
x = new AtomicInteger(0);
z = new AtomicInteger(0);
height = new KMap<Long, Double>();
@@ -27,83 +30,108 @@ public class AtomicMulticache {
region = new KMap<Long, IrisRegion>();
}
public void targetChunk(int x, int z) {
public void targetChunk(int x, int z)
{
this.x.set(x);
this.z.set(z);
r = 0;
w = 0;
m = 0;
if(!IrisSettings.get().sharedCaching || getSize() > 42000)
{
drop();
}
}
public double getHeight(int x, int z, Supplier<Double> g)
{
return height.compute(pos(x, z), (k, v) ->
{
if(v == null)
{
m++;
w++;
return g.get();
}
r++;
return v;
});
}
public IrisRegion getRegion(int x, int z, Supplier<IrisRegion> g)
{
return region.compute(pos(x, z), (k, v) ->
{
if(v == null)
{
m++;
w++;
return g.get();
}
r++;
return v;
});
}
public BiomeResult getBiome(int x, int z, Supplier<BiomeResult> g)
{
return biome.compute(pos(x, z), (k, v) ->
{
if(v == null)
{
m++;
w++;
return g.get();
}
r++;
return v;
});
}
public BiomeResult getRawBiome(int x, int z, Supplier<BiomeResult> g)
{
return rawBiome.compute(pos(x, z), (k, v) ->
{
if(v == null)
{
m++;
w++;
return g.get();
}
r++;
return v;
});
}
private long pos(int x, int z)
{
return (((long) x) << 32) | (z & 0xffffffffL);
}
public void updateHeight(int x, int z, int h)
{
height.put(pos(x, z), (double) h);
}
public double getSize()
{
return height.size() + region.size() + biome.size() + rawBiome.size();
}
public void drop()
{
height.clear();
region.clear();
biome.clear();
rawBiome.clear();
r = 0;
w = 0;
m = 0;
}
public double getHeight(int x, int z, Supplier<Double> g) {
return height.compute(pos(x, z), (k, v) -> {
if (v == null) {
m++;
w++;
return g.get();
}
r++;
return v;
});
}
public IrisRegion getRegion(int x, int z, Supplier<IrisRegion> g) {
return region.compute(pos(x, z), (k, v) -> {
if (v == null) {
m++;
w++;
return g.get();
}
r++;
return v;
});
}
public BiomeResult getBiome(int x, int z, Supplier<BiomeResult> g) {
return biome.compute(pos(x, z), (k, v) -> {
if (v == null) {
m++;
w++;
return g.get();
}
r++;
return v;
});
}
public BiomeResult getRawBiome(int x, int z, Supplier<BiomeResult> g) {
return rawBiome.compute(pos(x, z), (k, v) -> {
if (v == null) {
m++;
w++;
return g.get();
}
r++;
return v;
});
}
private long pos(int x, int z) {
return (((long) x) << 32) | (z & 0xffffffffL);
}
public void updateHeight(int x, int z, int h) {
height.put(pos(x, z), (double) h);
}
public double getSize() {
return height.size();
}
}

View File

@@ -1,6 +1,7 @@
package com.volmit.iris.gen.layer;
import com.volmit.iris.Iris;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.gen.DimensionChunkGenerator;
import com.volmit.iris.noise.CNG;
import com.volmit.iris.object.InferredType;
@@ -144,7 +145,7 @@ public class GenLayerBiome extends GenLayer {
public BiomeResult implode(double bx, double bz, IrisRegion regionData, CNG parentCell, BiomeResult parent,
int hits) {
if (hits > 9) {
if (hits > IrisSettings.get().maxBiomeChildDepth) {
return parent;
}