This commit is contained in:
Daniel Mills 2020-07-29 00:23:48 -04:00
parent 7d4b980e59
commit 0ecde9531e
10 changed files with 200 additions and 63 deletions

View File

@ -6,8 +6,8 @@ import org.bukkit.World;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.layer.post.PostFloatingNippleDeleter; import com.volmit.iris.layer.post.PostFloatingNibDeleter;
import com.volmit.iris.layer.post.PostNippleSmoother; import com.volmit.iris.layer.post.PostNibSmoother;
import com.volmit.iris.layer.post.PostPotholeFiller; import com.volmit.iris.layer.post.PostPotholeFiller;
import com.volmit.iris.layer.post.PostSlabber; import com.volmit.iris.layer.post.PostSlabber;
import com.volmit.iris.layer.post.PostWallPatcher; import com.volmit.iris.layer.post.PostWallPatcher;
@ -20,6 +20,11 @@ import com.volmit.iris.util.KList;
import com.volmit.iris.util.PrecisionStopwatch; import com.volmit.iris.util.PrecisionStopwatch;
import com.volmit.iris.util.RNG; import com.volmit.iris.util.RNG;
import lombok.Data;
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 generatingCeiling = false;
@ -32,6 +37,8 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
private KList<IrisPostBlockFilter> filters; private KList<IrisPostBlockFilter> filters;
private String postKey; private String postKey;
private ReentrantLock lock; private ReentrantLock lock;
private int minPhase;
private int maxPhase;
public PostBlockChunkGenerator(String dimensionName, int threads) public PostBlockChunkGenerator(String dimensionName, int threads)
{ {
@ -44,12 +51,23 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
public void onInit(World world, RNG rng) public void onInit(World world, RNG rng)
{ {
super.onInit(world, rng); super.onInit(world, rng);
filters.add(new PostNippleSmoother(this)); filters.add(new PostNibSmoother(this));
filters.add(new PostFloatingNippleDeleter(this)); filters.add(new PostFloatingNibDeleter(this));
filters.add(new PostPotholeFiller(this)); filters.add(new PostPotholeFiller(this));
filters.add(new PostSlabber(this));
filters.add(new PostWallPatcher(this)); filters.add(new PostWallPatcher(this));
filters.add(new PostWaterlogger(this)); filters.add(new PostSlabber(this));
filters.add(new PostWaterlogger(this, 2));
setMinPhase(0);
setMaxPhase(0);
for(IrisPostBlockFilter i : filters)
{
setMinPhase(Math.min(getMinPhase(), i.getPhase()));
setMaxPhase(Math.max(getMaxPhase(), i.getPhase()));
}
Iris.info("Post Processing: " + filters.size() + " filters. Phases: " + getMinPhase() + " - " + getMaxPhase());
} }
@Override @Override
@ -69,29 +87,39 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
PrecisionStopwatch p = PrecisionStopwatch.start(); PrecisionStopwatch p = PrecisionStopwatch.start();
for(i = 0; i < 16; i++) for(int h = getMinPhase(); h <= getMaxPhase(); h++)
{ {
rx = (x * 16) + i; for(i = 0; i < 16; i++)
for(j = 0; j < 16; j++)
{ {
int rxx = rx; rx = (x << 4) + i;
int rzz = (z * 16) + j;
getAccelerant().queue(postKey, () -> for(j = 0; j < 16; j++)
{ {
int rxx = rx;
int rzz = (z << 4) + j;
for(IrisPostBlockFilter f : filters) for(IrisPostBlockFilter f : filters)
{ {
int rxxx = rxx; if(f.getPhase() == h)
int rzzx = rzz; {
f.onPost(rxx, rzz);
f.onPost(rxxx, rzzx); }
} }
}); }
}
for(IrisPostBlockFilter f : filters)
{
if(f.getPhase() == h)
{
while(f.getQueue().size() > 0)
{
f.getQueue().pop().run();
}
}
} }
} }
getAccelerant().waitFor(postKey);
p.end(); p.end();
getMetrics().getPost().put(p.getMilliseconds()); getMetrics().getPost().put(p.getMilliseconds());
} }
@ -99,7 +127,15 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
@Override @Override
public void updateHeight(int x, int z, int h) public void updateHeight(int x, int z, int h)
{ {
getCacheHeightMap()[(z << 4) | x] = h; if(x >> 4 == currentPostX && z >> 4 == currentPostZ)
{
getCacheHeightMap()[((z & 15) << 4) | (x & 15)] = h;
}
else
{
Iris.error("Invalid Heightmap set! Chunk Currently at " + currentPostX + "," + currentPostZ + ". Attempted to place at " + (x >> 4) + " " + (z >> 4) + " which is bad.");
}
} }
@Override @Override

View File

@ -0,0 +1,14 @@
package com.volmit.iris.layer.post;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(RUNTIME)
@Target(TYPE)
public @interface Post
{
String value();
}

View File

@ -6,13 +6,19 @@ import com.volmit.iris.generator.PostBlockChunkGenerator;
import com.volmit.iris.util.BlockDataTools; import com.volmit.iris.util.BlockDataTools;
import com.volmit.iris.util.IrisPostBlockFilter; import com.volmit.iris.util.IrisPostBlockFilter;
public class PostFloatingNippleDeleter extends IrisPostBlockFilter @Post("floating-block-remover")
public class PostFloatingNibDeleter extends IrisPostBlockFilter
{ {
private static final BlockData AIR = BlockDataTools.getBlockData("AIR"); private static final BlockData AIR = BlockDataTools.getBlockData("AIR");
public PostFloatingNippleDeleter(PostBlockChunkGenerator gen) public PostFloatingNibDeleter(PostBlockChunkGenerator gen, int phase)
{ {
super(gen); super(gen, phase);
}
public PostFloatingNibDeleter(PostBlockChunkGenerator gen)
{
this(gen, 0);
} }
@Override @Override

View File

@ -6,11 +6,17 @@ import org.bukkit.block.data.BlockData;
import com.volmit.iris.generator.PostBlockChunkGenerator; import com.volmit.iris.generator.PostBlockChunkGenerator;
import com.volmit.iris.util.IrisPostBlockFilter; import com.volmit.iris.util.IrisPostBlockFilter;
public class PostNippleSmoother extends IrisPostBlockFilter @Post("nib-smoother")
public class PostNibSmoother extends IrisPostBlockFilter
{ {
public PostNippleSmoother(PostBlockChunkGenerator gen) public PostNibSmoother(PostBlockChunkGenerator gen, int phase)
{ {
super(gen); super(gen, phase);
}
public PostNibSmoother(PostBlockChunkGenerator gen)
{
this(gen, 0);
} }
@Override @Override

View File

@ -3,11 +3,17 @@ package com.volmit.iris.layer.post;
import com.volmit.iris.generator.PostBlockChunkGenerator; import com.volmit.iris.generator.PostBlockChunkGenerator;
import com.volmit.iris.util.IrisPostBlockFilter; import com.volmit.iris.util.IrisPostBlockFilter;
@Post("pothole-filler")
public class PostPotholeFiller extends IrisPostBlockFilter public class PostPotholeFiller extends IrisPostBlockFilter
{ {
public PostPotholeFiller(PostBlockChunkGenerator gen, int phase)
{
super(gen, phase);
}
public PostPotholeFiller(PostBlockChunkGenerator gen) public PostPotholeFiller(PostBlockChunkGenerator gen)
{ {
super(gen); this(gen, 0);
} }
@Override @Override

View File

@ -7,16 +7,22 @@ import com.volmit.iris.generator.PostBlockChunkGenerator;
import com.volmit.iris.util.IrisPostBlockFilter; import com.volmit.iris.util.IrisPostBlockFilter;
import com.volmit.iris.util.RNG; import com.volmit.iris.util.RNG;
@Post("slabber")
public class PostSlabber extends IrisPostBlockFilter public class PostSlabber extends IrisPostBlockFilter
{ {
public static final Material AIR = Material.AIR; public static final Material AIR = Material.AIR;
public static final Material WATER = Material.WATER; public static final Material WATER = Material.WATER;
private RNG rng; private RNG rng;
public PostSlabber(PostBlockChunkGenerator gen, int phase)
{
super(gen, phase);
rng = gen.getMasterRandom().nextParallelRNG(166456);
}
public PostSlabber(PostBlockChunkGenerator gen) public PostSlabber(PostBlockChunkGenerator gen)
{ {
super(gen); this(gen, 0);
rng = gen.getMasterRandom().nextParallelRNG(1239456);
} }
@Override @Override
@ -41,8 +47,11 @@ public class PostSlabber extends IrisPostBlockFilter
if(isAir(x, h + 2, z) || getPostBlock(x, h + 2, z).getMaterial().equals(WATER)) if(isAir(x, h + 2, z) || getPostBlock(x, h + 2, z).getMaterial().equals(WATER))
{ {
setPostBlock(x, h + 1, z, d); queue(() ->
updateHeight(x, z, h + 1); {
setPostBlock(x, h + 1, z, d);
updateHeight(x, z, h + 1);
});
} }
} }
} }

View File

@ -8,15 +8,21 @@ import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.util.IrisPostBlockFilter; import com.volmit.iris.util.IrisPostBlockFilter;
import com.volmit.iris.util.RNG; import com.volmit.iris.util.RNG;
@Post("wall-painter")
public class PostWallPatcher extends IrisPostBlockFilter public class PostWallPatcher extends IrisPostBlockFilter
{ {
public static final Material AIR = Material.AIR; public static final Material AIR = Material.AIR;
private RNG rng; private RNG rng;
public PostWallPatcher(PostBlockChunkGenerator gen, int phase)
{
super(gen, phase);
rng = gen.getMasterRandom().nextParallelRNG(1239456);
}
public PostWallPatcher(PostBlockChunkGenerator gen) public PostWallPatcher(PostBlockChunkGenerator gen)
{ {
super(gen); this(gen, 0);
rng = gen.getMasterRandom().nextParallelRNG(1239456);
} }
@Override @Override
@ -40,8 +46,11 @@ public class PostWallPatcher extends IrisPostBlockFilter
if(s != null) if(s != null)
{ {
setPostBlock(x, h + 1, z, s); if(!s.getMaterial().equals(AIR))
updateHeight(x, z, h + 1); {
setPostBlock(x, h + 1, z, s);
updateHeight(x, z, h + 1);
}
} }
for(int i = h; i > h - max; i--) for(int i = h; i > h - max; i--)

View File

@ -1,14 +1,23 @@
package com.volmit.iris.layer.post; package com.volmit.iris.layer.post;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.Waterlogged;
import com.volmit.iris.Iris;
import com.volmit.iris.generator.PostBlockChunkGenerator; import com.volmit.iris.generator.PostBlockChunkGenerator;
import com.volmit.iris.util.BlockDataTools;
import com.volmit.iris.util.IrisPostBlockFilter; import com.volmit.iris.util.IrisPostBlockFilter;
@Post("waterlogger")
public class PostWaterlogger extends IrisPostBlockFilter public class PostWaterlogger extends IrisPostBlockFilter
{ {
private static final BlockData WATER = BlockDataTools.getBlockData("WATER");
public PostWaterlogger(PostBlockChunkGenerator gen, int phase)
{
super(gen, phase);
}
public PostWaterlogger(PostBlockChunkGenerator gen) public PostWaterlogger(PostBlockChunkGenerator gen)
{ {
super(gen); super(gen);
@ -23,32 +32,31 @@ public class PostWaterlogger extends IrisPostBlockFilter
if(b instanceof Waterlogged) if(b instanceof Waterlogged)
{ {
Waterlogged ww = (Waterlogged) b; Waterlogged ww = (Waterlogged) b;
boolean w = ww.isWaterlogged();
if(isWater(x, h + 1, z)) if(ww.isWaterlogged())
{
return;
}
if(isWaterOrWaterlogged(x, h + 1, z) && !ww.isWaterlogged())
{ {
ww.setWaterlogged(true); ww.setWaterlogged(true);
}
else if(h < 98)
{
Iris.info("Data is " + getPostBlock(x, h + 1, z).getAsString());
}
else if(isWater(x + 1, h, z) || isWater(x - 1, h, z) || isWater(x, h, z + 1) || isWater(x, h, z - 1))
{
ww.setWaterlogged(true);
}
else
{
ww.setWaterlogged(false);
}
if(ww.isWaterlogged() != w)
{
setPostBlock(x, h, z, ww); setPostBlock(x, h, z, ww);
} }
else if(!ww.isWaterlogged() && (isWaterOrWaterlogged(x + 1, h, z) || isWaterOrWaterlogged(x - 1, h, z) || isWaterOrWaterlogged(x, h, z + 1) || isWaterOrWaterlogged(x, h, z - 1)))
{
ww.setWaterlogged(true);
setPostBlock(x, h, z, ww);
}
}
else if(b.getMaterial().equals(Material.AIR) && h <= gen.getFluidHeight())
{
if((isWaterOrWaterlogged(x + 1, h, z) || isWaterOrWaterlogged(x - 1, h, z) || isWaterOrWaterlogged(x, h, z + 1) || isWaterOrWaterlogged(x, h, z - 1)))
{
setPostBlock(x, h, z, WATER);
}
} }
} }
} }

View File

@ -59,6 +59,16 @@ public class IrisBiomePaletteLayer
cacheGenerator(rng); cacheGenerator(rng);
} }
if(getBlockData().isEmpty())
{
return null;
}
if(getBlockData().size() == 1)
{
return getBlockData().get(0);
}
if(layerGenerator != null) if(layerGenerator != null)
{ {
if(dispersion.equals(Dispersion.SCATTER)) if(dispersion.equals(Dispersion.SCATTER))
@ -72,11 +82,6 @@ public class IrisBiomePaletteLayer
} }
} }
if(getBlockData().isEmpty())
{
return null;
}
return getBlockData().get(0); return getBlockData().get(0);
} }

View File

@ -2,16 +2,31 @@ package com.volmit.iris.util;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Levelled;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Slab;
import com.volmit.iris.generator.PostBlockChunkGenerator; import com.volmit.iris.generator.PostBlockChunkGenerator;
import lombok.Data;
@Data
public abstract class IrisPostBlockFilter implements IPostBlockAccess public abstract class IrisPostBlockFilter implements IPostBlockAccess
{ {
public PostBlockChunkGenerator gen; public PostBlockChunkGenerator gen;
private int phase;
private KList<Runnable> queue;
public IrisPostBlockFilter(PostBlockChunkGenerator gen, int phase)
{
this.gen = gen;
this.phase = phase;
queue = new KList<>();
}
public IrisPostBlockFilter(PostBlockChunkGenerator gen) public IrisPostBlockFilter(PostBlockChunkGenerator gen)
{ {
this.gen = gen; this(gen, 0);
} }
public abstract void onPost(int x, int z); public abstract void onPost(int x, int z);
@ -46,18 +61,41 @@ public abstract class IrisPostBlockFilter implements IPostBlockAccess
return d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(Material.CAVE_AIR); return d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(Material.CAVE_AIR);
} }
public boolean isSlab(int x, int y, int z)
{
BlockData d = getPostBlock(x, y, z);
return d instanceof Slab;
}
public boolean isWater(int x, int y, int z) public boolean isWater(int x, int y, int z)
{ {
BlockData d = getPostBlock(x, y, z); BlockData d = getPostBlock(x, y, z);
return d.getMaterial().equals(Material.WATER); return d.getMaterial().equals(Material.WATER);
} }
public boolean isWaterOrWaterlogged(int x, int y, int z)
{
BlockData d = getPostBlock(x, y, z);
return d.getMaterial().equals(Material.WATER) || (d instanceof Waterlogged && ((Waterlogged) d).isWaterlogged());
}
public boolean isLiquid(int x, int y, int z)
{
BlockData d = getPostBlock(x, y, z);
return d instanceof Levelled;
}
@Override @Override
public KList<CaveResult> caveFloors(int x, int z) public KList<CaveResult> caveFloors(int x, int z)
{ {
return gen.caveFloors(x, z); return gen.caveFloors(x, z);
} }
public void queue(Runnable a)
{
queue.add(a);
}
@Override @Override
public void updateHeight(int x, int z, int h) public void updateHeight(int x, int z, int h)
{ {