Fix ProcessingTracesState performance
This commit is contained in:
@@ -24,6 +24,7 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.slaves.laufbau.BlockBoundingBox;
|
||||
import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
|
||||
import de.steamwar.bausystem.features.tracer.TNTPoint;
|
||||
import de.steamwar.bausystem.features.tracer.Trace;
|
||||
import de.steamwar.bausystem.features.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
@@ -34,7 +35,6 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ProcessingTracesState implements LaufbauState {
|
||||
|
||||
@@ -45,8 +45,9 @@ public class ProcessingTracesState implements LaufbauState {
|
||||
private final List<BlockBoundingBox> elements;
|
||||
private final int factor;
|
||||
|
||||
private final List<TNTPoint> TNTPoints;
|
||||
private final int totalTntRecords;
|
||||
private final List<Trace> Traces;
|
||||
private final List<TNTPoint> TNTPoints = new ArrayList<>();
|
||||
private final int totalTraces;
|
||||
|
||||
private final Set<Point> affectedBlocks = new HashSet<>();
|
||||
private final Map<Point, Set<Cuboid>> cuboidsPerChunk = new HashMap<>();
|
||||
@@ -58,18 +59,13 @@ public class ProcessingTracesState implements LaufbauState {
|
||||
this.elements = elements;
|
||||
this.factor = factor;
|
||||
|
||||
// TODO: Optimize only retrieving traces inside of the affected regions!
|
||||
TNTPoints = TraceManager.instance.getAll()
|
||||
.stream()
|
||||
.flatMap(trace -> trace.getHistories().stream())
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
totalTntRecords = TNTPoints.size();
|
||||
Traces = new ArrayList<>(TraceManager.instance.getAll());
|
||||
totalTraces = Traces.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String actionBarMessage(Player p) {
|
||||
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalTntRecords - TNTPoints.size(), totalTntRecords, eta(p, start, totalTntRecords - TNTPoints.size(), totalTntRecords));
|
||||
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalTraces - Traces.size(), totalTraces, eta(p, start, totalTraces - Traces.size(), totalTraces));
|
||||
}
|
||||
|
||||
private boolean inRegion(Vector location, int expansion) {
|
||||
@@ -78,11 +74,17 @@ public class ProcessingTracesState implements LaufbauState {
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return !TNTPoints.isEmpty();
|
||||
return !Traces.isEmpty() || !TNTPoints.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
if (TNTPoints.isEmpty()) {
|
||||
Trace trace = Traces.remove(0);
|
||||
trace.getHistories().stream().flatMap(Collection::stream).forEach(TNTPoints::add);
|
||||
return;
|
||||
}
|
||||
|
||||
TNTPoint current = TNTPoints.remove(0);
|
||||
if (FlatteningWrapper.impl.inWater(world, current.getLocation().toVector())) return;
|
||||
if (!(inRegion(current.getLocation().toVector(), 1) || (current.getPrevious().isPresent() && inRegion(current.getPrevious().get().getLocation().toVector(), 1))))
|
||||
|
||||
Reference in New Issue
Block a user