Slightly faster.

This commit is contained in:
Harrison Deng 2020-04-29 22:53:28 -05:00
parent 1b80c26348
commit 64a3e3db27

View File

@ -24,9 +24,9 @@ import ca.recrown.islandsurvivalcraft.world.IslandWorldMapper;
import ca.recrown.islandsurvivalcraft.world.shaders.WorldHeightShader;
public class IslandWorldChunkGenerator extends ChunkGenerator implements Listener {
private final Cache<Point2, Double> blockValueCache = new Cache<>(102400);
private final Cache<Point2, Biome[]> biomeCache = new Cache<>(102400);
private final Cache<Point2, Boolean> chunkExistenceCache = new Cache<>(16384);
private final Cache<Point2, Double> blockValueCache = new Cache<>(262144);
private final Cache<Point2, Biome[]> biomeCache = new Cache<>(262144);
private final Cache<Point2, Boolean> chunkExistenceCache = new Cache<>(32768);
private final BiomeSelector biomeSelector = new BiomeSelector();
private final ExecutorService executor = Utilities.ISC_EXECUTOR;
private volatile World currentWorld;
@ -59,25 +59,25 @@ public class IslandWorldChunkGenerator extends ChunkGenerator implements Listene
Biome[][] biomes = new Biome[Utilities.CHUNK_SIZE][Utilities.CHUNK_SIZE];
for (int x = 0; x < Utilities.CHUNK_SIZE; x++) {
for (int z = 0; z < Utilities.CHUNK_SIZE; z++) {
final int desX = x;
final int desZ = z;
if (biomes[desX][desZ] == null) {
biomeGenerator.generateBiomeColumn(biomes, world, chunkX, chunkZ, desX, desZ, mapper, biomeSelector,
final int localX = x;
final int localZ = z;
if (biomes[localX][localZ] == null) {
biomeGenerator.generateBiomeColumn(biomes, world, chunkX, chunkZ, localX, localZ, mapper, biomeSelector,
temperatureMapGenerator, biomeCache, chunkExistenceCache);
}
if (biomes[desX][desZ] == null) throw new IllegalStateException("Biome was null.");
if (biomes[localX][localZ] == null) throw new IllegalStateException("Biome was null.");
tasks.add(executor.submit(() -> {
for (int y = 0; y < maxHeight; y++) {
biomeGrid.setBiome(desX, y, desZ, biomes[desX][desZ]);
biomeGrid.setBiome(localX, y, localZ, biomes[localX][localZ]);
}
return true;
}));
final int worldX = Utilities.CHUNK_SIZE * chunkX + desX;
final int worldZ = Utilities.CHUNK_SIZE * chunkZ + desZ;
int height = heightShader.getAltitude(worldX, worldZ, biomes[desX][desZ]);
chunkData.setRegion(desX, 1, desZ, desX + 1, height, desZ + 1, Material.DIAMOND_BLOCK);
final int worldX = Utilities.CHUNK_SIZE * chunkX + localX;
final int worldZ = Utilities.CHUNK_SIZE * chunkZ + localZ;
int height = heightShader.getAltitude(worldX, worldZ, biomes[localX][localZ]);
chunkData.setRegion(localX, 1, localZ, localX + 1, height, localZ + 1, Material.DIAMOND_BLOCK);
}
}
chunkData.setRegion(0, 0, 0, 16, 1, 16, Material.BEDROCK);