forked from SteamWar/SteamWar
Reduce unnecessary branch propagation by early abort with primary direction visibility.
This commit is contained in:
@@ -51,6 +51,7 @@ public class Hull {
|
||||
|
||||
private final BitSet occluding;
|
||||
private final BitSet visibility;
|
||||
private final BitSet primaryVisible;
|
||||
private final Int2IntOpenHashMap visibilityDirections = new Int2IntOpenHashMap(); // Contains the visible directions of each occluding visible block
|
||||
private final Set<IntVector> uncoveredSurface = new HashSet<>();
|
||||
|
||||
@@ -64,6 +65,7 @@ public class Hull {
|
||||
this.primaryDirection = new IntVector(0, 0, team.isBlue() == (Config.BlueToRedZ > 0) ? -1 : 1);
|
||||
this.occluding = new BitSet(region.volume());
|
||||
this.visibility = new BitSet(region.volume());
|
||||
this.primaryVisible = new BitSet(region.volume());
|
||||
|
||||
branchDirections = IntStream.range(0, 27)
|
||||
.mapToObj(v -> new IntVector(v%3 -1, (v/3)%3 -1, v/9 -1))
|
||||
@@ -137,6 +139,7 @@ public class Hull {
|
||||
visibility.clear();
|
||||
occluding.clear();
|
||||
visibilityDirections.clear();
|
||||
primaryVisible.clear();
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
region.forEach((x, y, z) -> {
|
||||
@@ -250,11 +253,14 @@ public class Hull {
|
||||
visibilityDirections.compute(id, (pos, v) -> (v == null ? 0 : v) | directionId(direction));
|
||||
return;
|
||||
}
|
||||
if(primaryVisible.get(id))
|
||||
return;
|
||||
|
||||
updateBlocks(uncovered, block.add(direction), direction);
|
||||
if(!direction.equals(primaryDirection))
|
||||
return;
|
||||
|
||||
primaryVisible.set(id);
|
||||
for(IntVector branchDirection : branchDirections)
|
||||
updateBlocks(uncovered, block.add(branchDirection), branchDirection);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user