Improve biome generator performance (sync) efficiency

This commit is contained in:
Daniel Mills 2021-07-17 00:29:09 -04:00
parent 7cd0070d90
commit bcdd470567
3 changed files with 33 additions and 8 deletions

View File

@ -179,7 +179,7 @@ public class CommandIrisCreate extends MortarCommand {
});
});
};
if (multiverse) {
dim = IrisDataManager.loadAnyDimension(type);

View File

@ -62,13 +62,14 @@ public class IrisBiomeActuator extends EngineAssignedActuator<Biome> {
@Override
public void onActuate(int x, int z, Hunk<Biome> h) {
PrecisionStopwatch p = PrecisionStopwatch.start();
int zf;
int zf, maxHeight;
IrisBiome ib;
for (int xf = 0; xf < h.getWidth(); xf++) {
for (zf = 0; zf < h.getDepth(); zf++) {
IrisBiome ib = getComplex().getTrueBiomeStream().get(modX(xf + x), modZ(zf + z));
ib = getComplex().getTrueBiomeStream().get(modX(xf + x), modZ(zf + z));
maxHeight = (int) (getComplex().getFluidHeight() + ib.getMaxWithObjectHeight(getData()));
if (ib.isCustom()) {
try {
IrisBiomeCustom custom = ib.getCustomBiome(rng, x, 0, z);
@ -78,20 +79,20 @@ public class IrisBiomeActuator extends EngineAssignedActuator<Biome> {
throw new RuntimeException("Cant inject biome!");
}
for (int i = 0; i < h.getHeight(); i++) {
for (int i = 0; i < maxHeight; i++) {
injectBiome(h, xf, i, zf, biomeBase);
}
} catch (Throwable e) {
Iris.reportError(e);
e.printStackTrace();
Biome v = ib.getSkyBiome(rng, x, 0, z);
for (int i = 0; i < h.getHeight(); i++) {
for (int i = 0; i < maxHeight; i++) {
h.set(xf, i, zf, v);
}
}
} else {
Biome v = ib.getSkyBiome(rng, x, 0, z);
for (int i = 0; i < h.getHeight(); i++) {
for (int i = 0; i < maxHeight; i++) {
h.set(xf, i, zf, v);
}
}

View File

@ -212,6 +212,7 @@ public class IrisBiome extends IrisRegistrant implements IRare {
private final transient AtomicCache<CNG> childrenCell = new AtomicCache<>();
private final transient AtomicCache<CNG> biomeGenerator = new AtomicCache<>();
private final transient AtomicCache<Integer> maxHeight = new AtomicCache<>();
private final transient AtomicCache<Integer> maxWithObjectHeight = new AtomicCache<>();
private final transient AtomicCache<IrisBiome> realCarveBiome = new AtomicCache<>();
private final transient AtomicCache<KList<IrisBiome>> realChildren = new AtomicCache<>();
private final transient AtomicCache<KList<CNG>> layerHeightGenerators = new AtomicCache<>();
@ -425,7 +426,7 @@ public class IrisBiome extends IrisRegistrant implements IRare {
return real;
}
private int getMaxHeight() {
public int getMaxHeight() {
return maxHeight.aquire(() ->
{
int maxHeight = 0;
@ -438,6 +439,29 @@ public class IrisBiome extends IrisRegistrant implements IRare {
});
}
public int getMaxWithObjectHeight(IrisDataManager data) {
return maxWithObjectHeight.aquire(() ->
{
int maxHeight = 0;
for (IrisBiomeGeneratorLink i : getGenerators()) {
maxHeight += i.getMax();
}
int gg = 0;
for(IrisObjectPlacement i : getObjects())
{
for(IrisObject j : data.getObjectLoader().loadAll(i.getPlace()))
{
gg = Math.max(gg, j.getH());
}
}
return maxHeight + gg+3;
});
}
public IrisBiome infer(InferredType t, InferredType type) {
setInferredType(t.equals(InferredType.DEFER) ? type : t);
return this;