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
11 geänderte Dateien mit 75 neuen und 75 gelöschten Zeilen
Nur Änderungen aus Commit e06d612a0e werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -23,7 +23,7 @@ import com.sk89q.worldedit.EditSession;
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.TNTRecord;
import de.steamwar.bausystem.features.tracer.TraceRecord;
import de.steamwar.bausystem.features.tracer.TraceRecorder;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.utils.FlatteningWrapper;
@ -45,7 +45,7 @@ public class ProcessingTracesState implements LaufbauState {
private final List<BlockBoundingBox> elements;
private final int factor;
private final List<TNTRecord> tntRecords;
private final List<TraceRecord> traceRecords;
private final int totalTntRecords;
private final Set<Point> affectedBlocks = new HashSet<>();
@ -59,17 +59,17 @@ public class ProcessingTracesState implements LaufbauState {
this.factor = factor;
// TODO: Optimize only retrieving traces inside of the affected regions!
tntRecords = TraceRecorder.instance.manager.getAll()
traceRecords = TraceRecorder.instance.manager.getAll()
.stream()
.flatMap(trace -> trace.getHistories().stream())
.flatMap(Collection::stream)
.collect(Collectors.toList());
totalTntRecords = tntRecords.size();
totalTntRecords = traceRecords.size();
}
@Override
public String actionBarMessage(Player p) {
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalTntRecords - tntRecords.size(), totalTntRecords, eta(p, start, totalTntRecords - tntRecords.size(), totalTntRecords));
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalTntRecords - traceRecords.size(), totalTntRecords, eta(p, start, totalTntRecords - traceRecords.size(), totalTntRecords));
}
private boolean inRegion(Vector location, int expansion) {
@ -78,12 +78,12 @@ public class ProcessingTracesState implements LaufbauState {
@Override
public boolean hasNext() {
return !tntRecords.isEmpty();
return !traceRecords.isEmpty();
}
@Override
public void next() {
TNTRecord current = tntRecords.remove(0);
TraceRecord current = traceRecords.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))))
return;

Datei anzeigen

@ -50,7 +50,7 @@ public class Trace { // TODO: Add UUID for file saving and so on!
* Records of TNTs, making up the trace
*/
@Getter
private List<TNTRecord> records = new ArrayList<>();
private List<TraceRecord> records = new ArrayList<>();
/**
* ID that should be assigned to the next record of a unique tnt
@ -66,7 +66,7 @@ public class Trace { // TODO: Add UUID for file saving and so on!
public List<String> getUsedIds() {
return getRecords()
.stream()
.map(TNTRecord::getTntId)
.map(TraceRecord::getTntId)
.map(i -> i + "")
.collect(Collectors.toList());
}
@ -87,7 +87,7 @@ public class Trace { // TODO: Add UUID for file saving and so on!
/**
* Adds the given records and updates potential trace renderings
*/
protected void addAll(List<TNTRecord> records, Function<Player, PlayerTraceShowData> getter) {
protected void addAll(List<TraceRecord> records, Function<Player, PlayerTraceShowData> getter) {
this.records.addAll(records);
Iterator<Player> keySetIterator = entityServerMap.keySet().iterator();
while (keySetIterator.hasNext()) {
@ -106,7 +106,7 @@ public class Trace { // TODO: Add UUID for file saving and so on!
*
* @param records immutable records list
*/
protected void setRecords(List<TNTRecord> records) {
protected void setRecords(List<TraceRecord> records) {
this.records = records;
}
@ -115,10 +115,10 @@ public class Trace { // TODO: Add UUID for file saving and so on!
*
* @return the historys of this trace
*/
public Set<List<TNTRecord>> getHistories() {
Set<List<TNTRecord>> histories = new HashSet<>();
public Set<List<TraceRecord>> getHistories() {
Set<List<TraceRecord>> histories = new HashSet<>();
for (TNTRecord record : getRecords()) {
for (TraceRecord record : getRecords()) {
histories.add(record.getHistory());
}
@ -149,10 +149,10 @@ public class Trace { // TODO: Add UUID for file saving and so on!
* @param records Records to render
* @param playerTraceShowData The showData for modifying the rendering
*/
private void render(List<TNTRecord> records, REntityServer entityServer, PlayerTraceShowData playerTraceShowData) {
private void render(List<TraceRecord> records, REntityServer entityServer, PlayerTraceShowData playerTraceShowData) {
if (records.isEmpty()) return;
List<TNTRecord> workingRecords = records;
List<TraceRecord> workingRecords = records;
Set<ViewFlag> flagList = playerTraceShowData.getEffectiveViewFlags();
//Apply filters
@ -161,12 +161,12 @@ public class Trace { // TODO: Add UUID for file saving and so on!
}
//Bundle records at unique positions
List<List<TNTRecord>> bundles = bundleRecords(workingRecords, playerTraceShowData.getBundleFilter());
List<List<TraceRecord>> bundles = bundleRecords(workingRecords, playerTraceShowData.getBundleFilter());
//Render bundled records
List<TraceEntity> entities = new LinkedList<>();
for (List<TNTRecord> bundle : bundles) {
for (List<TraceRecord> bundle : bundles) {
entities.add(new TraceEntity(entityServer, bundle.get(0).getLocation(), bundle.get(0).isExplosion(), bundle));
}
@ -190,23 +190,23 @@ public class Trace { // TODO: Add UUID for file saving and so on!
* @param records The TNTRecords that are supposed to be bundled
* @return A list of bundles
*/
private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records, BundleFilter filter) {
List<List<TNTRecord>> bundles = new ArrayList<>();
private List<List<TraceRecord>> bundleRecords(List<TraceRecord> records, BundleFilter filter) {
List<List<TraceRecord>> bundles = new ArrayList<>();
recordsLoop:
for (TNTRecord record : records) {
for (TraceRecord record : records) {
if (bundles.isEmpty()) {
List<TNTRecord> firstBundle = new ArrayList<>();
List<TraceRecord> firstBundle = new ArrayList<>();
firstBundle.add(record);
bundles.add(firstBundle);
}
for (int i = bundles.size() - 1; i >= 0; i--) {
List<TNTRecord> bundle = bundles.get(i);
List<TraceRecord> bundle = bundles.get(i);
Boolean filterResult = filter.function.apply(record, bundle.get(0));
if (filterResult == null || !filterResult) {
ArrayList<TNTRecord> newBundle = new ArrayList<>();
ArrayList<TraceRecord> newBundle = new ArrayList<>();
newBundle.add(record);
bundles.add(newBundle);
continue recordsLoop;

Datei anzeigen

@ -143,7 +143,7 @@ public class TraceCommand extends SWCommand {
}
@Register(value = "isolate", description = "TRACE_COMMAND_HELP_ISOLATE")
public void isolate(@Validator Player player, Trace trace, @ErrorMessage("TRACE_RECORD_ID_INVALID") TNTRecord... records) {
public void isolate(@Validator Player player, Trace trace, @ErrorMessage("TRACE_RECORD_ID_INVALID") TraceRecord... records) {
manager.isolate(player, records);
// TODO: Add Message!
}
@ -186,11 +186,11 @@ public class TraceCommand extends SWCommand {
};
}
@ClassMapper(value = TNTRecord.class, local = true)
public TypeMapper<TNTRecord> recordMapper() {
@ClassMapper(value = TraceRecord.class, local = true)
public TypeMapper<TraceRecord> recordMapper() {
return new TypeMapper<>() {
@Override
public TNTRecord map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
public TraceRecord map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
Trace trace = previousArguments.getFirst(Trace.class).orElse(null);
if (trace == null) return null;

Datei anzeigen

@ -61,8 +61,8 @@ public class TraceManager implements Listener {
return nextOpenId;
}
protected void addAll(Trace trace, List<TNTRecord> tntRecords) {
trace.addAll(tntRecords, player -> {
protected void addAll(Trace trace, List<TraceRecord> traceRecords) {
trace.addAll(traceRecords, player -> {
return showDataPerRegionPerPlayer.getOrDefault(trace.getRegion(), Collections.emptyMap()).get(player);
});
}
@ -195,7 +195,7 @@ public class TraceManager implements Listener {
* @param player the player the trace is shown to
* @param records the record for which isolation is toggled
*/
public void isolate(Player player, TNTRecord... records) {
public void isolate(Player player, TraceRecord... records) {
Region region = Region.getRegion(player.getLocation());
PlayerTraceShowData playerTraceShowData = showDataPerRegionPerPlayer.computeIfAbsent(region, ignored -> new HashMap<>()).computeIfAbsent(player, ignored -> new PlayerTraceShowData(BundleFilter.STRICT));
@ -212,7 +212,7 @@ public class TraceManager implements Listener {
showDataPerRegionPerPlayer.get(region).put(player, playerTraceShowData);
}
for (TNTRecord record : records) {
for (TraceRecord record : records) {
isolateFlag.toggleId(record.getTntId());
}

Datei anzeigen

@ -32,7 +32,7 @@ import java.util.List;
import java.util.Optional;
@Getter
public class TNTRecord {
public class TraceRecord {
/**
* Unique number to identify records being of the same tnt
@ -87,9 +87,9 @@ public class TNTRecord {
/**
* List of all tnt records, that are represent the same tnt
*/
private final List<TNTRecord> history;
private final List<TraceRecord> history;
public TNTRecord(int tntId, TNTPrimed tnt, boolean explosion, boolean afterFirstExplosion, long ticksSinceStart, List<TNTRecord> history, List<Block> destroyedBlocks) {
public TraceRecord(int tntId, TNTPrimed tnt, boolean explosion, boolean afterFirstExplosion, long ticksSinceStart, List<TraceRecord> history, List<Block> destroyedBlocks) {
this.tntId = tntId;
this.explosion = explosion;
this.inWater = tnt.isInWater();
@ -115,12 +115,12 @@ public class TNTRecord {
destroyedTestBlock = testblockDestroy;
}
public Optional<TNTRecord> getNext() {
public Optional<TraceRecord> getNext() {
int index = history.indexOf(this);
return index == history.size() - 1 ? Optional.empty() : Optional.of(history.get(index + 1));
}
public Optional<TNTRecord> getPrevious() {
public Optional<TraceRecord> getPrevious() {
int index = history.indexOf(this);
return index == 0 ? Optional.empty() : Optional.of(history.get(index - 1));
}
@ -138,8 +138,8 @@ public class TNTRecord {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof TNTRecord)) return false;
TNTRecord record = (TNTRecord) obj;
if (!(obj instanceof TraceRecord)) return false;
TraceRecord record = (TraceRecord) obj;
if (record.isExplosion() != explosion) return false;
if (!record.getLocation().equals(location)) return false;
if (!record.getVelocity().equals(velocity)) return false;

Datei anzeigen

@ -72,12 +72,12 @@ public class TraceRecorder implements Listener {
/**
* A map for records that have been taken in the same tick and now have to be added to the traces
*/
private final Map<Trace, List<TNTRecord>> recordsToAddMap = new HashMap<>();
private final Map<Trace, List<TraceRecord>> recordsToAddMap = new HashMap<>();
/**
* Maps a tracked tnt entity to its entire recording history
*/
private final Map<TNTPrimed, List<TNTRecord>> historyMap = new HashMap<>();
private final Map<TNTPrimed, List<TraceRecord>> historyMap = new HashMap<>();
/**
* Regions where auto-trace is enabled
@ -160,9 +160,9 @@ public class TraceRecorder implements Listener {
record(tnt, trace, Collections.emptyList());
}
List<TNTRecord> tntRecords = recordsToAddMap.get(trace);
manager.addAll(trace, tntRecords);
tntRecords.clear();
List<TraceRecord> traceRecords = recordsToAddMap.get(trace);
manager.addAll(trace, traceRecords);
traceRecords.clear();
}
}
@ -173,7 +173,7 @@ public class TraceRecorder implements Listener {
* @param trace trace to record the tnt for
*/
private void record(TNTPrimed tntPrimed, Trace trace, List<Block> destroyedBlocks) {
List<TNTRecord> history = historyMap.getOrDefault(tntPrimed, new ArrayList<>());
List<TraceRecord> history = historyMap.getOrDefault(tntPrimed, new ArrayList<>());
int tntID;
if (history.size() == 0) {
@ -189,7 +189,7 @@ public class TraceRecorder implements Listener {
}
boolean afterFirstExplosion = noExplosionRecorded.contains(trace);
TNTRecord record = new TNTRecord(tntID, tntPrimed, isExplosion, afterFirstExplosion, TPSUtils.currentTick.get() - trace.getStartTime(), history, destroyedBlocks);
TraceRecord record = new TraceRecord(tntID, tntPrimed, isExplosion, afterFirstExplosion, TPSUtils.currentTick.get() - trace.getStartTime(), history, destroyedBlocks);
history.add(record);
recordsToAddMap.get(trace).add(record);

Datei anzeigen

@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.tracer.rendering;
import de.steamwar.bausystem.features.tracer.TNTRecord;
import de.steamwar.bausystem.features.tracer.TraceRecord;
import lombok.RequiredArgsConstructor;
import java.util.function.BiFunction;
@ -27,14 +27,14 @@ import java.util.function.BiFunction;
@RequiredArgsConstructor
public enum BundleFilter {
LOOSE((TNTRecord a, TNTRecord b) -> {
LOOSE((TraceRecord a, TraceRecord b) -> {
if (a.isExplosion() != b.isExplosion()) return false;
if (a.getLocation().distanceSquared(b.getLocation()) <= BundleFilter.pixelSizeSquared) return false;
if (a.getVelocity().distanceSquared(b.getVelocity()) <= BundleFilter.pixelSizeSquared) return false;
return true;
}),
DEFAULT((TNTRecord a, TNTRecord b) -> {
DEFAULT((TraceRecord a, TraceRecord b) -> {
if (a.isExplosion() != b.isExplosion()) return false;
if (a.getTicksSinceStart() != b.getTicksSinceStart()) return null;
if (a.getLocation().distanceSquared(b.getLocation()) <= BundleFilter.pixelSizeSquared) return false;
@ -42,7 +42,7 @@ public enum BundleFilter {
return true;
}),
STRICT((TNTRecord a, TNTRecord b) -> {
STRICT((TraceRecord a, TraceRecord b) -> {
if (a.isExplosion() != b.isExplosion()) return false;
if (!a.getLocation().equals(b.getLocation())) return false;
if (!a.getVelocity().equals(b.getVelocity())) return false;
@ -50,7 +50,7 @@ public enum BundleFilter {
return true;
}),
NONE((TNTRecord a, TNTRecord b) -> {
NONE((TraceRecord a, TraceRecord b) -> {
return null;
});
@ -59,7 +59,7 @@ public enum BundleFilter {
* {@code false}: No bundling allowed
* {@code true}: Bundling should be applied
*/
public final BiFunction<TNTRecord, TNTRecord, Boolean> function;
public final BiFunction<TraceRecord, TraceRecord, Boolean> function;
private static final double pixelSize = 0.0625;
private static final double pixelSizeSquared = pixelSize * pixelSize;

Datei anzeigen

@ -20,7 +20,7 @@
package de.steamwar.bausystem.features.tracer.rendering;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tracer.TNTRecord;
import de.steamwar.bausystem.features.tracer.TraceRecord;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import lombok.Getter;
@ -36,16 +36,16 @@ public class TraceEntity extends RFallingBlockEntity {
* The records represented by this REntity
*/
@Getter
private final List<TNTRecord> records;
private final List<TraceRecord> records;
public TraceEntity(REntityServer server, Location location, boolean isExplosion, List<TNTRecord> records) {
public TraceEntity(REntityServer server, Location location, boolean isExplosion, List<TraceRecord> records) {
super(server, location, isExplosion ? Material.RED_STAINED_GLASS : Material.TNT);
setNoGravity(true);
this.records = records;
}
public void printIntoChat(Player player) {
TNTRecord representative = records.get(0);
TraceRecord representative = records.get(0);
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", player);
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", player, representative.getFuse());

Datei anzeigen

@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.tracer.rendering;
import de.steamwar.bausystem.features.tracer.TNTRecord;
import de.steamwar.bausystem.features.tracer.TraceRecord;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import org.bukkit.Location;
@ -45,16 +45,16 @@ public abstract class ViewFlag {
public static ViewFlag EXPLOSION = new ViewFlag(true, false, "explosion", "e") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) {
public List<TraceRecord> filter(List<TraceRecord> records) {
return records.stream()
.filter(TNTRecord::isExplosion)
.filter(TraceRecord::isExplosion)
.collect(Collectors.toList());
}
};
public static ViewFlag IGNITE = new ViewFlag(true, true, "ignite", "i") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) {
public List<TraceRecord> filter(List<TraceRecord> records) {
return records.stream()
.filter(record -> !record.isAfterFirstExplosion())
.collect(Collectors.toList());
@ -63,7 +63,7 @@ public abstract class ViewFlag {
public static ViewFlag SOURCE = new ViewFlag(true, false, IGNITE, "source", "s") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) {
public List<TraceRecord> filter(List<TraceRecord> records) {
return records.stream()
.filter(record -> record.getFuse() == 80)
.collect(Collectors.toList());
@ -72,7 +72,7 @@ public abstract class ViewFlag {
public static ViewFlag BUILD_DESTROY_ONLY = new ViewFlag(true, false, "build-destroy-only") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) {
public List<TraceRecord> filter(List<TraceRecord> records) {
return records.stream()
.filter(record -> record.getHistory().get(record.getHistory().size() - 1).isDestroyedBuildArea())
.collect(Collectors.toList());
@ -81,7 +81,7 @@ public abstract class ViewFlag {
public static ViewFlag TESTBLOCK_DESTROY_ONLY = new ViewFlag(true, false, "testblock-destroy-only") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) {
public List<TraceRecord> filter(List<TraceRecord> records) {
return records.stream()
.filter(record -> record.getHistory().get(record.getHistory().size() - 1).isDestroyedTestBlock())
.collect(Collectors.toList());
@ -90,15 +90,15 @@ public abstract class ViewFlag {
public static ViewFlag MICROMOTION = new ViewFlag(true, false, "micromotion", "m") {
@Override
public List<TNTRecord> filter(List<TNTRecord> records) {
public List<TraceRecord> filter(List<TraceRecord> records) {
Set<Integer> seen = new HashSet<>();
Set<TNTRecord> toRemove = new HashSet<>();
Set<TraceRecord> toRemove = new HashSet<>();
for (TNTRecord uniqueRecord : records) {
for (TraceRecord uniqueRecord : records) {
if (seen.contains(uniqueRecord.getTntId())) continue;
boolean hasMicromotion = false;
for (TNTRecord record : uniqueRecord.getHistory()) {
for (TraceRecord record : uniqueRecord.getHistory()) {
Vector velocity = record.getVelocity();
if (velocity.getY() == 0 && (Math.abs(velocity.getX()) < 0.001 || Math.abs(velocity.getZ()) < 0.001)) {
hasMicromotion = true;
@ -112,7 +112,7 @@ public abstract class ViewFlag {
seen.add(uniqueRecord.getTntId());
}
for (TNTRecord record : toRemove) {
for (TraceRecord record : toRemove) {
records.removeAll(record.getHistory());
}
@ -124,9 +124,9 @@ public abstract class ViewFlag {
@Override
public void modify(REntityServer server, List<TraceEntity> entities) {
for (TraceEntity entity : entities) {
TNTRecord current = entity.getRecords().get(0);
TraceRecord current = entity.getRecords().get(0);
if (current.isExplosion()) continue;
TNTRecord next = current.getNext().orElse(null);
TraceRecord next = current.getNext().orElse(null);
if (next == null) continue;
Location pos = current.getLocation().clone();
@ -214,7 +214,7 @@ public abstract class ViewFlag {
* @param records Records to be filtered
* @return Filtered records
*/
public List<TNTRecord> filter(List<TNTRecord> records) {
public List<TraceRecord> filter(List<TraceRecord> records) {
return records;
}

Datei anzeigen

@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.tracer.rendering.dynamicflags;
import de.steamwar.bausystem.features.tracer.TNTRecord;
import de.steamwar.bausystem.features.tracer.TraceRecord;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import java.util.List;
@ -47,7 +47,7 @@ public class AtFlag extends ViewFlag {
}
@Override
public List<TNTRecord> filter(List<TNTRecord> records) {
public List<TraceRecord> filter(List<TraceRecord> records) {
return records.stream()
.filter(record -> record.getTicksSinceStart() >= start && record.getTicksSinceStart() <= end)
.collect(Collectors.toList());

Datei anzeigen

@ -19,7 +19,7 @@
package de.steamwar.bausystem.features.tracer.rendering.dynamicflags;
import de.steamwar.bausystem.features.tracer.TNTRecord;
import de.steamwar.bausystem.features.tracer.TraceRecord;
import de.steamwar.bausystem.features.tracer.rendering.ViewFlag;
import java.util.HashSet;
@ -50,7 +50,7 @@ public class IsolateFlag extends ViewFlag {
}
@Override
public List<TNTRecord> filter(List<TNTRecord> records) {
public List<TraceRecord> filter(List<TraceRecord> records) {
return records.stream()
.filter(record -> tntToIsolate.contains(record.getTntId()))
.collect(Collectors.toList());