Hightlighting cluster perimeter components

master
D4VID 7 months ago
parent a176609c27
commit 58e603bdbe

@ -9,18 +9,35 @@ using LogicWorld.Outlines;
namespace CriticalPathAnalyzer.Client.Tool {
public class PathHighLighter {
private static readonly OutlineData Color = new OutlineData(new Color24(0xff0000));
private static readonly OutlineData PerimeterColor = new OutlineData(new Color24(0xffff00));
private static List<ClusterDetails> _clusters = new List<ClusterDetails>();
private static List<ComponentAddress> _highlightedComponents = new List<ComponentAddress>();
private static List<WireAddress> _highlightedWires = new List<WireAddress>();
public static void HighlightWires(AnalyzePathResponse response) {
_clusters = response.Clusters;
foreach (ClusterDetails clusterDetails in _clusters) {
HighlightCluster(clusterDetails);
}
IWorldData world = Instances.MainWorld.Data;
foreach (ComponentAddress componentAddress in response.PerimeterComponents) {
if (!world.Contains(componentAddress)) {
continue;
}
foreach (ClusterDetails clusterDetails in _clusters) {
foreach (ComponentAddress address in clusterDetails.ConnectingComponents) {
Outliner.Outline(componentAddress, PerimeterColor);
_highlightedComponents.Add(componentAddress);
}
}
private static void HighlightCluster(ClusterDetails cluster) {
IWorldData world = Instances.MainWorld.Data;
foreach (ComponentAddress address in cluster.ConnectingComponents) {
if (!world.Contains(address)) {
continue;
}
@ -28,7 +45,7 @@ namespace CriticalPathAnalyzer.Client.Tool {
Outliner.Outline(address, Color);
}
foreach (ComponentAddress address in clusterDetails.LinkingComponents) {
foreach (ComponentAddress address in cluster.LinkingComponents) {
if (!world.Contains(address)) {
continue;
}
@ -36,7 +53,7 @@ namespace CriticalPathAnalyzer.Client.Tool {
Outliner.Outline(address, Color);
}
foreach (PegAddress pegAddress in clusterDetails.Pegs) {
foreach (PegAddress pegAddress in cluster.Pegs) {
if (!world.Contains(pegAddress.ComponentAddress)) {
continue;
}
@ -62,13 +79,13 @@ namespace CriticalPathAnalyzer.Client.Tool {
}
}
}
}
public static void RemoveHighLighting() {
if (_clusters == null) {
CriticalPathAnalyzerClient.LoggerInstance.Warn("Ignoring remove highlighting, clusters is null");
return;
}
foreach (ClusterDetails cluster in _clusters) {
UnhighlightCluster(cluster);
}
@ -77,8 +94,13 @@ namespace CriticalPathAnalyzer.Client.Tool {
Outliner.RemoveOutline(wireAddress);
}
foreach (ComponentAddress componentAddress in _highlightedComponents) {
Outliner.RemoveOutline(componentAddress);
}
_clusters = null;
_highlightedWires.Clear();
_highlightedComponents.Clear();
}
private static void UnhighlightCluster(ClusterDetails cluster) {

@ -54,27 +54,43 @@ 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> primaryClusters)) {
if (!CollectMainClusters(start, out HashSet<Cluster> collectedClusters)) {
return false; // Whoops, cannot collect the primary clusters, probably probing an output peg.
}
CriticalPathAnalyzerServer.LoggerInstance.Info("collected main clusters");
// Collect clusters that get powered by the original cluster by fast buffers
var collectedDrains = new HashSet<Cluster>();
foreach (Cluster cluster in primaryClusters) {
CollectClusters(cluster, collectedDrains, GetFollowers);
foreach (Cluster cluster in collectedClusters) {
GetLinkedClusters(cluster, collectedDrains, GetFollowers);
}
foreach (Cluster cluster in primaryClusters) {
collectedDrains.Remove(cluster);
collectedClusters.UnionWith(collectedDrains);
CriticalPathAnalyzerServer.LoggerInstance.Info("collected linked clusters");
var perimeterComponents = new HashSet<ComponentAddress>();
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);
}
}
CriticalPathAnalyzerServer.LoggerInstance.Info("collected perimeter components");
// Collect information about each cluster:
response = new AnalyzePathResponse() {
RequestGuid = requestGuid,
Clusters = new List<ClusterDetails>(),
Clusters = collectedClusters.Select(CollectClusterInformation).ToList(),
PerimeterComponents = perimeterComponents.ToList()
};
response.Clusters.AddRange(primaryClusters.Select(CollectClusterInformation));
response.Clusters.AddRange(collectedDrains.Select(CollectClusterInformation));
CriticalPathAnalyzerServer.LoggerInstance.Info("Trace end");
return true;
}
@ -141,7 +157,7 @@ namespace CriticalPathAnalyzer.Server {
return true;
}
private static void CollectClusters(
private static void GetLinkedClusters(
Cluster startingPoint,
HashSet<Cluster> collectedClusters,
Func<ClusterLinker, List<ClusterLinker>> linkedLinkerGetter

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

Loading…
Cancel
Save