This commit is contained in:
Daniel Mills
2020-07-28 20:49:35 -04:00
parent bccb4e154d
commit 7d4b980e59
16 changed files with 337 additions and 26 deletions

View File

@@ -57,12 +57,12 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
masterFracture = CNG.signature(rng.nextParallelRNG(13)).scale(0.12);
}
protected IrisBiome getCachedBiome(int x, int z)
protected IrisBiome getCachedInternalBiome(int x, int z)
{
return biomeCache[(z << 4) | x];
}
protected void cacheBiome(int x, int z, IrisBiome b)
protected void cacheInternalBiome(int x, int z, IrisBiome b)
{
biomeCache[(z << 4) | x] = b;
}

View File

@@ -1,6 +1,7 @@
package com.volmit.iris.generator;
import java.lang.reflect.Method;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Chunk;
import org.bukkit.entity.Player;
@@ -11,6 +12,7 @@ import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.BiomeResult;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.RNG;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -20,11 +22,21 @@ import lombok.EqualsAndHashCode;
public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisContext
{
private Method initLighting;
private ReentrantLock lock;
private KMap<Player, IrisBiome> b = new KMap<>();
public IrisChunkGenerator(String dimensionName, int threads)
{
super(dimensionName, threads);
lock = new ReentrantLock();
}
@Override
protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid)
{
lock.lock();
super.onGenerate(random, x, z, data, grid);
lock.unlock();
}
@Override

View File

@@ -22,6 +22,8 @@ import com.volmit.iris.util.HeightMap;
import com.volmit.iris.util.IObjectPlacer;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.NastyRunnable;
import com.volmit.iris.util.PrecisionStopwatch;
import com.volmit.iris.util.RNG;
import lombok.Data;
@@ -37,6 +39,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
protected AtomicWorldData ceilingParallaxMap;
private MasterLock masterLock;
private ReentrantLock lock = new ReentrantLock();
private ReentrantLock lockq = new ReentrantLock();
private int sliverBuffer;
public ParallaxChunkGenerator(String dimensionName, int threads)
@@ -154,7 +157,10 @@ 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)
{
setCaching(false);
getSliverCache().clear();
super.onPostGenerate(random, x, z, data, grid, height, biomeMap);
PrecisionStopwatch p = PrecisionStopwatch.start();
getBiomeHitCache().clear();
if(getDimension().isPlaceObjects())
@@ -164,11 +170,13 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
getParallaxChunk(x, z).inject(data);
setSliverBuffer(getSliverCache().size());
getParallaxChunk(x, z).setWorldGenerated(true);
getSliverCache().clear();
getMasterLock().clear();
}
p.end();
getMetrics().getParallax().put(p.getMilliseconds());
super.onPostParallaxPostGenerate(random, x, z, data, grid, height, biomeMap);
setCaching(true);
}
protected void injectBiomeSky(int x, int z, BiomeGrid grid)
@@ -193,7 +201,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
if(min < max)
{
IrisBiome biome = getCachedBiome(i, j);
IrisBiome biome = getCachedInternalBiome(i, j);
for(int g = min; g <= max; g++)
{
@@ -208,6 +216,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
{
String key = "par." + x + "." + "z";
ChunkPosition rad = Iris.data.getObjectLoader().getParallaxSize();
KList<NastyRunnable> q = new KList<>();
for(int ii = x - (rad.getX() / 2); ii <= x + (rad.getX() / 2); ii++)
{
@@ -237,14 +246,25 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
for(IrisObjectPlacement k : b.getObjects())
{
placeObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + g++) * i * j) + i - j + 3569222));
int gg = g++;
lockq.lock();
q.add(() ->
{
placeObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 3569222));
});
lockq.unlock();
}
for(IrisDepositGenerator k : getDimension().getDeposits())
{
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this);
lockq.lock();
q.add(() ->
{
k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this);
});
lockq.unlock();
}
}
@@ -252,7 +272,12 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
{
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this);
lockq.lock();
q.add(() ->
{
k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this);
});
lockq.unlock();
}
}
@@ -260,7 +285,12 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
{
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this);
lockq.lock();
q.add(() ->
{
k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this);
});
lockq.unlock();
}
}
@@ -283,7 +313,13 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
for(IrisObjectPlacement k : biome.getObjects())
{
placeCaveObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + g++) * i * j) + i - j + 1869322));
int gg = g++;
lockq.lock();
q.add(() ->
{
placeCaveObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1869322));
});
lockq.unlock();
}
}
});
@@ -293,6 +329,15 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
}
getAccelerant().waitFor(key);
lockq.lock();
for(NastyRunnable i : q)
{
getAccelerant().queue(key + "-obj", i);
}
lockq.unlock();
getAccelerant().waitFor(key + "-obj");
}
public void placeObject(IrisObjectPlacement o, int x, int z, RNG rng)

View File

@@ -1,5 +1,7 @@
package com.volmit.iris.generator;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.World;
import com.volmit.iris.Iris;
@@ -8,6 +10,7 @@ import com.volmit.iris.object.atomics.AtomicSliverMap;
import com.volmit.iris.util.BiomeMap;
import com.volmit.iris.util.GroupedExecutor;
import com.volmit.iris.util.HeightMap;
import com.volmit.iris.util.PrecisionStopwatch;
import com.volmit.iris.util.RNG;
import lombok.Data;
@@ -19,11 +22,19 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator
{
private GroupedExecutor accelerant;
private int threads;
protected boolean unsafe;
protected int cacheX;
protected int cacheZ;
private ReentrantLock genlock;
public ParallelChunkGenerator(String dimensionName, int threads)
{
super(dimensionName);
unsafe = false;
cacheX = 0;
cacheZ = 0;
this.threads = threads;
genlock = new ReentrantLock();
}
public void changeThreadCount(int tc)
@@ -52,11 +63,16 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator
protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid)
{
genlock.lock();
cacheX = x;
cacheZ = z;
PrecisionStopwatch p = PrecisionStopwatch.start();
AtomicSliverMap map = new AtomicSliverMap();
HeightMap height = new HeightMap();
String key = "c" + x + "," + z;
BiomeMap biomeMap = new BiomeMap();
int ii, jj;
unsafe = true;
for(ii = 0; ii < 16; ii++)
{
@@ -78,7 +94,11 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator
accelerant.waitFor(key);
map.write(data, grid, height);
getMetrics().getTerrain().put(p.getMilliseconds());
p = PrecisionStopwatch.start();
unsafe = false;
onPostGenerate(random, x, z, data, grid, height, biomeMap);
genlock.unlock();
}
protected void onClose()
@@ -92,6 +112,11 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator
changeThreadCount(threads);
}
public boolean isSafe()
{
return !unsafe;
}
@Override
public boolean isParallelCapable()
{

View File

@@ -6,14 +6,18 @@ import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.Iris;
import com.volmit.iris.layer.post.PostFloatingNippleDeleter;
import com.volmit.iris.layer.post.PostNippleSmoother;
import com.volmit.iris.layer.post.PostPotholeFiller;
import com.volmit.iris.layer.post.PostSlabber;
import com.volmit.iris.layer.post.PostWallPatcher;
import com.volmit.iris.layer.post.PostWaterlogger;
import com.volmit.iris.object.IrisDimension;
import com.volmit.iris.util.CaveResult;
import com.volmit.iris.util.IPostBlockAccess;
import com.volmit.iris.util.IrisPostBlockFilter;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.PrecisionStopwatch;
import com.volmit.iris.util.RNG;
public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator implements IPostBlockAccess
@@ -41,9 +45,11 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
{
super.onInit(world, rng);
filters.add(new PostNippleSmoother(this));
filters.add(new PostFloatingNippleDeleter(this));
filters.add(new PostPotholeFiller(this));
filters.add(new PostWallPatcher(this));
filters.add(new PostSlabber(this));
filters.add(new PostWallPatcher(this));
filters.add(new PostWaterlogger(this));
}
@Override
@@ -61,6 +67,8 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
currentPostZ = z;
int rx, i, j;
PrecisionStopwatch p = PrecisionStopwatch.start();
for(i = 0; i < 16; i++)
{
rx = (x * 16) + i;
@@ -84,6 +92,14 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
}
getAccelerant().waitFor(postKey);
p.end();
getMetrics().getPost().put(p.getMilliseconds());
}
@Override
public void updateHeight(int x, int z, int h)
{
getCacheHeightMap()[(z << 4) | x] = h;
}
@Override
@@ -127,4 +143,10 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
{
return getHighest(x, z, true);
}
@Override
public KList<CaveResult> caveFloors(int x, int z)
{
return getCaves(x, z);
}
}

View File

@@ -1,5 +1,7 @@
package com.volmit.iris.generator;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.Bisected;
@@ -33,10 +35,18 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
private long lastChunkLoad = M.ms();
private GenLayerCave glCave;
private RNG rockRandom;
private int[] cacheHeightMap;
private IrisBiome[] cacheTrueBiome;
private ReentrantLock cacheLock;
private boolean caching;
public TerrainChunkGenerator(String dimensionName, int threads)
{
super(dimensionName, threads);
cacheHeightMap = new int[256];
cacheTrueBiome = new IrisBiome[256];
caching = true;
cacheLock = new ReentrantLock();
}
public void onInit(World world, RNG rng)
@@ -67,9 +77,16 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
int height = (int) Math.round(noise) + fluidHeight;
IrisRegion region = sampleRegion(rx, rz);
IrisBiome biome = sampleTrueBiome(rx, rz).getBiome();
if(caching)
{
cacheLock.lock();
cacheTrueBiome[(z << 4) | x] = biome;
cacheHeightMap[(z << 4) | x] = height;
cacheLock.unlock();
}
KList<BlockData> layers = biome.generateLayers(wx, wz, masterRandom, height, height - getFluidHeight());
KList<BlockData> seaLayers = biome.isSea() ? biome.generateSeaLayers(wx, wz, masterRandom, fluidHeight - height) : new KList<>();
cacheBiome(x, z, biome);
cacheInternalBiome(x, z, biome);
// Set ground biome (color) to HEIGHT - HEIGHT+3
for(int k = Math.max(height, fluidHeight); k < Math.max(height, fluidHeight) + 3; k++)
@@ -461,6 +478,11 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
return focus();
}
if(isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ)
{
return new BiomeResult(cacheTrueBiome[((z & 15) << 4) | (x & 15)], 0);
}
double wx = getModifiedX(x, z);
double wz = getModifiedZ(x, z);
IrisRegion region = sampleRegion(x, z);
@@ -508,6 +530,11 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
public double getTerrainHeight(int x, int z)
{
if(isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ)
{
return cacheHeightMap[((z & 15) << 4) | (x & 15)];
}
return getNoiseHeight(x, z) + getFluidHeight();
}