From ccc75c9f1e6ece6d0e871c7ca92a4b95bed89386 Mon Sep 17 00:00:00 2001 From: D4VID Date: Fri, 21 Feb 2025 21:42:32 +0100 Subject: [PATCH] Find neighbouring clusters --- .../src/client/tool/PathHighLighter.cs | 18 ++++++--- .../src/server/ServerPathTracer.cs | 38 +++++++++++-------- .../shared/packets/s2c/AnalyzePathResponse.cs | 1 + 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighLighter.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighLighter.cs index 1e837a6..67e4c4b 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighLighter.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighLighter.cs @@ -9,6 +9,7 @@ using LogicWorld.Outlines; namespace CriticalPathAnalyzer.Client.Tool { public class PathHighLighter { private static readonly OutlineData Color = new OutlineData(new Color24(0xff0000)); + private static readonly OutlineData NextColor = new OutlineData(new Color24(0xff00ff)); private static readonly OutlineData PerimeterColor = new OutlineData(new Color24(0xffff00)); private static List _clusters = new List(); @@ -19,7 +20,7 @@ namespace CriticalPathAnalyzer.Client.Tool { _clusters = response.Clusters; foreach (ClusterDetails clusterDetails in _clusters) { - HighlightCluster(clusterDetails); + HighlightCluster(clusterDetails, Color); } IWorldData world = Instances.MainWorld.Data; @@ -32,9 +33,14 @@ namespace CriticalPathAnalyzer.Client.Tool { Outliner.Outline(componentAddress, PerimeterColor); _highlightedComponents.Add(componentAddress); } + + _clusters.AddRange(response.NextClusters); // add to the collection to unhighlight + foreach (ClusterDetails clusterDetails in response.NextClusters) { + HighlightCluster(clusterDetails, NextColor); + } } - private static void HighlightCluster(ClusterDetails cluster) { + private static void HighlightCluster(ClusterDetails cluster, OutlineData outline) { IWorldData world = Instances.MainWorld.Data; foreach (ComponentAddress address in cluster.ConnectingComponents) { @@ -42,7 +48,7 @@ namespace CriticalPathAnalyzer.Client.Tool { continue; } - Outliner.Outline(address, Color); + Outliner.Outline(address, outline); } foreach (ComponentAddress address in cluster.LinkingComponents) { @@ -50,7 +56,7 @@ namespace CriticalPathAnalyzer.Client.Tool { continue; } - Outliner.Outline(address, Color); + Outliner.Outline(address, outline); } foreach (PegAddress pegAddress in cluster.Pegs) { @@ -58,7 +64,7 @@ namespace CriticalPathAnalyzer.Client.Tool { continue; } - Outliner.Outline(pegAddress, Color); + Outliner.Outline(pegAddress, outline); HashSet wires = Instances.MainWorld.Data.LookupPegWires(pegAddress); if (wires == null) { @@ -74,7 +80,7 @@ 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()) { _highlightedWires.Add(wireAddress); - Outliner.Outline(wireAddress, Color); + Outliner.Outline(wireAddress, outline); } } } diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/ServerPathTracer.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/ServerPathTracer.cs index 11c5b24..d83791e 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/ServerPathTracer.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/ServerPathTracer.cs @@ -5,6 +5,7 @@ using CriticalPathAnalyzer.Shared.Packets.S2C; using EccsLogicWorldAPI.Server; using EccsLogicWorldAPI.Shared.AccessHelper; using LogicAPI.Data; +using LogicAPI.Server.Components; using LogicAPI.Services; using LogicWorld.Server.Circuitry; @@ -43,6 +44,8 @@ namespace CriticalPathAnalyzer.Server { ) { response = null; + var clusterTime = new Dictionary(); + CriticalPathAnalyzerServer.LoggerInstance.Info("Trace start"); // Validate, that the peg is actually existing: @@ -54,10 +57,9 @@ namespace CriticalPathAnalyzer.Server { // An input peg, only has a single cluster. // An output peg however can be connected to multiple clusters. // It only makes sense to then select all these clusters as primary cluster. - if (!CollectMainClusters(start, out HashSet collectedClusters)) { - return false; // Whoops, cannot collect the primary clusters, probably probing an output peg. - } - + var collectedClusters = new HashSet(); + CollectMainClusters(start, collectedClusters); + CriticalPathAnalyzerServer.LoggerInstance.Info("collected main clusters"); // Collect clusters that get powered by the original cluster by fast buffers @@ -65,31 +67,38 @@ namespace CriticalPathAnalyzer.Server { foreach (Cluster cluster in collectedClusters) { GetLinkedClusters(cluster, collectedDrains, GetFollowers); } - + collectedClusters.UnionWith(collectedDrains); - + CriticalPathAnalyzerServer.LoggerInstance.Info("collected linked clusters"); var perimeterComponents = new HashSet(); + var collectedNextClusters = new HashSet(); foreach (Cluster cluster in collectedClusters) { foreach (InputPeg inputPeg in cluster.ConnectedInputs) { if (inputPeg.LogicComponent == null) { // These are regular pegs, they are not attached to any logic component, skip them continue; } + perimeterComponents.Add(inputPeg.LogicComponent.Address); + + foreach (IOutputPeg outputPeg in inputPeg.LogicComponent.Outputs) { + CollectMainClusters(outputPeg.Address, collectedNextClusters); + } } } CriticalPathAnalyzerServer.LoggerInstance.Info("collected perimeter components"); - + // Collect information about each cluster: response = new AnalyzePathResponse() { RequestGuid = requestGuid, Clusters = collectedClusters.Select(CollectClusterInformation).ToList(), - PerimeterComponents = perimeterComponents.ToList() + PerimeterComponents = perimeterComponents.ToList(), + NextClusters = collectedNextClusters.Select(CollectClusterInformation).ToList(), }; - + CriticalPathAnalyzerServer.LoggerInstance.Info("Trace end"); return true; @@ -128,14 +137,13 @@ namespace CriticalPathAnalyzer.Server { return linker != null; } - private static bool CollectMainClusters(PegAddress pegAddress, out HashSet primaryClusters) { - primaryClusters = new HashSet(); + private static void CollectMainClusters(PegAddress pegAddress, HashSet primaryClusters) { if (pegAddress.IsInputAddress(out InputAddress inputAddress)) { primaryClusters.Add(GetClusterAt(inputAddress)); } else { HashSet wires = World.LookupPegWires(pegAddress); if (wires == null) { - return true; + return; } foreach (WireAddress wireAddress in wires) { @@ -146,15 +154,13 @@ namespace CriticalPathAnalyzer.Server { } PegAddress otherSide = wire.Point1 == pegAddress ? wire.Point2 : wire.Point1; - if (!otherSide.IsInputAddress(out var otherSideInputAddress)) { - continue; //Not supported, this wire would be invalid anyway. + if (!otherSide.IsInputAddress(out InputAddress otherSideInputAddress)) { + continue; // Not supported, this wire would be invalid anyway. } primaryClusters.Add(GetClusterAt(otherSideInputAddress)); } } - - return true; } private static void GetLinkedClusters( diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs index d5bf778..7d6dd2e 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs @@ -10,6 +10,7 @@ namespace CriticalPathAnalyzer.Shared.Packets.S2C { [Key(0)] public Guid RequestGuid; [Key(1)] public List Clusters; [Key(2)] public List PerimeterComponents; + [Key(3)] public List NextClusters; } [MessagePackObject]