increase efficiency of scanChunkInto by ~25%

This commit is contained in:
Logan Darklock 2019-08-30 22:52:20 -07:00
parent c938983ff5
commit 9f3eaac3df
No known key found for this signature in database
GPG Key ID: B8C37CEDE1AC60EA
3 changed files with 21 additions and 20 deletions

View File

@ -45,7 +45,7 @@ public abstract class MixinBlockStateContainer implements IBlockStateContainer {
@Override @Override
@Unique @Unique
public IBlockState getFast(int x, int y, int z) { public IBlockState getFast(int index) {
return palette.getBlockState(storage.getAt(y << 8 | z << 4 | x)); return palette.getBlockState(storage.getAt(index));
} }
} }

View File

@ -116,14 +116,13 @@ public enum WorldScanner implements IWorldScanner {
IBlockStateContainer bsc = (IBlockStateContainer) extendedblockstorage.getData(); IBlockStateContainer bsc = (IBlockStateContainer) extendedblockstorage.getData();
// the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x; // the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x;
// for better cache locality, iterate in that order // for better cache locality, iterate in that order
for (int y = 0; y < 16; y++) { int imax = 1 << 12;
for (int z = 0; z < 16; z++) { for (int i = 0; i < imax; i++) {
for (int x = 0; x < 16; x++) { IBlockState state = bsc.getFast(i);
IBlockState state = bsc.getFast(x, y, z);
if (filter.has(state)) { if (filter.has(state)) {
int yy = yReal | y; int y = yReal | (i >> 8 & 15);
if (result.size() >= max) { if (result.size() >= max) {
if (Math.abs(yy - playerY) < yLevelThreshold) { if (Math.abs(y - playerY) < yLevelThreshold) {
foundWithinY = true; foundWithinY = true;
} else { } else {
if (foundWithinY) { if (foundWithinY) {
@ -133,9 +132,7 @@ public enum WorldScanner implements IWorldScanner {
} }
} }
} }
result.add(new BlockPos(chunkX | x, yy, chunkZ | z)); result.add(new BlockPos(chunkX | (i & 15), y, chunkZ | (i >> 4 & 15)));
}
}
} }
} }
} }

View File

@ -9,5 +9,9 @@ public interface IBlockStateContainer {
BitArray getStorage(); BitArray getStorage();
IBlockState getFast(int x, int y, int z); IBlockState getFast(int index);
default IBlockState getFast(int x, int y, int z) {
return getFast(y << 8 | z << 4 | x);
};
} }