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

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.tracer2;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
public enum BundleFilter {

Datei anzeigen

@ -40,7 +40,7 @@ public class Recorder implements Listener {
* Linked instance of TraceManager
*/
@LinkedInstance
TraceManager manager;
public TraceManager manager;
/**
* Map for all traces beeing activly recorded
@ -63,19 +63,17 @@ public class Recorder implements Listener {
private final Map<TNTPrimed, TNTRecord> lastRecordMap = new HashMap<>();
public Recorder(){
BauSystem.runTaskTimer(BauSystem.getInstance(), () ->{
record();
}, 0, 1);
BauSystem.runTaskTimer(BauSystem.getInstance(), this::record, 0, 1);
}
/** Starts a recording at the given region
*
* @param region region to be recorded
*/
public void startRecording(Region region){
public int startRecording(Region region){
Trace trace = new Trace(region);
activeTraces.put(region, trace);
manager.add(trace);
return manager.add(trace);
}
/** Stops the recording at the given region

Datei anzeigen

@ -78,4 +78,15 @@ public class TNTRecord {
protected void setNext(TNTRecord next){
if(this.next == null) this.next = next;
}
@Override
public String toString() {
return "TNTRecord{" +
"explosion=" + explosion +
", ticksSinceStart=" + ticksSinceStart +
", fuse=" + fuse +
", location=" + location +
", velocity=" + velocity +
'}';
}
}

Datei anzeigen

@ -50,7 +50,7 @@ public class Trace {
/**
* A map of players -> REntityServers for rendering traces to a player
*/
private Map<Player, REntityServer> serverMap = new HashMap<>();
private final Map<Player, REntityServer> serverMap = new HashMap<>();
public Trace (Region region){
this.region = region;
@ -72,13 +72,21 @@ public class Trace {
this.records = records;
}
//TODO default options
//TODO Life rendering
/** Renders this traces
*
* @param player The player the trace is rendered to
* @param flags Flags modefieing the rendering
*/
public void render(Player player, Collection<ViewFlag> flags, BundleFilter bundleFilter){
if(serverMap.containsKey(player)){
REntityServer server = serverMap.get(player);
server.close();
serverMap.remove(player);
}
List<TNTRecord> workingRecords = records;
//Apply filters
@ -91,6 +99,7 @@ public class Trace {
//Render bundled records
REntityServer server = new REntityServer();
serverMap.put(player, server);
server.addPlayer(player);
List<TraceEntity> entities = new LinkedList<>();
for(List<TNTRecord> bundle : bundles)
@ -107,9 +116,15 @@ public class Trace {
* @return A list of bundles
*/
private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records, BundleFilter filter){
ArrayList<List<TNTRecord>> bundles = new ArrayList<>();
List<List<TNTRecord>> bundles = new ArrayList<>();
recordsLoop : for(TNTRecord record : records) {
if(bundles.isEmpty()){
List<TNTRecord> firstBundle = new ArrayList<>();
firstBundle.add(record);
bundles.add(firstBundle);
}
for(int i = bundles.size() - 1; i >= 0; i--){
List<TNTRecord> bundle = bundles.get(i);
@ -120,6 +135,7 @@ public class Trace {
else{
ArrayList<TNTRecord> newBundle = new ArrayList<>();
newBundle.add(record);
bundles.add(newBundle);
continue recordsLoop;
}
@ -139,4 +155,13 @@ public class Trace {
server.close();
}
@Override
public String toString() {
return "Trace{" +
"region=" + region +
", startTime=" + startTime +
", records=" + records +
'}';
}
}

Datei anzeigen

@ -25,16 +25,38 @@ import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.HashSet;
@Linked
public class TraceCommand extends SWCommand {
@LinkedInstance
public Recorder recorder;
int traceId = 0;
public TraceCommand(){super("tracetest");}
@Register(value = "start")
public void test(@Validator Player player){
public void test(Player player){
Region region = Region.getRegion(player.getLocation());
traceId = recorder.startRecording(region);
System.out.println(traceId);
}
@Register(value = "stop")
public void test2(Player player){
Region region = Region.getRegion(player.getLocation());
recorder.stopRecording(region);
Trace trace = recorder.manager.get(traceId);
if(trace != null)
System.out.println(trace.getRecords());
}
@Register(value = "show")
public void test3(Player player){
Trace trace = recorder.manager.get(traceId);
trace.render(player, Collections.emptyList(), BundleFilter.DEFAULT);
}
}

Datei anzeigen

@ -37,6 +37,7 @@ public class TraceEntity extends RFallingBlockEntity {
public TraceEntity(REntityServer server, Location location, boolean isExplosion, List<TNTRecord> records) {
super(server, location, isExplosion ? Material.RED_STAINED_GLASS : Material.TNT);
setNoGravity(true);
this.records = records;
}
}

Datei anzeigen

@ -28,6 +28,8 @@ import java.util.stream.Collectors;
@Linked
public class TraceManager implements Listener {
//TODO no null returns
/**
* Map of all current traces
*/