From 78c6142689d7d007c195e07b9067e1c725bcd71a Mon Sep 17 00:00:00 2001 From: D4VID Date: Sun, 23 Feb 2025 17:37:58 +0100 Subject: [PATCH] Working correct propagation --- .../client/tool/CriticalPathAnalyzerTool.cs | 2 ++ .../src/server/tool/ClusterNode.cs | 4 +-- .../src/server/tool/ServerPathTracer.cs | 34 +++++++++++++------ .../shared/packets/s2c/AnalyzePathResponse.cs | 6 ++-- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs index da74588..eab78b4 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/CriticalPathAnalyzerTool.cs @@ -95,6 +95,8 @@ namespace CriticalPathAnalyzer.Client.Tool { return; } + _logger.Info($"Critical path length is: {response.CriticalPathLength}"); + PathHighLighter.RemoveHighLighting(); PathHighLighter.HighlightWires(response); } diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs index 92fd8e7..dae59c5 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs @@ -4,9 +4,9 @@ using LogicWorld.Server.Circuitry; namespace CriticalPathAnalyzer.Server.Tool { public class ClusterNode { public int Index; // "identifier" - public List Clusters; // bidirectionally connected clusters without delay + 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 int? PrevNodeIndex; // the last cluster that updated this one + public HashSet PrevNodeIndexes; // the last cluster that updated this one } } \ 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 33b3b0e..04caafb 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs @@ -4,7 +4,6 @@ using System.Linq; using CriticalPathAnalyzer.Shared.Packets.S2C; using EccsLogicWorldAPI.Server; using EccsLogicWorldAPI.Shared.AccessHelper; -using JimmysUnityUtilities; using LogicAPI.Data; using LogicAPI.Server.Components; using LogicAPI.Services; @@ -65,6 +64,9 @@ namespace CriticalPathAnalyzer.Server.Tool { var collectedClusters = new HashSet(); CollectMainClusters(start, collectedClusters); + var endingClusters = new HashSet(); + CollectMainClusters(end, endingClusters); + foreach (Cluster startingCluster in collectedClusters) { // ignore already mapped clusters if (clusterToNodeMapping.ContainsKey(startingCluster)) { @@ -77,9 +79,9 @@ namespace CriticalPathAnalyzer.Server.Tool { int index = clusterNodes.Count; var node = new ClusterNode() { Index = index, - Clusters = new List() {startingCluster}, + Clusters = new HashSet() {startingCluster}, Time = 0, - PrevNodeIndex = null, + PrevNodeIndexes = new HashSet(), NextNodes = new Dictionary(), }; clusterNodes.Add(node); @@ -100,8 +102,6 @@ namespace CriticalPathAnalyzer.Server.Tool { break; } - logger.Warn(">> cluster node iter <<"); - // var perimeterComponents = new HashSet(); var collectedNextClusters = new HashSet(); foreach (Cluster cluster in node.Clusters) { @@ -112,7 +112,6 @@ namespace CriticalPathAnalyzer.Server.Tool { } // perimeterComponents.Add(inputPeg.LogicComponent.Address); - foreach (IOutputPeg outputPeg in inputPeg.LogicComponent.Outputs) { CollectMainClusters(outputPeg.Address, collectedNextClusters); } @@ -122,9 +121,19 @@ namespace CriticalPathAnalyzer.Server.Tool { foreach (Cluster nextCluster in collectedNextClusters) { // ignore already mapped clusters if (clusterToNodeMapping.TryGetValue(nextCluster, out int nextNodeIndex)) { + ClusterNode nextNode = clusterNodes[nextNodeIndex]; // only add the link, don't propagate + if (!nextNode.PrevNodeIndexes.Add(node.Index)) { + logger.Warn("Loop detected"); + // already been here - there is a cycle + continue; + } + + // Replace the time with a later one and continue int timeDelay = 1; - node.NextNodes.Add(nextNodeIndex, 1); + node.NextNodes.TryAdd(nextNodeIndex, 1); + nextNode.Time = node.Time + timeDelay; + queue.Enqueue(nextNode); } else { // var nextClusters = new HashSet(); // var twoWayConnectedClusters = new HashSet(); @@ -133,15 +142,16 @@ namespace CriticalPathAnalyzer.Server.Tool { nextNodeIndex = clusterNodes.Count; var nextNode = new ClusterNode() { Index = nextNodeIndex, - Clusters = new List() {nextCluster}, + Clusters = new HashSet() {nextCluster}, Time = node.Time + timeDelay, - PrevNodeIndex = node.Index, NextNodes = new Dictionary(), + PrevNodeIndexes = new HashSet() {node.Index}, }; - node.NextNodes.Add(nextNodeIndex, timeDelay); clusterNodes.Add(nextNode); + node.NextNodes.TryAdd(nextNodeIndex, timeDelay); + foreach (Cluster nextNodeCluster in nextNode.Clusters) { clusterToNodeMapping.Add(nextNodeCluster, nextNodeIndex); } @@ -156,6 +166,8 @@ namespace CriticalPathAnalyzer.Server.Tool { RequestGuid = requestGuid, Clusters = clusterNodes.SelectMany(node => node.Clusters.Select(cluster => CollectClusterInformation(cluster, node.Time))).ToList(), + CriticalPathLength = clusterNodes[clusterToNodeMapping[endingClusters.First()]].Time, + // PerimeterComponents = perimeterComponents.ToList(), // NextClusters = collectedNextClusters.Select(CollectClusterInformation).ToList(), }; @@ -305,7 +317,7 @@ namespace CriticalPathAnalyzer.Server.Tool { float x = c * (1 - Math.Abs((h / 60.0f) % 2 - 1)); float m = v - c; - float r = 0, g = 0, b = 0; + float r, g, b; if (h < 60) { r = c; diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs index aaf23c7..454cc0b 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs @@ -9,8 +9,10 @@ namespace CriticalPathAnalyzer.Shared.Packets.S2C { public class AnalyzePathResponse : Packet { [Key(0)] public Guid RequestGuid; [Key(1)] public List Clusters; - // [Key(2)] public List PerimeterComponents; - // [Key(3)] public List NextClusters; + + [Key(2)] public int CriticalPathLength; + // [Key(3)] public List PerimeterComponents; + // [Key(4)] public List NextClusters; } [MessagePackObject]