Support Getters instead of fields

This commit is contained in:
Daniel Mills 2020-09-04 03:24:52 -04:00
parent b8f58b9cc7
commit dd4edb8ba5
7 changed files with 131 additions and 153 deletions

View File

@ -59,22 +59,22 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
private BlockPosition allowLoot; private BlockPosition allowLoot;
private AtomicMulticache cache; private AtomicMulticache cache;
private IrisDataManager data; private IrisDataManager data;
protected boolean failing; private boolean failing;
protected int task; private int task;
protected boolean dev; private boolean dev;
protected boolean initialized; private boolean initialized;
protected RNG masterRandom; private RNG masterRandom;
protected ChronoLatch perSecond; private ChronoLatch perSecond;
protected ChronoLatch tickLatch; private ChronoLatch tickLatch;
protected ChronoLatch pushLatch; private ChronoLatch pushLatch;
private AtomicCache<IrisDimension> dimCache; private AtomicCache<IrisDimension> dimCache;
protected IrisMetrics metrics; private IrisMetrics metrics;
protected World world; private World world;
protected int generated; private int generated;
protected int ticks; private int ticks;
protected long hlast; private long hlast;
private boolean fastPregen = false; private boolean fastPregen = false;
protected boolean pregenDone; private boolean pregenDone;
private volatile boolean hotloadable = false; private volatile boolean hotloadable = false;
public ContextualChunkGenerator() public ContextualChunkGenerator()
@ -137,7 +137,7 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
public IrisDimension loadDimension(String i) public IrisDimension loadDimension(String i)
{ {
return dimCache.aquire(() -> (getData() == null ? Iris.globaldata : getData()).getDimensionLoader().load(i)); return getDimCache().aquire(() -> (getData() == null ? Iris.globaldata : getData()).getDimensionLoader().load(i));
} }
public IrisGenerator loadGenerator(String i) public IrisGenerator loadGenerator(String i)
@ -158,40 +158,40 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
} }
this.world = world; this.world = world;
data = new IrisDataManager(getWorld().getWorldFolder()); setData(new IrisDataManager(getWorld().getWorldFolder()));
this.masterRandom = new RNG(world.getSeed()); setMasterRandom(new RNG(world.getSeed()));
metrics = new IrisMetrics(128); setMetrics(new IrisMetrics(128));
initialized = true; setInitialized(true);
setTask(Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::tick, 0, 0));
Bukkit.getServer().getPluginManager().registerEvents(this, Iris.instance); Bukkit.getServer().getPluginManager().registerEvents(this, Iris.instance);
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::tick, 0, 0);
onInit(world, masterRandom); onInit(world, masterRandom);
setHotloadable(true); setHotloadable(true);
} }
private void tick() private void tick()
{ {
if(dev) if(isDev())
{ {
if(perSecond.flip()) if(getPerSecond().flip())
{ {
if(generated > (fastPregen ? 1950 : 770)) if(getGenerated() > (isFastPregen() ? 1950 : 770))
{ {
pregenDone = true; setPregenDone(true);
} }
if(pregenDone) if(isPregenDone())
{ {
metrics.getPerSecond().put(generated); getMetrics().getPerSecond().put(generated);
generated = 0; setGenerated(0);
} }
checkHotload(); checkHotload();
if(noLoot.size() > 1024) if(getNoLoot().size() > 1024)
{ {
for(int i = 0; i < 64; i++) for(int i = 0; i < 64; i++)
{ {
noLoot.remove(0); getNoLoot().remove(0);
} }
} }
} }
@ -199,8 +199,8 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
else else
{ {
pregenDone = true; setPregenDone(true);
fastPregen = false; setFastPregen(false);
} }
onTick(ticks++); onTick(ticks++);
@ -243,7 +243,7 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
return; return;
} }
noLoot.addIfMissing(new BlockPosition(e.getBlock().getX(), e.getBlock().getY(), e.getBlock().getZ())); getNoLoot().addIfMissing(new BlockPosition(e.getBlock().getX(), e.getBlock().getY(), e.getBlock().getZ()));
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
@ -333,8 +333,8 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
public void close() public void close()
{ {
noLoot.clear(); getNoLoot().clear();
noLoot.trimToSize(); getNoLoot().trimToSize();
HandlerList.unregisterAll(this); HandlerList.unregisterAll(this);
Bukkit.getScheduler().cancelTask(getTask()); Bukkit.getScheduler().cancelTask(getTask());
onClose(); onClose();
@ -400,10 +400,10 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
public ChunkData generateChunkData(World world, Random no, int x, int z, BiomeGrid biomeGrid) public ChunkData generateChunkData(World world, Random no, int x, int z, BiomeGrid biomeGrid)
{ {
setHotloadable(false); setHotloadable(false);
if(!dev) if(!isDev())
{ {
pregenDone = true; setPregenDone(true);
fastPregen = false; setFastPregen(false);
} }
if(failing) if(failing)
@ -447,14 +447,14 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
public void checkHotload() public void checkHotload()
{ {
if(M.ms() - hlast < 1000) if(M.ms() - getHlast() < 1000)
{ {
return; return;
} }
if(world != null) if(getWorld() != null)
{ {
checkHotload(world); checkHotload(getWorld());
} }
} }
@ -465,11 +465,11 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
return; return;
} }
if(pushLatch.flip()) if(getPushLatch().flip())
{ {
if(this.world == null) if(getWorld() == null)
{ {
this.world = world; setWorld(world);
} }
Iris.hotloader.check((IrisContext) this); Iris.hotloader.check((IrisContext) this);
@ -483,18 +483,18 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
public void onHotload() public void onHotload()
{ {
hlast = M.ms(); setHlast(M.ms());
dimCache.reset(); getDimCache().reset();
} }
protected void fail(Throwable e) protected void fail(Throwable e)
{ {
if(failing) if(isFailing())
{ {
return; return;
} }
failing = true; setFailing(true);
e.printStackTrace(); e.printStackTrace();
J.a(() -> J.a(() ->

View File

@ -22,7 +22,7 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public abstract class DimensionChunkGenerator extends ContextualChunkGenerator public abstract class DimensionChunkGenerator extends ContextualChunkGenerator
{ {
protected String dimensionName; private String dimensionName;
protected static final BlockData AIR = Material.AIR.createBlockData(); protected static final BlockData AIR = Material.AIR.createBlockData();
protected static final BlockData CAVE_AIR = B.get("CAVE_AIR"); protected static final BlockData CAVE_AIR = B.get("CAVE_AIR");
protected static final BlockData BEDROCK = Material.BEDROCK.createBlockData(); protected static final BlockData BEDROCK = Material.BEDROCK.createBlockData();
@ -31,7 +31,7 @@ public abstract class DimensionChunkGenerator extends ContextualChunkGenerator
public DimensionChunkGenerator(String dimensionName) public DimensionChunkGenerator(String dimensionName)
{ {
super(); super();
this.dimensionName = dimensionName; setDimensionName(dimensionName);
} }
public void onPlayerLeft(Player p) public void onPlayerLeft(Player p)
@ -46,14 +46,14 @@ public abstract class DimensionChunkGenerator extends ContextualChunkGenerator
public void onInit(World world, RNG masterRandom) public void onInit(World world, RNG masterRandom)
{ {
if(dimensionName.isEmpty()) if(getDimensionName().isEmpty())
{ {
File folder = new File(world.getWorldFolder(), "iris/dimensions"); File folder = new File(world.getWorldFolder(), "iris/dimensions");
if(!folder.exists()) if(!folder.exists())
{ {
Iris.error("Missing World iris/dimensions folder!"); Iris.error("Missing World iris/dimensions folder!");
dimensionName = "error-missing-dimension"; setDimensionName("error-missing-dimension");
return; return;
} }
@ -61,13 +61,13 @@ public abstract class DimensionChunkGenerator extends ContextualChunkGenerator
{ {
if(i.isFile() && i.getName().endsWith(".json")) if(i.isFile() && i.getName().endsWith(".json"))
{ {
dimensionName = i.getName().replaceAll("\\Q.json\\E", ""); setDimensionName(i.getName().replaceAll("\\Q.json\\E", ""));
return; return;
} }
} }
Iris.error("Missing World iris/dimensions/<dimension-name>.json file. Assuming overworld!"); Iris.error("Missing World iris/dimensions/<dimension-name>.json file. Assuming overworld!");
dimensionName = "error-missing-dimension"; setDimensionName("error-missing-dimension");
fail(new RuntimeException("Missing dimension folder/file in " + folder.getAbsolutePath())); fail(new RuntimeException("Missing dimension folder/file in " + folder.getAbsolutePath()));
} }
@ -76,11 +76,11 @@ public abstract class DimensionChunkGenerator extends ContextualChunkGenerator
public IrisDimension getDimension() public IrisDimension getDimension()
{ {
IrisDimension d = loadDimension(dimensionName); IrisDimension d = loadDimension(getDimensionName());
if(d == null) if(d == null)
{ {
Iris.error("Can't find dimension: " + dimensionName); Iris.error("Can't find dimension: " + getDimensionName());
} }
return d; return d;
@ -118,16 +118,12 @@ public abstract class DimensionChunkGenerator extends ContextualChunkGenerator
public double getModifiedX(int rx, int rz) public double getModifiedX(int rx, int rz)
{ {
return (getDimension().cosRotate() * rx) + (-getDimension().sinRotate() * rz) + return (getDimension().cosRotate() * rx) + (-getDimension().sinRotate() * rz) + getDimension().getCoordFracture(getMasterRandom(), 39392).fitDouble(-getDimension().getCoordFractureDistance() / 2, getDimension().getCoordFractureDistance() / 2, rx, rz);
getDimension().getCoordFracture(masterRandom, 39392).fitDouble(-getDimension().getCoordFractureDistance() / 2, getDimension().getCoordFractureDistance() / 2, rx, rz);
} }
public double getModifiedZ(int rx, int rz) public double getModifiedZ(int rx, int rz)
{ {
return (getDimension().sinRotate() * rx) + (getDimension().cosRotate() * rz) + return (getDimension().sinRotate() * rx) + (getDimension().cosRotate() * rz) + getDimension().getCoordFracture(getMasterRandom(), 39392).fitDouble(-getDimension().getCoordFractureDistance() / 2, getDimension().getCoordFractureDistance() / 2, rx, rz);
getDimension().getCoordFracture(masterRandom, 39392).fitDouble(-getDimension().getCoordFractureDistance() / 2, getDimension().getCoordFractureDistance() / 2, rx, rz);
} }
public double getZoomed(double modified) public double getZoomed(double modified)

View File

@ -2,7 +2,6 @@ package com.volmit.iris.gen;
import java.awt.Color; import java.awt.Color;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Random; import java.util.Random;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -30,7 +29,6 @@ import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.Form; import com.volmit.iris.util.Form;
import com.volmit.iris.util.IrisStructureResult; import com.volmit.iris.util.IrisStructureResult;
import com.volmit.iris.util.KList; import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.PrecisionStopwatch; import com.volmit.iris.util.PrecisionStopwatch;
import com.volmit.iris.util.RNG; import com.volmit.iris.util.RNG;
@ -41,10 +39,8 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisContext public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisContext
{ {
private Method initLighting;
private IrisBiome hb = null; private IrisBiome hb = null;
private IrisRegion hr = null; private IrisRegion hr = null;
private KMap<Player, IrisBiome> b = new KMap<>();
private boolean spawnable = false; private boolean spawnable = false;
public IrisChunkGenerator(String dimensionName, int threads) public IrisChunkGenerator(String dimensionName, int threads)
@ -69,9 +65,9 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
public void retry() public void retry()
{ {
if(failing) if(isFailing())
{ {
failing = false; setFailing(false);
hotload(); hotload();
} }
} }
@ -82,7 +78,7 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
PrecisionStopwatch s = PrecisionStopwatch.start(); PrecisionStopwatch s = PrecisionStopwatch.start();
ChunkData c = super.generateChunkData(world, no, x, z, biomeGrid); ChunkData c = super.generateChunkData(world, no, x, z, biomeGrid);
s.end(); s.end();
metrics.getTotal().put(s.getMilliseconds()); getMetrics().getTotal().put(s.getMilliseconds());
return c; return c;
} }
@ -153,9 +149,9 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
try try
{ {
parallaxMap.saveAll(); getParallaxMap().saveAll();
parallaxMap.getLoadedChunks().clear(); getParallaxMap().getLoadedChunks().clear();
parallaxMap.getLoadedRegions().clear(); getParallaxMap().getLoadedRegions().clear();
} }
catch(IOException e) catch(IOException e)
@ -222,17 +218,17 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
{ {
long bytes = 1024 * 1024 * (8 + (getThreads() / 3)); long bytes = 1024 * 1024 * (8 + (getThreads() / 3));
for(AtomicRegionData i : parallaxMap.getLoadedRegions().values()) for(AtomicRegionData i : getParallaxMap().getLoadedRegions().values())
{ {
bytes += i.guessMemoryUsage(); bytes += i.guessMemoryUsage();
} }
bytes += getCache().getSize() * 65; bytes += getCache().getSize() * 65;
bytes += parallaxMap.getLoadedChunks().size() * 256 * 4 * 460; bytes += getParallaxMap().getLoadedChunks().size() * 256 * 4 * 460;
bytes += getSliverBuffer() * 220; bytes += getSliverBuffer() * 220;
bytes += 823 * getData().getObjectLoader().getTotalStorage(); bytes += 823 * getData().getObjectLoader().getTotalStorage();
return bytes; return bytes / 2;
} }
@Override @Override
@ -314,6 +310,7 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
{ {
getParallaxMap().saveAll(); getParallaxMap().saveAll();
} }
catch(IOException e) catch(IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
@ -438,7 +435,7 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
@Override @Override
protected void onSpawn(EntitySpawnEvent e) protected void onSpawn(EntitySpawnEvent e)
{ {
if(spawnable) if(isSpawnable())
{ {
int x = e.getEntity().getLocation().getBlockX(); int x = e.getEntity().getLocation().getBlockX();
int y = e.getEntity().getLocation().getBlockY(); int y = e.getEntity().getLocation().getBlockY();
@ -500,7 +497,7 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
{ {
for(IrisEntitySpawn i : s) for(IrisEntitySpawn i : s)
{ {
spawnable = false; setSpawnable(false);
if(i.on(this, e.getLocation(), e.getEntityType(), e) != null) if(i.on(this, e.getLocation(), e.getEntityType(), e) != null)
{ {
@ -511,7 +508,7 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
else else
{ {
spawnable = true; setSpawnable(true);
} }
} }

View File

@ -39,8 +39,8 @@ import lombok.EqualsAndHashCode;
public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator implements IObjectPlacer public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator implements IObjectPlacer
{ {
private short cacheID = 0; private short cacheID = 0;
protected KMap<ChunkPosition, AtomicSliver> sliverCache; private KMap<ChunkPosition, AtomicSliver> sliverCache;
protected AtomicWorldData parallaxMap; private AtomicWorldData parallaxMap;
private MasterLock masterLock; private MasterLock masterLock;
private IrisLock flock = new IrisLock("ParallaxLock"); private IrisLock flock = new IrisLock("ParallaxLock");
private IrisLock lock = new IrisLock("ParallaxLock"); private IrisLock lock = new IrisLock("ParallaxLock");
@ -51,21 +51,17 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
public ParallaxChunkGenerator(String dimensionName, int threads) public ParallaxChunkGenerator(String dimensionName, int threads)
{ {
super(dimensionName, threads); super(dimensionName, threads);
sliverCache = new KMap<>(); setSliverCache(new KMap<>());
sliverBuffer = 0; setSliverBuffer(sliverBuffer);
masterLock = new MasterLock(); setMasterLock(new MasterLock());
} }
public void onInit(World world, RNG rng) public void onInit(World world, RNG rng)
{ {
super.onInit(world, rng); super.onInit(world, rng);
parallaxMap = new AtomicWorldData(world); setParallaxMap(new AtomicWorldData(world));
glText = new GenLayerText(this, rng.nextParallelRNG(32485)); setGlText(new GenLayerText(this, rng.nextParallelRNG(32485)));
} setGlUpdate(null);
protected KMap<ChunkPosition, AtomicSliver> getSliverCache()
{
return sliverCache;
} }
protected void onClose() protected void onClose()
@ -74,7 +70,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
try try
{ {
parallaxMap.unloadAll(true); getParallaxMap().unloadAll(true);
} }
catch(IOException e) catch(IOException e)
@ -94,7 +90,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
{ {
getData().preferFolder(getDimension().getLoadFile().getParentFile().getParentFile().getName()); getData().preferFolder(getDimension().getLoadFile().getParentFile().getParentFile().getName());
super.onHotload(); super.onHotload();
cacheID = RNG.r.simax(); setCacheID(RNG.r.simax());
} }
@Override @Override
@ -144,11 +140,6 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
return getParallaxChunk(x, z).isWorldGenerated(); return getParallaxChunk(x, z).isWorldGenerated();
} }
public AtomicWorldData getParallaxMap()
{
return parallaxMap;
}
public AtomicSliverMap getParallaxChunk(int x, int z) public AtomicSliverMap getParallaxChunk(int x, int z)
{ {
try try
@ -169,12 +160,12 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
{ {
List<BlockPopulator> g = super.getDefaultPopulators(world); List<BlockPopulator> g = super.getDefaultPopulators(world);
if(glUpdate == null) if(getGlUpdate() == null)
{ {
glUpdate = new GenLayerUpdate(this, world); setGlUpdate(new GenLayerUpdate(this, world));
} }
g.add(glUpdate); g.add(getGlUpdate());
return g; return g;
} }
@ -199,11 +190,10 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
setSliverBuffer(getSliverCache().size()); setSliverBuffer(getSliverCache().size());
getParallaxChunk(x, z).setWorldGenerated(true); getParallaxChunk(x, z).setWorldGenerated(true);
getMasterLock().clear(); getMasterLock().clear();
p.end(); p.end();
getMetrics().getParallax().put(p.getMilliseconds()); getMetrics().getParallax().put(p.getMilliseconds());
super.onPostParallaxPostGenerate(random, x, z, data, grid, height, biomeMap, map); super.onPostParallaxPostGenerate(random, x, z, data, grid, height, biomeMap, map);
getParallaxMap().clean(ticks); getParallaxMap().clean(getTicks());
getData().getObjectLoader().clean(); getData().getObjectLoader().clean();
} }

View File

@ -20,32 +20,29 @@ public abstract class ParallelChunkGenerator extends DimensionChunkGenerator
{ {
private GroupedExecutor accelerant; private GroupedExecutor accelerant;
private int threads; private int threads;
protected int cacheX; private boolean cachingAllowed;
protected int cacheZ;
protected boolean cachingAllowed;
public ParallelChunkGenerator(String dimensionName, int threads) public ParallelChunkGenerator(String dimensionName, int threads)
{ {
super(dimensionName); super(dimensionName);
cacheX = 0; setThreads(threads);
cacheZ = 0; setCachingAllowed(false);
this.threads = threads;
cachingAllowed = false;
} }
public void changeThreadCount(int tc) public void changeThreadCount(int tc)
{ {
threads = tc; setThreads(tc);
GroupedExecutor e = accelerant; GroupedExecutor e = getAccelerant();
accelerant = new GroupedExecutor(threads, Thread.MAX_PRIORITY, "Iris Generator - " + world.getName()); setAccelerant(new GroupedExecutor(threads, Thread.MAX_PRIORITY, "Iris Generator - " + getWorld().getName()));
Iris.executors.add(accelerant); ;
Iris.executors.add(getAccelerant());
if(e != null) if(e != null)
{ {
e.close(); e.close();
} }
Iris.info("Thread Count changed to " + tc); Iris.info("Thread Count changed to " + getThreads());
} }
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);
@ -68,9 +65,7 @@ public abstract class ParallelChunkGenerator extends DimensionChunkGenerator
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)
{ {
cacheX = x; getCache().targetChunk(x, z);
cacheZ = z;
getCache().targetChunk(cacheX, cacheZ);
PrecisionStopwatch p = PrecisionStopwatch.start(); PrecisionStopwatch p = PrecisionStopwatch.start();
AtomicSliverMap map = new AtomicSliverMap(); AtomicSliverMap map = new AtomicSliverMap();
HeightMap height = new HeightMap(); HeightMap height = new HeightMap();
@ -114,14 +109,14 @@ public abstract class ParallelChunkGenerator extends DimensionChunkGenerator
protected void onClose() protected void onClose()
{ {
accelerant.close(); getAccelerant().close();
Iris.executors.remove(accelerant); Iris.executors.remove(accelerant);
} }
public void onInit(World world, RNG rng) public void onInit(World world, RNG rng)
{ {
super.onInit(world, rng); super.onInit(world, rng);
changeThreadCount(threads); changeThreadCount(getThreads());
} }
@Override @Override

View File

@ -26,15 +26,15 @@ import lombok.EqualsAndHashCode;
public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator implements IPostBlockAccess public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator implements IPostBlockAccess
{ {
private String postKey; private String postKey;
private IrisLock lock; private IrisLock postLock;
private int minPhase; private int minPhase;
private int maxPhase; private int maxPhase;
public PostBlockChunkGenerator(String dimensionName, int threads) public PostBlockChunkGenerator(String dimensionName, int threads)
{ {
super(dimensionName, threads); super(dimensionName, threads);
postKey = "post-" + dimensionName; setPostKey("post-" + dimensionName);
lock = new IrisLock("PostChunkGenerator"); setPostLock(new IrisLock("PostChunkGenerator"));
} }
public void onInit(World world, RNG rng) public void onInit(World world, RNG rng)
@ -156,9 +156,9 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
{ {
if(x >> 4 == currentPostX && z >> 4 == currentPostZ) if(x >> 4 == currentPostX && z >> 4 == currentPostZ)
{ {
lock.lock(); getPostLock().lock();
BlockData d = currentData.getBlockData(x & 15, y, z & 15); BlockData d = currentData.getBlockData(x & 15, y, z & 15);
lock.unlock(); getPostLock().unlock();
return d == null ? AIR : d; return d == null ? AIR : d;
} }
@ -170,9 +170,9 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
{ {
if(x >> 4 == currentPostX && z >> 4 == currentPostZ) if(x >> 4 == currentPostX && z >> 4 == currentPostZ)
{ {
lock.lock(); getPostLock().lock();
currentData.setBlock(x & 15, y, z & 15, d); currentData.setBlock(x & 15, y, z & 15, d);
lock.unlock(); getPostLock().unlock();
} }
else else

View File

@ -45,18 +45,18 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
private long lastChunkLoad = M.ms(); private long lastChunkLoad = M.ms();
private GenLayerCave glCave; private GenLayerCave glCave;
private GenLayerCarve glCarve; private GenLayerCarve glCarve;
protected GenLayerBiome glBiome; private GenLayerBiome glBiome;
private RNG rockRandom; private RNG rockRandom;
protected IrisLock regLock; private IrisLock regionLock;
private KMap<String, IrisGenerator> generators; private KMap<String, IrisGenerator> generators;
protected CNG masterFracture; private CNG masterFracture;
protected ChronoLatch cwarn = new ChronoLatch(1000); private ChronoLatch cwarn = new ChronoLatch(1000);
public TerrainChunkGenerator(String dimensionName, int threads) public TerrainChunkGenerator(String dimensionName, int threads)
{ {
super(dimensionName, threads); super(dimensionName, threads);
generators = new KMap<>(); setGenerators(new KMap<>());
regLock = new IrisLock("BiomeChunkGenerator"); setRegionLock(new IrisLock("BiomeChunkGenerator"));
} }
@Override @Override
@ -64,16 +64,16 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
{ {
super.onInit(world, rng); super.onInit(world, rng);
loadGenerators(); loadGenerators();
buildGenLayers(masterRandom); buildGenLayers(getMasterRandom());
} }
private void buildGenLayers(RNG rng) private void buildGenLayers(RNG rng)
{ {
glBiome = new GenLayerBiome(this, rng.nextParallelRNG(24671)); setGlBiome(new GenLayerBiome(this, rng.nextParallelRNG(24671)));
masterFracture = CNG.signature(rng.nextParallelRNG(13)).scale(0.12); setMasterFracture(CNG.signature(rng.nextParallelRNG(13)).scale(0.12));
rockRandom = getMasterRandom().nextParallelRNG(2858678); setRockRandom(getMasterRandom().nextParallelRNG(2858678));
glCave = new GenLayerCave(this, rng.nextParallelRNG(238948)); setGlCave(new GenLayerCave(this, rng.nextParallelRNG(238948)));
glCarve = new GenLayerCarve(this, rng.nextParallelRNG(968346576)); setGlCarve(new GenLayerCarve(this, rng.nextParallelRNG(968346576)));
} }
public int getCarvedHeight(int x, int z, boolean ignoreFluid) public int getCarvedHeight(int x, int z, boolean ignoreFluid)
@ -144,9 +144,9 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
throw new RuntimeException("Null Biome!"); throw new RuntimeException("Null Biome!");
} }
KList<BlockData> layers = biome.generateLayers(rx, rz, masterRandom, height, height - getFluidHeight()); KList<BlockData> layers = biome.generateLayers(rx, rz, getMasterRandom(), height, height - getFluidHeight());
KList<BlockData> cavernLayers = null; KList<BlockData> cavernLayers = null;
KList<BlockData> seaLayers = biome.isAquatic() || biome.isShore() ? biome.generateSeaLayers(rx, rz, masterRandom, fluidHeight - height) : new KList<>(); KList<BlockData> seaLayers = biome.isAquatic() || biome.isShore() ? biome.generateSeaLayers(rx, rz, getMasterRandom(), fluidHeight - height) : new KList<>();
boolean caverning = false; boolean caverning = false;
KList<Integer> cavernHeights = new KList<>(); KList<Integer> cavernHeights = new KList<>();
int lastCavernHeight = -1; int lastCavernHeight = -1;
@ -174,13 +174,13 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
} }
// Carving // Carving
if(carvable && glCarve.isCarved(rx, k, rz)) if(carvable && getGlCarve().isCarved(rx, k, rz))
{ {
if(biomeMap != null) if(biomeMap != null)
{ {
if(landBiome == null) if(landBiome == null)
{ {
landBiome = glBiome.generateData(InferredType.LAND, x, z, x, z, region); landBiome = getGlBiome().generateData(InferredType.LAND, x, z, x, z, region);
} }
sliver.set(k, landBiome.getDerivative()); sliver.set(k, landBiome.getDerivative());
@ -204,19 +204,19 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
if(!biomeAssigned && biomeMap != null) if(!biomeAssigned && biomeMap != null)
{ {
biomeAssigned = true; biomeAssigned = true;
sliver.set(k, biome.getGroundBiome(masterRandom, rz, k, rx)); sliver.set(k, biome.getGroundBiome(getMasterRandom(), rz, k, rx));
biomeMap.setBiome(x, z, biome); biomeMap.setBiome(x, z, biome);
for(int kv = max; kv < biomeMax; kv++) for(int kv = max; kv < biomeMax; kv++)
{ {
Biome skyBiome = biome.getSkyBiome(masterRandom, rz, kv, rx); Biome skyBiome = biome.getSkyBiome(getMasterRandom(), rz, kv, rx);
sliver.set(kv, skyBiome); sliver.set(kv, skyBiome);
} }
} }
if(k <= Math.max(height, fluidHeight)) if(k <= Math.max(height, fluidHeight))
{ {
sliver.set(k, biome.getGroundBiome(masterRandom, rz, k, rx)); sliver.set(k, biome.getGroundBiome(getMasterRandom(), rz, k, rx));
} }
// Set Sea Material (water/lava) // Set Sea Material (water/lava)
@ -230,12 +230,12 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
{ {
if(landBiome == null) if(landBiome == null)
{ {
landBiome = glBiome.generateData(InferredType.LAND, x, z, x, z, region); landBiome = getGlBiome().generateData(InferredType.LAND, x, z, x, z, region);
} }
if(cavernLayers == null) if(cavernLayers == null)
{ {
cavernLayers = landBiome.generateLayers(rx, rz, masterRandom, 5, height - getFluidHeight()); cavernLayers = landBiome.generateLayers(rx, rz, getMasterRandom(), 5, height - getFluidHeight());
} }
block = cavernLayers.get(lastCavernHeight - k); block = cavernLayers.get(lastCavernHeight - k);
@ -262,7 +262,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
{ {
if(landBiome == null) if(landBiome == null)
{ {
landBiome = glBiome.generateData(InferredType.LAND, z, x, x, z, region); landBiome = getGlBiome().generateData(InferredType.LAND, z, x, x, z, region);
} }
decorateLand(landBiome, sliver, wx, k, wz, rx, rz, block); decorateLand(landBiome, sliver, wx, k, wz, rx, rz, block);
@ -281,7 +281,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
for(int j = i.getFloor(); j <= i.getCeiling(); j++) for(int j = i.getFloor(); j <= i.getCeiling(); j++)
{ {
sliver.set(j, caveBiome); sliver.set(j, caveBiome);
sliver.set(j, caveBiome.getGroundBiome(masterRandom, rz, j, rx)); sliver.set(j, caveBiome.getGroundBiome(getMasterRandom(), rz, j, rx));
} }
KList<BlockData> floor = caveBiome.generateLayers(wx, wz, rockRandom, i.getFloor() - 2, i.getFloor() - 2); KList<BlockData> floor = caveBiome.generateLayers(wx, wz, rockRandom, i.getFloor() - 2, i.getFloor() - 2);
@ -700,21 +700,21 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
super.onHotload(); super.onHotload();
getData().preferFolder(getDimension().getLoadFile().getParentFile().getParentFile().getName()); getData().preferFolder(getDimension().getLoadFile().getParentFile().getParentFile().getName());
loadGenerators(); loadGenerators();
buildGenLayers(masterRandom); buildGenLayers(getMasterRandom());
} }
public void registerGenerator(IrisGenerator g, IrisDimension dim) public void registerGenerator(IrisGenerator g, IrisDimension dim)
{ {
KMap<String, IrisGenerator> generators = this.generators; KMap<String, IrisGenerator> generators = this.generators;
regLock.lock(); getRegionLock().lock();
if(g.getLoadKey() == null || generators.containsKey(g.getLoadKey())) if(g.getLoadKey() == null || generators.containsKey(g.getLoadKey()))
{ {
regLock.unlock(); getRegionLock().unlock();
return; return;
} }
regLock.unlock(); getRegionLock().unlock();
generators.put(g.getLoadKey(), g); generators.put(g.getLoadKey(), g);
} }
@ -793,7 +793,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
return 0; return 0;
}); });
return M.lerp(lo, hi, gen.getHeight(rx, rz, world.getSeed() + 239945)); return M.lerp(lo, hi, gen.getHeight(rx, rz, getWorld().getSeed() + 239945));
} }
protected void loadGenerators() protected void loadGenerators()