From a64e1bb2b23f08c9012bb63a955cfa505ce83cb9 Mon Sep 17 00:00:00 2001 From: D4VID Date: Fri, 21 Feb 2025 20:02:58 +0100 Subject: [PATCH] Correct highlighting and unhighlighting --- .../src/client/CriticalPathAnalyzerClient.cs | 15 +---- .../client/tool/CriticalPathAnalyzerTool.cs | 17 +++++- .../src/client/tool/PathHighLighter.cs | 58 ++++++++----------- .../src/client/tool/WireTracerColors.cs | 34 ----------- .../shared/packets/s2c/AnalyzePathResponse.cs | 7 --- 5 files changed, 40 insertions(+), 91 deletions(-) delete mode 100644 CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/WireTracerColors.cs diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/CriticalPathAnalyzerClient.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/CriticalPathAnalyzerClient.cs index 4ecad61..43e1d6f 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/CriticalPathAnalyzerClient.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/CriticalPathAnalyzerClient.cs @@ -34,20 +34,7 @@ namespace CriticalPathAnalyzer.Client { public static void OnAnalyzePathResponse(AnalyzePathResponse response) { LoggerInstance.Info($"Got response from server"); - PathHighLighter.HighlightWires(response); - // if(!CurrentRequestID.HasValue || response.requestGuid != currentRequestID.Value) - // { - // //Not matching Guid, old or wrong request, discard. - // return; - // } - // currentRequestID = null; //Received response, clear GUID. - // - // //Clear up all data immediately: - // if(currentTracer != null) - // { - // currentTracer.stop(); - // currentTracer = null; - // } + CriticalPathAnalyzerTool.Highlight(response); } } } \ No newline at end of file diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs index 9f1de3f..1f69e3d 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs @@ -1,5 +1,6 @@ using System; using CriticalPathAnalyzer.Shared.Packets.C2S; +using CriticalPathAnalyzer.Shared.Packets.S2C; using LogicAPI.Data; using LogicLog; using LogicWorld.Interfaces; @@ -15,6 +16,8 @@ namespace CriticalPathAnalyzer.Client.Tool { private static PegAddress? _startPegAddress; private static PegAddress? _endPegAddress; + private static Guid _currentRequestGuid = Guid.NewGuid(); + public static void Init(ILogicLogger logger) { _logger = logger; } @@ -77,11 +80,23 @@ namespace CriticalPathAnalyzer.Client.Tool { return; } + _currentRequestGuid = Guid.NewGuid(); Instances.SendData.Send(new AnalyzePathRequest { - RequestGuid = Guid.NewGuid(), + RequestGuid = _currentRequestGuid, StartPegAddress = _startPegAddress.Value, EndPegAddress = _endPegAddress.Value, }); } + + public static void Highlight(AnalyzePathResponse response) { + if (_currentRequestGuid != response.RequestGuid) { + // Not matching Guid, old or wrong request, discard. + _logger.Warn("Got response to wrong request, discarding"); + return; + } + + PathHighLighter.RemoveHighLighting(); + PathHighLighter.HighlightWires(response); + } } } \ No newline at end of file diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighLighter.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighLighter.cs index f6e5f5b..e729f40 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighLighter.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighLighter.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -using CriticalPathAnalyzer.client.tool; using CriticalPathAnalyzer.Shared.Packets.S2C; +using JimmysUnityUtilities; using LogicAPI.Data; using LogicAPI.Services; using LogicWorld.Interfaces; @@ -8,20 +8,24 @@ using LogicWorld.Outlines; namespace CriticalPathAnalyzer.Client.Tool { public class PathHighLighter { - private static List _clusters; + private static readonly OutlineData Color = new OutlineData(new Color24(0xff0000)); + + private static List _clusters = new List(); + private static List _highlightedWires = new List(); public static void HighlightWires(AnalyzePathResponse response) { _clusters = response.SelectedClusters; IWorldData world = Instances.MainWorld.Data; + foreach (ClusterDetails clusterDetails in _clusters) { foreach (ComponentAddress address in clusterDetails.ConnectingComponents) { if (!world.Contains(address)) { continue; } - Outliner.Outline(address, WireTracerColors.primaryConnected); + Outliner.Outline(address, Color); } foreach (ComponentAddress address in clusterDetails.LinkingComponents) { @@ -29,23 +33,16 @@ namespace CriticalPathAnalyzer.Client.Tool { continue; } - Outliner.Outline(address, WireTracerColors.linking); + Outliner.Outline(address, Color); } - clusterDetails.HighlightedWires = new List(); - clusterDetails.HighlightedOutputWires = new List(); - foreach (PegAddress pegAddress in clusterDetails.Pegs) { if (!world.Contains(pegAddress.ComponentAddress)) { + CriticalPathAnalyzerClient.LoggerInstance.Warn("Peg's component doesn't exist in world"); continue; } - if (!pegAddress.IsInputAddress()) { - Outliner.Outline(pegAddress, WireTracerColors.primaryOutput); - continue; - } - - Outliner.Outline(pegAddress, WireTracerColors.primaryNormal); + Outliner.Outline(pegAddress, Color); HashSet wires = Instances.MainWorld.Data.LookupPegWires(pegAddress); if (wires == null) { @@ -60,30 +57,29 @@ namespace CriticalPathAnalyzer.Client.Tool { // We do not collect wires from output pegs. So if the first is an output peg, the other side must be an input -> collect. if (wire.Point1 == pegAddress || !wire.Point1.IsInputAddress()) { - if (wire.Point1.IsInputAddress() && wire.Point2.IsInputAddress()) { - clusterDetails.HighlightedWires.Add(wireAddress); - } else { - clusterDetails.HighlightedOutputWires.Add(wireAddress); - } + _highlightedWires.Add(wireAddress); + Outliner.Outline(wireAddress, Color); } } } - - foreach (WireAddress address in clusterDetails.HighlightedWires) { - Outliner.Outline(address, WireTracerColors.primaryNormal); - } - - foreach (WireAddress address in clusterDetails.HighlightedOutputWires) { - Outliner.Outline(address, WireTracerColors.primaryOutput); - } } } public static void RemoveHighLighting() { - if (_clusters == null) return; + if (_clusters == null) { + CriticalPathAnalyzerClient.LoggerInstance.Warn("Ignoring remove highlighting, clusters is null"); + return; + } foreach (ClusterDetails cluster in _clusters) { UnhighlightCluster(cluster); } + + foreach (WireAddress wireAddress in _highlightedWires) { + Outliner.RemoveOutline(wireAddress); + } + + _clusters = null; + _highlightedWires.Clear(); } private static void UnhighlightCluster(ClusterDetails cluster) { @@ -98,14 +94,6 @@ namespace CriticalPathAnalyzer.Client.Tool { foreach (ComponentAddress address in cluster.LinkingComponents) { Outliner.RemoveOutline(address); } - - foreach (WireAddress address in cluster.HighlightedWires) { - Outliner.RemoveOutline(address); - } - - foreach (WireAddress address in cluster.HighlightedOutputWires) { - Outliner.RemoveOutline(address); - } } } } \ No newline at end of file diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/WireTracerColors.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/WireTracerColors.cs deleted file mode 100644 index 7faec00..0000000 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/WireTracerColors.cs +++ /dev/null @@ -1,34 +0,0 @@ -using JimmysUnityUtilities; -using LogicWorld.Outlines; - -namespace CriticalPathAnalyzer.client.tool -{ - public static class WireTracerColors - { - //All clusters: - //Linking color is the intersection between clusters, it does not make sense to have this once per cluster type. - // The only change that could be done is to give linking separators between two non-primary clusters a different color. - // That is currently not supported nor detected. - public static readonly OutlineData linking = new OutlineData(new Color24(200, 200, 200)); - - //Primary cluster: - public static readonly OutlineData primaryNormal = new OutlineData(new Color24( 50, 255, 50)); - public static readonly OutlineData primaryConnected = new OutlineData(new Color24( 20, 150, 20)); - public static readonly OutlineData primaryOutput = new OutlineData(new Color24( 50, 50, 255)); - - //Sourcing cluster: - public static readonly OutlineData sourcingNormal = new OutlineData(new Color24(255, 50, 255)); - public static readonly OutlineData sourcingConnected = new OutlineData(new Color24(150, 20, 150)); - public static readonly OutlineData sourcingOutput = new OutlineData(new Color24( 80, 0, 255)); - - //Connected cluster: - public static readonly OutlineData connectedNormal = new OutlineData(new Color24(255, 255, 50)); - public static readonly OutlineData connectedConnected = new OutlineData(new Color24(150, 150, 20)); - public static readonly OutlineData connectedOutput = new OutlineData(new Color24( 80, 80, 255)); - - //Draining cluster: - public static readonly OutlineData drainingNormal = new OutlineData(new Color24( 50, 255, 255)); - public static readonly OutlineData drainingConnected = new OutlineData(new Color24( 20, 150, 150)); - public static readonly OutlineData drainingOutput = new OutlineData(new Color24( 0, 50, 150)); - } -} diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs index 05056ad..53be1af 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs @@ -21,12 +21,5 @@ namespace CriticalPathAnalyzer.Shared.Packets.S2C { public List ConnectingComponents; [Key(2)] public List LinkingComponents; - - // The following two entries are used on the client to temporary store wires until their outline is being removed again. - // This information is just not collected on the server, hence the client collects them. - [IgnoreMember] - public List HighlightedWires; - [IgnoreMember] - public List HighlightedOutputWires; } } \ No newline at end of file