Calculate color on the client instead the server

master
D4VID 6 months ago
parent 2d075f6c16
commit 578138fa6c

@ -1,7 +1,7 @@
ID: CriticalPathAnalyzer
Name: CriticalPathAnalyzer
Author: D4VID
Version: 0.0.4
Version: 0.1.0
Priority: 0
Dependencies:
- HarmonyForLogicWorld

@ -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);
}
}
/// <summary>
/// Convert HSB to RGB
/// </summary>
/// <param name="h">0 - 360</param>
/// <param name="s">0.0 - 1.0</param>
/// <param name="v">0.0 - 1.0</param>
/// <returns>0xrrggbb</returns>
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;
}
}
}

@ -399,11 +399,15 @@ namespace CriticalPathAnalyzer.Server.Tool {
}
/// <summary>
/// Obtain additional information about the cluster:
/// Collect all it's pegs and sockets.
/// </summary>
private static ClusterDetails CollectClusterInformation(Cluster cluster, int time) {
var details = new ClusterDetails {
Pegs = new List<PegAddress>(),
ConnectingComponents = new List<ComponentAddress>(),
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;
}
/// <param name="h">0 - 360</param>
/// <param name="s">0.0 - 1.0</param>
/// <param name="v">0.0 - 1.0</param>
/// <returns>0xrrggbb</returns>
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;
}
}
}

@ -27,6 +27,9 @@ namespace CriticalPathAnalyzer.Shared.Packets.S2C {
/// </summary>
[Key(1)] public List<ComponentAddress> ConnectingComponents;
[Key(3)] public int Color;
/// <summary>
/// Delay in ticks after which this cluster gets last updated
/// </summary>
[Key(2)] public int Time;
}
}
Loading…
Cancel
Save