Skip to content

Commit

Permalink
fix compile issues after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
SirYwell committed Aug 18, 2023
1 parent 4b9b60f commit 95bc238
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,10 @@ public boolean hasBiomes(int layer) {

@Override
public ThreadUnsafeCharBlocks createCopy() {
char[][] blocksCopy = new char[sectionCount][];
DataArray[] blocksCopy = new DataArray[sectionCount];
for (int i = 0; i < sectionCount; i++) {
if (blocks[i] != null) {
blocksCopy[i] = new char[FaweCache.INSTANCE.BLOCKS_PER_LAYER];
System.arraycopy(blocks[i], 0, blocksCopy[i], 0, FaweCache.INSTANCE.BLOCKS_PER_LAYER);
blocksCopy[i] = DataArray.createCopy(blocks[i]);
}
}
BiomeType[][] biomesCopy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import java.util.UUID;

/**
* Equivalent to {@link CharSetBlocks} without any attempt to make thread-safe for improved performance.
* This is currently only used as a "copy" of {@link CharSetBlocks} to provide to
* Equivalent to {@link DataArraySetBlocks} without any attempt to make thread-safe for improved performance.
* This is currently only used as a "copy" of {@link DataArraySetBlocks} to provide to
* {@link com.fastasyncworldedit.core.queue.IBatchProcessor} instances for processing without overlapping the continuing edit.
*
* @since 2.6.2
Expand All @@ -37,7 +37,7 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks {
private static final Logger LOGGER = LogManagerCompat.getLogger();

private final char defaultOrdinal;
private char[][] blocks;
private DataArray[] blocks;
private int minSectionPosition;
private int maxSectionPosition;
private int sectionCount;
Expand All @@ -52,12 +52,12 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks {
private int bitMask;

/**
* New instance given the data stored in a {@link CharSetBlocks} instance.
* New instance given the data stored in a {@link DataArraySetBlocks} instance.
*
* @since 2.6.2
*/
ThreadUnsafeCharBlocks(
char[][] blocks,
DataArray[] blocks,
int minSectionPosition,
int maxSectionPosition,
BiomeType[][] biomes,
Expand Down Expand Up @@ -91,11 +91,11 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks {
@Override
public boolean hasSection(int layer) {
layer -= minSectionPosition;
return layer >= 0 && layer < blocks.length && blocks[layer] != null && blocks[layer].length == FaweCache.INSTANCE.BLOCKS_PER_LAYER;
return layer >= 0 && layer < blocks.length && blocks[layer] != null;
}

@Override
public char[] load(int layer) {
public DataArray load(int layer) {
updateSectionIndexRange(layer);
layer -= minSectionPosition;
char[] arr = blocks[layer];
Expand All @@ -107,7 +107,7 @@ public char[] load(int layer) {

@Nullable
@Override
public char[] loadIfPresent(int layer) {
public DataArray loadIfPresent(int layer) {
if (layer < minSectionPosition || layer > maxSectionPosition) {
return null;
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public char get(int x, int y, int z) {
return defaultOrdinal;
}
final int index = (y & 15) << 8 | z << 4 | x;
return blocks[layer - minSectionPosition][index];
return (char) blocks[layer - minSectionPosition].getAt(index);
}

@Override
Expand Down Expand Up @@ -225,7 +225,7 @@ public void set(int x, int y, int z, char value) {
final int layer = y >> 4;
final int index = (y & 15) << 8 | z << 4 | x;
try {
blocks[layer][index] = value;
blocks[layer].setAt(index, value);
} catch (ArrayIndexOutOfBoundsException exception) {
LOGGER.error("Tried setting block at coordinates (" + x + "," + y + "," + z + ")");
assert Fawe.platform() != null;
Expand All @@ -242,7 +242,7 @@ public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T h
}

@Override
public void setBlocks(int layer, char[] data) {
public void setBlocks(int layer, DataArray data) {
updateSectionIndexRange(layer);
layer -= minSectionPosition;
this.blocks[layer] = data;
Expand Down Expand Up @@ -425,7 +425,7 @@ public boolean hasLight() {

@Override
public IChunkSet reset() {
blocks = new char[sectionCount][];
blocks = new DataArray[sectionCount];
biomes = new BiomeType[sectionCount][];
light = new char[sectionCount][];
skyLight = new char[sectionCount][];
Expand All @@ -444,11 +444,12 @@ public boolean hasBiomes(int layer) {

@Override
public IChunkSet createCopy() {
char[][] blocksCopy = new char[sectionCount][];
DataArray[] blocksCopy = new DataArray[sectionCount];
for (int i = 0; i < sectionCount; i++) {
blocksCopy[i] = new char[FaweCache.INSTANCE.BLOCKS_PER_LAYER];
if (blocks[i] != null) {
System.arraycopy(blocks[i], 0, blocksCopy[i], 0, FaweCache.INSTANCE.BLOCKS_PER_LAYER);
blocksCopy[i] = DataArray.createCopy(blocks[i]);
} else {
blocksCopy[i] = DataArray.createEmpty();
}
}
BiomeType[][] biomesCopy;
Expand All @@ -463,8 +464,8 @@ public IChunkSet createCopy() {
}
}
}
char[][] lightCopy = CharSetBlocks.createLightCopy(light, sectionCount);
char[][] skyLightCopy = CharSetBlocks.createLightCopy(skyLight, sectionCount);
char[][] lightCopy = DataArraySetBlocks.createLightCopy(light, sectionCount);
char[][] skyLightCopy = DataArraySetBlocks.createLightCopy(skyLight, sectionCount);
return new ThreadUnsafeCharBlocks(
blocksCopy,
minSectionPosition,
Expand Down Expand Up @@ -496,6 +497,9 @@ private void updateSectionIndexRange(int layer) {
if (layer < minSectionPosition) {
int diff = minSectionPosition - layer;
sectionCount += diff;
DataArray[] tmpBlocks = new DataArray[sectionCount];
System.arraycopy(blocks, 0, tmpBlocks, diff, blocks.length);
blocks = tmpBlocks;
minSectionPosition = layer;
resizeSectionsArrays(layer, diff, false); // prepend new layer(s)
} else {
Expand All @@ -507,7 +511,7 @@ private void updateSectionIndexRange(int layer) {
}

private void resizeSectionsArrays(int layer, int diff, boolean appendNew) {
char[][] tmpBlocks = new char[sectionCount][];
DataArray[] tmpBlocks = new DataArray[sectionCount];
int destPos = appendNew ? 0 : diff;
System.arraycopy(blocks, 0, tmpBlocks, destPos, blocks.length);
blocks = tmpBlocks;
Expand Down

0 comments on commit 95bc238

Please sign in to comment.