Speed up plax mgr

This commit is contained in:
Daniel Mills 2021-07-18 04:46:55 -04:00
parent c420a8a686
commit a03539ad8b
7 changed files with 76 additions and 27 deletions

View File

@ -197,10 +197,15 @@ public class IrisComplex implements DataProvider {
}, Interpolated.DOUBLE).cache2D(cacheSize);
slopeStream = heightStream.slope(3).interpolate().bilinear(3, 3).cache2D(cacheSize);
objectChanceStream = ProceduralStream.ofDouble((x, z) -> {
if(engine.getDimension().hasFeatures(engine))
{
AtomicDouble str = new AtomicDouble(1D);
engine.getFramework().getEngineParallax().forEachFeature(x, z, (i)
-> str.set(Math.min(str.get(), i.getObjectChanceModifier(x, z))));
return str.get();
}
return 1D;
});
trueBiomeStream = focus != null ? ProceduralStream.of((x, y) -> focus, Interpolated.of(a -> 0D,

View File

@ -162,22 +162,21 @@ public class IrisEngine extends BlockPopulator implements Engine {
public void generate(int x, int z, Hunk<BlockData> vblocks, Hunk<Biome> vbiomes) {
try {
PrecisionStopwatch p = PrecisionStopwatch.start();
Hunk<BlockData> blocks = vblocks;
switch (getDimension().getTerrainMode()) {
case NORMAL -> {
getFramework().getEngineParallax().generateParallaxArea(x >> 4, z >> 4);
getFramework().getBiomeActuator().actuate(x, z, vbiomes);
getFramework().getTerrainActuator().actuate(x, z, blocks);
getFramework().getCaveModifier().modify(x, z, blocks);
getFramework().getRavineModifier().modify(x, z, blocks);
getFramework().getPostModifier().modify(x, z, blocks);
getFramework().getDecorantActuator().actuate(x, z, blocks);
getFramework().getEngineParallax().insertParallax(x, z, blocks);
getFramework().getDepositModifier().modify(x, z, blocks);
getFramework().getTerrainActuator().actuate(x, z, vblocks);
getFramework().getCaveModifier().modify(x, z, vblocks);
getFramework().getRavineModifier().modify(x, z, vblocks);
getFramework().getPostModifier().modify(x, z, vblocks);
getFramework().getDecorantActuator().actuate(x, z, vblocks);
getFramework().getEngineParallax().insertParallax(x, z, vblocks);
getFramework().getDepositModifier().modify(x, z, vblocks);
}
case ISLANDS -> {
getFramework().getTerrainActuator().actuate(x, z, blocks);
getFramework().getTerrainActuator().actuate(x, z, vblocks);
}
}
getMetrics().getTotal().put(p.getMilliseconds());

View File

@ -199,6 +199,11 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
IrisLock getFeatureLock();
default void forEachFeature(double x, double z, Consumer<IrisFeaturePositional> f) {
if(!getEngine().getDimension().hasFeatures(getEngine()))
{
return;
}
long key = Cache.key(((int) x) >> 4, ((int) z) >> 4);
for (IrisFeaturePositional ipf : getFeatureCache().compute(key, (ke, v) -> {
@ -225,17 +230,13 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
ParallaxChunkMeta m = getParallaxAccess().getMetaR(i + cx, j + cz);
try {
synchronized (m.getFeatures()) {
for (IrisFeaturePositional k : m.getFeatures()) {
if (k.shouldFilter(x, z)) {
pos.add(k);
}
}
}
} catch (Throwable e) {
Iris.reportError(e);
e.printStackTrace();
Iris.warn("Failed to read positional features in chunk " + (i + cx) + " " + (j + cz) + "(" + e.getClass().getSimpleName() + ")");
}
}
}

View File

@ -22,7 +22,7 @@ import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisDataManager;
import com.volmit.iris.engine.IrisComplex;
import com.volmit.iris.engine.data.DataProvider;
import com.volmit.iris.engine.data.DirectWorldWriter;
import com.volmit.iris.engine.data.mca.NBTWorld;
import com.volmit.iris.engine.object.IrisBiome;
import com.volmit.iris.engine.object.IrisRegion;
import com.volmit.iris.engine.parallel.MultiBurst;
@ -44,9 +44,9 @@ import java.util.function.Consumer;
@SuppressWarnings("EmptyMethod")
public interface IrisAccess extends Hotloadable, DataProvider {
void directWriteMCA(World w, int x, int z, DirectWorldWriter writer, MultiBurst burst);
void directWriteMCA(World w, int x, int z, NBTWorld writer, MultiBurst burst);
void directWriteChunk(World w, int x, int z, DirectWorldWriter writer);
void directWriteChunk(World w, int x, int z, NBTWorld writer);
int getGenerated();

View File

@ -343,6 +343,7 @@ public class IrisDimension extends IrisRegistrant {
private final transient AtomicCache<Double> sinr = new AtomicCache<>();
private final transient AtomicCache<Double> cosr = new AtomicCache<>();
private final transient AtomicCache<Double> rad = new AtomicCache<>();
private final transient AtomicCache<Boolean> featuresUsed = new AtomicCache<>();
public boolean hasSky() {
return getSky() != null;
@ -511,4 +512,48 @@ public class IrisDimension extends IrisRegistrant {
return changed;
}
public boolean hasFeatures(DataProvider data) {
return featuresUsed.aquire(() -> {
if(getFeatures().isNotEmpty() || getSpecificFeatures().isNotEmpty())
{
return true;
}
for(IrisRegion i : getAllRegions(data))
{
if(i.getFeatures().isNotEmpty())
{
return true;
}
for(IrisObjectPlacement j : i.getObjects())
{
if(j.isVacuum())
{
return true;
}
}
for(IrisBiome j : i.getAllBiomes(data))
{
if(j.getFeatures().isNotEmpty())
{
return true;
}
for(IrisObjectPlacement k : i.getObjects())
{
if(k.isVacuum())
{
return true;
}
}
}
}
Iris.verbose("Not using parallax noise features (they arent used in this dimension)");
return false;
});
}
}

View File

@ -30,6 +30,7 @@ import lombok.Data;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Function;
@AllArgsConstructor
@ -56,9 +57,9 @@ public class ParallaxChunkMeta {
private int maxObject = -1;
private int minObject = -1;
private int count;
private KList<IrisFeaturePositional> features;
private CopyOnWriteArrayList<IrisFeaturePositional> features;
public ParallaxChunkMeta() {
this(false, false, false, false, false, false, -1, -1, 0, new KList<>());
this(false, false, false, false, false, false, -1, -1, 0, new CopyOnWriteArrayList<>());
}
}

View File

@ -156,7 +156,6 @@ public class ParallaxRegion extends HunkRegion {
}
public synchronized void save() throws IOException {
PrecisionStopwatch p = PrecisionStopwatch.start();
blockSlice.save();
objectSlice.save();
entitySlice.save();
@ -164,7 +163,6 @@ public class ParallaxRegion extends HunkRegion {
updateSlice.save();
saveMetaHunk();
super.save();
Iris.debug("Saved Parallax Region " + C.AQUA + getX() + "," + getZ() + C.LIGHT_PURPLE + " in " + C.RED + Form.duration(p.getMilliseconds(), 0));
}
public int unload() {