Prevent CMOD on feature iteration in parallax insertion

This commit is contained in:
Daniel Mills 2021-01-12 05:44:42 -05:00
parent 6cb15d004e
commit b7b15a8f7b

View File

@ -167,17 +167,26 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
int cz = (int) z >> 4; int cz = (int) z >> 4;
for (i = -s; i <= s; i++) { for (i = -s; i <= s; i++) {
int ii = i;
for (j = -s; j <= s; j++) { for (j = -s; j <= s; j++) {
int jj = j; ParallaxChunkMeta m = getParallaxAccess().getMetaR(i + cx, j + cz);
ParallaxChunkMeta m = getParallaxAccess().getMetaR(ii + cx, jj + cz);
for (IrisFeaturePositional k : m.getZones()) { synchronized (m.getFeatures())
{
try
{
for (IrisFeaturePositional k : m.getFeatures()) {
if (k.shouldFilter(x, z)) { if (k.shouldFilter(x, z)) {
f.accept(k); f.accept(k);
} }
} }
} }
catch(Throwable e)
{
Iris.warn("Failed to read positional features in chunk " + (i + cx) + " " + (j + cz) + "(" + e.getClass().getSimpleName() + ")");
}
}
}
} }
} }
@ -189,6 +198,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
int s = (int) Math.ceil(getParallaxSize() / 2D); int s = (int) Math.ceil(getParallaxSize() / 2D);
int i,j; int i,j;
KList<Runnable> after = new KList<>();
// Generate Initial Features // Generate Initial Features
for (i = -s; i <= s; i++) { for (i = -s; i <= s; i++) {
@ -210,7 +220,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
for (i = -s; i <= s; i++) { for (i = -s; i <= s; i++) {
for (j = -s; j <= s; j++) { for (j = -s; j <= s; j++) {
generateParallaxVacuumLayer(i +x, j +z); after.addAll(generateParallaxVacuumLayer(i +x, j +z));
} }
} }
@ -220,6 +230,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
} }
} }
after.forEach(Runnable::run);
getParallaxAccess().setChunkGenerated(x, z); getParallaxAccess().setChunkGenerated(x, z);
p.end(); p.end();
getEngine().getMetrics().getParallax().put(p.getMilliseconds()); getEngine().getMetrics().getParallax().put(p.getMilliseconds());
@ -232,19 +243,21 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
} }
} }
default void generateParallaxVacuumLayer(int x, int z) default KList<Runnable> generateParallaxVacuumLayer(int x, int z)
{ {
KList<Runnable> after = new KList<>();
if(getParallaxAccess().isParallaxGenerated(x, z)) if(getParallaxAccess().isParallaxGenerated(x, z))
{ {
return; return after;
} }
int xx = x<<4; int xx = x<<4;
int zz = z<<4; int zz = z<<4;
RNG rng = new RNG(Cache.key(x, z)).nextParallelRNG(getEngine().getTarget().getWorld().getSeed()); RNG rng = new RNG(Cache.key(x, z)).nextParallelRNG(getEngine().getTarget().getWorld().getSeed());
IrisBiome biome = getComplex().getTrueBiomeStream().get(xx+8, zz+8); IrisBiome biome = getComplex().getTrueBiomeStream().get(xx+8, zz+8);
after.addAll(generateParallaxJigsaw(rng, x, z, biome));
generateParallaxSurface(rng, x, z, biome, true); generateParallaxSurface(rng, x, z, biome, true);
generateParallaxMutations(rng, x, z, true); generateParallaxMutations(rng, x, z, true);
return after;
} }
default void generateParallaxLayer(int x, int z, boolean force) default void generateParallaxLayer(int x, int z, boolean force)
@ -260,7 +273,6 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
RNG rng = new RNG(Cache.key(x, z)).nextParallelRNG(getEngine().getTarget().getWorld().getSeed()); RNG rng = new RNG(Cache.key(x, z)).nextParallelRNG(getEngine().getTarget().getWorld().getSeed());
IrisRegion region = getComplex().getRegionStream().get(xx+8, zz+8); IrisRegion region = getComplex().getRegionStream().get(xx+8, zz+8);
IrisBiome biome = getComplex().getTrueBiomeStream().get(xx+8, zz+8); IrisBiome biome = getComplex().getTrueBiomeStream().get(xx+8, zz+8);
generateParallaxJigsaw(rng, x, z, biome);
generateParallaxSurface(rng, x, z, biome, false); generateParallaxSurface(rng, x, z, biome, false);
generateParallaxMutations(rng, x, z, false); generateParallaxMutations(rng, x, z, false);
generateStructures(rng, x, z, region, biome); generateStructures(rng, x, z, region, biome);
@ -288,7 +300,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
{ {
if(i.hasZone(rng, cx, cz)) if(i.hasZone(rng, cx, cz))
{ {
getParallaxAccess().getMetaRW(cx, cz).getZones().add(new IrisFeaturePositional((cx << 4) + rng.nextInt(16), (cz << 4)+ rng.nextInt(16), i.getZone())); getParallaxAccess().getMetaRW(cx, cz).getFeatures().add(new IrisFeaturePositional((cx << 4) + rng.nextInt(16), (cz << 4)+ rng.nextInt(16), i.getZone()));
} }
} }
@ -321,14 +333,31 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
} }
} }
default void generateParallaxJigsaw(RNG rng, int x, int z, IrisBiome biome) { default KList<Runnable> generateParallaxJigsaw(RNG rng, int x, int z, IrisBiome biome) {
KList<Runnable> placeAfter = new KList<>();
for (IrisJigsawStructurePlacement i : biome.getJigsaw()) for (IrisJigsawStructurePlacement i : biome.getJigsaw())
{ {
if(rng.nextInt(i.getRarity()) == 0) if(rng.nextInt(i.getRarity()) == 0)
{ {
new PlannedStructure(getData().getJigsawStructureLoader().load(i.getStructure()), new IrisPosition((x<<4) + rng.nextInt(15),0,(z<<4) + rng.nextInt(15)), rng).place(this, this); IrisPosition position = new IrisPosition((x<<4) + rng.nextInt(15),0,(z<<4) + rng.nextInt(15));
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure());
if(structure.getFeature() != null)
{
if(structure.getFeature().getBlockRadius() == 32)
{
structure.getFeature().setBlockRadius((double)structure.getMaxDimension()/3);
}
getParallaxAccess().getMetaRW(position.getX() >> 4, position.getZ() >> 4).getFeatures()
.add(new IrisFeaturePositional(position.getX(), position.getZ(), structure.getFeature()));
}
placeAfter.addAll(new PlannedStructure(structure, position, rng).place(this, this));
} }
} }
return placeAfter;
} }
default void generateParallaxSurface(RNG rng, int x, int z, IrisBiome biome, boolean vacuum) { default void generateParallaxSurface(RNG rng, int x, int z, IrisBiome biome, boolean vacuum) {
@ -416,16 +445,18 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
f.setInterpolator(InterpolationMethod.BILINEAR_STARCAST_9); f.setInterpolator(InterpolationMethod.BILINEAR_STARCAST_9);
f.setStrength(1D); f.setStrength(1D);
getParallaxAccess().getMetaRW(xx>>4, zz>>4) getParallaxAccess().getMetaRW(xx>>4, zz>>4)
.getZones() .getFeatures()
.add(new IrisFeaturePositional(xx, zz, f)); .add(new IrisFeaturePositional(xx, zz, f));
} }
} }
default void place(RNG rng, int x, int forceY, int z, IrisObjectPlacement objectPlacement) default void place(RNG rng, int x, int forceY, int z, IrisObjectPlacement objectPlacement)
{
try
{ {
for(int i = 0; i < objectPlacement.getDensity(); i++) for(int i = 0; i < objectPlacement.getDensity(); i++)
{ {
IrisObject v = objectPlacement.getSchematic(getComplex(), rng); IrisObject v = objectPlacement.getObject(getComplex(), rng);
int xx = rng.i(x, x+16); int xx = rng.i(x, x+16);
int zz = rng.i(z, z+16); int zz = rng.i(z, z+16);
int id = rng.i(0, Integer.MAX_VALUE); int id = rng.i(0, Integer.MAX_VALUE);
@ -455,12 +486,19 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
f.setInterpolator(InterpolationMethod.BILINEAR_STARCAST_9); f.setInterpolator(InterpolationMethod.BILINEAR_STARCAST_9);
f.setStrength(1D); f.setStrength(1D);
getParallaxAccess().getMetaRW(xx>>4, zz>>4) getParallaxAccess().getMetaRW(xx>>4, zz>>4)
.getZones() .getFeatures()
.add(new IrisFeaturePositional(xx, zz, f)); .add(new IrisFeaturePositional(xx, zz, f));
} }
} }
} }
catch(Throwable e)
{
Iris.error("Failed to place one of the following object(s) " + objectPlacement.getPlace().toString(", ") + " (" + e.getClass().getSimpleName() + "). Are these objects missing?");
e.printStackTrace();
}
}
default void updateParallaxChunkObjectData(int minY, int maxY, int x, int z, IrisObject v) default void updateParallaxChunkObjectData(int minY, int maxY, int x, int z, IrisObject v)
{ {
ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(x >> 4, z >> 4); ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(x >> 4, z >> 4);