From ce0ac67dcd7703edca9d4c04d2a2466fc7e81431 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Mon, 11 Feb 2019 23:51:26 -0600 Subject: [PATCH] Remove some struct copying from lightbar routine --- DS4Windows/DS4Control/DS4LightBar.cs | 36 +++++++++++++++++++++------- DS4Windows/DS4Control/Mapping.cs | 4 ++-- DS4Windows/DS4Control/ScpUtil.cs | 17 +++++++------ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/DS4Windows/DS4Control/DS4LightBar.cs b/DS4Windows/DS4Control/DS4LightBar.cs index 0a146c6..c81baf4 100644 --- a/DS4Windows/DS4Control/DS4LightBar.cs +++ b/DS4Windows/DS4Control/DS4LightBar.cs @@ -49,7 +49,7 @@ namespace DS4Windows { DS4Color fullColor = getCustomColor(deviceNum); DS4Color lowColor = getLowColor(deviceNum); - color = getTransitionedColor(lowColor, fullColor, device.getBattery()); + color = getTransitionedColor(ref lowColor, ref fullColor, device.getBattery()); } else color = getCustomColor(deviceNum); @@ -85,7 +85,7 @@ namespace DS4Windows { DS4Color fullColor = getMainColor(deviceNum); DS4Color lowColor = getLowColor(deviceNum); - color = getTransitionedColor(lowColor, fullColor, device.getBattery()); + color = getTransitionedColor(ref lowColor, ref fullColor, device.getBattery()); } else { @@ -144,7 +144,8 @@ namespace DS4Windows } } - color = getTransitionedColor(color, new DS4Color(0, 0, 0), ratio); + DS4Color tempCol = new DS4Color(0, 0, 0); + color = getTransitionedColor(ref color, ref tempCol, ratio); } } @@ -159,11 +160,16 @@ namespace DS4Windows double ratio = 100.0 * (botratio / topratio), elapsed = ratio; if (ratio >= 50.0 && ratio < 100.0) { - color = getTransitionedColor(color, new DS4Color(0, 0, 0), + DS4Color emptyCol = new DS4Color(0, 0, 0); + color = getTransitionedColor(ref color, ref emptyCol, (uint)(-100.0 * (elapsed = 0.02 * (ratio - 50.0)) * (elapsed - 2.0))); } else if (ratio >= 100.0) - color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100.0); + { + DS4Color emptyCol = new DS4Color(0, 0, 0); + color = getTransitionedColor(ref color, ref emptyCol, 100.0); + } + } if (device.isCharging() && device.getBattery() < 100) @@ -217,7 +223,8 @@ namespace DS4Windows } } - color = getTransitionedColor(color, new DS4Color(0, 0, 0), ratio); + DS4Color emptyCol = new DS4Color(0, 0, 0); + color = getTransitionedColor(ref color, ref emptyCol, ratio); break; } case 2: @@ -257,9 +264,22 @@ namespace DS4Windows float rumble = device.getLeftHeavySlowRumble() / 2.55f; byte max = Max(color.red, Max(color.green, color.blue)); if (device.getLeftHeavySlowRumble() > 100) - color = getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), rumble); + { + DS4Color maxCol = new DS4Color(max, max, 0); + DS4Color redCol = new DS4Color(255, 0, 0); + color = getTransitionedColor(ref maxCol, ref redCol, rumble); + } + else - color = getTransitionedColor(color, getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), 39.6078f), device.getLeftHeavySlowRumble()); + { + DS4Color maxCol = new DS4Color(max, max, 0); + DS4Color redCol = new DS4Color(255, 0, 0); + DS4Color tempCol = getTransitionedColor(ref maxCol, + ref redCol, 39.6078f); + color = getTransitionedColor(ref color, ref tempCol, + device.getLeftHeavySlowRumble()); + } + } DS4HapticState haptics = new DS4HapticState diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index 29a0bcd..391456d 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -1885,9 +1885,9 @@ namespace DS4Windows } DS4Color empty = new DS4Color(byte.Parse(dets[3]), byte.Parse(dets[4]), byte.Parse(dets[5])); DS4Color full = new DS4Color(byte.Parse(dets[6]), byte.Parse(dets[7]), byte.Parse(dets[8])); - DS4Color trans = getTransitionedColor(empty, full, d.Battery); + DS4Color trans = getTransitionedColor(ref empty, ref full, d.Battery); if (fadetimer[device] < 100) - DS4LightBar.forcedColor[device] = getTransitionedColor(lastColor[device], trans, fadetimer[device] += 2); + DS4LightBar.forcedColor[device] = getTransitionedColor(ref lastColor[device], ref trans, fadetimer[device] += 2); } actionDone[index].dev[device] = true; } diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 4e2ee7a..9e707bc 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -1319,17 +1319,20 @@ namespace DS4Windows else if (r < 0.0) r = 0.0; - r /= 100.0; - return (byte)Math.Round((b1 * (1 - r) + b2 * r), 0); + r *= 0.01; + return (byte)Math.Round((b1 * (1 - r)) + b2 * r, 0); } - public static DS4Color getTransitionedColor(DS4Color c1, DS4Color c2, double ratio) + public static DS4Color getTransitionedColor(ref DS4Color c1, ref DS4Color c2, double ratio) { //Color cs = Color.FromArgb(c1.red, c1.green, c1.blue); - c1.red = applyRatio(c1.red, c2.red, ratio); - c1.green = applyRatio(c1.green, c2.green, ratio); - c1.blue = applyRatio(c1.blue, c2.blue, ratio); - return c1; + DS4Color cs = new DS4Color + { + red = applyRatio(c1.red, c2.red, ratio), + green = applyRatio(c1.green, c2.green, ratio), + blue = applyRatio(c1.blue, c2.blue, ratio) + }; + return cs; } private static Color applyRatio(Color c1, Color c2, uint r)