9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-19 15:09:18 +00:00

No Caching

This commit is contained in:
Dan Macbook
2020-08-14 03:39:35 -04:00
parent 7406da66a7
commit 948317c27a
20 changed files with 397 additions and 498 deletions

BIN
.DS_Store vendored

Binary file not shown.

2
.gitignore vendored
View File

@@ -11,3 +11,5 @@ lint/in.jar
lint/out.jar
lint/mapping.txt
.DS_Store

View File

@@ -41,8 +41,7 @@ import com.volmit.iris.util.Permission;
import com.volmit.iris.util.RollingSequence;
import com.volmit.iris.util.ScoreDirection;
public class Iris extends MortarPlugin implements BoardProvider
{
public class Iris extends MortarPlugin implements BoardProvider {
public static KList<GroupedExecutor> executors = new KList<>();
public static Iris instance;
public static IrisDataManager globaldata;
@@ -66,31 +65,27 @@ public class Iris extends MortarPlugin implements BoardProvider
@com.volmit.iris.util.Command
public CommandIris commandIris;
public Iris()
{
public Iris() {
IO.delete(new File("iris"));
}
@Override
public void start()
{
public void start() {
}
@Override
public void stop()
{
public void stop() {
}
@Override
public String getTag(String subTag)
{
return ChatColor.BOLD + "" + ChatColor.DARK_GRAY + "[" + ChatColor.BOLD + "" + ChatColor.GREEN + "Iris" + ChatColor.BOLD + ChatColor.DARK_GRAY + "]" + ChatColor.RESET + "" + ChatColor.GRAY + ": ";
public String getTag(String subTag) {
return ChatColor.BOLD + "" + ChatColor.DARK_GRAY + "[" + ChatColor.BOLD + "" + ChatColor.GREEN + "Iris"
+ ChatColor.BOLD + ChatColor.DARK_GRAY + "]" + ChatColor.RESET + "" + ChatColor.GRAY + ": ";
}
public void onEnable()
{
public void onEnable() {
lock = new IrisLock("Iris");
instance = this;
hotloader = new IrisHotloadManager();
@@ -98,25 +93,22 @@ public class Iris extends MortarPlugin implements BoardProvider
wand = new WandController();
postProcessors = loadPostProcessors();
proj = new ProjectManager();
manager = new BoardManager(this, BoardSettings.builder().boardProvider(this).scoreDirection(ScoreDirection.UP).build());
manager = new BoardManager(this,
BoardSettings.builder().boardProvider(this).scoreDirection(ScoreDirection.UP).build());
super.onEnable();
}
public void onDisable()
{
public void onDisable() {
lock.unlock();
proj.close();
for(GroupedExecutor i : executors)
{
for (GroupedExecutor i : executors) {
i.close();
}
for(World i : Bukkit.getWorlds())
{
if(i.getGenerator() instanceof IrisChunkGenerator)
{
for (World i : Bukkit.getWorlds()) {
if (i.getGenerator() instanceof IrisChunkGenerator) {
((IrisChunkGenerator) i).close();
}
}
@@ -129,28 +121,23 @@ public class Iris extends MortarPlugin implements BoardProvider
}
@Override
public String getTitle(Player player)
{
public String getTitle(Player player) {
return ChatColor.GREEN + "Iris";
}
@Override
public List<String> getLines(Player player)
{
if(!clf.flip())
{
public List<String> getLines(Player player) {
if (!clf.flip()) {
return lines;
}
World world = player.getWorld();
lines.clear();
if(world.getGenerator() instanceof IrisChunkGenerator)
{
if (world.getGenerator() instanceof IrisChunkGenerator) {
IrisChunkGenerator g = (IrisChunkGenerator) world.getGenerator();
if(cl.flip())
{
if (cl.flip()) {
mem = Form.memSize(g.guessMemoryUsage(), 2);
}
@@ -163,21 +150,23 @@ public class Iris extends MortarPlugin implements BoardProvider
tp.put(g.getMetrics().getSpeed());
lines.add("&7&m-----------------");
lines.add(ChatColor.GREEN + "Speed" + ChatColor.GRAY + ": " + ChatColor.BOLD + "" + ChatColor.GRAY + Form.f(g.getMetrics().getPerSecond().getAverage(), 0) + "/s " + Form.duration(g.getMetrics().getTotal().getAverage(), 1) + "");
lines.add(ChatColor.GREEN + "Speed" + ChatColor.GRAY + ": " + ChatColor.BOLD + "" + ChatColor.GRAY
+ Form.f(g.getMetrics().getPerSecond().getAverage(), 0) + "/s "
+ Form.duration(g.getMetrics().getTotal().getAverage(), 1) + "");
lines.add(ChatColor.GREEN + "Generators" + ChatColor.GRAY + ": " + Form.f(CNG.creates));
lines.add(ChatColor.GREEN + "Noise" + ChatColor.GRAY + ": " + Form.f((int) hits.getAverage()));
lines.add(ChatColor.GREEN + "Parallax Chunks" + ChatColor.GRAY + ": " + Form.f((int) g.getParallaxMap().getLoadedChunks().size()));
lines.add(ChatColor.GREEN + "Objects" + ChatColor.GRAY + ": " + Form.f(g.getData().getObjectLoader().count()));
lines.add(ChatColor.GREEN + "Parallax Chunks" + ChatColor.GRAY + ": "
+ Form.f((int) g.getParallaxMap().getLoadedChunks().size()));
lines.add(ChatColor.GREEN + "Objects" + ChatColor.GRAY + ": "
+ Form.f(g.getData().getObjectLoader().count()));
lines.add(ChatColor.GREEN + "Memory" + ChatColor.GRAY + ": " + mem);
if(er != null && b != null)
{
if (er != null && b != null) {
lines.add(ChatColor.GREEN + "Biome" + ChatColor.GRAY + ": " + b.getName());
lines.add(ChatColor.GREEN + "File" + ChatColor.GRAY + ": " + b.getLoadKey());
}
if(st != null)
{
if (st != null) {
lines.add(ChatColor.GREEN + "Structure" + ChatColor.GRAY + ": " + st.getStructure().getName());
lines.add(ChatColor.GREEN + "Tile" + ChatColor.GRAY + ": " + st.getTile().toString());
}
@@ -185,16 +174,14 @@ public class Iris extends MortarPlugin implements BoardProvider
lines.add("&7&m-----------------");
}
else
{
else {
lines.add(ChatColor.GREEN + "Join an Iris World!");
}
return lines;
}
private static KList<Class<? extends IrisPostBlockFilter>> loadPostProcessors()
{
private static KList<Class<? extends IrisPostBlockFilter>> loadPostProcessors() {
KList<Class<? extends IrisPostBlockFilter>> g = new KList<Class<? extends IrisPostBlockFilter>>();
g.add(PostFloatingNibDeleter.class);
@@ -208,65 +195,55 @@ public class Iris extends MortarPlugin implements BoardProvider
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
return super.onCommand(sender, command, label, args);
}
public void imsg(CommandSender s, String msg)
{
s.sendMessage(ChatColor.GREEN + "[" + ChatColor.DARK_GRAY + "Iris" + ChatColor.GREEN + "]" + ChatColor.GRAY + ": " + msg);
public void imsg(CommandSender s, String msg) {
s.sendMessage(ChatColor.GREEN + "[" + ChatColor.DARK_GRAY + "Iris" + ChatColor.GREEN + "]" + ChatColor.GRAY
+ ": " + msg);
}
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id)
{
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
return new IrisChunkGenerator(16);
}
public static void msg(String string)
{
public static void msg(String string) {
lock.lock();
String msg = ChatColor.GREEN + "[Iris]: " + ChatColor.GRAY + string;
if(last.equals(msg))
{
if (last.equals(msg)) {
lock.unlock();
return;
}
last = msg;
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> Bukkit.getConsoleSender().sendMessage(msg));
Bukkit.getConsoleSender().sendMessage(msg);
lock.unlock();
}
public static void warn(String string)
{
public static void warn(String string) {
msg(ChatColor.YELLOW + string);
}
public static void error(String string)
{
public static void error(String string) {
msg(ChatColor.RED + string);
}
public static void verbose(String string)
{
public static void verbose(String string) {
msg(ChatColor.GRAY + string);
}
public static void success(String string)
{
public static void success(String string) {
msg(ChatColor.GREEN + string);
}
public static void info(String string)
{
public static void info(String string) {
msg(ChatColor.WHITE + string);
}
public void hit(long hits2)
{
public void hit(long hits2) {
hits.put(hits2);
}
}

View File

@@ -56,6 +56,8 @@ public class NoiseView extends JPanel implements MouseWheelListener {
double lx = Double.MAX_VALUE;
double lz = Double.MAX_VALUE;
double tz = 1D;
double t = 1D;
public NoiseView() {
@@ -82,7 +84,13 @@ public class NoiseView extends JPanel implements MouseWheelListener {
}
public void mouseWheelMoved(MouseWheelEvent e) {
int notches = e.getWheelRotation();
if (e.isControlDown()) {
t = t + ((0.001 * t) * notches);
return;
}
scale = scale + ((0.044 * scale) * notches);
scale = scale < 0.00001 ? 0.00001 : scale;
}
@@ -98,6 +106,14 @@ public class NoiseView extends JPanel implements MouseWheelListener {
ascale += Math.abs(ascale - scale) * 0.16;
}
if (t < tz) {
tz -= Math.abs(t - tz) * 0.29;
}
if (t > tz) {
tz += Math.abs(tz - t) * 0.29;
}
if (ox < oxp) {
oxp -= Math.abs(ox - oxp) * 0.16;
}
@@ -134,8 +150,7 @@ public class NoiseView extends JPanel implements MouseWheelListener {
int xx = x;
gx.queue("a", () -> {
for (int z = 0; z < getParent().getHeight(); z += accuracy) {
double n = cng.noise((xx * ascale) + oxp, Math.sin((double) M.ms() / 20000D) * 800D,
(z * ascale) + ozp);
double n = cng.noise((xx * ascale) + oxp, tz, (z * ascale) + ozp);
if (n > 1 || n < 0) {
System.out.println("EXCEEDED " + n);
@@ -162,6 +177,8 @@ public class NoiseView extends JPanel implements MouseWheelListener {
}
p.end();
t += 1D;
r.put(p.getMilliseconds());
EventQueue.invokeLater(() -> {
repaint();

View File

@@ -13,7 +13,6 @@ import com.volmit.iris.object.IrisGenerator;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.BiomeResult;
import com.volmit.iris.util.ChronoLatch;
import com.volmit.iris.util.ChunkPosition;
import com.volmit.iris.util.IrisInterpolation;
import com.volmit.iris.util.IrisLock;
import com.volmit.iris.util.KList;
@@ -26,68 +25,39 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
{
public abstract class BiomeChunkGenerator extends DimensionChunkGenerator {
protected IrisLock regLock;
private KMap<String, IrisGenerator> generators;
private KMap<String, IrisGenerator> ceilingGenerators;
protected GenLayerBiome glBiome;
protected CNG masterFracture;
private KMap<ChunkPosition, BiomeResult> biomeHitCache;
private KMap<ChunkPosition, BiomeResult> ceilingBiomeHitCache;
protected ChronoLatch cwarn = new ChronoLatch(1000);
private IrisBiome[] biomeCache;
public BiomeChunkGenerator(String dimensionName)
{
public BiomeChunkGenerator(String dimensionName) {
super(dimensionName);
generators = new KMap<>();
ceilingGenerators = new KMap<>();
regLock = new IrisLock("BiomeChunkGenerator");
biomeHitCache = new KMap<>();
ceilingBiomeHitCache = new KMap<>();
biomeCache = new IrisBiome[256];
}
public void onInit(World world, RNG rng)
{
public void onInit(World world, RNG rng) {
super.onInit(world, rng);
loadGenerators();
glBiome = new GenLayerBiome(this, masterRandom.nextParallelRNG(1));
masterFracture = CNG.signature(rng.nextParallelRNG(13)).scale(0.12);
}
protected IrisBiome getCachedInternalBiome(int x, int z)
{
return biomeCache[(z << 4) | x];
}
protected void cacheInternalBiome(int x, int z, IrisBiome b)
{
biomeCache[(z << 4) | x] = b;
}
public KMap<ChunkPosition, BiomeResult> getBiomeHitCache()
{
return getDimension().isInverted() ? ceilingBiomeHitCache : biomeHitCache;
}
@Override
public void onHotload()
{
public void onHotload() {
super.onHotload();
biomeHitCache = new KMap<>();
ceilingBiomeHitCache = new KMap<>();
loadGenerators();
}
public void registerGenerator(IrisGenerator g, IrisDimension dim)
{
public void registerGenerator(IrisGenerator g, IrisDimension dim) {
KMap<String, IrisGenerator> generators = dim.isInverted() ? ceilingGenerators : this.generators;
regLock.lock();
if(g.getLoadKey() == null || generators.containsKey(g.getLoadKey()))
{
if (g.getLoadKey() == null || generators.containsKey(g.getLoadKey())) {
regLock.unlock();
return;
}
@@ -96,66 +66,56 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
generators.put(g.getLoadKey(), g);
}
protected KMap<String, IrisGenerator> getGenerators()
{
protected KMap<String, IrisGenerator> getGenerators() {
return getDimension().isInverted() ? ceilingGenerators : generators;
}
protected double getBiomeHeight(double rx, double rz, int x, int z)
{
protected double getBiomeHeight(double rx, double rz, int x, int z) {
double h = 0;
for(IrisGenerator i : getGenerators().values())
{
for (IrisGenerator i : getGenerators().values()) {
h += interpolateGenerator(rx, rz, i);
}
return h;
}
protected double interpolateGenerator(double rx, double rz, IrisGenerator gen)
{
double hi = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) ->
{
try
{
protected double interpolateGenerator(double rx, double rz, IrisGenerator gen) {
double hi = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx),
(int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) -> {
try {
IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome();
for(IrisBiomeGeneratorLink i : b.getGenerators())
{
if(i.getGenerator().equals(gen.getLoadKey()))
{
for (IrisBiomeGeneratorLink i : b.getGenerators()) {
if (i.getGenerator().equals(gen.getLoadKey())) {
return i.getMax();
}
}
}
catch(Throwable e)
{
Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator " + gen.getLoadKey());
catch (Throwable e) {
Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator "
+ gen.getLoadKey());
}
return 0;
});
double lo = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) ->
{
try
{
double lo = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx),
(int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) -> {
try {
IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome();
for(IrisBiomeGeneratorLink i : b.getGenerators())
{
if(i.getGenerator().equals(gen.getLoadKey()))
{
for (IrisBiomeGeneratorLink i : b.getGenerators()) {
if (i.getGenerator().equals(gen.getLoadKey())) {
return i.getMin();
}
}
}
catch(Throwable e)
{
Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator " + gen.getLoadKey());
catch (Throwable e) {
Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator "
+ gen.getLoadKey());
}
return 0;
@@ -164,30 +124,25 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
return M.lerp(lo, hi, gen.getHeight(rx, rz, world.getSeed() + 239945));
}
protected void loadGenerators()
{
protected void loadGenerators() {
generators.clear();
ceilingGenerators.clear();
loadGenerators(((CeilingChunkGenerator) this).getFloorDimension());
loadGenerators(((CeilingChunkGenerator) this).getCeilingDimension());
}
protected void loadGenerators(IrisDimension dim)
{
if(dim == null)
{
protected void loadGenerators(IrisDimension dim) {
if (dim == null) {
return;
}
KList<String> touch = new KList<>();
KList<String> loadQueue = new KList<>();
for(String i : dim.getRegions())
{
for (String i : dim.getRegions()) {
IrisRegion r = loadRegion(i);
if(r != null)
{
if (r != null) {
loadQueue.addAll(r.getLandBiomes());
loadQueue.addAll(r.getSeaBiomes());
loadQueue.addAll(r.getShoreBiomes());
@@ -196,12 +151,10 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
}
}
while(!loadQueue.isEmpty())
{
while (!loadQueue.isEmpty()) {
String next = loadQueue.pop();
if(!touch.contains(next))
{
if (!touch.contains(next)) {
touch.add(next);
IrisBiome biome = loadBiome(next);
biome.getGenerators().forEach((i) -> registerGenerator(i.getCachedGenerator(this), dim));
@@ -210,37 +163,31 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
}
}
public IrisRegion sampleRegion(int x, int z)
{
public IrisRegion sampleRegion(int x, int z) {
double wx = getModifiedX(x, z);
double wz = getModifiedZ(x, z);
return glBiome.getRegion(wx, wz);
}
public BiomeResult sampleBiome(int x, int z)
{
if(!getDimension().getFocus().equals(""))
{
public BiomeResult sampleBiome(int x, int z) {
if (!getDimension().getFocus().equals("")) {
IrisBiome biome = loadBiome(getDimension().getFocus());
for(String i : getDimension().getRegions())
{
for (String i : getDimension().getRegions()) {
IrisRegion reg = loadRegion(i);
if(reg.getLandBiomes().contains(biome.getLoadKey()))
{
if (reg.getLandBiomes().contains(biome.getLoadKey())) {
biome.setInferredType(InferredType.LAND);
break;
}
if(reg.getSeaBiomes().contains(biome.getLoadKey()))
{
if (reg.getSeaBiomes().contains(biome.getLoadKey())) {
biome.setInferredType(InferredType.SEA);
break;
}
if(reg.getShoreBiomes().contains(biome.getLoadKey()))
{
if (reg.getShoreBiomes().contains(biome.getLoadKey())) {
biome.setInferredType(InferredType.SHORE);
break;
}
@@ -249,18 +196,10 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
return new BiomeResult(biome, 0);
}
ChunkPosition pos = new ChunkPosition(x, z);
if(getBiomeHitCache().containsKey(pos))
{
return getBiomeHitCache().get(pos);
}
double wx = getModifiedX(x, z);
double wz = getModifiedZ(x, z);
IrisRegion region = glBiome.getRegion(wx, wz);
BiomeResult res = glBiome.generateRegionData(wx, wz, x, z, region);
getBiomeHitCache().put(pos, res);
return res;
}

View File

@@ -270,7 +270,7 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
@Override
public ChunkData generateChunkData(World world, Random no, int x, int z, BiomeGrid biomeGrid) {
hlock.getLock();
hlock.lock();
if (!dev) {
pregenDone = true;
fastPregen = false;

View File

@@ -123,11 +123,7 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon
e.printStackTrace();
}
setBiomeCache(null);
setAvailableFilters(null);
setBiomeHitCache(null);
setCacheTrueBiome(null);
setCacheHeightMap(null);
setCeilingSliverCache(null);
setSliverCache(null);
Iris.info("Closing Iris Dimension " + getWorld().getName());

View File

@@ -33,8 +33,7 @@ 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;
@@ -44,8 +43,7 @@ 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<>();
@@ -53,49 +51,40 @@ 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)
{
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--;
}
@@ -106,28 +95,24 @@ 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);
@@ -138,30 +123,24 @@ 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);
}
@@ -169,19 +148,16 @@ 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();
getBiomeHitCache().clear();
if(getDimension().isPlaceObjects())
{
if (getDimension().isPlaceObjects()) {
onGenerateParallax(random, x, z);
getParallaxChunk(x, z).inject(data);
setSliverBuffer(getSliverCache().size());
@@ -196,58 +172,50 @@ 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));
}
}
@@ -255,58 +223,52 @@ 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();
}
@@ -318,61 +280,52 @@ 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();
}
@@ -386,8 +339,7 @@ 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();
@@ -395,39 +347,34 @@ 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);
}
@@ -439,8 +386,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
}
@Override
public boolean isPreventingDecay()
{
public boolean isPreventingDecay() {
return getDimension().isPreventLeafDecay();
}
}

View File

@@ -17,57 +17,54 @@ 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 boolean unsafe;
protected boolean safe;
protected int cacheX;
protected int cacheZ;
private IrisLock genlock;
protected boolean cachingAllowed;
public ParallelChunkGenerator(String dimensionName, int threads)
{
public ParallelChunkGenerator(String dimensionName, int threads) {
super(dimensionName);
unsafe = false;
safe = false;
cacheX = 0;
cacheZ = 0;
this.threads = threads;
genlock = new IrisLock("ParallelGenLock");
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;
@@ -78,28 +75,25 @@ 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);
});
}
}
setCachingAllowed(true);
setUnsafe(true);
setSafe(false);
accelerant.waitFor(key);
setUnsafe(false);
setSafe(true);
setCachingAllowed(false);
map.write(data, grid, height);
getMetrics().getTerrain().put(p.getMilliseconds());
@@ -108,26 +102,18 @@ 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);
}
public boolean isSafe()
{
return !unsafe;
}
@Override
public boolean isParallelCapable()
{
public boolean isParallelCapable() {
return false;
}
}

View File

@@ -18,8 +18,7 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator implements IPostBlockAccess
{
public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator implements IPostBlockAccess {
protected boolean generatingCeiling = false;
protected boolean ceilingCached = false;
protected IrisDimension cacheCeiling = null;
@@ -33,27 +32,22 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
private int minPhase;
private int maxPhase;
public PostBlockChunkGenerator(String dimensionName, int threads)
{
public PostBlockChunkGenerator(String dimensionName, int threads) {
super(dimensionName, threads);
availableFilters = new KList<>();
postKey = "post-" + dimensionName;
lock = new IrisLock("PostChunkGenerator");
}
public void onInit(World world, RNG rng)
{
public void onInit(World world, RNG rng) {
super.onInit(world, rng);
for(Class<? extends IrisPostBlockFilter> i : Iris.postProcessors)
{
try
{
for (Class<? extends IrisPostBlockFilter> i : Iris.postProcessors) {
try {
availableFilters.add(i.getConstructor(PostBlockChunkGenerator.class).newInstance(this));
}
catch(Throwable e)
{
catch (Throwable e) {
Iris.error("Failed to initialize post processor: " + i.getCanonicalName());
fail(e);
}
@@ -61,12 +55,10 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
}
@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);
if(!getDimension().isPostProcessing())
{
if (!getDimension().isPostProcessing()) {
return;
}
@@ -77,24 +69,18 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
int rx, i, j;
PrecisionStopwatch p = PrecisionStopwatch.start();
for(int h = getMinPhase(); h <= getMaxPhase(); h++)
{
for(i = 0; i < 16; i++)
{
for (int h = getMinPhase(); h <= getMaxPhase(); h++) {
for (i = 0; i < 16; i++) {
rx = (x << 4) + i;
for(j = 0; j < 16; j++)
{
for (j = 0; j < 16; j++) {
int rxx = rx;
int rzz = (z << 4) + j;
int hh = h;
getAccelerant().queue("post", () ->
{
for(IrisPostBlockFilter f : filters)
{
if(f.getPhase() == hh)
{
getAccelerant().queue("post", () -> {
for (IrisPostBlockFilter f : filters) {
if (f.getPhase() == hh) {
f.onPost(rxx, rzz);
}
}
@@ -104,19 +90,14 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
getAccelerant().waitFor("post");
for(IrisPostBlockFilter f : filters)
{
if(f.getPhase() == h)
{
while(f.getQueue().size() > 0)
{
try
{
for (IrisPostBlockFilter f : filters) {
if (f.getPhase() == h) {
while (f.getQueue().size() > 0) {
try {
f.getQueue().pop().run();
}
catch(Throwable e)
{
catch (Throwable e) {
}
}
@@ -128,19 +109,15 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
getMetrics().getPost().put(p.getMilliseconds());
}
public IrisPostBlockFilter createProcessor(String processor, int phase)
{
for(IrisPostBlockFilter i : availableFilters)
{
if(i.getKey().equals(processor))
{
try
{
return i.getClass().getConstructor(PostBlockChunkGenerator.class, int.class).newInstance(this, phase);
public IrisPostBlockFilter createProcessor(String processor, int phase) {
for (IrisPostBlockFilter i : availableFilters) {
if (i.getKey().equals(processor)) {
try {
return i.getClass().getConstructor(PostBlockChunkGenerator.class, int.class).newInstance(this,
phase);
}
catch(Throwable e)
{
catch (Throwable e) {
Iris.error("Failed initialize find post processor: " + processor);
fail(e);
}
@@ -153,24 +130,20 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
}
@Override
public void updateHeight(int x, int z, int h)
{
if(x >> 4 == currentPostX && z >> 4 == currentPostZ)
{
getCacheHeightMap()[((z & 15) << 4) | (x & 15)] = h;
public void updateHeight(int x, int z, int h) {
if (x >> 4 == currentPostX && z >> 4 == currentPostZ) {
//cacheHeight(x, z, h);
}
else
{
Iris.error("Invalid Heightmap set! Chunk Currently at " + currentPostX + "," + currentPostZ + ". Attempted to place at " + (x >> 4) + " " + (z >> 4) + " which is bad.");
else {
Iris.error("Invalid Heightmap set! Chunk Currently at " + currentPostX + "," + currentPostZ
+ ". Attempted to place at " + (x >> 4) + " " + (z >> 4) + " which is bad.");
}
}
@Override
public BlockData getPostBlock(int x, int y, int z)
{
if(x >> 4 == currentPostX && z >> 4 == currentPostZ)
{
public BlockData getPostBlock(int x, int y, int z) {
if (x >> 4 == currentPostX && z >> 4 == currentPostZ) {
lock.lock();
BlockData d = currentData.getBlockData(x & 15, y, z & 15);
lock.unlock();
@@ -181,36 +154,31 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
}
@Override
public void setPostBlock(int x, int y, int z, BlockData d)
{
if(x >> 4 == currentPostX && z >> 4 == currentPostZ)
{
public void setPostBlock(int x, int y, int z, BlockData d) {
if (x >> 4 == currentPostX && z >> 4 == currentPostZ) {
lock.lock();
currentData.setBlock(x & 15, y, z & 15, d);
lock.unlock();
}
else
{
Iris.warn("Post Block Overdraw: " + currentPostX + "," + currentPostZ + " into " + (x >> 4) + ", " + (z >> 4));
else {
Iris.warn("Post Block Overdraw: " + currentPostX + "," + currentPostZ + " into " + (x >> 4) + ", "
+ (z >> 4));
}
}
@Override
public int highestTerrainOrFluidBlock(int x, int z)
{
public int highestTerrainOrFluidBlock(int x, int z) {
return getHighest(x, z, false);
}
@Override
public int highestTerrainBlock(int x, int z)
{
public int highestTerrainBlock(int x, int z) {
return getHighest(x, z, true);
}
@Override
public KList<CaveResult> caveFloors(int x, int z)
{
public KList<CaveResult> caveFloors(int x, int z) {
return getCaves(x, z);
}
}

View File

@@ -6,7 +6,6 @@ import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.Bisected.Half;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.atomics.AtomicSliver;
import com.volmit.iris.gen.layer.GenLayerCarve;
import com.volmit.iris.gen.layer.GenLayerCave;
@@ -16,12 +15,11 @@ import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisBiomeDecorator;
import com.volmit.iris.object.IrisDepositGenerator;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.B;
import com.volmit.iris.util.BiomeMap;
import com.volmit.iris.util.BiomeResult;
import com.volmit.iris.util.B;
import com.volmit.iris.util.CaveResult;
import com.volmit.iris.util.HeightMap;
import com.volmit.iris.util.IrisLock;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.M;
import com.volmit.iris.util.RNG;
@@ -37,16 +35,9 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
private GenLayerCave glCave;
private GenLayerCarve glCarve;
private RNG rockRandom;
private int[] cacheHeightMap;
private BiomeResult[] cacheTrueBiome;
private IrisLock cacheLock;
public TerrainChunkGenerator(String dimensionName, int threads) {
super(dimensionName, threads);
cacheHeightMap = new int[256];
cacheTrueBiome = new BiomeResult[256];
cachingAllowed = true;
cacheLock = new IrisLock("TerrainCacheLock");
}
public void onInit(World world, RNG rng) {
@@ -68,6 +59,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
}
try {
int highestPlaced = 0;
BlockData block;
int fluidHeight = getDimension().getFluidHeight();
@@ -87,8 +79,6 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
throw new RuntimeException("Null Biome!");
}
cacheBiome(cachingAllowed && !sampled, x, z, biomeResult, height);
cacheInternalBiome(cachingAllowed && !sampled, x, z, biome);
KList<BlockData> layers = biome.generateLayers(rx, rz, masterRandom, height, height - getFluidHeight());
KList<BlockData> seaLayers = biome.isSea()
? biome.generateSeaLayers(rx, rz, masterRandom, fluidHeight - height)
@@ -213,11 +203,6 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
if (block.getMaterial().isSolid()) {
decorateLand(biome, sliver, wx, Math.max(height, fluidHeight), wz, rx, rz, block);
}
// Update Height Map
if (!sampled && cachingAllowed && highestPlaced < height) {
cacheHeightMap[(z << 4) | x] = highestPlaced;
}
}
catch (Throwable e) {
@@ -225,25 +210,6 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
}
}
protected void cacheInternalBiome(boolean b, int x, int z, IrisBiome bv) {
if (b) {
cacheInternalBiome(x, z, bv);
}
}
private void cacheBiome(boolean b, int x, int z, BiomeResult biomeResult, int height) {
if (b) {
try {
cacheTrueBiome[(z << 4) | x] = biomeResult;
cacheHeightMap[(z << 4) | x] = height;
}
catch (Throwable e) {
Iris.error("Failed to write cache at " + x + " " + z);
}
}
}
@Override
protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) {
super.onGenerate(random, x, z, data, grid);
@@ -446,8 +412,9 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
protected double getNoiseHeight(int rx, int rz) {
double wx = getZoomed(rx);
double wz = getZoomed(rz);
double h = getBiomeHeight(wx, wz, rx, rz);
return getBiomeHeight(wx, wz, rx, rz);
return h;
}
public BiomeResult sampleTrueBiomeBase(int x, int z, int height) {
@@ -508,15 +475,18 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
return sampleTrueBiome(x, z, getTerrainHeight(x, z));
}
@Override
public IrisRegion sampleRegion(int x, int z) {
IrisRegion r = super.sampleRegion(x, z);
return r;
}
public BiomeResult sampleTrueBiome(int x, int z, double noise) {
if (!getDimension().getFocus().equals("")) {
return focus();
}
if (isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ) {
return cacheTrueBiome[((z & 15) << 4) | (x & 15)];
}
double wx = getModifiedX(x, z);
double wz = getModifiedZ(x, z);
IrisRegion region = sampleRegion(x, z);
@@ -558,10 +528,6 @@ 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();
}

View File

@@ -0,0 +1,7 @@
package com.volmit.iris.gen.atomics;
import com.volmit.iris.object.IrisBiome;
public class AtomicBiomeMap extends AtomicObjectMap<IrisBiome> {
}

View File

@@ -0,0 +1,23 @@
package com.volmit.iris.gen.atomics;
import com.google.common.util.concurrent.AtomicDoubleArray;
public class AtomicDoubleMap {
private final AtomicDoubleArray data;
public AtomicDoubleMap() {
data = new AtomicDoubleArray(256);
}
public double get(int x, int z) {
return data.get((z << 4) | x);
}
public int getInt(int x, int z) {
return (int) Math.round(get(x, z));
}
public void set(int x, int z, double v) {
data.set((z << 4) | x, v);
}
}

View File

@@ -0,0 +1,19 @@
package com.volmit.iris.gen.atomics;
import java.util.concurrent.atomic.AtomicIntegerArray;
public class AtomicIntMap {
private final AtomicIntegerArray data;
public AtomicIntMap() {
data = new AtomicIntegerArray(256);
}
public int get(int x, int z) {
return data.get((z << 4) | x);
}
public void set(int x, int z, int v) {
data.set((z << 4) | x, v);
}
}

View File

@@ -0,0 +1,19 @@
package com.volmit.iris.gen.atomics;
import java.util.concurrent.atomic.AtomicReferenceArray;
public class AtomicObjectMap<T> {
private final AtomicReferenceArray<T> data;
public AtomicObjectMap() {
data = new AtomicReferenceArray<T>(256);
}
public T get(int x, int z) {
return data.get((z << 4) | x);
}
public void set(int x, int z, T v) {
data.set((z << 4) | x, v);
}
}

View File

@@ -0,0 +1,7 @@
package com.volmit.iris.gen.atomics;
import com.volmit.iris.object.IrisRegion;
public class AtomicRegionMap extends AtomicObjectMap<IrisRegion> {
}

View File

@@ -0,0 +1,22 @@
package com.volmit.iris.noise;
public class FlatNoise implements NoiseGenerator {
public FlatNoise(long seed) {
}
@Override
public double noise(double x) {
return 0.5;
}
@Override
public double noise(double x, double z) {
return 0.5;
}
@Override
public double noise(double x, double y, double z) {
return 0.5;
}
}

View File

@@ -8,6 +8,7 @@ public enum NoiseType {
FRACTAL_BILLOW_PERLIN(seed -> new FractalBillowPerlinNoise(seed)),
FRACTAL_FBM_SIMPLEX(seed -> new FractalFBMSimplexNoise(seed)),
FRACTAL_RIGID_MULTI_SIMPLEX(seed -> new FractalRigidMultiSimplexNoise(seed)),
FLAT(seed -> new FlatNoise(seed)),
CELLULAR(seed -> new CellularNoise(seed)),
GLOB(seed -> new GlobNoise(seed)),
CUBIC(seed -> new CubicNoise(seed)),

View File

@@ -14,8 +14,8 @@ import lombok.Data;
@Data
public class IrisObjectTranslate
{
@MinNumber(-8)
@MaxNumber(8)
@MinNumber(-128)
@MaxNumber(128)
@DontObfuscate
@Desc("The x shift in blocks")
private int x = 0;
@@ -27,8 +27,8 @@ public class IrisObjectTranslate
@Desc("The x shift in blocks")
private int y = 0;
@MinNumber(-8)
@MaxNumber(8)
@MinNumber(-128)
@MaxNumber(128)
@DontObfuscate
@Desc("The x shift in blocks")
private int z = 0;

View File

@@ -392,6 +392,10 @@ public enum NoiseStyle {
@DontObfuscate
VASCULAR(rng -> new CNG(rng, NoiseType.VASCULAR, 1D, 1)),
@Desc("It always returns 0.5")
@DontObfuscate
FLAT(rng -> new CNG(rng, NoiseType.FLAT, 1D, 1)),
@Desc("Vascular noise gets higher as the position nears a cell border. Cells are distorted using Iris styled wispy noise.")
@DontObfuscate
VASCULAR_IRIS(rng -> CNG.signature(rng, NoiseType.VASCULAR)),