Minor ChunkWrapper.getBlockState() GC optimization
This commit is contained in:
+24
-2
@@ -76,6 +76,9 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
private final byte[] blockLightArray;
|
||||
private final byte[] skyLightArray;
|
||||
|
||||
/** cache so we don't have to hit the vanilla chunk as often. */
|
||||
private final IBlockStateWrapper[] blockStateWrappers;
|
||||
|
||||
private ArrayList<DhBlockPos> blockLightPosList = null;
|
||||
|
||||
private boolean useDhLighting;
|
||||
@@ -115,6 +118,8 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
this.blockLightArray = new byte[LodUtil.CHUNK_WIDTH * LodUtil.CHUNK_WIDTH * (this.getHeight() + 1)];
|
||||
this.skyLightArray = new byte[LodUtil.CHUNK_WIDTH * LodUtil.CHUNK_WIDTH * (this.getHeight() + 1)];
|
||||
|
||||
this.blockStateWrappers = new IBlockStateWrapper[LodUtil.CHUNK_WIDTH * LodUtil.CHUNK_WIDTH * (this.getHeight() + 1)];
|
||||
|
||||
chunksNeedingClientLightUpdating.add(this);
|
||||
}
|
||||
|
||||
@@ -314,7 +319,7 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DhBlockPos> getBlockLightPosList()
|
||||
public ArrayList<DhBlockPos> getBlockLightPosList()
|
||||
{
|
||||
// only populate the list once
|
||||
if (this.blockLightPosList == null)
|
||||
@@ -372,7 +377,21 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
@Override
|
||||
public IBlockStateWrapper getBlockState(int relX, int relY, int relZ)
|
||||
{
|
||||
return BlockStateWrapper.fromBlockState(this.chunk.getBlockState(new BlockPos(relX, relY, relZ)), this.wrappedLevel);
|
||||
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, relY, relZ);
|
||||
|
||||
int index = this.relativeBlockPosToIndex(relX, relY, relZ);
|
||||
IBlockStateWrapper cachedBlockState = this.blockStateWrappers[index];
|
||||
if (cachedBlockState != null)
|
||||
{
|
||||
return cachedBlockState;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the wrapper is cached to prevent having to create a bunch of new BlockPos and hitting the vanilla chunk object
|
||||
IBlockStateWrapper blockState = BlockStateWrapper.fromBlockState(this.chunk.getBlockState(new BlockPos(relX, relY, relZ)), this.wrappedLevel);
|
||||
this.blockStateWrappers[index] = blockState;
|
||||
return blockState;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -442,7 +461,10 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
private void throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(int x, int y, int z) throws IndexOutOfBoundsException
|
||||
{
|
||||
if (RUN_RELATIVE_POS_INDEX_VALIDATION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// FIXME +1 is to handle the fact that LodDataBuilder adds +1 to all block lighting calculations, also done in the constructor
|
||||
int minHeight = this.getMinBuildHeight();
|
||||
|
||||
+1
-1
Submodule coreSubProjects updated: 7d84e05b1f...d3865551a5
Reference in New Issue
Block a user