This commit is contained in:
mika-n 2019-02-19 15:09:00 +02:00
commit 7da6b3434a
2 changed files with 177 additions and 172 deletions

View File

@ -2,10 +2,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Diagnostics; using System.Diagnostics;
using static DS4Windows.Global; using static DS4Windows.Global;
namespace DS4Windows namespace DS4Windows
{ {
public class Mapping public class Mapping
@ -77,6 +79,8 @@ namespace DS4Windows
new Queue<ControlToXInput>(), new Queue<ControlToXInput>() new Queue<ControlToXInput>(), new Queue<ControlToXInput>()
}; };
static ReaderWriterLockSlim syncStateLock = new ReaderWriterLockSlim();
public static SyntheticState globalState = new SyntheticState(); public static SyntheticState globalState = new SyntheticState();
public static SyntheticState[] deviceState = new SyntheticState[4] public static SyntheticState[] deviceState = new SyntheticState[4]
{ new SyntheticState(), new SyntheticState(), new SyntheticState(), { new SyntheticState(), new SyntheticState(), new SyntheticState(),
@ -190,8 +194,8 @@ namespace DS4Windows
public static void Commit(int device) public static void Commit(int device)
{ {
SyntheticState state = deviceState[device]; SyntheticState state = deviceState[device];
lock (globalState) syncStateLock.EnterWriteLock();
{
globalState.currentClicks.leftCount += state.currentClicks.leftCount - state.previousClicks.leftCount; globalState.currentClicks.leftCount += state.currentClicks.leftCount - state.previousClicks.leftCount;
globalState.currentClicks.middleCount += state.currentClicks.middleCount - state.previousClicks.middleCount; globalState.currentClicks.middleCount += state.currentClicks.middleCount - state.previousClicks.middleCount;
globalState.currentClicks.rightCount += state.currentClicks.rightCount - state.previousClicks.rightCount; globalState.currentClicks.rightCount += state.currentClicks.rightCount - state.previousClicks.rightCount;
@ -389,7 +393,8 @@ namespace DS4Windows
} }
} }
globalState.SaveToPrevious(false); globalState.SaveToPrevious(false);
}
syncStateLock.ExitWriteLock();
state.SaveToPrevious(true); state.SaveToPrevious(true);
} }

View File

@ -43,12 +43,12 @@ namespace DS4Windows
{ {
byte alphacolor = Math.Max(red, Math.Max(green, blue)); byte alphacolor = Math.Max(red, Math.Max(green, blue));
Color reg = Color.FromArgb(red, green, blue); Color reg = Color.FromArgb(red, green, blue);
Color full = HuetoRGB(reg.GetHue(), reg.GetBrightness(), reg); Color full = HuetoRGB(reg.GetHue(), reg.GetBrightness(), ref reg);
return Color.FromArgb((alphacolor > 205 ? 255 : (alphacolor + 50)), full); return Color.FromArgb((alphacolor > 205 ? 255 : (alphacolor + 50)), full);
} }
} }
private Color HuetoRGB(float hue, float light, Color rgb) private Color HuetoRGB(float hue, float light, ref Color rgb)
{ {
float L = (float)Math.Max(.5, light); float L = (float)Math.Max(.5, light);
float C = (1 - Math.Abs(2 * L - 1)); float C = (1 - Math.Abs(2 * L - 1));