Minor optimizations

This commit is contained in:
Travis Nickles 2017-04-12 13:54:38 -07:00
parent 65e7add5b3
commit af3c1c8531
2 changed files with 14 additions and 4 deletions

View File

@ -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<UInt16, SyntheticState.KeyPresses> kvp in state.keyPresses)
{
SyntheticState.KeyPresses gkp;
@ -1317,11 +1319,14 @@ namespace DS4Windows
int actionDoneCount = actionDone.Count;
int totalActionCount = GetActions().Count;
List<string> 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;

View File

@ -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