From 578138fa6cbb7a63c357e8a277db5afb886e4c6f Mon Sep 17 00:00:00 2001 From: D4VID Date: Sat, 8 Mar 2025 19:49:28 +0100 Subject: [PATCH] Calculate color on the client instead the server --- .../CriticalPathAnalyzer/manifest.jecs | 2 +- .../src/client/tool/PathHighlighter.cs | 54 ++++++++++++++++- .../src/server/tool/ServerPathTracer.cs | 58 ++----------------- .../shared/packets/s2c/AnalyzePathResponse.cs | 5 +- 4 files changed, 64 insertions(+), 55 deletions(-) diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/manifest.jecs b/CriticalPathAnalyzer/CriticalPathAnalyzer/manifest.jecs index 659fc76..1fb9d3d 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/manifest.jecs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/manifest.jecs @@ -1,7 +1,7 @@ ID: CriticalPathAnalyzer Name: CriticalPathAnalyzer Author: D4VID -Version: 0.0.4 +Version: 0.1.0 Priority: 0 Dependencies: - HarmonyForLogicWorld diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighlighter.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighlighter.cs index baa46e1..fa48927 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighlighter.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/client/tool/PathHighlighter.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using CriticalPathAnalyzer.Shared.Packets.S2C; using JimmysUnityUtilities; @@ -25,7 +26,7 @@ namespace CriticalPathAnalyzer.Client.Tool { private static void HighlightCluster(ClusterDetails cluster) { IWorldData world = Instances.MainWorld.Data; - var outline = new OutlineData(new Color24(cluster.Color)); + var outline = new OutlineData(new Color24(HsvToRgb(cluster.Time * 20, 1.0f, 1.0f))); foreach (ComponentAddress address in cluster.ConnectingComponents) { if (!world.Contains(address)) { @@ -88,5 +89,56 @@ namespace CriticalPathAnalyzer.Client.Tool { Outliner.RemoveOutline(address); } } + + /// + /// Convert HSB to RGB + /// + /// 0 - 360 + /// 0.0 - 1.0 + /// 0.0 - 1.0 + /// 0xrrggbb + private static int HsvToRgb(int h, float s, float v) { + s = Math.Clamp(s, 0, 1); + v = Math.Clamp(v, 0, 1); + h = (h % 360 + 360) % 360; // Ensure hue is within 0-359 range + + float c = v * s; + float x = c * (1 - Math.Abs((h / 60.0f) % 2 - 1)); + float m = v - c; + + float r, g, b; + + if (h < 60) { + r = c; + g = x; + b = 0; + } else if (h < 120) { + r = x; + g = c; + b = 0; + } else if (h < 180) { + r = 0; + g = c; + b = x; + } else if (h < 240) { + r = 0; + g = x; + b = c; + } else if (h < 300) { + r = x; + g = 0; + b = c; + } else { + r = c; + g = 0; + b = x; + } + + int rInt = (byte) ((r + m) * 255); + int gInt = (byte) ((g + m) * 255); + int bInt = (byte) ((b + m) * 255); + + return (rInt << 16) | (gInt << 8) | bInt; + } } } \ 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 b315556..9df8c03 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs @@ -399,11 +399,15 @@ namespace CriticalPathAnalyzer.Server.Tool { } + /// + /// Obtain additional information about the cluster: + /// Collect all it's pegs and sockets. + /// private static ClusterDetails CollectClusterInformation(Cluster cluster, int time) { var details = new ClusterDetails { Pegs = new List(), ConnectingComponents = new List(), - Color = HsvToRgb(time * 20, 1, 1), + Time = time, }; // Two lists are never null, according to how it is created and used: @@ -418,59 +422,9 @@ namespace CriticalPathAnalyzer.Server.Tool { } } - foreach (OutputPeg peg in outputPegs) { - details.Pegs.Add(peg.Address); - } + details.Pegs.AddRange(outputPegs.Select(peg => peg.Address)); return details; } - - /// 0 - 360 - /// 0.0 - 1.0 - /// 0.0 - 1.0 - /// 0xrrggbb - private static int HsvToRgb(int h, float s, float v) { - s = Math.Clamp(s, 0, 1); - v = Math.Clamp(v, 0, 1); - h = (h % 360 + 360) % 360; // Ensure hue is within 0-359 range - - float c = v * s; - float x = c * (1 - Math.Abs((h / 60.0f) % 2 - 1)); - float m = v - c; - - float r, g, b; - - if (h < 60) { - r = c; - g = x; - b = 0; - } else if (h < 120) { - r = x; - g = c; - b = 0; - } else if (h < 180) { - r = 0; - g = c; - b = x; - } else if (h < 240) { - r = 0; - g = x; - b = c; - } else if (h < 300) { - r = x; - g = 0; - b = c; - } else { - r = c; - g = 0; - b = x; - } - - int rInt = (byte) ((r + m) * 255); - int gInt = (byte) ((g + m) * 255); - int bInt = (byte) ((b + m) * 255); - - return (rInt << 16) | (gInt << 8) | bInt; - } } } \ 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 a9f8b24..c3132ac 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/shared/packets/s2c/AnalyzePathResponse.cs @@ -27,6 +27,9 @@ namespace CriticalPathAnalyzer.Shared.Packets.S2C { /// [Key(1)] public List ConnectingComponents; - [Key(3)] public int Color; + /// + /// Delay in ticks after which this cluster gets last updated + /// + [Key(2)] public int Time; } } \ No newline at end of file