Find neighbouring clusters

master
D4VID 7 months ago
parent 58e603bdbe
commit ccc75c9f1e

@ -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<ClusterDetails> _clusters = new List<ClusterDetails>();
@ -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<WireAddress> 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);
}
}
}

@ -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<Cluster, int>();
CriticalPathAnalyzerServer.LoggerInstance.Info("Trace start");
// Validate, that the peg is actually existing:
@ -54,9 +57,8 @@ 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<Cluster> collectedClusters)) {
return false; // Whoops, cannot collect the primary clusters, probably probing an output peg.
}
var collectedClusters = new HashSet<Cluster>();
CollectMainClusters(start, collectedClusters);
CriticalPathAnalyzerServer.LoggerInstance.Info("collected main clusters");
@ -71,13 +73,19 @@ namespace CriticalPathAnalyzer.Server {
CriticalPathAnalyzerServer.LoggerInstance.Info("collected linked clusters");
var perimeterComponents = new HashSet<ComponentAddress>();
var collectedNextClusters = new HashSet<Cluster>();
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);
}
}
}
@ -87,7 +95,8 @@ namespace CriticalPathAnalyzer.Server {
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");
@ -128,14 +137,13 @@ namespace CriticalPathAnalyzer.Server {
return linker != null;
}
private static bool CollectMainClusters(PegAddress pegAddress, out HashSet<Cluster> primaryClusters) {
primaryClusters = new HashSet<Cluster>();
private static void CollectMainClusters(PegAddress pegAddress, HashSet<Cluster> primaryClusters) {
if (pegAddress.IsInputAddress(out InputAddress inputAddress)) {
primaryClusters.Add(GetClusterAt(inputAddress));
} else {
HashSet<WireAddress> 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)) {
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(

@ -10,6 +10,7 @@ namespace CriticalPathAnalyzer.Shared.Packets.S2C {
[Key(0)] public Guid RequestGuid;
[Key(1)] public List<ClusterDetails> Clusters;
[Key(2)] public List<ComponentAddress> PerimeterComponents;
[Key(3)] public List<ClusterDetails> NextClusters;
}
[MessagePackObject]

Loading…
Cancel
Save