Hightlight connected and draining clusters

master
D4VID 7 months ago
parent a64e1bb2b2
commit a176609c27

@ -14,7 +14,7 @@ namespace CriticalPathAnalyzer.Client.Tool {
private static List<WireAddress> _highlightedWires = new List<WireAddress>();
public static void HighlightWires(AnalyzePathResponse response) {
_clusters = response.SelectedClusters;
_clusters = response.Clusters;
IWorldData world = Instances.MainWorld.Data;
@ -38,7 +38,6 @@ namespace CriticalPathAnalyzer.Client.Tool {
foreach (PegAddress pegAddress in clusterDetails.Pegs) {
if (!world.Contains(pegAddress.ComponentAddress)) {
CriticalPathAnalyzerClient.LoggerInstance.Warn("Peg's component doesn't exist in world");
continue;
}

@ -13,7 +13,6 @@ namespace CriticalPathAnalyzer.Server {
// Reflection/Delegate access helpers:
private static readonly Func<InputPeg, Cluster> GetCluster;
private static readonly Func<Cluster, ClusterLinker> GetLinker;
private static readonly Func<ClusterLinker, List<ClusterLinker>> GetLeaders;
private static readonly Func<ClusterLinker, List<ClusterLinker>> GetFollowers;
@ -28,9 +27,6 @@ namespace CriticalPathAnalyzer.Server {
GetLinker = Delegator.createFieldGetter<Cluster, ClusterLinker>(
Fields.getPrivate(typeof(Cluster), "Linker")
);
GetLeaders = Delegator.createFieldGetter<ClusterLinker, List<ClusterLinker>>(
Fields.getPrivate(typeof(ClusterLinker), "LinkedLeaders")
);
GetFollowers = Delegator.createFieldGetter<ClusterLinker, List<ClusterLinker>>(
Fields.getPrivate(typeof(ClusterLinker), "LinkedFollowers")
);
@ -62,55 +58,23 @@ namespace CriticalPathAnalyzer.Server {
return false; // Whoops, cannot collect the primary clusters, probably probing an output peg.
}
// Collect clusters that get powered by the original cluster or will power it.
var collectedSources = new HashSet<Cluster>();
// Collect clusters that get powered by the original cluster by fast buffers
var collectedDrains = new HashSet<Cluster>();
foreach (Cluster cluster in primaryClusters) {
CollectClusters(cluster, collectedSources, GetLeaders);
CollectClusters(cluster, collectedDrains, GetFollowers);
}
foreach (Cluster cluster in primaryClusters) {
collectedSources.Remove(cluster);
collectedDrains.Remove(cluster);
}
// Collect and filter clusters that are both source and drain:
var collectedEquals = new HashSet<Cluster>();
foreach (Cluster collectedSource in collectedSources) {
if (collectedDrains.Remove(collectedSource)) {
collectedEquals.Add(collectedSource);
}
}
foreach (Cluster collectedEqual in collectedEquals) {
collectedSources.Remove(collectedEqual);
}
//Collect information about each cluster:
response = new AnalyzePathResponse() {
RequestGuid = requestGuid,
SelectedClusters = new List<ClusterDetails>(),
Clusters = new List<ClusterDetails>(),
};
foreach (Cluster cluster in primaryClusters) {
response.SelectedClusters.Add(CollectClusterInformation(cluster));
}
// response.sourcingClusters = new List<ClusterDetails>();
// foreach (var cluster in collectedSources) {
// response.sourcingClusters.Add(CollectClusterInformation(cluster));
// }
//
// response.connectedClusters = new List<ClusterDetails>();
// foreach (var cluster in collectedEquals) {
// response.connectedClusters.Add(CollectClusterInformation(cluster));
// }
//
// response.drainingClusters = new List<ClusterDetails>();
// foreach (var cluster in collectedDrains) {
// response.drainingClusters.Add(CollectClusterInformation(cluster));
// }
response.Clusters.AddRange(primaryClusters.Select(CollectClusterInformation));
response.Clusters.AddRange(collectedDrains.Select(CollectClusterInformation));
return true;
}
@ -189,7 +153,7 @@ namespace CriticalPathAnalyzer.Server {
clustersToProcess.Enqueue(startingLinker);
// While the starting cluster is no source, the algorithm needs to skip it when encountered.
collectedClusters.Add(startingPoint);
// collectedClusters.Add(startingPoint);
while (clustersToProcess.TryDequeue(out ClusterLinker linkerToCheck)) {
List<ClusterLinker> listOfLinkedLinkers = linkedLinkerGetter(linkerToCheck); // Is never null.
foreach (ClusterLinker linkedLinker in listOfLinkedLinkers) {
@ -216,7 +180,7 @@ namespace CriticalPathAnalyzer.Server {
foreach (InputPeg peg in inputPegs) {
details.Pegs.Add(peg.Address);
if (peg.SecretLinks != null && peg.SecretLinks.Any()) {
// Highlight this component somehow.
// Socket
details.ConnectingComponents.Add(peg.Address.ComponentAddress);
}
@ -224,6 +188,7 @@ namespace CriticalPathAnalyzer.Server {
|| (peg.OneWayPhasicLinksFollowers != null && peg.OneWayPhasicLinksFollowers.Any())
|| (peg.OneWayPhasicLinksLeaders != null && peg.OneWayPhasicLinksLeaders.Any())
) {
// Relay / fast buffer
details.LinkingComponents.Add(peg.Address.ComponentAddress);
}
}

@ -8,18 +8,13 @@ namespace CriticalPathAnalyzer.Shared.Packets.S2C {
[MessagePackObject]
public class AnalyzePathResponse : Packet {
[Key(0)] public Guid RequestGuid;
[Key(1)]
public List<ClusterDetails> SelectedClusters;
[Key(1)] public List<ClusterDetails> Clusters;
}
[MessagePackObject]
public sealed class ClusterDetails
{
[Key(0)]
public List<PegAddress> Pegs;
[Key(1)]
public List<ComponentAddress> ConnectingComponents;
[Key(2)]
public List<ComponentAddress> LinkingComponents;
public sealed class ClusterDetails {
[Key(0)] public List<PegAddress> Pegs;
[Key(1)] public List<ComponentAddress> ConnectingComponents;
[Key(2)] public List<ComponentAddress> LinkingComponents;
}
}
Loading…
Cancel
Save