SteamWar/BauSystem2.0
Archiviert
12
0

Trace Refactor #233

Zusammengeführt
YoyoNow hat 121 Commits von TracerGUI nach master 2024-04-21 16:03:26 +02:00 zusammengeführt
2 geänderte Dateien mit 25 neuen und 19 gelöschten Zeilen
Nur Änderungen aus Commit 40f4af2a06 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -20,10 +20,12 @@
package de.steamwar.bausystem.features.slaves.laufbau.states; package de.steamwar.bausystem.features.slaves.laufbau.states;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.features.tracer.Trace;
import de.steamwar.bausystem.features.tracer.TraceManager;
import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.Record;
import de.steamwar.bausystem.features.tracer.show.StoredRecords; import de.steamwar.bausystem.features.tracer.show.StoredRecords;
import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.linkage.LinkedInstance;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -35,21 +37,24 @@ import java.util.function.BiPredicate;
public class FilteringTracesState implements LaufbauState { public class FilteringTracesState implements LaufbauState {
@LinkedInstance
TraceManager traceManager;
private long start = System.currentTimeMillis(); private long start = System.currentTimeMillis();
private World world; private World world;
private BiPredicate<Location, Integer> inRegionCheck; private BiPredicate<Location, Integer> inRegionCheck;
private int totalRecord; private final int totalRecord;
private List<Record> recordList;
List<Trace> traces;
private List<Record.TNTRecord> tntRecords = new ArrayList<>(); private List<Record.TNTRecord> tntRecords = new ArrayList<>();
@Getter @Getter
private List<TNTPosition> tntPositions = new ArrayList<>(); private List<TNTPosition> tntPositions = new ArrayList<>();
public FilteringTracesState(World world, BiPredicate<Location, Integer> inRegionCheck) { public FilteringTracesState(World world, BiPredicate<Location, Integer> inRegionCheck) {
recordList = new ArrayList<>(StoredRecords.getRecords()); List<Trace> traces = new ArrayList<>(traceManager.getAll());
totalRecord = recordList.size(); totalRecord = traces.size();
this.world = world; this.world = world;
this.inRegionCheck = inRegionCheck; this.inRegionCheck = inRegionCheck;
@ -57,19 +62,19 @@ public class FilteringTracesState implements LaufbauState {
@Override @Override
public String actionBarMessage(Player p) { public String actionBarMessage(Player p) {
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_FILTERING_TRACES", p), totalRecord - recordList.size(), totalRecord, eta(p, start, totalRecord - recordList.size(), totalRecord)); return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_FILTERING_TRACES", p), totalRecord - traces.size(), totalRecord, eta(p, start, totalRecord - traces.size(), totalRecord));
} }
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return !recordList.isEmpty() || !tntRecords.isEmpty(); return !traces.isEmpty() || !tntRecords.isEmpty();
} }
@Override @Override
public void next() { public void next() {
if (tntRecords.isEmpty()) { if (tntRecords.isEmpty()) {
Record record = recordList.remove(0); Trace trace = traces.remove(0);
tntRecords.addAll(record.getTnt()); tntRecords.addAll(trace.getTnt());
} }
if (tntRecords.isEmpty()) { if (tntRecords.isEmpty()) {
return; return;

Datei anzeigen

@ -21,9 +21,10 @@ package de.steamwar.bausystem.features.slaves.laufbau.states;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.slaves.laufbau.Cuboid; import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.features.tracer.TNTRecord;
import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Point;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -35,7 +36,7 @@ public class ProcessingTracesState implements LaufbauState {
private long start = System.currentTimeMillis(); private long start = System.currentTimeMillis();
private int totalCuboids; private int totalCuboids;
private List<TNTPosition> tntPositionList; private List<TNTRecord> tntPositionList;
private BiPredicate<Vector, Integer> inRegionCheck; private BiPredicate<Vector, Integer> inRegionCheck;
private int factor; private int factor;
@ -49,9 +50,9 @@ public class ProcessingTracesState implements LaufbauState {
@Getter @Getter
private Map<Point, Set<Cuboid>> cuboidIntersectionCache = new HashMap<>(); private Map<Point, Set<Cuboid>> cuboidIntersectionCache = new HashMap<>();
public ProcessingTracesState(List<TNTPosition> tntPositionList, BiPredicate<Vector, Integer> inRegionCheck, int factor) { public ProcessingTracesState(List<TNTRecord> tntPositionList, BiPredicate<Vector, Integer> inRegionCheck, int factor) {
this.tntPositionList = tntPositionList; this.tntPositionList = tntPositionList;
this.totalCuboids = tntPositionList.stream().mapToInt(tntPosition -> tntPosition.getPreviousLocation() == null ? 1 : 3).sum(); this.totalCuboids = tntPositionList.stream().mapToInt(tntPosition -> tntPosition.getPrevious() == null ? 1 : 3).sum();
this.inRegionCheck = inRegionCheck; this.inRegionCheck = inRegionCheck;
this.factor = factor; this.factor = factor;
} }
@ -72,21 +73,21 @@ public class ProcessingTracesState implements LaufbauState {
Cuboid cuboid = toExpand.remove(0); Cuboid cuboid = toExpand.remove(0);
expandCuboid(cuboid); expandCuboid(cuboid);
} else { } else {
TNTPosition tntPosition = tntPositionList.remove(0); TNTRecord tntPosition = tntPositionList.remove(0);
createCuboid(tntPosition); createCuboid(tntPosition);
} }
} }
private void createCuboid(TNTPosition tntPosition) { private void createCuboid(TNTRecord tntPosition) {
Vector location = tntPosition.getLocation(); Location location = tntPosition.getLocation();
Vector previousLocation = tntPosition.getPreviousLocation(); Location previousLocation = tntPosition.getPrevious().getLocation();
if (previousLocation == null) { if (previousLocation == null) {
toExpand.add(new Cuboid(location.getX() - 0.49, location.getY(), location.getZ() - 0.49, 0.98, 0.98, 0.98)); toExpand.add(new Cuboid(location.getX() - 0.49, location.getY(), location.getZ() - 0.49, 0.98, 0.98, 0.98));
} else { } else {
Vector movement = location.clone().subtract(previousLocation); Location movement = location.clone().subtract(previousLocation);
toExpand.add(new Cuboid(previousLocation.getX() - 0.49, Math.min(previousLocation.getY(), location.getY()), previousLocation.getZ() - 0.49, 0.98, Math.abs(movement.getY()) + 0.98, 0.98)); toExpand.add(new Cuboid(previousLocation.getX() - 0.49, Math.min(previousLocation.getY(), location.getY()), previousLocation.getZ() - 0.49, 0.98, Math.abs(movement.getY()) + 0.98, 0.98));
if (tntPosition.getUpdateOrder() == TNTPosition.UpdateOrder.X) { if (tntPosition.getVelocity().getX() >= tntPosition.getVelocity().getZ()) {
toExpand.add(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), previousLocation.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98)); toExpand.add(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), previousLocation.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98));
toExpand.add(new Cuboid(location.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98)); toExpand.add(new Cuboid(location.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98));
} else { } else {