Fix parallax

This commit is contained in:
Daniel Mills 2020-12-26 06:12:50 -05:00
parent 5f50fa4202
commit b44501566c
2 changed files with 43 additions and 17 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.volmit</groupId> <groupId>com.volmit</groupId>
<artifactId>Iris</artifactId> <artifactId>Iris</artifactId>
<version>1.1.7</version> <version>1.1.8</version>
<name>Iris</name> <name>Iris</name>
<properties> <properties>
<skip.copy>false</skip.copy> <skip.copy>false</skip.copy>

View File

@ -74,6 +74,16 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer
default void insertParallax(int x, int z, Hunk<BlockData> data) default void insertParallax(int x, int z, Hunk<BlockData> data)
{ {
insertParallax(x, z, data, 5);
}
default void insertParallax(int x, int z, Hunk<BlockData> data, int tries)
{
if(tries <= 0)
{
Iris.error("Parallax In " + x + " " + z + " placed nothing even though there is data there? (Tried 5 times, FAILED!!!)");
}
try try
{ {
PrecisionStopwatch p = PrecisionStopwatch.start(); PrecisionStopwatch p = PrecisionStopwatch.start();
@ -93,23 +103,43 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer
int min = Math.max(meta.getMinObject(), 0); int min = Math.max(meta.getMinObject(), 0);
int max = meta.getMaxObject(); int max = meta.getMaxObject();
max = max < 0 ? 255 : max; max = max < 0 ? 255 : max;
boolean placed = false;
for(int i = x; i < x+ data.getWidth(); i++) for(int i = x; i < x+ data.getWidth(); i++)
{ {
for(int j= z; j < z + data.getDepth(); j++) for(int j= z; j < z + data.getDepth(); j++)
{ {
for(int k = min; k < max; k++) for(int k = min; k <= max; k++)
{ {
BlockData d = getParallaxAccess().getBlock(i, k, j); BlockData d = getParallaxAccess().getBlock(i, k, j);
if(d != null) if(d != null)
{ {
data.set(i - x, k, j - z, d); data.set(i - x, k, j - z, d);
placed = true;
} }
} }
} }
} }
if(!placed)
{
Iris.warn("Parallax In " + x + " " + z + " had issues placing Retrying: " + tries);
if(tries < 4)
{
Iris.warn("Parallax Regenerating the entire parallax Layer at " + x + " " + z + " since it's not recovering data...");
generateParallaxLayer(x, z, true);
}
insertParallax(x, z, data, tries-1);
}
else if(tries < 5)
{
Iris.info("Parallax Fixed in " + x + " " + z);
}
getEngine().getMetrics().getParallaxInsert().put(p.getMilliseconds()); getEngine().getMetrics().getParallaxInsert().put(p.getMilliseconds());
} }
@ -148,9 +178,11 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer
} }
} }
default void generateParallaxLayer(int x, int z)
default void generateParallaxLayer(int x, int z, boolean force)
{ {
if(getParallaxAccess().isParallaxGenerated(x >> 4, z >> 4)) if(!force && getParallaxAccess().isParallaxGenerated(x >> 4, z >> 4))
{ {
return; return;
} }
@ -163,6 +195,10 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer
generateParallaxMutations(rng, x, z); generateParallaxMutations(rng, x, z);
generateStructures(rng, x>>4, z>>4, region, biome); generateStructures(rng, x>>4, z>>4, region, biome);
} }
default void generateParallaxLayer(int x, int z)
{
generateParallaxLayer(x, z, false);
}
default KList<PlacedObject> generateParallaxLayerObjects(int x, int z) default KList<PlacedObject> generateParallaxLayerObjects(int x, int z)
{ {
@ -238,6 +274,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer
default void generateParallaxSurface(RNG rng, int x, int z, IrisBiome biome, KList<PlacedObject> objects) { default void generateParallaxSurface(RNG rng, int x, int z, IrisBiome biome, KList<PlacedObject> objects) {
for (IrisObjectPlacement i : biome.getSurfaceObjects()) for (IrisObjectPlacement i : biome.getSurfaceObjects())
{ {
Iris.info("Found Placement: " + i.getPlace());
if(rng.chance(i.getChance())) if(rng.chance(i.getChance()))
{ {
place(rng, x, z, i, objects); place(rng, x, z, i, objects);
@ -348,20 +385,9 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer
getParallaxAccess().setObject(xf, yf, zf, v.getLoadKey() + "@" + id); getParallaxAccess().setObject(xf, yf, zf, v.getLoadKey() + "@" + id);
ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(xf>>4, zf>>4); ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(xf>>4, zf>>4);
meta.setObjects(true); meta.setObjects(true);
if(meta.getMinObject() == -1) meta.setMinObject(Math.min(Math.max(meta.getMinObject(), 0), yf));
{ meta.setMaxObject(Math.max(Math.max(meta.getMaxObject(), 0), yf));
meta.setMinObject(yf);
}
if(meta.getMinObject() > yf)
{
meta.setMinObject(yf);
}
if(meta.getMaxObject() < yf)
{
meta.setMaxObject(yf);
}
}, null, getData()); }, null, getData());
} }
} }