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
@Unique
public IBlockState getFast(int x, int y, int z) {
return palette.getBlockState(storage.getAt(y << 8 | z << 4 | x));
public IBlockState getFast(int index) {
return palette.getBlockState(storage.getAt(index));
}
}

View File

@ -116,26 +116,23 @@ public enum WorldScanner implements IWorldScanner {
IBlockStateContainer bsc = (IBlockStateContainer) extendedblockstorage.getData();
// the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x;
// for better cache locality, iterate in that order
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
IBlockState state = bsc.getFast(x, y, z);
if (filter.has(state)) {
int yy = yReal | y;
if (result.size() >= max) {
if (Math.abs(yy - playerY) < yLevelThreshold) {
foundWithinY = true;
} else {
if (foundWithinY) {
// have found within Y in this chunk, so don't need to consider outside Y
// TODO continue iteration to one more sorted Y coordinate block
return true;
}
}
int imax = 1 << 12;
for (int i = 0; i < imax; i++) {
IBlockState state = bsc.getFast(i);
if (filter.has(state)) {
int y = yReal | (i >> 8 & 15);
if (result.size() >= max) {
if (Math.abs(y - playerY) < yLevelThreshold) {
foundWithinY = true;
} else {
if (foundWithinY) {
// have found within Y in this chunk, so don't need to consider outside Y
// TODO continue iteration to one more sorted Y coordinate block
return true;
}
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();
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);
};
}