From af3c1c8531a246cc332ad0aa66372bb9b2375c2a Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Wed, 12 Apr 2017 13:54:38 -0700 Subject: [PATCH] Minor optimizations --- DS4Windows/DS4Control/Mapping.cs | 11 +++++++++-- DS4Windows/DS4Control/X360Device.cs | 7 +++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index 4215732..6d1b6cc 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -38,6 +38,7 @@ namespace DS4Windows previousClicks = currentClicks; if (performClear) currentClicks.leftCount = currentClicks.middleCount = currentClicks.rightCount = currentClicks.fourthCount = currentClicks.fifthCount = currentClicks.wUpCount = currentClicks.wDownCount = currentClicks.toggleCount = 0; + /* TODO: Change foreach loop to for loop when I can test the performance difference */ foreach (KeyPresses kp in keyPresses.Values) { kp.previous = kp.current; @@ -234,6 +235,7 @@ namespace DS4Windows // Merge and synthesize all key presses/releases that are present in this device's mapping. // TODO what about the rest? e.g. repeat keys really ought to be on some set schedule + /* TODO: Change foreach loop to for loop when I can test the performance difference */ foreach (KeyValuePair kvp in state.keyPresses) { SyntheticState.KeyPresses gkp; @@ -1317,11 +1319,14 @@ namespace DS4Windows int actionDoneCount = actionDone.Count; int totalActionCount = GetActions().Count; List profileActions = getProfileActions(device); - foreach (string actionname in profileActions) + //foreach (string actionname in profileActions) + for (int actionIndex = 0, profileListLen = profileActions.Count; + actionIndex < profileListLen; actionIndex++) { //DS4KeyType keyType = getShiftCustomKeyType(device, customKey.Key); //SpecialAction action = GetAction(actionname); //int index = GetActionIndexOf(actionname); + string actionname = profileActions[actionIndex]; SpecialAction action = GetProfileAction(device, actionname); int index = GetProfileActionIndexOf(device, actionname); @@ -1772,8 +1777,10 @@ namespace DS4Windows SpecialAction action = untriggeraction[device]; int index = untriggerindex[device]; bool utriggeractivated = true; - foreach (DS4Controls dc in action.uTrigger) + //foreach (DS4Controls dc in action.uTrigger) + for (int i = 0, uTrigLen = action.uTrigger.Count; i < uTrigLen; i++) { + DS4Controls dc = action.uTrigger[i]; if (!getBoolMapping(device, dc, cState, eState, tp)) { utriggeractivated = false; diff --git a/DS4Windows/DS4Control/X360Device.cs b/DS4Windows/DS4Control/X360Device.cs index aca2414..372c755 100644 --- a/DS4Windows/DS4Control/X360Device.cs +++ b/DS4Windows/DS4Control/X360Device.cs @@ -13,6 +13,7 @@ namespace DS4Windows private const String DS3_BUS_CLASS_GUID = "{F679F562-3164-42CE-A4DB-E7DDBE723909}"; private const int CONTROLLER_OFFSET = 1; // Device 0 is the virtual USB hub itself, and we leave devices 1-10 available for other software (like the Scarlet.Crush DualShock driver itself) private const int inputResolution = 127 - (-128); + private const float reciprocalInputResolution = 1 / (float)inputResolution; private const int outputResolution = 32767 - (-32768); private int firstController = 1; @@ -27,7 +28,8 @@ namespace DS4Windows { Value -= 0x80; - float temp = (Value - (-128)) / (float)inputResolution; + //float temp = (Value - (-128)) / (float)inputResolution; + float temp = (Value - (-128)) * reciprocalInputResolution; if (Flip) temp = (temp - 0.5f) * -1.0f + 0.5f; return (Int32)(temp * outputResolution + (-32768)); @@ -107,10 +109,11 @@ namespace DS4Windows Output[4] = (Byte)(device + firstController); Output[9] = 0x14; - for (int i = 10; i < Output.Length; i++) + for (int i = 10, outLen = Output.Length; i < outLen; i++) { Output[i] = 0; } + if (state.Share) Output[10] |= (Byte)(1 << 5); // Back if (state.L3) Output[10] |= (Byte)(1 << 6); // Left Thumb if (state.R3) Output[10] |= (Byte)(1 << 7); // Right Thumb