mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 05:50:08 +00:00
use resolution in CachingBiomeProviders
This commit is contained in:
1 parent
cfeeb432ea
commit
9081f3a004
2 files changed
+36
-11
No files matched your search
+5
@@ -60,4 +60,9 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
|
|||||||
public Iterable<Biome> getBiomes() {
|
public Iterable<Biome> getBiomes() {
|
||||||
return delegate.getBiomes();
|
return delegate.getBiomes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int resolution() {
|
||||||
|
return delegate.resolution();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+31
-11
@@ -1,14 +1,13 @@
|
|||||||
package com.dfsek.terra.api.world.biome.generation;
|
package com.dfsek.terra.api.world.biome.generation;
|
||||||
|
|
||||||
import com.dfsek.terra.api.util.Column;
|
|
||||||
import com.dfsek.terra.api.util.generic.Construct;
|
|
||||||
import com.dfsek.terra.api.world.biome.Biome;
|
|
||||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
|
||||||
|
|
||||||
import net.jafama.FastMath;
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.util.Column;
|
||||||
|
import com.dfsek.terra.api.world.biome.Biome;
|
||||||
|
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A biome provider implementation that lazily evaluates biomes, and caches them.
|
* A biome provider implementation that lazily evaluates biomes, and caches them.
|
||||||
@@ -20,17 +19,25 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
public class ChunkLocalCachingBiomeProvider extends CachingBiomeProvider {
|
public class ChunkLocalCachingBiomeProvider extends CachingBiomeProvider {
|
||||||
private final BiomeChunk[] chunks = new BiomeChunk[9];
|
private final BiomeChunk[] chunks = new BiomeChunk[9];
|
||||||
private final Column<Biome>[] columnCache = new Column[256]; // x + z * 16
|
private final Column<Biome>[] columnCache; // x + z * 16
|
||||||
|
|
||||||
private final int chunkX;
|
private final int chunkX;
|
||||||
private final int chunkZ;
|
private final int chunkZ;
|
||||||
private final int height;
|
private final int height;
|
||||||
|
|
||||||
|
private final int zMul;
|
||||||
|
private final int yMul;
|
||||||
|
private final int resolution;
|
||||||
|
|
||||||
protected ChunkLocalCachingBiomeProvider(BiomeProvider delegate, WorldProperties worldProperties, int chunkX, int chunkZ) {
|
protected ChunkLocalCachingBiomeProvider(BiomeProvider delegate, WorldProperties worldProperties, int chunkX, int chunkZ) {
|
||||||
super(delegate, worldProperties.getMinHeight(), worldProperties.getMaxHeight());
|
super(delegate, worldProperties.getMinHeight(), worldProperties.getMaxHeight());
|
||||||
this.height = maxY - minY;
|
this.height = maxY - minY;
|
||||||
this.chunkX = chunkX;
|
this.chunkX = chunkX;
|
||||||
this.chunkZ = chunkZ;
|
this.chunkZ = chunkZ;
|
||||||
|
this.resolution = delegate.resolution();
|
||||||
|
this.zMul = 16 / resolution;
|
||||||
|
this.yMul = zMul * zMul;
|
||||||
|
this.columnCache = new Column[yMul];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -43,16 +50,21 @@ public class ChunkLocalCachingBiomeProvider extends CachingBiomeProvider {
|
|||||||
int localChunkX = FastMath.floorDiv(x, 16) - this.chunkX + 1;
|
int localChunkX = FastMath.floorDiv(x, 16) - this.chunkX + 1;
|
||||||
int localChunkZ = FastMath.floorDiv(z, 16) - this.chunkZ + 1;
|
int localChunkZ = FastMath.floorDiv(z, 16) - this.chunkZ + 1;
|
||||||
|
|
||||||
|
|
||||||
if(localChunkX >= 0 && localChunkZ >= 0 && localChunkX <= 2 && localChunkZ <= 2) {
|
if(localChunkX >= 0 && localChunkZ >= 0 && localChunkX <= 2 && localChunkZ <= 2) {
|
||||||
int chunkIndex = localChunkX + localChunkZ * 3;
|
int chunkIndex = localChunkX + localChunkZ * 3;
|
||||||
|
|
||||||
BiomeChunk chunk = chunks[chunkIndex];
|
BiomeChunk chunk = chunks[chunkIndex];
|
||||||
if(chunk == null) {
|
if(chunk == null) {
|
||||||
chunk = new BiomeChunk(height);
|
chunk = new BiomeChunk(height / resolution, yMul);
|
||||||
chunks[chunkIndex] = chunk;
|
chunks[chunkIndex] = chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int scaledX = FastMath.floorDiv(x & 15, resolution);
|
||||||
|
int scaledY = FastMath.floorDiv(y - minY, resolution);
|
||||||
|
int scaledZ = FastMath.floorDiv(z & 15, resolution);
|
||||||
|
|
||||||
int biomeIndex = (x & 15) + 16 * (z & 15) + 256 * (y - minY);
|
int biomeIndex = scaledX + zMul * scaledZ + yMul * scaledY;
|
||||||
Biome biome = chunk.cache[biomeIndex];
|
Biome biome = chunk.cache[biomeIndex];
|
||||||
if(biome == null) {
|
if(biome == null) {
|
||||||
biome = delegate.getBiome(x, y, z, seed);
|
biome = delegate.getBiome(x, y, z, seed);
|
||||||
@@ -71,8 +83,11 @@ public class ChunkLocalCachingBiomeProvider extends CachingBiomeProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Column<Biome> getColumn(int x, int z, long seed, int min, int max) {
|
public Column<Biome> getColumn(int x, int z, long seed, int min, int max) {
|
||||||
|
int scaledX = (x & 15) / resolution;
|
||||||
|
int scaledZ = (z & 15) / resolution;
|
||||||
|
|
||||||
if(FastMath.floorDiv(x, 16) == chunkX && FastMath.floorDiv(z, 16) == chunkZ) {
|
if(FastMath.floorDiv(x, 16) == chunkX && FastMath.floorDiv(z, 16) == chunkZ) {
|
||||||
int index = (x & 15) + (16 * (z & 15));
|
int index = scaledX + (zMul * scaledZ);
|
||||||
Column<Biome> column = columnCache[index];
|
Column<Biome> column = columnCache[index];
|
||||||
if(column == null) {
|
if(column == null) {
|
||||||
column = new BiomeColumn(this, min, max, x, z, seed);
|
column = new BiomeColumn(this, min, max, x, z, seed);
|
||||||
@@ -88,11 +103,16 @@ public class ChunkLocalCachingBiomeProvider extends CachingBiomeProvider {
|
|||||||
return delegate.getBiomes();
|
return delegate.getBiomes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int resolution() {
|
||||||
|
return resolution;
|
||||||
|
}
|
||||||
|
|
||||||
private static class BiomeChunk {
|
private static class BiomeChunk {
|
||||||
final Biome[] cache; // x + z * 16 + y * 256
|
final Biome[] cache; // x + z * 16 + y * 256
|
||||||
|
|
||||||
private BiomeChunk(int height) {
|
private BiomeChunk(int height, int widthSq) {
|
||||||
this.cache = new Biome[16 * 16 * height];
|
this.cache = new Biome[widthSq * height];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user