Skip to content

Commit

Permalink
Defer pattern evaluation until cache miss
Browse files Browse the repository at this point in the history
  • Loading branch information
TomyLobo authored and me4502 committed Jun 18, 2023
1 parent 9dd2aee commit dae319d
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,11 @@ private BaseBlock getMaterial(BlockVector3 position, Pattern pattern, boolean ho
int y = position.getBlockY();
int z = position.getBlockZ();

final BaseBlock defaultMaterial = pattern.applyBlock(position);

if (!hollow) {
return getMaterial(x, y, z, defaultMaterial);
return getMaterial(x, y, z, pattern.applyBlock(position));
}

final Object cacheEntry = getMaterialCached(x, y, z, defaultMaterial);
final Object cacheEntry = getMaterialCached(x, y, z, pattern);
if (cacheEntry == OUTSIDE) {
return null;
}
Expand Down Expand Up @@ -157,14 +155,14 @@ private BaseBlock getMaterial(BlockVector3 position, Pattern pattern, boolean ho
}

private boolean isOutsideCached(int x, int y, int z, Pattern pattern) {
return getMaterialCached(x, y, z, pattern.applyBlock(BlockVector3.at(x, y, z))) == OUTSIDE;
return getMaterialCached(x, y, z, pattern) == OUTSIDE;
}

private Object getMaterialCached(int x, int y, int z, BaseBlock defaultMaterial) {
private Object getMaterialCached(int x, int y, int z, Pattern pattern) {
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
final Object cacheEntry = cache[index];
if (cacheEntry == null) {
final BaseBlock material = getMaterial(x, y, z, defaultMaterial);
final BaseBlock material = getMaterial(x, y, z, pattern.applyBlock(BlockVector3.at(x, y, z)));
if (material == null) {
return cache[index] = OUTSIDE;
} else {
Expand Down

0 comments on commit dae319d

Please sign in to comment.