diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/manifest.jecs b/CriticalPathAnalyzer/CriticalPathAnalyzer/manifest.jecs index 1fb9d3d..fda759a 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/manifest.jecs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/manifest.jecs @@ -1,7 +1,7 @@ ID: CriticalPathAnalyzer Name: CriticalPathAnalyzer Author: D4VID -Version: 0.1.0 +Version: 0.2.0 Priority: 0 Dependencies: - HarmonyForLogicWorld diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs index 73ce9f0..d382861 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs @@ -130,11 +130,11 @@ namespace CriticalPathAnalyzer.Client.Tool { PathHighlighter.RemoveHighlighting(); - if (_response.LoopingClusters.Count > 0) { - PathHighlighter.HighlightWires(_response.LoopingClusters); + if (_response.LoopingNodes.Count > 0) { + PathHighlighter.HighlightClusterNodes(_response.LoopingNodes); } else { _logger.Info($"Critical path length is: {_response.CriticalPathLength}"); - PathHighlighter.HighlightWires(_response.Clusters); + PathHighlighter.HighlightClusterNodes(_response.Nodes); } } } diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighlighter.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighlighter.cs index fa48927..2785db2 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighlighter.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighlighter.cs @@ -9,26 +9,26 @@ using LogicWorld.Outlines; namespace CriticalPathAnalyzer.Client.Tool { public class PathHighlighter { - private static List _clusters = new List(); + private static List _nodes = new List(); private static List _highlightedWires = new List(); - public static void HighlightWires(List clusters) { - _clusters = clusters; + public static void HighlightClusterNodes(List nodes) { + _nodes = nodes; - foreach (ClusterDetails clusterDetails in _clusters) { - HighlightCluster(clusterDetails); + foreach (Node node in _nodes) { + HighlightNode(node); } } /// /// Highlight all pegs and wires of the given cluster. /// - private static void HighlightCluster(ClusterDetails cluster) { + private static void HighlightNode(Node node) { IWorldData world = Instances.MainWorld.Data; - var outline = new OutlineData(new Color24(HsvToRgb(cluster.Time * 20, 1.0f, 1.0f))); + var outline = new OutlineData(new Color24(HsvToRgb(node.Time * 20, 1.0f, 1.0f))); - foreach (ComponentAddress address in cluster.ConnectingComponents) { + foreach (ComponentAddress address in node.ConnectingComponents) { if (!world.Contains(address)) { continue; } @@ -36,7 +36,7 @@ namespace CriticalPathAnalyzer.Client.Tool { Outliner.Outline(address, outline); } - foreach (PegAddress pegAddress in cluster.Pegs) { + foreach (PegAddress pegAddress in node.Pegs) { if (!world.Contains(pegAddress.ComponentAddress)) { continue; } @@ -64,28 +64,28 @@ namespace CriticalPathAnalyzer.Client.Tool { } public static void RemoveHighlighting() { - if (_clusters == null) { + if (_nodes == null) { return; } - foreach (ClusterDetails cluster in _clusters) { - UnhighlightCluster(cluster); + foreach (Node cluster in _nodes) { + UnhighlightNode(cluster); } foreach (WireAddress wireAddress in _highlightedWires) { Outliner.RemoveOutline(wireAddress); } - _clusters = null; + _nodes = null; _highlightedWires.Clear(); } - private static void UnhighlightCluster(ClusterDetails cluster) { - foreach (PegAddress address in cluster.Pegs) { + private static void UnhighlightNode(Node node) { + foreach (PegAddress address in node.Pegs) { Outliner.RemoveOutline(address); } - foreach (ComponentAddress address in cluster.ConnectingComponents) { + foreach (ComponentAddress address in node.ConnectingComponents) { Outliner.RemoveOutline(address); } } diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs index 5cececc..fb0cacb 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs @@ -3,10 +3,29 @@ using LogicWorld.Server.Circuitry; namespace CriticalPathAnalyzer.Server.Tool { public class ClusterNode { - public int Index; // "identifier" - public HashSet Clusters; // bidirectionally connected clusters without delay - public int Time; // what point in time has been this cluster last updated - public Dictionary NextNodes; // next node index / delay between them - public HashSet PrevNodeIndexes; // node indexes that update this one + /// + /// Identifier + /// + public int Index; + + /// + /// All bidirectionally connected clusters without delay that form this node + /// + public HashSet Clusters; + + /// + /// Next node index / delay between them + /// + public Dictionary NextNodes; + + /// + /// Node indexes that update this one + /// + public HashSet PrevNodeIndexes; + + /// + /// After how many ticks has been this cluster last updated + /// + public int Time; } } \ No newline at end of file diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs index 9df8c03..1b0da26 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs @@ -109,14 +109,16 @@ namespace CriticalPathAnalyzer.Server.Tool { } } + foreach (ClusterNode node in clusterNodes) { + FillNodeInformation(node); + } + // Collect information about each cluster: response = new AnalyzePathResponse() { RequestGuid = requestGuid, - Clusters = clusterNodes.SelectMany(node => - node.Clusters.Select(cluster => CollectClusterInformation(cluster, node.Time))).ToList(), + Nodes = clusterNodes.Select(FillNodeInformation).ToList(), CriticalPathLength = criticalPathLength, - LoopingClusters = loopingNodes.SelectMany(loopingNode => loopingNode.Clusters - .Select(cluster => CollectClusterInformation(cluster, 0))).ToList(), + LoopingNodes = loopingNodes.Select(FillNodeInformation).ToList(), }; logger.Info("Trace end"); @@ -400,31 +402,36 @@ namespace CriticalPathAnalyzer.Server.Tool { /// - /// Obtain additional information about the cluster: - /// Collect all it's pegs and sockets. + /// Obtain additional information about the clusters: + /// Collect all their pegs and sockets. /// - private static ClusterDetails CollectClusterInformation(Cluster cluster, int time) { - var details = new ClusterDetails { + private static Node FillNodeInformation(ClusterNode node) { + var clientNode = new Node() { + Index = node.Index, + NextNodes = node.NextNodes, + PrevNodeIndexes = node.PrevNodeIndexes, + Time = node.Time, Pegs = new List(), ConnectingComponents = new List(), - Time = time, }; - // Two lists are never null, according to how it is created and used: - IReadOnlyList inputPegs = cluster.ConnectedInputs; - IReadOnlyList outputPegs = cluster.ConnectedOutputs; + foreach (Cluster cluster in node.Clusters) { + // Two lists are never null, according to how it is created and used: + IReadOnlyList inputPegs = cluster.ConnectedInputs; + IReadOnlyList outputPegs = cluster.ConnectedOutputs; - foreach (InputPeg peg in inputPegs) { - details.Pegs.Add(peg.Address); - if (peg.SecretLinks != null && peg.SecretLinks.Any()) { - // Socket - details.ConnectingComponents.Add(peg.Address.ComponentAddress); + foreach (InputPeg peg in inputPegs) { + clientNode.Pegs.Add(peg.Address); + if (peg.SecretLinks != null && peg.SecretLinks.Any()) { + // Socket + clientNode.ConnectingComponents.Add(peg.Address.ComponentAddress); + } } - } - details.Pegs.AddRange(outputPegs.Select(peg => peg.Address)); + clientNode.Pegs.AddRange(outputPegs.Select(peg => peg.Address)); + } - return details; + return clientNode; } } } \ No newline at end of file diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs index c3132ac..027c39a 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs @@ -8,28 +8,42 @@ namespace CriticalPathAnalyzer.Shared.Packets.S2C { [MessagePackObject] public class AnalyzePathResponse : Packet { [Key(0)] public Guid RequestGuid; - [Key(1)] public List Clusters; - + [Key(1)] public List Nodes; [Key(2)] public int CriticalPathLength; - - [Key(3)] public List LoopingClusters; + [Key(3)] public List LoopingNodes; } [MessagePackObject] - public sealed class ClusterDetails { + public sealed class Node { /// - /// List of all pegs inside the cluster + /// Identifier /// - [Key(0)] public List Pegs; + [Key(0)] public int Index; /// - /// Sockets + /// Next node index / delay between them /// - [Key(1)] public List ConnectingComponents; + [Key(1)] public Dictionary NextNodes; /// - /// Delay in ticks after which this cluster gets last updated + /// Node indexes that update this one + /// + [Key(2)] public HashSet PrevNodeIndexes; + + /// + /// After how many ticks has been this cluster last updated + /// + [Key(3)] public int Time; + + /// + /// List of all pegs inside the cluster + /// + [Key(4)] public List Pegs; + + /// + /// Sockets /// - [Key(2)] public int Time; + [Key(5)] public List ConnectingComponents; } + } \ No newline at end of file