Refactored roof search complexity

This commit is contained in:
tastybento 2020-10-11 08:08:17 -07:00
parent 2a75722f35
commit 50e3bf2988
1 changed files with 29 additions and 18 deletions

View File

@ -61,24 +61,7 @@ public class Roof extends MinMaxXZ {
}
// If the roof was not found start going around in circles until something is found
// Expand in ever increasing squares around location until a wall block is found
for (int radius = 0; radius < 3 && !roofFound; radius++) {
for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius && !roofFound; x++) {
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius && !roofFound; z++) {
if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius) && (z > loc.getBlockZ() - radius && z < loc.getBlockZ() + radius))) {
Block b = world.getBlockAt(x, roofY, z);
if (!Walls.wallBlocks(b.getType())) {
// Look up
for (int y = roofY; y < world.getMaxHeight() && !roofFound; y++) {
if (roofBlocks(world.getBlockAt(x,y,z).getType())) {
roofFound = true;
loc = new Location(world,x,y,z);
}
}
}
}
}
}
}
spiralSearch(loc, roofY);
if (!roofFound) return false;
// Record the height
this.height = loc.getBlockY();
@ -110,6 +93,34 @@ public class Roof extends MinMaxXZ {
return true;
}
private void spiralSearch(Location loc, int roofY) {
for (int radius = 0; radius < 3 && !roofFound; radius++) {
for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius && !roofFound; x++) {
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius && !roofFound; z++) {
if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius) && (z > loc.getBlockZ() - radius && z < loc.getBlockZ() + radius))) {
checkVertically(loc, x, roofY, z);
}
}
}
}
}
private void checkVertically(Location loc, int x, int roofY, int z) {
World world = loc.getWorld();
Block b = world.getBlockAt(x, roofY, z);
if (!Walls.wallBlocks(b.getType())) {
// Look up
for (int y = roofY; y < world.getMaxHeight() && !roofFound; y++) {
if (roofBlocks(world.getBlockAt(x,y,z).getType())) {
roofFound = true;
loc = new Location(world,x,y,z);
}
}
}
}
/**
* This takes any location and tries to go as far as possible in NWSE directions finding contiguous roof blocks
* up to 100 in any direction