mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-10 17:56:03 +00:00
cache columns in BiomeProvider
This commit is contained in:
@@ -63,12 +63,8 @@ public interface BiomeProvider {
|
||||
return getBiome(vector3.getX(), vector3.getY(), vector3.getZ(), seed);
|
||||
}
|
||||
|
||||
default Column<Biome> getColumn(int x, int z, int min, int max, long seed) {
|
||||
return new BiomeColumn(this, min, max, x, z, seed);
|
||||
}
|
||||
|
||||
default Column<Biome> getColumn(int x, int z, WorldProperties properties) {
|
||||
return getColumn(x, z, properties.getMinHeight(), properties.getMaxHeight(), properties.getSeed());
|
||||
return new BiomeColumn(this, x, z, properties.getMinHeight(), properties.getMaxHeight(), properties.getSeed());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.dfsek.terra.api.world.biome.generation;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.util.Column;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -18,6 +21,7 @@ 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;
|
||||
@@ -41,6 +45,11 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
|
||||
return biomes[yi];
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Biome> getBiomes() {
|
||||
return delegate.getBiomes();
|
||||
|
||||
Reference in New Issue
Block a user