Minor performance improvements to generation

This commit is contained in:
dfsek 2020-11-17 14:39:05 -07:00
parent 291d0aaf1c
commit 2100718b2a
3 changed files with 23 additions and 14 deletions

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.biome;
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
import com.dfsek.terra.config.genconfig.biome.GeneratorOptions;
import com.dfsek.terra.generation.UserDefinedDecorator;
import org.bukkit.World;
@ -18,15 +19,17 @@ public class UserDefinedBiome implements Biome {
private final UserDefinedDecorator decorator;
private final org.bukkit.block.Biome vanilla;
private final String id;
private final BiomeConfig config;
private final boolean erode;
public UserDefinedBiome(org.bukkit.block.Biome vanilla, UserDefinedDecorator dec, GeneratorOptions gen, boolean erode, String id) {
public UserDefinedBiome(org.bukkit.block.Biome vanilla, UserDefinedDecorator dec, GeneratorOptions gen, boolean erode, BiomeConfig config) {
this.vanilla = vanilla;
this.decorator = dec;
this.gen = gen;
this.id = id;
this.id = config.getID();
this.erode = erode;
this.config = config;
}
/**
@ -77,6 +80,10 @@ public class UserDefinedBiome implements Biome {
return erode;
}
public BiomeConfig getConfig() {
return config;
}
@Override
public Generator getGenerator(World w) {
return gen.getGenerator(w.getSeed());

View File

@ -171,7 +171,7 @@ public class BiomeConfig extends TerraConfig {
try {
// Get UserDefinedBiome instance representing this config.
GeneratorOptions gen = new GeneratorOptions(eq, elevation, config.getVariableScope(), palette.getPaletteMap(), slant, config.getNoiseBuilders(), getBoolean("prevent-smooth", false), doElevationInterpolation);
this.biome = new UserDefinedBiome(vanillaBiome, dec, gen, getBoolean("erodible", false), biomeID);
this.biome = new UserDefinedBiome(vanillaBiome, dec, gen, getBoolean("erodible", false), this);
} catch(ParseException e) {
e.printStackTrace();
throw new ConfigException("Unable to parse noise equation!", getID());

View File

@ -80,17 +80,19 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
private static Palette<BlockData> getPalette(int x, int y, int z, BiomeConfig c, ChunkInterpolator interpolator, ElevationInterpolator elevationInterpolator) {
Palette<BlockData> slant = ((WorldGenerator) c.getBiome().getGenerator()).getSlantPalette(y);
if(slant != null) {
boolean north = interpolator.getNoise(x, y - elevationInterpolator.getElevation(x, z + 1), z + 1) > 0;
boolean south = interpolator.getNoise(x, y - elevationInterpolator.getElevation(x, z - 1), z - 1) > 0;
boolean east = interpolator.getNoise(x + 1, y - elevationInterpolator.getElevation(x + 1, z), z) > 0;
boolean west = interpolator.getNoise(x - 1, y - elevationInterpolator.getElevation(x - 1, z), z) > 0;
double ySlantOffsetTop = c.getYSlantOffsetTop();
double ySlantOffsetBottom = c.getYSlantOffsetBottom();
boolean top = interpolator.getNoise(x, y + ySlantOffsetTop - elevationInterpolator.getElevation(x, z), z) > 0;
boolean bottom = interpolator.getNoise(x, y - ySlantOffsetBottom - elevationInterpolator.getElevation(x, z), z) > 0;
if((top && bottom) && (north || south || east || west) && (!(north && south && east && west))) return slant;
if(top && bottom) {
boolean north = interpolator.getNoise(x, y - elevationInterpolator.getElevation(x, z + 1), z + 1) > 0;
boolean south = interpolator.getNoise(x, y - elevationInterpolator.getElevation(x, z - 1), z - 1) > 0;
boolean east = interpolator.getNoise(x + 1, y - elevationInterpolator.getElevation(x + 1, z), z) > 0;
boolean west = interpolator.getNoise(x - 1, y - elevationInterpolator.getElevation(x - 1, z), z) > 0;
if((north || south || east || west) && (!(north && south && east && west))) return slant;
}
}
return c.getBiome().getGenerator().getPalette(y);
}
@ -104,10 +106,10 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ());
Stairs stairNew = (Stairs) stair.clone();
double elevationN = elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ() - 1); // Northern elevation
double elevationS = elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ() + 1); // Southern elevation
double elevationE = elevationInterpolator.getElevation(block.getBlockX() + 1, block.getBlockZ()); // Eastern elevation
double elevationW = elevationInterpolator.getElevation(block.getBlockX() - 1, block.getBlockZ()); // Western elevation
int elevationN = (int) elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ() - 1); // Northern elevation
int elevationS = (int) elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ() + 1); // Southern elevation
int elevationE = (int) elevationInterpolator.getElevation(block.getBlockX() + 1, block.getBlockZ()); // Eastern elevation
int elevationW = (int) elevationInterpolator.getElevation(block.getBlockX() - 1, block.getBlockZ()); // Western elevation
if(interpolator.getNoise(block.getBlockX() - 0.5, block.getBlockY() - elevationW, block.getBlockZ()) > thresh) {
stairNew.setFacing(BlockFace.WEST);
} else if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - elevationN, block.getBlockZ() - 0.5) > thresh) {
@ -163,7 +165,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
int cz = zOrig + z;
Biome b = grid.getBiome(xOrig + x, zOrig + z, GenerationPhase.PALETTE_APPLY);
BiomeConfig c = config.getBiome((UserDefinedBiome) b);
BiomeConfig c = ((UserDefinedBiome) b).getConfig();
double elevate = elevationInterpolator.getElevation(x, z);