Some optimizations. Use reverse mapping array. Skip xinput report in dinput mode.

This commit is contained in:
Travis Nickles 2017-05-04 08:42:27 -07:00
parent 3f190bb4bb
commit be27af50d3
3 changed files with 72 additions and 70 deletions

View File

@ -649,17 +649,20 @@ namespace DS4Windows
// Update the GUI/whatever. // Update the GUI/whatever.
DS4LightBar.updateLightBar(device, ind, cState, ExposedState[ind], touchPad[ind]); DS4LightBar.updateLightBar(device, ind, cState, ExposedState[ind], touchPad[ind]);
x360Bus.Parse(cState, processingData[ind].Report, ind); if (!getDInputOnly(ind))
// We push the translated Xinput state, and simultaneously we
// pull back any possible rumble data coming from Xinput consumers.
if (x360Bus.Report(processingData[ind].Report, processingData[ind].Rumble))
{ {
Byte Big = (Byte)(processingData[ind].Rumble[3]); x360Bus.Parse(cState, processingData[ind].Report, ind);
Byte Small = (Byte)(processingData[ind].Rumble[4]); // We push the translated Xinput state, and simultaneously we
// pull back any possible rumble data coming from Xinput consumers.
if (processingData[ind].Rumble[1] == 0x08) if (x360Bus.Report(processingData[ind].Report, processingData[ind].Rumble))
{ {
setRumble(Big, Small, ind); Byte Big = (Byte)(processingData[ind].Rumble[3]);
Byte Small = (Byte)(processingData[ind].Rumble[4]);
if (processingData[ind].Rumble[1] == 0x08)
{
setRumble(Big, Small, ind);
}
} }
} }

View File

@ -846,7 +846,8 @@ namespace DS4Windows
} }
else if (actionType == DS4ControlSettings.ActionType.Key) else if (actionType == DS4ControlSettings.ActionType.Key)
{ {
ushort value = ushort.Parse(action.ToString()); //ushort value = ushort.Parse(action.ToString());
ushort value = Convert.ToUInt16(action);
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
{ {
resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping); resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping);
@ -901,99 +902,80 @@ namespace DS4Windows
xboxControl = getX360ControlsByName(action.ToString()); xboxControl = getX360ControlsByName(action.ToString());
} }
if (xboxControl >= X360Controls.X && xboxControl <= X360Controls.A) if (xboxControl >= X360Controls.LXNeg && xboxControl <= X360Controls.Start)
{ {
switch (xboxControl) DS4Controls tempDS4Control = reverseX360ButtonMapping[(int)xboxControl];
{ tempControlDict.Add(dcs.control, tempDS4Control);
case X360Controls.A: tempControlDict.Add(dcs.control, DS4Controls.Cross); break;
case X360Controls.B: tempControlDict.Add(dcs.control, DS4Controls.Circle); break;
case X360Controls.X: tempControlDict.Add(dcs.control, DS4Controls.Square); break;
case X360Controls.Y: tempControlDict.Add(dcs.control, DS4Controls.Triangle); break;
default: break;
}
}
else if (xboxControl >= X360Controls.LB && xboxControl <= X360Controls.RS)
{
switch (xboxControl)
{
case X360Controls.LB: tempControlDict.Add(dcs.control, DS4Controls.L1); break;
case X360Controls.LT: tempControlDict.Add(dcs.control, DS4Controls.L2); break;
case X360Controls.LS: tempControlDict.Add(dcs.control, DS4Controls.L3); break;
case X360Controls.RB: tempControlDict.Add(dcs.control, DS4Controls.R1); break;
case X360Controls.RT: tempControlDict.Add(dcs.control, DS4Controls.R2); break;
case X360Controls.RS: tempControlDict.Add(dcs.control, DS4Controls.R3); break;
default: break;
}
}
else if (xboxControl >= X360Controls.DpadUp && xboxControl <= X360Controls.DpadLeft)
{
switch (xboxControl)
{
case X360Controls.DpadUp: tempControlDict.Add(dcs.control, DS4Controls.DpadUp); break;
case X360Controls.DpadDown: tempControlDict.Add(dcs.control, DS4Controls.DpadDown); break;
case X360Controls.DpadLeft: tempControlDict.Add(dcs.control, DS4Controls.DpadLeft); break;
case X360Controls.DpadRight: tempControlDict.Add(dcs.control, DS4Controls.DpadRight); break;
default: break;
}
}
else if (xboxControl >= X360Controls.LXNeg && xboxControl <= X360Controls.RYPos)
{
switch (xboxControl)
{
case X360Controls.LXNeg: tempControlDict.Add(dcs.control, DS4Controls.LXNeg); break;
case X360Controls.LYNeg: tempControlDict.Add(dcs.control, DS4Controls.LYNeg); break;
case X360Controls.RXNeg: tempControlDict.Add(dcs.control, DS4Controls.RXNeg); break;
case X360Controls.RYNeg: tempControlDict.Add(dcs.control, DS4Controls.RYNeg); break;
case X360Controls.LXPos: tempControlDict.Add(dcs.control, DS4Controls.LXPos); break;
case X360Controls.LYPos: tempControlDict.Add(dcs.control, DS4Controls.LYPos); break;
case X360Controls.RXPos: tempControlDict.Add(dcs.control, DS4Controls.RXPos); break;
case X360Controls.RYPos: tempControlDict.Add(dcs.control, DS4Controls.RYPos); break;
default: break;
}
} }
else if (xboxControl >= X360Controls.LeftMouse && xboxControl <= X360Controls.WDOWN) else if (xboxControl >= X360Controls.LeftMouse && xboxControl <= X360Controls.WDOWN)
{ {
switch (xboxControl) switch (xboxControl)
{ {
case X360Controls.LeftMouse: case X360Controls.LeftMouse:
{
keyvalue = 256; keyvalue = 256;
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
deviceState.currentClicks.leftCount++; deviceState.currentClicks.leftCount++;
break; break;
}
case X360Controls.RightMouse: case X360Controls.RightMouse:
{
keyvalue = 257; keyvalue = 257;
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
deviceState.currentClicks.rightCount++; deviceState.currentClicks.rightCount++;
break; break;
}
case X360Controls.MiddleMouse: case X360Controls.MiddleMouse:
{
keyvalue = 258; keyvalue = 258;
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
deviceState.currentClicks.middleCount++; deviceState.currentClicks.middleCount++;
break; break;
}
case X360Controls.FourthMouse: case X360Controls.FourthMouse:
{
keyvalue = 259; keyvalue = 259;
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
deviceState.currentClicks.fourthCount++; deviceState.currentClicks.fourthCount++;
break; break;
}
case X360Controls.FifthMouse: case X360Controls.FifthMouse:
{
keyvalue = 260; keyvalue = 260;
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
deviceState.currentClicks.fifthCount++; deviceState.currentClicks.fifthCount++;
break; break;
}
case X360Controls.WUP: case X360Controls.WUP:
{
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
{
if (isAnalog) if (isAnalog)
getMouseWheelMapping(device, dcs.control, cState, eState, tp, false); getMouseWheelMapping(device, dcs.control, cState, eState, tp, false);
else else
deviceState.currentClicks.wUpCount++; deviceState.currentClicks.wUpCount++;
}
break; break;
}
case X360Controls.WDOWN: case X360Controls.WDOWN:
{
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
{
if (isAnalog) if (isAnalog)
getMouseWheelMapping(device, dcs.control, cState, eState, tp, true); getMouseWheelMapping(device, dcs.control, cState, eState, tp, true);
else else
deviceState.currentClicks.wDownCount++; deviceState.currentClicks.wDownCount++;
}
break; break;
}
default: break; default: break;
} }
} }
@ -1002,44 +984,46 @@ namespace DS4Windows
switch (xboxControl) switch (xboxControl)
{ {
case X360Controls.MouseUp: case X360Controls.MouseUp:
{
if (tempMouseDeltaY == 0) if (tempMouseDeltaY == 0)
{ {
tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 0); tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 0);
tempMouseDeltaY = -Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY)); tempMouseDeltaY = -Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY));
} }
break; break;
}
case X360Controls.MouseDown: case X360Controls.MouseDown:
{
if (tempMouseDeltaY == 0) if (tempMouseDeltaY == 0)
{ {
tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 1); tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 1);
tempMouseDeltaY = Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY)); tempMouseDeltaY = Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY));
} }
break; break;
}
case X360Controls.MouseLeft: case X360Controls.MouseLeft:
{
if (tempMouseDeltaX == 0) if (tempMouseDeltaX == 0)
{ {
tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 2); tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 2);
tempMouseDeltaX = -Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX)); tempMouseDeltaX = -Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX));
} }
break; break;
}
case X360Controls.MouseRight: case X360Controls.MouseRight:
{
if (tempMouseDeltaX == 0) if (tempMouseDeltaX == 0)
{ {
tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 3); tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 3);
tempMouseDeltaX = Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX)); tempMouseDeltaX = Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX));
} }
break;
default: break; break;
} }
}
else
{
switch (xboxControl)
{
case X360Controls.Start: tempControlDict.Add(dcs.control, DS4Controls.Options); break;
case X360Controls.Guide: tempControlDict.Add(dcs.control, DS4Controls.PS); break;
case X360Controls.Back: tempControlDict.Add(dcs.control, DS4Controls.Share); break;
default: break; default: break;
} }
} }
@ -1078,6 +1062,7 @@ namespace DS4Windows
p = dcs.shiftExtras; p = dcs.shiftExtras;
else else
p = dcs.extras; p = dcs.extras;
string[] extraS = p.Split(','); string[] extraS = p.Split(',');
int extrasSLen = extraS.Length; int extrasSLen = extraS.Length;
int[] extras = new int[extrasSLen]; int[] extras = new int[extrasSLen];
@ -1087,11 +1072,13 @@ namespace DS4Windows
if (int.TryParse(extraS[i], out b)) if (int.TryParse(extraS[i], out b))
extras[i] = b; extras[i] = b;
} }
held[device] = true; held[device] = true;
try try
{ {
if (!(extras[0] == extras[1] && extras[1] == 0)) if (!(extras[0] == extras[1] && extras[1] == 0))
ctrl.setRumble((byte)extras[0], (byte)extras[1], device); ctrl.setRumble((byte)extras[0], (byte)extras[1], device);
if (extras[2] == 1) if (extras[2] == 1)
{ {
DS4Color color = new DS4Color { red = (byte)extras[3], green = (byte)extras[4], blue = (byte)extras[5] }; DS4Color color = new DS4Color { red = (byte)extras[3], green = (byte)extras[4], blue = (byte)extras[5] };
@ -1099,6 +1086,7 @@ namespace DS4Windows
DS4LightBar.forcedFlash[device] = (byte)extras[6]; DS4LightBar.forcedFlash[device] = (byte)extras[6];
DS4LightBar.forcelight[device] = true; DS4LightBar.forcelight[device] = true;
} }
if (extras[7] == 1) if (extras[7] == 1)
{ {
if (oldmouse[device] == -1) if (oldmouse[device] == -1)
@ -1179,7 +1167,7 @@ namespace DS4Windows
//foreach (KeyValuePair<DS4Controls, DS4Controls> entry in tempControlDict) //foreach (KeyValuePair<DS4Controls, DS4Controls> entry in tempControlDict)
for (int i = 0, keyCount = controlKeys.Count; i < keyCount; i++) for (int i = 0, keyCount = controlKeys.Count; i < keyCount; i++)
{ {
DS4Controls key = controlKeys.ElementAt<DS4Controls>(i); DS4Controls key = controlKeys.ElementAt(i);
DS4Controls dc = tempControlDict[key]; DS4Controls dc = tempControlDict[key];
//DS4Controls key = entry.Key; //DS4Controls key = entry.Key;
//DS4Controls dc = entry.Value; //DS4Controls dc = entry.Value;

View File

@ -228,6 +228,17 @@ namespace DS4Windows
X360Controls.None, X360Controls.None, X360Controls.None, X360Controls.None X360Controls.None, X360Controls.None, X360Controls.None, X360Controls.None
}; };
public static DS4Controls[] reverseX360ButtonMapping = new Func<DS4Controls[]>(() =>
{
DS4Controls[] temp = new DS4Controls[defaultButtonMapping.Length];
for (int i = 0, arlen = defaultButtonMapping.Length; i < arlen; i++)
{
temp[i] = (DS4Controls)defaultButtonMapping[i];
}
return temp;
})();
public static void SaveWhere(string path) public static void SaveWhere(string path)
{ {
appdatapath = path; appdatapath = path;