Hex chunk multithread fix
This commit is contained in:
parent
bed87c7d8a
commit
b46875599d
2 changed files with 10 additions and 9 deletions
|
@ -19,12 +19,13 @@ public class HexBiomeChunk implements BiomeChunk {
|
||||||
private static final byte SIDE_OFFSET = (byte) Math.round(Math.log(SIDE) / Math.log(2));
|
private static final byte SIDE_OFFSET = (byte) Math.round(Math.log(SIDE) / Math.log(2));
|
||||||
private static final byte SIDE_PRE_OFFSET = (byte) Math.round(Math.log(SIDE_PRE) / Math.log(2));
|
private static final byte SIDE_PRE_OFFSET = (byte) Math.round(Math.log(SIDE_PRE) / Math.log(2));
|
||||||
private static final short[][] NEIGHBOURS;
|
private static final short[][] NEIGHBOURS;
|
||||||
private static final BCLBiome[][] BUFFERS = new BCLBiome[2][SIZE];
|
|
||||||
|
|
||||||
private final BCLBiome[] biomes = new BCLBiome[SIZE];
|
private final BCLBiome[] biomes = new BCLBiome[SIZE];
|
||||||
|
|
||||||
public HexBiomeChunk(Random random, BiomePicker picker) {
|
public HexBiomeChunk(Random random, BiomePicker picker) {
|
||||||
for (BCLBiome[] buffer: BUFFERS) {
|
BCLBiome[][] buffers = new BCLBiome[2][SIZE];
|
||||||
|
|
||||||
|
for (BCLBiome[] buffer: buffers) {
|
||||||
Arrays.fill(buffer, null);
|
Arrays.fill(buffer, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,15 +34,15 @@ public class HexBiomeChunk implements BiomeChunk {
|
||||||
byte pz = (byte) (index & SIDE_PRE_MASK);
|
byte pz = (byte) (index & SIDE_PRE_MASK);
|
||||||
px = (byte) (px * SCALE_PRE + random.nextInt(SCALE_PRE));
|
px = (byte) (px * SCALE_PRE + random.nextInt(SCALE_PRE));
|
||||||
pz = (byte) (pz * SCALE_PRE + random.nextInt(SCALE_PRE));
|
pz = (byte) (pz * SCALE_PRE + random.nextInt(SCALE_PRE));
|
||||||
circle(BUFFERS[0], getIndex(px, pz), picker.getBiome(random), null);
|
circle(buffers[0], getIndex(px, pz), picker.getBiome(random), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasEmptyCells = true;
|
boolean hasEmptyCells = true;
|
||||||
byte bufferIndex = 0;
|
byte bufferIndex = 0;
|
||||||
while (hasEmptyCells) {
|
while (hasEmptyCells) {
|
||||||
BCLBiome[] inBuffer = BUFFERS[bufferIndex];
|
BCLBiome[] inBuffer = buffers[bufferIndex];
|
||||||
bufferIndex = (byte) ((bufferIndex + 1) & 1);
|
bufferIndex = (byte) ((bufferIndex + 1) & 1);
|
||||||
BCLBiome[] outBuffer = BUFFERS[bufferIndex];
|
BCLBiome[] outBuffer = buffers[bufferIndex];
|
||||||
hasEmptyCells = false;
|
hasEmptyCells = false;
|
||||||
|
|
||||||
for (short index = SIDE; index < MAX_SIDE; index++) {
|
for (short index = SIDE; index < MAX_SIDE; index++) {
|
||||||
|
@ -63,7 +64,7 @@ public class HexBiomeChunk implements BiomeChunk {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BCLBiome[] outBuffer = BUFFERS[bufferIndex];
|
BCLBiome[] outBuffer = buffers[bufferIndex];
|
||||||
byte preN = (byte) (SIDE_MASK - 2);
|
byte preN = (byte) (SIDE_MASK - 2);
|
||||||
for (byte index = 0; index < SIDE; index++) {
|
for (byte index = 0; index < SIDE; index++) {
|
||||||
outBuffer[getIndex(index, (byte) 0)] = outBuffer[getIndex(index, (byte) 2)];
|
outBuffer[getIndex(index, (byte) 0)] = outBuffer[getIndex(index, (byte) 2)];
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class HexBiomeMap implements BiomeMap {
|
||||||
noises[0] = new OpenSimplexNoise(random.nextInt());
|
noises[0] = new OpenSimplexNoise(random.nextInt());
|
||||||
noises[1] = new OpenSimplexNoise(random.nextInt());
|
noises[1] = new OpenSimplexNoise(random.nextInt());
|
||||||
noiseIterations = (byte) Math.min(Math.ceil(Math.log(scale) / Math.log(2)), 5);
|
noiseIterations = (byte) Math.min(Math.ceil(Math.log(scale) / Math.log(2)), 5);
|
||||||
this.seed = (int) (seed & 0xFFFFFFFF);
|
this.seed = random.nextInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,8 +73,8 @@ public class HexBiomeMap implements BiomeMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BiomeChunk getChunk(int cx, int cz, boolean update) {
|
public BiomeChunk getChunk(final int cx, final int cz, final boolean update) {
|
||||||
ChunkPos pos = new ChunkPos(cx, cz);
|
final ChunkPos pos = new ChunkPos(cx, cz);
|
||||||
return chunks.computeIfAbsent(pos, i -> {
|
return chunks.computeIfAbsent(pos, i -> {
|
||||||
Random random = new Random(MHelper.getSeed(seed, cx, cz));
|
Random random = new Random(MHelper.getSeed(seed, cx, cz));
|
||||||
HexBiomeChunk chunk = new HexBiomeChunk(random, picker);
|
HexBiomeChunk chunk = new HexBiomeChunk(random, picker);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue