Use temp arrays to help cache some data

This commit is contained in:
Travis Nickles 2017-06-08 14:26:50 -07:00
parent 63dddf4373
commit 1c613139ef
2 changed files with 13 additions and 9 deletions

View File

@ -644,6 +644,8 @@ namespace DS4Windows
public bool[] lag = { false, false, false, false }; public bool[] lag = { false, false, false, false };
public bool[] inWarnMonitor = { 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 // Called every time a new input report has arrived
protected virtual void On_Report(object sender, EventArgs e) protected virtual void On_Report(object sender, EventArgs e)
@ -673,7 +675,7 @@ namespace DS4Windows
int flashWhenLateAt = getFlashWhenLateAt(); int flashWhenLateAt = getFlashWhenLateAt();
if (!lag[ind] && device.Latency >= flashWhenLateAt) 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); LagFlashWarning(ind, true);
}), null); }), null);
@ -682,7 +684,7 @@ namespace DS4Windows
} }
else if (lag[ind] && device.Latency < flashWhenLateAt) 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); LagFlashWarning(ind, false);
}), null); }), null);
@ -706,7 +708,7 @@ namespace DS4Windows
if (!device.firstReport && device.IsAlive()) if (!device.firstReport && device.IsAlive())
{ {
device.firstReport = true; device.firstReport = true;
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state4) device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
{ {
OnDeviceStatusChanged(this, ind); OnDeviceStatusChanged(this, ind);
}), null); }), null);
@ -716,9 +718,11 @@ namespace DS4Windows
} }
else if (pState.Battery != cState.Battery || device.oldCharging != device.isCharging()) 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); }), null);
//OnBatteryStatusChange(this, ind, cState.Battery, device.isCharging()); //OnBatteryStatusChange(this, ind, cState.Battery, device.isCharging());

View File

@ -128,8 +128,8 @@ namespace DS4Windows
// Define here to save some time processing. // Define here to save some time processing.
// It is enough to feel a difference during gameplay. // It is enough to feel a difference during gameplay.
private static int rsOutCurveMode = 0; private static int[] rsOutCurveModeArray = { 0, 0, 0, 0 };
private static int lsOutCurveMode = 0; private static int[] lsOutCurveModeArray = { 0, 0, 0, 0 };
// Special macros // Special macros
static bool altTabDone = true; static bool altTabDone = true;
@ -745,7 +745,7 @@ namespace DS4Windows
if (r2Sens != 1.0) if (r2Sens != 1.0)
dState.R2 = (byte)Global.Clamp(0, r2Sens * dState.R2, 255); dState.R2 = (byte)Global.Clamp(0, r2Sens * dState.R2, 255);
lsOutCurveMode = getLsOutCurveMode(device); int lsOutCurveMode = lsOutCurveModeArray[device] = getLsOutCurveMode(device);
if (lsOutCurveMode != 0) if (lsOutCurveMode != 0)
{ {
double tempX = (dState.LX - 127.5f) / 127.5; 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) if (rsOutCurveMode != 0)
{ {
double tempX = (dState.RX - 127.5f) / 127.5; double tempX = (dState.RX - 127.5f) / 127.5;