mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-04 14:56:28 +00:00
optimize biome pipeline cache for 3 dimensions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
version = version("1.0.0")
|
||||
version = version("1.0.1")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline;
|
||||
|
||||
import com.dfsek.terra.api.util.Column;
|
||||
import com.dfsek.terra.api.util.function.IntIntObjConsumer;
|
||||
import com.dfsek.terra.api.util.function.IntObjConsumer;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
class BiomePipelineColumn implements Column<Biome> {
|
||||
private final int min;
|
||||
private final int max;
|
||||
|
||||
private final int x;
|
||||
private final int z;
|
||||
private final Biome biome;
|
||||
|
||||
protected BiomePipelineColumn(BiomeProvider biomeProvider, int min, int max, int x, int z, long seed) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.biome = biomeProvider.getBiome(x, 0, z, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinY() {
|
||||
return min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxY() {
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome get(int y) {
|
||||
return biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forRanges(IntIntObjConsumer<Biome> consumer) {
|
||||
consumer.accept(min, max, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<Biome> consumer) {
|
||||
for(int y = min; y < max; y++) {
|
||||
consumer.accept(biome);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(IntObjConsumer<Biome> consumer) {
|
||||
for(int y = min; y < max; y++) {
|
||||
consumer.accept(y, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
package com.dfsek.terra.addons.biome.pipeline;
|
||||
|
||||
import com.dfsek.terra.api.util.Column;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import net.jafama.FastMath;
|
||||
@@ -92,6 +95,11 @@ public class BiomePipelineProvider implements BiomeProvider {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Column<Biome> getColumn(int x, int z, WorldProperties properties) {
|
||||
return new BiomePipelineColumn(this, properties.getMinHeight(), properties.getMaxHeight(), x, z, properties.getSeed());
|
||||
}
|
||||
|
||||
private record SeededVector(int x, int z, long seed) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ public interface Column<T> {
|
||||
|
||||
int getMaxY();
|
||||
|
||||
int getX();
|
||||
int getZ();
|
||||
|
||||
T get(int y);
|
||||
|
||||
default void forEach(Consumer<T> consumer) {
|
||||
|
||||
@@ -32,6 +32,16 @@ class BiomeColumn implements Column<Biome> {
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome get(int y) {
|
||||
return biomeProvider.getBiome(x, y, z, seed);
|
||||
|
||||
@@ -21,7 +21,6 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
|
||||
private final int minY;
|
||||
private final int maxY;
|
||||
private final Map<Long, Biome[]> cache = new HashMap<>();
|
||||
private final Map<Long, Column<Biome>> columns = new HashMap<>();
|
||||
|
||||
protected CachingBiomeProvider(BiomeProvider delegate, int minY, int maxY) {
|
||||
this.delegate = delegate;
|
||||
@@ -47,7 +46,7 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
|
||||
|
||||
@Override
|
||||
public Column<Biome> getColumn(int x, int z, WorldProperties properties) {
|
||||
return columns.computeIfAbsent(MathUtil.squash(x, z), k -> BiomeProvider.super.getColumn(x, z, properties));
|
||||
return delegate.getColumn(x, z, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -87,7 +87,17 @@ public class ColumnTest {
|
||||
public int getMaxY() {
|
||||
return max;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int y) {
|
||||
return p.apply(y);
|
||||
|
||||
Reference in New Issue
Block a user