Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ApplyTask<F extends Filter> extends RecursiveAction implements Runnable {
private static final int SHIFT_REDUCTION = 1;

private final CommonState<F> commonState;
private final Region region;
private final ApplyTask<F> before;
private final int minChunkX;
private final int minChunkZ;
Expand All @@ -39,7 +40,6 @@ public void run() {

private record CommonState<F extends Filter>(
F originalFilter,
Region region,
ParallelQueueExtent parallelQueueExtent,
ConcurrentMap<Thread, ThreadState<F>> stateCache,
boolean full,
Expand Down Expand Up @@ -69,12 +69,12 @@ private ThreadState(SingleThreadQueueExtent queue, F filter) {
) {
this.commonState = new CommonState<>(
filter,
region.clone(), // clone only once, assuming the filter doesn't modify that clone
parallelQueueExtent,
new ConcurrentHashMap<>(),
full,
faweExceptionReasonsUsed
);
this.region = region.clone();
this.before = null;
final BlockVector3 minimumPoint = region.getMinimumPoint();
this.minChunkX = minimumPoint.x() >> 4;
Expand All @@ -88,6 +88,7 @@ private ThreadState(SingleThreadQueueExtent queue, F filter) {

private ApplyTask(
final CommonState<F> commonState,
final Region region,
final ApplyTask<F> before,
final int minChunkX,
final int maxChunkX,
Expand All @@ -96,6 +97,7 @@ private ApplyTask(
final int higherShift
) {
this.commonState = commonState;
this.region = region.clone();
this.minChunkX = minChunkX;
this.maxChunkX = maxChunkX;
this.minChunkZ = minChunkZ;
Expand All @@ -120,14 +122,15 @@ protected void compute() {
processRegion(regionX, regionZ, this.shift);
continue;
}
if (this.shift == 0 && !this.commonState.region.containsChunk(regionX, regionZ)) {
if (this.shift == 0 && !this.region.containsChunk(regionX, regionZ)) {
// if shift == 0, region coords are chunk coords
continue; // chunks not intersecting with the region don't need a task
}

// creating more tasks will likely help parallelism as other threads aren't *that* busy
subtask = new ApplyTask<>(
this.commonState,
this.region,
subtask,
regionX << this.shift,
((regionX + 1) << this.shift) - 1,
Expand Down Expand Up @@ -166,7 +169,7 @@ private void processRegion(int regionX, int regionZ, int shift) {
try {
for (int chunkX = regionX << shift; chunkX <= ((regionX + 1) << shift) - 1; chunkX++) {
for (int chunkZ = regionZ << shift; chunkZ <= ((regionZ + 1) << shift) - 1; chunkZ++) {
if (!this.commonState.region.containsChunk(chunkX, chunkZ)) {
if (!this.region.containsChunk(chunkX, chunkZ)) {
continue; // chunks not intersecting with the region must not be processed
}
applyChunk(chunkX, chunkZ, state);
Expand Down Expand Up @@ -204,7 +207,7 @@ private void applyChunk(int chunkX, int chunkZ, ThreadState<F> state) {
state.block = state.queue.apply(
state.block,
state.filter,
this.commonState.region,
this.region,
chunkX,
chunkZ,
this.commonState.full
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public ConvexPolyhedralRegion(@Nullable World world) {
public ConvexPolyhedralRegion(ConvexPolyhedralRegion region) {
this(region.world);
vertices.addAll(region.vertices);
triangles.addAll(region.triangles);
region.triangles.forEach(triangle -> triangles.add(triangle.clone()));
vertexBacklog.addAll(region.vertexBacklog);

minimumPoint = region.minimumPoint;
maximumPoint = region.maximumPoint;
centerAccum = region.centerAccum;
lastTriangle = region.lastTriangle;
lastTriangle = lastTriangle == null ? null : region.lastTriangle.clone();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public Triangle tag(String tag) {
return this;
}

@Override
public Triangle clone() {
return new Triangle(vertices[0], vertices[1], vertices[2]);
}

@Override
public String toString() {
return tag + "(" + this.vertices[0] + "," + this.vertices[1] + "," + this.vertices[2] + ")";
Expand Down
Loading