minor perf improvements

This commit is contained in:
dfsek
2021-01-13 14:03:52 -07:00
parent 54f732176d
commit d1c018690d
7 changed files with 40 additions and 52 deletions

View File

@@ -1616,30 +1616,29 @@ public class FastNoiseLite implements NoiseSampler {
return lerp(xf0, xf1, ys) * 1.4247691104677813f;
}
private static long hash(long in) {
in = (in + 0x7ed55d16) + (in << 12);
in = (in ^ 0xc761c23c) ^ (in >> 19);
in = (in + 0x165667b1) + (in << 5);
in = (in + 0xd3a2646c) ^ (in << 9);
in = (in + 0xfd7046c5) + (in << 3);
in = (in ^ 0xb55a4f09) ^ (in >> 16);
return in;
long murmur64(long h) {
h ^= h >>> 33;
h *= 0xff51afd7ed558ccdL;
h ^= h >>> 33;
h *= 0xc4ceb9fe1a85ec53L;
h ^= h >>> 33;
return h;
}
private double singleWhiteNoise(int seed, double x, double y, double z) {
long hashX = hash(Double.doubleToRawLongBits(x) ^ seed);
long hashZ = hash(Double.doubleToRawLongBits(y) ^ seed);
long hashX = murmur64(Double.doubleToRawLongBits(x) ^ seed);
long hashZ = murmur64(Double.doubleToRawLongBits(y) ^ seed);
long hash = (((hashX ^ (hashX >>> 32)) + ((hashZ ^ (hashZ >>> 32)) << 32)) ^ seed) + Double.doubleToRawLongBits(z);
long base = ((hash(hash)) & 0x000fffffffffffffL)
long base = ((murmur64(hash)) & 0x000fffffffffffffL)
+ POSITIVE_POW1; // Sign and exponent
return (Double.longBitsToDouble(base) - 1.5) * 2;
}
private double singleWhiteNoise(int seed, double x, double y) {
long hashX = hash(Double.doubleToRawLongBits(x) ^ seed);
long hashZ = hash(Double.doubleToRawLongBits(y) ^ seed);
long hashX = murmur64(Double.doubleToRawLongBits(x) ^ seed);
long hashZ = murmur64(Double.doubleToRawLongBits(y) ^ seed);
long hash = ((hashX ^ (hashX >>> 32)) + ((hashZ ^ (hashZ >>> 32)) << 32)) ^ seed;
long base = (hash(hash) & 0x000fffffffffffffL)
long base = (murmur64(hash) & 0x000fffffffffffffL)
+ POSITIVE_POW1; // Sign and exponent
return (Double.longBitsToDouble(base) - 1.5) * 2;
}

View File

@@ -41,7 +41,7 @@ public class StandardBiomeProvider implements BiomeProvider {
}
}
);
private int resolution = 4;
private int resolution = 1;
protected StandardBiomeProvider(BiomePipeline pipeline) {
this.pipeline = pipeline;

View File

@@ -21,7 +21,7 @@ public class BiomePipeline {
}
public BiomeHolder getBiomes(int x, int z) {
BiomeHolder holder = new TerraBiomeHolder(25, new Vector2(x * (init - 1), z * (init - 1)));
BiomeHolder holder = new TerraBiomeHolder(init, new Vector2(x * (init - 1), z * (init - 1)));
holder.fill(source);
for(Stage stage : stages) holder = stage.apply(holder);
return holder;

View File

@@ -12,6 +12,7 @@ public class TerraBiomeHolder implements BiomeHolder {
private TerraBiome[][] biomes;
public TerraBiomeHolder(int width, Vector2 origin) {
if(width % 2 == 0) throw new IllegalArgumentException();
this.width = width;
biomes = new TerraBiome[width][width];
this.origin = origin;
@@ -48,11 +49,7 @@ public class TerraBiomeHolder implements BiomeHolder {
public void mutate(BiomeMutator mutator) {
for(int x = 0; x < width; x++) {
for(int z = 0; z < width; z++) {
BiomeMutator.ViewPoint viewPoint = new BiomeMutator.ViewPoint(new TerraBiome[][] {
{getBiomeRaw(x - 1, z + 1), getBiomeRaw(x, z + 1), getBiomeRaw(x + 1, z + 1)},
{getBiomeRaw(x - 1, z), getBiomeRaw(x, z), getBiomeRaw(x + 1, z)},
{getBiomeRaw(x - 1, z - 1), getBiomeRaw(x, z - 1), getBiomeRaw(x + 1, z - 1)}
});
BiomeMutator.ViewPoint viewPoint = new BiomeMutator.ViewPoint(this, x, z);
biomes[x][z] = mutator.mutate(viewPoint, x + origin.getX(), z + origin.getZ());
}
}
@@ -67,11 +64,6 @@ public class TerraBiomeHolder implements BiomeHolder {
}
}
private TerraBiome getBiomeRaw(int x, int z) {
if(x >= width || z >= width || x < 0 || z < 0) return null;
return biomes[x][z];
}
@Override
public TerraBiome getBiome(int x, int z) {
if(x >= width || z >= width || x < 0 || z < 0) return null;

View File

@@ -1,19 +1,25 @@
package com.dfsek.terra.biome.pipeline.mutator;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.biome.pipeline.BiomeHolder;
public interface BiomeMutator {
TerraBiome mutate(ViewPoint viewPoint, double x, double z);
class ViewPoint {
private final TerraBiome[][] biomes;
private final BiomeHolder biomes;
private final int offX;
private final int offZ;
public ViewPoint(TerraBiome[][] biomes) {
public ViewPoint(BiomeHolder biomes, int offX, int offZ) {
this.biomes = biomes;
this.offX = offX;
this.offZ = offZ;
}
public TerraBiome getBiome(int x, int z) {
return biomes[x + 1][z + 1];
return biomes.getBiome(x + offX, z + offZ);
}
}
}

View File

@@ -146,6 +146,8 @@ public class ConfigPack implements LoaderRegistrar {
selfLoader.load(template, stream);
load(new ZIPLoader(file), l, main);
template.getProviderBuilder().build(0); // Build dummy provider to catch errors at load time.
}
private void load(Loader loader, long start, TerraPlugin main) throws ConfigException {