Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Minor tweaks to speed up action execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryochan7 committed Apr 1, 2017
1 parent 9a0966d commit 2a5ee9a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DS4Windows/DS4Control/DS4LightBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static void updateLightBar(DS4Device device, int deviceNum, DS4State cSta
}
else if (device.getBattery() <= getFlashAt(deviceNum) && getFlashType(deviceNum) == 0 && !defualtLight && !device.isCharging())
{
int level = device.Battery / 10;
int level = device.getBattery() / 10;
//if (level >= 10)
//level = 0; // all values of ~0% or >~100% are rendered the same
haptics.LightBarFlashDurationOn = BatteryIndicatorDurations[level, 0];
Expand Down
33 changes: 19 additions & 14 deletions DS4Windows/DS4Control/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ public static void MapCustom(int device, DS4State cState, DS4State MappedState,
int MouseDeltaY = 0;

SyntheticState deviceState = Mapping.deviceState[device];
if (GetActions().Count > 0 && (getProfileActions(device).Count > 0 || !string.IsNullOrEmpty(tempprofilename[device])))
if (containsCustomAction(device) && (getProfileActions(device).Count > 0 || !string.IsNullOrEmpty(tempprofilename[device])))
MapCustomAction(device, cState, MappedState, eState, tp, ctrl);
if (ctrl.DS4Controllers[device] == null) return;

Expand Down Expand Up @@ -1197,25 +1197,29 @@ private static bool IfAxisIsNotModified(int device, bool shift, DS4Controls dc)
}
public static async void MapCustomAction(int device, DS4State cState, DS4State MappedState, DS4StateExposed eState, Mouse tp, ControlService ctrl)
{
try {
foreach (string actionname in ProfileActions[device])
/* TODO: This method is slow sauce. Find ways to speed up action execution */
try
{
List<string> profileActions = getProfileActions(device);
foreach (string actionname in profileActions)
{
//DS4KeyType keyType = getShiftCustomKeyType(device, customKey.Key);
SpecialAction action = GetAction(actionname);
int index = GetActionIndexOf(actionname);
if (actionDone.Count < index + 1)
int actionDoneCount = actionDone.Count;
if (actionDoneCount < index + 1)
actionDone.Add(new ActionState());
else if (actionDone.Count > GetActions().Count())
actionDone.RemoveAt(actionDone.Count - 1);
double time;
else if (actionDoneCount > GetActions().Count())
actionDone.RemoveAt(actionDoneCount - 1);
double time = 0.0;
//If a key or button is assigned to the trigger, a key special action is used like
//a quick tap to use and hold to use the regular custom button/key
bool triggerToBeTapped = action.type == "Key" && action.trigger.Count == 1 &&
GetDS4Action(device, action.trigger[0].ToString(), false) == null;
GetDS4Action(device, action.trigger[0], false) == null;
if (!(action.name == "null" || index < 0))
{
bool triggeractivated = true;
if (action.delayTime > 0)
if (action.delayTime > 0.0)
{
triggeractivated = false;
bool subtriggeractivated = true;
Expand Down Expand Up @@ -1287,7 +1291,8 @@ public static async void MapCustomAction(int device, DS4State cState, DS4State M
}

bool utriggeractivated = true;
if (action.type == "Key" && action.uTrigger.Count > 0)
int uTriggerCount = action.uTrigger.Count;
if (action.type == "Key" && uTriggerCount > 0)
{
foreach (DS4Controls dc in action.uTrigger)
{
Expand Down Expand Up @@ -1328,7 +1333,7 @@ public static async void MapCustomAction(int device, DS4State cState, DS4State M
else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
{
int[] keys = (int[])dcs.action;
for (int i = 0; i < keys.Length; i++)
for (int i = 0, keysLen = keys.Length; i < keysLen; i++)
InputMethods.performKeyRelease((ushort)keys[i]);
}
}
Expand All @@ -1352,13 +1357,13 @@ public static async void MapCustomAction(int device, DS4State cState, DS4State M
}
else if (triggeractivated && action.type == "Key")
{
if (action.uTrigger.Count == 0 || (action.uTrigger.Count > 0 && untriggerindex[device] == -1 && !actionDone[index].dev[device]))
if (uTriggerCount == 0 || (uTriggerCount > 0 && untriggerindex[device] == -1 && !actionDone[index].dev[device]))
{
actionDone[index].dev[device] = true;
untriggerindex[device] = index;
ushort key;
ushort.TryParse(action.details, out key);
if (action.uTrigger.Count == 0)
if (uTriggerCount == 0)
{
SyntheticState.KeyPresses kp;
if (!deviceState[device].keyPresses.TryGetValue(key, out kp))
Expand All @@ -1375,7 +1380,7 @@ public static async void MapCustomAction(int device, DS4State cState, DS4State M
InputMethods.performKeyPress(key);
}
}
else if (action.uTrigger.Count > 0 && utriggeractivated && action.type == "Key")
else if (uTriggerCount > 0 && utriggeractivated && action.type == "Key")
{
if (untriggerindex[device] > -1 && !actionDone[index].dev[device])
{
Expand Down
25 changes: 23 additions & 2 deletions DS4Windows/DS4Control/ScpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ public static void UpdateDS4Extra(int deviceNum, string buttonName, bool shift,
m_Config.containsCustomExtras[deviceNum] = m_Config.HasCustomExtras(deviceNum);
}

public static object GetDS4Action(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4Action(deviceNum, buttonName, shift);
public static object GetDS4Action(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4Action(deviceNum, buttonName, shift);
public static object GetDS4Action(int deviceNum, DS4Controls control, bool shift) => m_Config.GetDS4Action(deviceNum, control, shift);
public static DS4KeyType GetDS4KeyType(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4KeyType(deviceNum, buttonName, shift);
public static string GetDS4Extra(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4Extra(deviceNum, buttonName, shift);
public static int GetDS4STrigger(int deviceNum, string buttonName) => m_Config.GetDS4STrigger(deviceNum, buttonName);
Expand Down Expand Up @@ -483,7 +484,7 @@ public static void RemoveAction(string name)

public static int GetActionIndexOf(string name)
{
for (int i = 0; i < m_Config.actions.Count; i++)
for (int i = 0, actionCount = m_Config.actions.Count; i < actionCount; i++)
if (m_Config.actions[i].name == name)
return i;
return -1;
Expand Down Expand Up @@ -2349,6 +2350,26 @@ public object GetDS4Action(int deviceNum, string buttonName, bool shift)
return null;
}

public object GetDS4Action(int deviceNum, DS4Controls dc, bool shift)
{
int temp = (int)dc;
if (temp > 0)
{
int index = temp - 1;
DS4ControlSettings dcs = ds4settings[deviceNum][index];
if (shift)
{
return dcs.shiftTrigger;
}
else
{
return dcs.action;
}
}

return null;
}

public string GetDS4Extra(int deviceNum, string buttonName, bool shift)
{
DS4Controls dc;
Expand Down

0 comments on commit 2a5ee9a

Please sign in to comment.