From f62d9e626b4fd45ebf07d4f432e4af655e607621 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Wed, 21 Feb 2024 13:34:25 +0100 Subject: [PATCH] Added live rendering --- .../bausystem/features/tracer2/Recorder.java | 1 + .../bausystem/features/tracer2/Trace.java | 63 ++++++++++++++++--- .../features/tracer2/TraceManager.java | 2 - 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java index f001325d..2f958334 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java @@ -102,6 +102,7 @@ public class Recorder implements Listener { for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){ record(tnt, trace); } + trace.comitAdd(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java index 77757a8d..4b0f1811 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java @@ -47,21 +47,49 @@ public class Trace { @Getter private List records = new ArrayList<>(); + /** + * Records to be added + */ + private List newRecords = new ArrayList<>(); + /** * A map of players -> REntityServers for rendering traces to a player */ private final Map serverMap = new HashMap<>(); + /** + * A map saving the bundle filters for rendered traces, for life rendering + */ + private final Map bundleFilterMap = new HashMap<>(); + + /** + * A map saving the view flags for rendered traces, for life rendering + */ + private final Map> viewFlagMap = new HashMap<>(); + public Trace (Region region){ this.region = region; } - /** Methode to add a record to the trace + /** Methode to add a records to add staging * - * @param record record to add + * @param records records to add */ - protected void add (TNTRecord record){ - records.add(record); + protected void add (TNTRecord records){ + newRecords.add(records); + } + + protected void comitAdd(){ + records.addAll(newRecords); + + for(Player player: serverMap.keySet()){ + REntityServer server = serverMap.get(player); + BundleFilter bundleFilter = bundleFilterMap.get(player); + Collection viewFlags = viewFlagMap.get(player); + + render(server, newRecords, viewFlags, bundleFilter); + } + newRecords.clear(); } /** Internal methode to make records immutable after recording is finished @@ -73,19 +101,41 @@ public class Trace { } //TODO default options - //TODO Life rendering /** Renders this traces * * @param player The player the trace is rendered to * @param flags Flags modefieing the rendering + * @param bundleFilter Filter to determin bundeling of records */ public void render(Player player, Collection flags, BundleFilter bundleFilter){ if(serverMap.containsKey(player)){ REntityServer server = serverMap.get(player); server.close(); + serverMap.remove(player); + viewFlagMap.remove(player); + bundleFilterMap.remove(player); } + viewFlagMap.put(player, flags); + bundleFilterMap.put(player, bundleFilter); + + REntityServer server = new REntityServer(); + server.addPlayer(player); + serverMap.put(player, server); + + render(server, records, flags, bundleFilter); + } + + /** Internal methode to render records to a REntityServer + * + * @param server Server to render to + * @param records Records to render + * @param flags Flags modefieing the rendering + * @param bundleFilter Filter to determin bundeling of records + */ + private void render (REntityServer server, List records, Collection flags, BundleFilter bundleFilter){ + if(records.size() == 0) return; List workingRecords = records; @@ -97,9 +147,6 @@ public class Trace { List> bundles = bundleRecords(workingRecords, bundleFilter); //Render bundled records - REntityServer server = new REntityServer(); - serverMap.put(player, server); - server.addPlayer(player); List entities = new LinkedList<>(); for(List bundle : bundles) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java index 51c8df5d..6a4d8e6b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java @@ -28,8 +28,6 @@ import java.util.stream.Collectors; @Linked public class TraceManager implements Listener { - //TODO no null returns - /** * Map of all current traces */