SteamWar/BauSystem2.0
Archiviert
12
0

Fixed bugs with trace rendering
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Added toString
Dieser Commit ist enthalten in:
D4rkr34lm 2024-02-20 23:11:58 +01:00
Ursprung beb49cdcd1
Commit 5c96da9acd
7 geänderte Dateien mit 70 neuen und 12 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -78,4 +78,15 @@ public class TNTRecord {
protected void setNext(TNTRecord next){ protected void setNext(TNTRecord next){
if(this.next == null) this.next = 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 * 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){ public Trace (Region region){
this.region = region; this.region = region;
@ -72,13 +72,21 @@ public class Trace {
this.records = records; this.records = records;
} }
//TODO default options
//TODO Life rendering
/** Renders this traces /** Renders this traces
* *
* @param player The player the trace is rendered to * @param player The player the trace is rendered to
* @param flags Flags modefieing the rendering * @param flags Flags modefieing the rendering
*/ */
public void render(Player player, Collection<ViewFlag> flags, BundleFilter bundleFilter){ 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; List<TNTRecord> workingRecords = records;
//Apply filters //Apply filters
@ -91,6 +99,7 @@ public class Trace {
//Render bundled records //Render bundled records
REntityServer server = new REntityServer(); REntityServer server = new REntityServer();
serverMap.put(player, server); serverMap.put(player, server);
server.addPlayer(player);
List<TraceEntity> entities = new LinkedList<>(); List<TraceEntity> entities = new LinkedList<>();
for(List<TNTRecord> bundle : bundles) for(List<TNTRecord> bundle : bundles)
@ -107,9 +116,15 @@ public class Trace {
* @return A list of bundles * @return A list of bundles
*/ */
private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records, BundleFilter filter){ 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) { 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--){ for(int i = bundles.size() - 1; i >= 0; i--){
List<TNTRecord> bundle = bundles.get(i); List<TNTRecord> bundle = bundles.get(i);
@ -120,6 +135,7 @@ public class Trace {
else{ else{
ArrayList<TNTRecord> newBundle = new ArrayList<>(); ArrayList<TNTRecord> newBundle = new ArrayList<>();
newBundle.add(record); newBundle.add(record);
bundles.add(newBundle);
continue recordsLoop; continue recordsLoop;
} }
@ -139,4 +155,13 @@ public class Trace {
server.close(); 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 de.steamwar.linkage.LinkedInstance;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.HashSet;
@Linked @Linked
public class TraceCommand extends SWCommand { public class TraceCommand extends SWCommand {
@LinkedInstance @LinkedInstance
public Recorder recorder; public Recorder recorder;
int traceId = 0;
public TraceCommand(){super("tracetest");} public TraceCommand(){super("tracetest");}
@Register(value = "start") @Register(value = "start")
public void test(@Validator Player player){ public void test(Player player){
Region region = Region.getRegion(player.getLocation()); 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) { public TraceEntity(REntityServer server, Location location, boolean isExplosion, List<TNTRecord> records) {
super(server, location, isExplosion ? Material.RED_STAINED_GLASS : Material.TNT); super(server, location, isExplosion ? Material.RED_STAINED_GLASS : Material.TNT);
setNoGravity(true);
this.records = records; this.records = records;
} }
} }

Datei anzeigen

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