Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad performance with passthroughblocks #708

Closed
wants to merge 2 commits into from
Closed
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 @@ -118,27 +118,30 @@ public void doUpdate() {
validExterior.addAll(hitBox.difference(craft.getHitBox()));
}
//Check to see which locations in the from set are actually outside of the craft
SetHitBox visited = new SetHitBox();
for (MovecraftLocation location : validExterior) {
if (craft.getHitBox().contains(location) || exterior.contains(location)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is exterior.contains(location) not redundant? exterior will now only be populated after the loop finishes, as exterior.addAll(visited) was moved outside of it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya that looks redundant to me

continue;
}
//use a modified BFS for multiple origin elements
SetHitBox visited = new SetHitBox();

Queue<MovecraftLocation> queue = new LinkedList<>();
queue.add(location);
while (!queue.isEmpty()) {
MovecraftLocation node = queue.poll();
//If the node is already a valid member of the exterior of the HitBox, continued search is unitary.
for (MovecraftLocation neighbor : CollectionUtils.neighbors(invertedHitBox, node)) {
if (visited.contains(neighbor)) {
continue;
// This is a set! If it already contains the element, it won't add it anyway!
//if (visited.contains(neighbor)) {
// continue;
//}
if (visited.add(neighbor)) {
queue.add(neighbor);
}
visited.add(neighbor);
queue.add(neighbor);
}
}
exterior.addAll(visited);
}
}
exterior.addAll(visited);
interior.addAll(invertedHitBox.difference(exterior));

final WorldHandler handler = Movecraft.getInstance().getWorldHandler();
Expand Down