Skip to content

Commit

Permalink
Further improve performance using guava sets
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Sep 5, 2024
1 parent 63ad89a commit d52a942
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.countercraft.movecraft.mapUpdater.update;

import com.google.common.collect.Sets;
import it.unimi.dsi.fastutil.Hash;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void doUpdate() {
originalLocations.add(MathUtils.rotateVec(counterRotation, movecraftLocation.subtract(originLocation)).add(originLocation));
}

final HitBox to = craft.getHitBox().difference(originalLocations);
final Set<MovecraftLocation> to = Sets.difference(craft.getHitBox().asSet(), originalLocations.asSet());

for (MovecraftLocation location : to) {
var data = location.toBukkit(craft.getWorld()).getBlock().getBlockData();
Expand All @@ -92,7 +93,7 @@ public void doUpdate() {
}
}
//The subtraction of the set of coordinates in the HitBox cube and the HitBox itself
final HitBox invertedHitBox = new SetHitBox(craft.getHitBox().boundingHitBox()).difference(craft.getHitBox());
final SetHitBox invertedHitBox = new SetHitBox(Sets.difference(craft.getHitBox().boundingHitBox().asSet(), craft.getHitBox().asSet()));
//A set of locations that are confirmed to be "exterior" locations
final SetHitBox exterior = new SetHitBox();
final SetHitBox interior = new SetHitBox();
Expand Down Expand Up @@ -138,10 +139,10 @@ public void doUpdate() {
}
}
exterior.addAll(visited);
interior.addAll(invertedHitBox.difference(exterior));
interior.addAll(Sets.difference(invertedHitBox.asSet(), exterior.asSet()));

final WorldHandler handler = Movecraft.getInstance().getWorldHandler();
for (MovecraftLocation location : invertedHitBox.difference(exterior)) {
for (MovecraftLocation location : Sets.difference(invertedHitBox.asSet(), exterior.asSet())) {
var data = location.toBukkit(craft.getWorld()).getBlock().getBlockData();
if (!passthroughBlocks.contains(data.getMaterial())) {
continue;
Expand Down

0 comments on commit d52a942

Please sign in to comment.