From 1c613139ef164c1a9e1ed1a3b509764b19a6d651 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 8 Jun 2017 14:26:50 -0700 Subject: [PATCH] Use temp arrays to help cache some data --- DS4Windows/DS4Control/ControlService.cs | 14 +++++++++----- DS4Windows/DS4Control/Mapping.cs | 8 ++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 18ac714..7fb9412 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -644,6 +644,8 @@ namespace DS4Windows public bool[] lag = { false, false, false, false }; public bool[] inWarnMonitor = { false, false, false, false }; + private byte[] currentBattery = { 0, 0, 0, 0, 0 }; + private bool[] charging = { false, false, false, false, false }; // Called every time a new input report has arrived protected virtual void On_Report(object sender, EventArgs e) @@ -673,7 +675,7 @@ namespace DS4Windows int flashWhenLateAt = getFlashWhenLateAt(); if (!lag[ind] && device.Latency >= flashWhenLateAt) { - device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state4) + device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) { LagFlashWarning(ind, true); }), null); @@ -682,7 +684,7 @@ namespace DS4Windows } else if (lag[ind] && device.Latency < flashWhenLateAt) { - device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state4) + device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) { LagFlashWarning(ind, false); }), null); @@ -706,7 +708,7 @@ namespace DS4Windows if (!device.firstReport && device.IsAlive()) { device.firstReport = true; - device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state4) + device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) { OnDeviceStatusChanged(this, ind); }), null); @@ -716,9 +718,11 @@ namespace DS4Windows } else if (pState.Battery != cState.Battery || device.oldCharging != device.isCharging()) { - device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state4) + byte tempBattery = currentBattery[ind] = cState.Battery; + bool tempCharging = charging[ind] = device.isCharging(); + device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state) { - OnBatteryStatusChange(this, ind, cState.Battery, device.isCharging()); + OnBatteryStatusChange(this, ind, tempBattery, tempCharging); }), null); //OnBatteryStatusChange(this, ind, cState.Battery, device.isCharging()); diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index c43010d..d088907 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -128,8 +128,8 @@ namespace DS4Windows // Define here to save some time processing. // It is enough to feel a difference during gameplay. - private static int rsOutCurveMode = 0; - private static int lsOutCurveMode = 0; + private static int[] rsOutCurveModeArray = { 0, 0, 0, 0 }; + private static int[] lsOutCurveModeArray = { 0, 0, 0, 0 }; // Special macros static bool altTabDone = true; @@ -745,7 +745,7 @@ namespace DS4Windows if (r2Sens != 1.0) dState.R2 = (byte)Global.Clamp(0, r2Sens * dState.R2, 255); - lsOutCurveMode = getLsOutCurveMode(device); + int lsOutCurveMode = lsOutCurveModeArray[device] = getLsOutCurveMode(device); if (lsOutCurveMode != 0) { double tempX = (dState.LX - 127.5f) / 127.5; @@ -805,7 +805,7 @@ namespace DS4Windows } } - rsOutCurveMode = getRsOutCurveMode(device); + int rsOutCurveMode = rsOutCurveModeArray[device] = getRsOutCurveMode(device); if (rsOutCurveMode != 0) { double tempX = (dState.RX - 127.5f) / 127.5;