mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-08 16:56:07 +00:00
remove unneeded Sampler interface
This commit is contained in:
@@ -10,6 +10,8 @@ package com.dfsek.terra.addons.chunkgenerator.generation.generators;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.BiomeNoiseProperties;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler3D;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -23,7 +25,6 @@ import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
@@ -60,7 +61,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
int xOrig = (chunkX << 4);
|
||||
int zOrig = (chunkZ << 4);
|
||||
|
||||
Sampler sampler = samplerCache.getChunk(chunkX, chunkZ, world);
|
||||
Sampler3D sampler = samplerCache.getChunk(chunkX, chunkZ, world);
|
||||
|
||||
long seed = world.getSeed();
|
||||
|
||||
@@ -110,7 +111,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
public BlockState getBlock(ServerWorld world, int x, int y, int z) {
|
||||
BiomeProvider provider = world.getBiomeProvider();
|
||||
Biome biome = provider.getBiome(x, z, world.getSeed());
|
||||
Sampler sampler = samplerCache.get(x, z, world);
|
||||
Sampler3D sampler = samplerCache.get(x, z, world);
|
||||
|
||||
PaletteInfo paletteInfo = biome.getContext().get(PaletteInfo.class);
|
||||
Palette palette = PaletteUtil.getPalette(x, y, z, sampler, paletteInfo);
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler3D;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteInfo;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.SlantHolder;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public final class PaletteUtil {
|
||||
*/
|
||||
private static final double DERIVATIVE_DIST = 0.55;
|
||||
|
||||
public static Palette getPalette(int x, int y, int z, Sampler sampler, PaletteInfo paletteInfo) {
|
||||
public static Palette getPalette(int x, int y, int z, Sampler3D sampler, PaletteInfo paletteInfo) {
|
||||
SlantHolder slant = paletteInfo.getSlantHolder();
|
||||
if(slant != null) {
|
||||
double slope = derivative(sampler, x, y, z);
|
||||
@@ -31,7 +31,7 @@ public final class PaletteUtil {
|
||||
return paletteInfo.getPaletteHolder().getPalette(y);
|
||||
}
|
||||
|
||||
public static double derivative(Sampler sampler, double x, double y, double z) {
|
||||
public static double derivative(Sampler3D sampler, double x, double y, double z) {
|
||||
double baseSample = sampler.sample(x, y, z);
|
||||
|
||||
double xVal1 = (sampler.sample(x + DERIVATIVE_DIST, y, z) - baseSample) / DERIVATIVE_DIST;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.samplers;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Sampler {
|
||||
double sample(double x, double y, double z);
|
||||
|
||||
default double sample(int x, int y,
|
||||
int z) { // Floating-point modulus operations are expensive. This allows implementations to optionally handle
|
||||
// integers separately.
|
||||
return sample((double) x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation.Eleva
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class Sampler3D implements Sampler {
|
||||
public class Sampler3D {
|
||||
private final ChunkInterpolator3D interpolator;
|
||||
private final ElevationInterpolator elevationInterpolator;
|
||||
|
||||
@@ -24,12 +24,10 @@ public class Sampler3D implements Sampler {
|
||||
this.elevationInterpolator = new ElevationInterpolator(seed, x, z, provider, elevationSmooth);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sample(double x, double y, double z) {
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sample(int x, int y, int z) {
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z));
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class SamplerProvider {
|
||||
private final LoadingCache<Pair<Long, World>, Sampler> cache;
|
||||
private final LoadingCache<Pair<Long, World>, Sampler3D> cache;
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SamplerProvider {
|
||||
cache = CacheBuilder.newBuilder().maximumSize(platform.getTerraConfig().getSamplerCache())
|
||||
.build(new CacheLoader<>() {
|
||||
@Override
|
||||
public Sampler load(@NotNull Pair<Long, World> pair) {
|
||||
public Sampler3D load(@NotNull Pair<Long, World> pair) {
|
||||
long key = pair.getLeft();
|
||||
int cx = (int) (key >> 32);
|
||||
int cz = (int) key;
|
||||
@@ -50,13 +50,13 @@ public class SamplerProvider {
|
||||
});
|
||||
}
|
||||
|
||||
public Sampler get(int x, int z, World world) {
|
||||
public Sampler3D get(int x, int z, World world) {
|
||||
int cx = FastMath.floorDiv(x, 16);
|
||||
int cz = FastMath.floorDiv(z, 16);
|
||||
return getChunk(cx, cz, world);
|
||||
}
|
||||
|
||||
public Sampler getChunk(int cx, int cz, World world) {
|
||||
public Sampler3D getChunk(int cx, int cz, World world) {
|
||||
long key = MathUtil.squash(cx, cz);
|
||||
return cache.getUnchecked(Pair.of(key, world));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user