summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authora1xd <[email protected]>2020-09-26 02:10:29 -0400
committerGitHub <[email protected]>2020-09-26 02:10:29 -0400
commit9353f5b9adc50456fefc2e55aab5e57029e89682 (patch)
tree5d28926aee87c077ffc4ed7222469bbf2f28bd2c
parentMerge pull request #22 from JacobPalecki/GUI (diff)
parentSetActive changes field default, bugs fixed (diff)
downloadrawaccel-9353f5b9adc50456fefc2e55aab5e57029e89682.tar.xz
rawaccel-9353f5b9adc50456fefc2e55aab5e57029e89682.zip
Merge pull request #23 from JacobPalecki/GUI
Settings writer; GUI performance enhancement and touchups
-rw-r--r--common/rawaccel-settings.h5
-rw-r--r--grapher/Form1.cs2
-rw-r--r--grapher/Layouts/LayoutBase.cs2
-rw-r--r--grapher/Layouts/MotivityLayout.cs2
-rw-r--r--grapher/Models/AccelGUI.cs28
-rw-r--r--grapher/Models/Calculations/AccelCalculator.cs73
-rw-r--r--grapher/Models/Calculations/AccelChartData.cs22
-rw-r--r--grapher/Models/Charts/AccelCharts.cs5
-rw-r--r--grapher/Models/Charts/ChartState/ChartState.cs7
-rw-r--r--grapher/Models/Charts/ChartXY.cs21
-rw-r--r--grapher/Models/Fields/Field.cs10
-rw-r--r--grapher/Models/Mouse/MouseWatcher.cs8
-rw-r--r--grapher/Models/Options/Option.cs2
-rw-r--r--grapher/Models/Serialized/DriverSettings.cs117
-rw-r--r--grapher/Models/Serialized/SettingsManager.cs41
-rw-r--r--grapher/ReadMe/Guide.md9
-rw-r--r--grapher/grapher.csproj5
-rw-r--r--rawaccel.sln7
-rw-r--r--wrapper/wrapper.cpp139
-rw-r--r--writer/App.config6
-rw-r--r--writer/Program.cs30
-rw-r--r--writer/Properties/AssemblyInfo.cs36
-rw-r--r--writer/writer.csproj65
23 files changed, 451 insertions, 191 deletions
diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h
index 2ba6a98..93f4768 100644
--- a/common/rawaccel-settings.h
+++ b/common/rawaccel-settings.h
@@ -4,6 +4,9 @@
#include "accel-base.hpp"
namespace rawaccel {
+ using milliseconds = double;
+
+ inline constexpr milliseconds WRITE_DELAY = 1000;
enum class accel_mode {
linear, classic, natural, naturalgain, power, logarithm, motivity, noaccel
@@ -15,7 +18,7 @@ namespace rawaccel {
vec2<accel_mode> modes = { accel_mode::noaccel, accel_mode::noaccel };
vec2<accel_args> argsv;
vec2d sens = { 1, 1 };
- double time_min = 0.4;
+ milliseconds time_min = 0.4;
};
}
diff --git a/grapher/Form1.cs b/grapher/Form1.cs
index 3f2ca2a..aa3d2ef 100644
--- a/grapher/Form1.cs
+++ b/grapher/Form1.cs
@@ -144,7 +144,7 @@ namespace grapher
private void RawAcceleration_Paint(object sender, PaintEventArgs e)
{
- AccelGUI.AccelCharts.DrawLastMovement();
+ //AccelGUI.AccelCharts.DrawLastMovement();
}
#endregion Method
diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs
index b89e2f7..04f5189 100644
--- a/grapher/Layouts/LayoutBase.cs
+++ b/grapher/Layouts/LayoutBase.cs
@@ -10,7 +10,7 @@ namespace grapher.Layouts
public const string Exponent = "Exponent";
public const string Limit = "Limit";
public const string Midpoint = "Midpoint";
- public const string Motility = "Motility";
+ public const string Motivity = "Motivity";
public const string Offset = "Offset";
public const string Cap = "Cap";
public const string Weight = "Weight";
diff --git a/grapher/Layouts/MotivityLayout.cs b/grapher/Layouts/MotivityLayout.cs
index dfef2de..c555ef0 100644
--- a/grapher/Layouts/MotivityLayout.cs
+++ b/grapher/Layouts/MotivityLayout.cs
@@ -20,7 +20,7 @@ namespace grapher.Layouts
CapLayout = new OptionLayout(false, string.Empty);
WeightLayout = new OptionLayout(true, Weight);
OffsetLayout = new OptionLayout(false, string.Empty);
- LimExpLayout = new OptionLayout(true, Motility);
+ LimExpLayout = new OptionLayout(true, Motivity);
MidpointLayout = new OptionLayout(true, Midpoint);
}
}
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs
index 95d0c25..cc86ff7 100644
--- a/grapher/Models/AccelGUI.cs
+++ b/grapher/Models/AccelGUI.cs
@@ -38,6 +38,7 @@ namespace grapher
WriteButton.Click += new System.EventHandler(OnWriteButtonClick);
ButtonTimer = SetupButtonTimer();
+ ChartRefresh = SetupChartTimer();
SetupWriteButton();
}
@@ -63,6 +64,8 @@ namespace grapher
public ToolStripMenuItem ScaleMenuItem { get; }
+ private Timer ChartRefresh { get; }
+
#endregion Properties
#region Methods
@@ -83,14 +86,8 @@ namespace grapher
minimumTime = .4
};
- Settings.UpdateActiveSettings(settings, () =>
- {
- AccelForm.Invoke((MethodInvoker)delegate
- {
- WriteButtonDelay();
- UpdateGraph();
- });
- });
+ WriteButtonDelay();
+ Settings.UpdateActiveSettings(settings);
RefreshOnRead();
}
@@ -116,6 +113,15 @@ namespace grapher
ApplyOptions.SetActiveValues(settings);
}
+ private Timer SetupChartTimer()
+ {
+ Timer chartTimer = new Timer();
+ chartTimer.Enabled = true;
+ chartTimer.Interval = 10;
+ chartTimer.Tick += new System.EventHandler(OnChartTimerTick);
+ return chartTimer;
+ }
+
private Timer SetupButtonTimer()
{
Timer buttonTimer = new Timer();
@@ -165,6 +171,12 @@ namespace grapher
ButtonTimer.Start();
}
+ private void OnChartTimerTick(object sender, EventArgs e)
+ {
+ AccelCharts.DrawLastMovement();
+ MouseWatcher.UpdateLastMove();
+ }
+
#endregion Methods
}
diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs
index f2a6c7c..e2f7bcc 100644
--- a/grapher/Models/Calculations/AccelCalculator.cs
+++ b/grapher/Models/Calculations/AccelCalculator.cs
@@ -67,9 +67,13 @@ namespace grapher.Models.Calculations
double maxSlope = 0.0;
double minSlope = Double.MaxValue;
+ double log = -2;
+ int index = 0;
+ int logIndex = 0;
+
foreach (var magnitudeDatum in magnitudeData)
{
- if (magnitudeDatum.magnitude <=0)
+ if (magnitudeDatum.magnitude <= 0)
{
continue;
}
@@ -77,7 +81,23 @@ namespace grapher.Models.Calculations
var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime);
var outMagnitude = Magnitude(output.Item1, output.Item2);
- var ratio = magnitudeDatum.magnitude > 0 ? outMagnitude / magnitudeDatum.magnitude : starter;
+ if (!data.VelocityPoints.ContainsKey(magnitudeDatum.magnitude))
+ {
+ data.VelocityPoints.Add(magnitudeDatum.magnitude, outMagnitude);
+ }
+ else
+ {
+ continue;
+ }
+
+ while (Math.Pow(10,log) < outMagnitude && logIndex < data.LogToIndex.Length)
+ {
+ data.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
+ }
+
+ var ratio = outMagnitude / magnitudeDatum.magnitude;
if (ratio > maxRatio)
{
@@ -108,11 +128,6 @@ namespace grapher.Models.Calculations
data.AccelPoints.Add(magnitudeDatum.magnitude, ratio);
}
- if (!data.VelocityPoints.ContainsKey(magnitudeDatum.magnitude))
- {
- data.VelocityPoints.Add(magnitudeDatum.magnitude, outMagnitude);
- }
-
if (!data.GainPoints.ContainsKey(magnitudeDatum.magnitude))
{
data.GainPoints.Add(magnitudeDatum.magnitude, slope);
@@ -120,9 +135,18 @@ namespace grapher.Models.Calculations
lastInputMagnitude = magnitudeDatum.magnitude;
lastOutputMagnitude = outMagnitude;
+ index += 1;
+ }
+
+ index--;
+
+ while (log <= 5.0)
+ {
+ data.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
}
- data.OrderedVelocityPointsList.AddRange(data.VelocityPoints.Values.ToList());
data.MaxAccel = maxRatio;
data.MinAccel = minRatio;
data.MaxGain = maxSlope;
@@ -143,18 +167,38 @@ namespace grapher.Models.Calculations
Sensitivity = GetSens(ref settings);
+ double log = -2;
+ int index = 0;
+ int logIndex = 0;
+
foreach (var magnitudeDatum in magnitudeData)
{
+ if (magnitudeDatum.magnitude <= 0)
+ {
+ continue;
+ }
+
var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime);
var outputWithoutSens = StripThisSens(output.Item1, output.Item2);
var magnitudeWithoutSens = Magnitude(outputWithoutSens.Item1, outputWithoutSens.Item2);
- var ratio = magnitudeDatum.magnitude > 0 ? magnitudeWithoutSens / magnitudeDatum.magnitude : 1;
+ var ratio = magnitudeWithoutSens / magnitudeDatum.magnitude;
if (!data.Combined.VelocityPoints.ContainsKey(magnitudeDatum.magnitude))
{
data.Combined.VelocityPoints.Add(magnitudeDatum.magnitude, magnitudeWithoutSens);
}
+ else
+ {
+ continue;
+ }
+
+ while (Math.Pow(10,log) < magnitudeWithoutSens && logIndex < data.Combined.LogToIndex.Length)
+ {
+ data.Combined.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
+ }
var xRatio = settings.sensitivity.x * ratio;
var yRatio = settings.sensitivity.y * ratio;
@@ -241,9 +285,18 @@ namespace grapher.Models.Calculations
lastInputMagnitude = magnitudeDatum.magnitude;
lastOutputMagnitudeX = xOut;
lastOutputMagnitudeY = yOut;
+ index += 1;
+ }
+
+ index--;
+
+ while (log <= 5.0)
+ {
+ data.Combined.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
}
- data.Combined.OrderedVelocityPointsList.AddRange(data.Combined.VelocityPoints.Values.ToList());
data.Combined.MaxAccel = maxRatio;
data.Combined.MinAccel = minRatio;
data.Combined.MaxGain = maxSlope;
diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs
index 54685a2..60d4c89 100644
--- a/grapher/Models/Calculations/AccelChartData.cs
+++ b/grapher/Models/Calculations/AccelChartData.cs
@@ -13,8 +13,8 @@ namespace grapher.Models.Calculations
AccelPoints = new SortedDictionary<double, double>();
VelocityPoints = new SortedDictionary<double, double>();
GainPoints = new SortedDictionary<double, double>();
- OrderedVelocityPointsList = new List<double>();
OutVelocityToPoints = new Dictionary<double, (double, double, double)>();
+ LogToIndex = new int[701];
}
#endregion Constructors
@@ -35,7 +35,7 @@ namespace grapher.Models.Calculations
public SortedDictionary<double, double> GainPoints { get; }
- public List<double> OrderedVelocityPointsList { get; }
+ public int[] LogToIndex { get; }
public Dictionary<double, (double, double, double)> OutVelocityToPoints { get; }
@@ -48,8 +48,8 @@ namespace grapher.Models.Calculations
AccelPoints.Clear();
VelocityPoints.Clear();
GainPoints.Clear();
- OrderedVelocityPointsList.Clear();
OutVelocityToPoints.Clear();
+ Array.Clear(LogToIndex, 0, LogToIndex.Length);
}
public (double, double, double) FindPointValuesFromOut(double outVelocityValue)
@@ -80,15 +80,19 @@ namespace grapher.Models.Calculations
public int GetVelocityIndex(double outVelocityValue)
{
- var velIdx = OrderedVelocityPointsList.BinarySearch(outVelocityValue);
-
- if (velIdx < 0)
+ var log = Math.Log10(outVelocityValue);
+ if (log < -2)
+ {
+ log = -2;
+ }
+ else if (log > 5)
{
- velIdx = ~velIdx;
+ log = 5;
}
- velIdx = Math.Min(velIdx, VelocityPoints.Count - 1);
- velIdx = Math.Max(velIdx, 0);
+ log = log * 100 + 200;
+
+ var velIdx = LogToIndex[(int)log];
return velIdx;
}
diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs
index a0e99c8..7484a3a 100644
--- a/grapher/Models/Charts/AccelCharts.cs
+++ b/grapher/Models/Charts/AccelCharts.cs
@@ -143,6 +143,11 @@ namespace grapher
AlignWriteButton();
}
+ public void Redraw()
+ {
+ ChartState.Redraw();
+ }
+
public void Calculate(ManagedAccel accel, DriverSettings settings)
{
ChartState.SetUpCalculate(settings);
diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs
index e1c7d01..1898e12 100644
--- a/grapher/Models/Charts/ChartState/ChartState.cs
+++ b/grapher/Models/Charts/ChartState/ChartState.cs
@@ -48,6 +48,13 @@ namespace grapher.Models.Charts.ChartState
public abstract void Calculate(ManagedAccel accel, DriverSettings settings);
+ public void Redraw()
+ {
+ SensitivityChart.Update();
+ VelocityChart.Update();
+ GainChart.Update();
+ }
+
public virtual void SetUpCalculate(DriverSettings settings)
{
Data.Clear();
diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs
index c30c993..d95c7ac 100644
--- a/grapher/Models/Charts/ChartXY.cs
+++ b/grapher/Models/Charts/ChartXY.cs
@@ -154,6 +154,15 @@ namespace grapher
*/
}
+ public void Update()
+ {
+ ChartX.Update();
+ if (ChartY.Visible)
+ {
+ ChartY.Update();
+ }
+ }
+
public void SetPointBinds(PointData combined, PointData x, PointData y)
{
CombinedPointData = combined;
@@ -213,8 +222,8 @@ namespace grapher
{
if (min < max)
{
- ChartX.ChartAreas[0].AxisY.Minimum = min;
- ChartX.ChartAreas[0].AxisY.Maximum = max;
+ ChartX.ChartAreas[0].AxisY.Minimum = min * 0.95;
+ ChartX.ChartAreas[0].AxisY.Maximum = max * 1.05;
}
}
@@ -222,14 +231,14 @@ namespace grapher
{
if (minX < maxX)
{
- ChartX.ChartAreas[0].AxisY.Minimum = minX;
- ChartX.ChartAreas[0].AxisY.Maximum = maxX;
+ ChartX.ChartAreas[0].AxisY.Minimum = minX * 0.95;
+ ChartX.ChartAreas[0].AxisY.Maximum = maxX * 1.05;
}
if (minY < maxY)
{
- ChartY.ChartAreas[0].AxisY.Minimum = minY;
- ChartY.ChartAreas[0].AxisY.Maximum = maxY;
+ ChartY.ChartAreas[0].AxisY.Minimum = minY * 0.95;
+ ChartY.ChartAreas[0].AxisY.Maximum = maxY * 1.05;
}
}
diff --git a/grapher/Models/Fields/Field.cs b/grapher/Models/Fields/Field.cs
index df73dd7..541bbe2 100644
--- a/grapher/Models/Fields/Field.cs
+++ b/grapher/Models/Fields/Field.cs
@@ -52,7 +52,7 @@ namespace grapher
public string FormatString { get; set; }
- public string DefaultText { get; }
+ public string DefaultText { get; set; }
public FieldState State { get; private set; }
@@ -120,7 +120,7 @@ namespace grapher
}
}
- private double DefaultData { get; }
+ private double DefaultData { get; set; }
#endregion Properties
@@ -138,6 +138,12 @@ namespace grapher
Box.Enabled = true;
}
+ public void SetNewDefault(double newDefault)
+ {
+ DefaultData = newDefault;
+ DefaultText = DecimalString(newDefault);
+ }
+
public void SetToDefault()
{
if (State != FieldState.Default)
diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs
index 86b1c2e..c6e85c1 100644
--- a/grapher/Models/Mouse/MouseWatcher.cs
+++ b/grapher/Models/Mouse/MouseWatcher.cs
@@ -716,10 +716,16 @@ namespace grapher.Models.Mouse
public void OnMouseMove(int x, int y, double timeInMs)
{
- Display.Text = $"Last (x, y): ({x}, {y})";
+ MouseData.Set(x,y);
AccelCharts.MakeDots(x, y, timeInMs);
}
+ public void UpdateLastMove()
+ {
+ MouseData.Get(out var x, out var y);
+ Display.Text = $"Last (x, y): ({x}, {y})";
+ }
+
public void ReadMouseMove(Message message)
{
RawInput rawInput = new RawInput();
diff --git a/grapher/Models/Options/Option.cs b/grapher/Models/Options/Option.cs
index c0d339e..d5129d5 100644
--- a/grapher/Models/Options/Option.cs
+++ b/grapher/Models/Options/Option.cs
@@ -136,6 +136,8 @@ namespace grapher
public void SetActiveValue(double value)
{
ActiveValueLabel.SetValue(value);
+ Field.SetNewDefault(value);
+ Field.SetToDefault();
}
public override void Hide()
diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs
deleted file mode 100644
index 5f9307c..0000000
--- a/grapher/Models/Serialized/DriverSettings.cs
+++ /dev/null
@@ -1,117 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-namespace grapher.Models.Serialized
-{
- #region Enumerations
-
- public enum AccelMode
- {
- linear, classic, natural, naturalgain, power, logarithm, motivity, noaccel
- }
-
- #endregion Enumerations
-
- #region Structs
-
- [StructLayout(LayoutKind.Sequential)]
- public struct AccelArgs
- {
- public double offset;
- public double legacy_offset;
- public double accel;
- public double limit;
- public double exponent;
- public double midpoint;
- public double powerScale;
- public double powerExponent;
- public double weight;
- public double rate;
- public double scaleCap;
- public double gainCap;
- };
-
- [StructLayout(LayoutKind.Sequential)]
- public struct Vec2 <T>
- {
- public T x;
- public T y;
- }
-
- #endregion Structs
-
- [StructLayout(LayoutKind.Sequential)]
- [Serializable]
- public class DriverSettings
- {
- #region Fields
-
- private static readonly IntPtr UnmanagedSettingsHandle =
- Marshal.AllocHGlobal(Marshal.SizeOf<DriverSettings>());
- private static object UnmanagedSettingsLock = new object();
-
- public double rotation;
- public bool combineMagnitudes;
- public Vec2<AccelMode> modes;
- public Vec2<AccelArgs> args;
- public Vec2<double> sensitivity;
- public double minimumTime;
-
- #endregion Fields
-
- #region Methods
-
- public static DriverSettings GetActive()
- {
- DriverInterop.GetActiveSettings(UnmanagedSettingsHandle);
- return Marshal.PtrToStructure<DriverSettings>(UnmanagedSettingsHandle);
- }
-
- public static void SetActive(DriverSettings settings, Action<IntPtr> unmanagedActionBefore = null)
- {
- new Thread(() =>
- {
- lock (UnmanagedSettingsLock)
- {
- Marshal.StructureToPtr(settings, UnmanagedSettingsHandle, false);
- unmanagedActionBefore?.Invoke(UnmanagedSettingsHandle);
- DriverInterop.SetActiveSettings(UnmanagedSettingsHandle);
- }
- }).Start();
-
- }
-
- public void SendToDriver(Action<IntPtr> unmanagedActionBefore = null)
- {
- SetActive(this, unmanagedActionBefore);
- }
-
- public void SendToDriverAndUpdate(ManagedAccel accel, Action betweenAccelAndWrite = null)
- {
- SendToDriver(settingsHandle =>
- {
- accel.UpdateFromSettings(settingsHandle);
- betweenAccelAndWrite?.Invoke();
- });
- }
-
- public bool verify()
- {
- /*
- if (args.accel < 0 || args.rate < 0)
- bad_arg("accel can not be negative, use a negative weight to compensate");
- if (args.rate > 1) bad_arg("rate can not be greater than 1");
- if (args.exponent <= 1) bad_arg("exponent must be greater than 1");
- if (args.limit <= 1) bad_arg("limit must be greater than 1");
- if (args.power_scale <= 0) bad_arg("scale must be positive");
- if (args.power_exp <= 0) bad_arg("exponent must be positive");
- if (args.midpoint < 0) bad_arg("midpoint must not be negative");
- if (args.time_min <= 0) bad_arg("min time must be positive");
- */
- return true;
- }
-
- #endregion Methods
- }
-}
diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs
index cac2bd0..26160f5 100644
--- a/grapher/Models/Serialized/SettingsManager.cs
+++ b/grapher/Models/Serialized/SettingsManager.cs
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Windows.Forms;
+using System.Threading;
namespace grapher.Models.Serialized
{
@@ -46,29 +47,28 @@ namespace grapher.Models.Serialized
#region Methods
- public void UpdateActiveSettings(DriverSettings settings, Action afterAccelSettingsUpdate = null)
+ public void UpdateActiveSettings(DriverSettings settings)
{
- settings.SendToDriverAndUpdate(ActiveAccel, () =>
- {
- RawAccelSettings.AccelerationSettings = settings;
- RawAccelSettings.GUISettings = new GUISettings
- {
- AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked,
- DPI = (int)DpiField.Data,
- PollRate = (int)PollRateField.Data,
- ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked,
- ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked,
- };
+ ActiveAccel.UpdateFromSettings(settings);
+ SendToDriver(settings);
- RawAccelSettings.Save();
+ RawAccelSettings.AccelerationSettings = settings;
+ RawAccelSettings.GUISettings = new GUISettings
+ {
+ AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked,
+ DPI = (int)DpiField.Data,
+ PollRate = (int)PollRateField.Data,
+ ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked,
+ ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked,
+ };
- afterAccelSettingsUpdate?.Invoke();
- });
+ RawAccelSettings.Save();
}
public void UpdateActiveAccelFromFileSettings(DriverSettings settings)
- {
- settings.SendToDriverAndUpdate(ActiveAccel);
+ {
+ ActiveAccel.UpdateFromSettings(settings);
+ SendToDriver(settings);
DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI);
PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate);
@@ -77,6 +77,11 @@ namespace grapher.Models.Serialized
ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain;
}
+ public static void SendToDriver(DriverSettings settings)
+ {
+ new Thread(() => DriverInterop.SetActiveSettings(settings)).Start();
+ }
+
public void Startup()
{
if (RawAccelSettings.Exists())
@@ -97,7 +102,7 @@ namespace grapher.Models.Serialized
}
RawAccelSettings = new RawAccelSettings(
- DriverSettings.GetActive(),
+ DriverInterop.GetActiveSettings(),
new GUISettings
{
AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked,
diff --git a/grapher/ReadMe/Guide.md b/grapher/ReadMe/Guide.md
index 3680c0a..1eae47e 100644
--- a/grapher/ReadMe/Guide.md
+++ b/grapher/ReadMe/Guide.md
@@ -1,7 +1,7 @@
# Raw Accel Guide
## Philosophy
-The Raw Accel driver and GUI's workings and exposed parameters are based on our understanding of mouse acceleration. Our understanding includes the concepts of "gain", "whole vs by component", and "anisotropy." For clarity, we will outline this understanding here.
+The Raw Accel driver and GUI's workings and exposed parameters are based on our understanding of mouse acceleration. Our understanding includes the concepts of "gain", "whole vs by component", and "anisotropy." For clarity, we will outline this understanding here. Those uninterested can skip to Features below.
### Measurements from Input Speed
Raw Accel, like any mouse modification program, works by acting on a passed in (x,y) input and passing back out an (x,y) output. The GUI program creates charts by feeding a set of (x,y) inputs to the driver code to receive a set of (x,y) outputs. The following measurements, available as charts in Raw Accel, are then found from the outputs:
@@ -57,6 +57,9 @@ See "Horizontal and Vertical" in the philosophy section to understand what these
### Last Mouse Move
The Raw Accel GUI reads the output of the raw input stream, and thus the output of the Raw Accel Driver, and displays on the graphs red points corresponding to the last mouse movements. These calculations are slightly slow but build up a cache, so shaking your mouse around on GUI start should make the points display fast and smoothly. This feature can be turned off in the "Charts" menu.
+### Scale by DPI and Poll Rate
+This option does not scale your acceleration curve in any way. Rather, it scales the set of points used to graph your curve, and shows you a window of input speed relevant for your chosen DPI and Poll Rate.
+
## Acceleration Styles
[To be added: pictures of the styles, typical settings]
@@ -72,8 +75,8 @@ This is the style found in CS:GO and Source Engine games. The user can set a rat
### Natural & NaturalGain
Natural is a style found in the game Diabotical. It features a concave curve which starts at 1 and approaches some maximum sensitivity. This style is unique and useful but causes an ugly dip in the gain graph. For this reason we have created the NaturalGain style, which recreates the Natural style shape in the gain graph without any dips. We recommend users use the NaturalGain style instead of the Natural style; on switch some small tweaks may be needed since for any particular settings the NaturalGain is slightly slower to ramp up than the Natural style. NaturalGain is another excellent choice for new users.
-### SigmoidGain
-A sigmoid curve is an s-shaped curve. SigmoidGain creates an s-shaped curve from 1 to some maximum gain in the gain graph, allowing a user to set the maximum gain, the midpoint of the s, and how fast the s ramps up (similarly to the Natural styles.) At one point there was a Sigmoid style but we removed it because it caused an awful dip in the gain graph.
+### Motivity
+This curve looks like an "S" with the top half bigger than the bottom. Mathematically it's a "Sigmoid function on a log-log plot". A user can set the "midpoint" of the S, the "acceleration" (i.e. slantedness) of the S, and the "motivity". "Motivity" sets min and max sensitivity, where the maximum is just "motility", and the minimum is "1/motility." (Sensitivity is 1 at the midpoint.) This curve is calculated and stored in a lookup table before applying acceleration, which makes the gain graph look a little funny. This is one author's favorite curve, and an excellent choice for power users and new users who don't mind playing with the settings a little.
### Logarithm
[Sidiouth needs to write this]
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index bc9fcf2..29b5cff 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -15,7 +15,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
- <OutputPath>bin\x64\Debug\</OutputPath>
+ <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
@@ -25,7 +25,7 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
- <OutputPath>bin\x64\Release\</OutputPath>
+ <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
@@ -101,7 +101,6 @@
<Compile Include="Models\Options\OptionBase.cs" />
<Compile Include="Models\Options\OptionXY.cs" />
<Compile Include="Models\Serialized\GUISettings.cs" />
- <Compile Include="Models\Serialized\DriverSettings.cs" />
<Compile Include="Models\Serialized\RawAccelSettings.cs" />
<Compile Include="Models\Serialized\SettingsManager.cs" />
<Compile Include="Program.cs" />
diff --git a/rawaccel.sln b/rawaccel.sln
index f2eab80..cfbbc23 100644
--- a/rawaccel.sln
+++ b/rawaccel.sln
@@ -17,6 +17,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wrapper", "wrapper\wrapper.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "grapher", "grapher\grapher.csproj", "{EF67F71F-ABF5-4760-B50D-D1B9836DF01C}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "writer", "writer\writer.csproj", "{28ACF254-E4EF-4A0E-9761-0FE22048D6FD}"
+EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
common-install\common-install.vcxitems*{058d66c6-d88b-4fdb-b0e4-0a6fe7483b95}*SharedItemsImports = 9
@@ -49,8 +51,13 @@ Global
{28A3656F-A1DE-405C-B547-191C32EC555F}.Release|x64.ActiveCfg = Release|x64
{28A3656F-A1DE-405C-B547-191C32EC555F}.Release|x64.Build.0 = Release|x64
{EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|x64.ActiveCfg = Debug|x64
+ {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|x64.Build.0 = Debug|x64
{EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|x64.ActiveCfg = Release|x64
{EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|x64.Build.0 = Release|x64
+ {28ACF254-E4EF-4A0E-9761-0FE22048D6FD}.Debug|x64.ActiveCfg = Debug|x64
+ {28ACF254-E4EF-4A0E-9761-0FE22048D6FD}.Debug|x64.Build.0 = Debug|x64
+ {28ACF254-E4EF-4A0E-9761-0FE22048D6FD}.Release|x64.ActiveCfg = Release|x64
+ {28ACF254-E4EF-4A0E-9761-0FE22048D6FD}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp
index 0778bc3..9a53189 100644
--- a/wrapper/wrapper.cpp
+++ b/wrapper/wrapper.cpp
@@ -1,21 +1,139 @@
#pragma once
+#include <type_traits>
+
#include <rawaccel.hpp>
#include "wrapper_io.hpp"
using namespace System;
+using namespace System::Runtime::InteropServices;
+
+public enum class AccelMode
+{
+ linear, classic, natural, naturalgain, power, logarithm, motivity, noaccel
+};
+
+[StructLayout(LayoutKind::Sequential)]
+public value struct AccelArgs
+{
+ double offset;
+ double legacy_offset;
+ double accel;
+ double limit;
+ double exponent;
+ double midpoint;
+ double powerScale;
+ double powerExponent;
+ double weight;
+ double rate;
+ double scaleCap;
+ double gainCap;
+};
+
+generic <typename T>
+[StructLayout(LayoutKind::Sequential)]
+public value struct Vec2
+{
+ T x;
+ T y;
+};
+
+[Serializable]
+[StructLayout(LayoutKind::Sequential)]
+public ref struct DriverSettings
+{
+ double rotation;
+ [MarshalAs(UnmanagedType::U1)]
+ bool combineMagnitudes;
+ Vec2<AccelMode> modes;
+ Vec2<AccelArgs> args;
+ Vec2<double> sensitivity;
+ double minimumTime;
+};
+
+
+template <typename NativeSettingsFunc>
+void as_native(DriverSettings^ managed_args, NativeSettingsFunc fn)
+{
+#ifndef NDEBUG
+ if (Marshal::SizeOf(managed_args) != sizeof(settings))
+ throw gcnew InvalidOperationException("setting sizes differ");
+#endif
+ IntPtr unmanagedHandle = Marshal::AllocHGlobal(sizeof(settings));
+ Marshal::StructureToPtr(managed_args, unmanagedHandle, false);
+ fn(*reinterpret_cast<settings*>(unmanagedHandle.ToPointer()));
+ if constexpr (!std::is_invocable_v<NativeSettingsFunc, const settings&>) {
+ Marshal::PtrToStructure(unmanagedHandle, managed_args);
+ }
+ Marshal::FreeHGlobal(unmanagedHandle);
+}
+
+DriverSettings^ get_default()
+{
+ DriverSettings^ managed = gcnew DriverSettings();
+ as_native(managed, [](settings& args) {
+ args = {};
+ });
+ return managed;
+}
+
+void set_active(DriverSettings^ managed)
+{
+ as_native(managed, [](const settings& args) {
+ wrapper_io::writeToDriver(args);
+ });
+}
+
+DriverSettings^ get_active()
+{
+ DriverSettings^ managed = gcnew DriverSettings();
+ as_native(managed, [](settings& args) {
+ wrapper_io::readFromDriver(args);
+ });
+ return managed;
+}
+
+void update_modifier(mouse_modifier& mod, DriverSettings^ managed, vec2<si_pair*> luts = {})
+{
+ as_native(managed, [&](const settings& args) {
+ mod = { args, luts };
+ });
+}
public ref struct DriverInterop
{
- static void GetActiveSettings(IntPtr argsOut)
+ static DriverSettings^ GetActiveSettings()
{
- wrapper_io::readFromDriver(*reinterpret_cast<settings*>(argsOut.ToPointer()));
+ return get_active();
}
- static void SetActiveSettings(IntPtr argsIn)
+ static void SetActiveSettings(DriverSettings^ args)
{
- wrapper_io::writeToDriver(*reinterpret_cast<settings*>(argsIn.ToPointer()));
+ set_active(args);
+ }
+
+ static DriverSettings^ GetDefaultSettings()
+ {
+ return get_default();
+ }
+
+ using error_list_t = Collections::Generic::List<String^>;
+
+ static error_list_t^ GetErrors(AccelArgs^ args)
+ {
+ auto error_list = gcnew error_list_t();
+
+ if (args->accel < 0 || args->rate < 0)
+ error_list->Add("accel can not be negative, use a negative weight to compensate");
+ if (args->rate > 1) error_list->Add("rate can not be greater than 1");
+ if (args->exponent <= 1) error_list->Add("exponent must be greater than 1");
+ if (args->limit <= 1) error_list->Add("limit must be greater than 1");
+ if (args->powerScale <= 0) error_list->Add("scale must be positive");
+ if (args->powerExponent <= 0) error_list->Add("exponent must be positive");
+ if (args->midpoint < 0) error_list->Add("midpoint must not be negative");
+
+ return error_list;
}
};
@@ -31,7 +149,7 @@ public ref class ManagedAccel
#endif
public:
- static initonly double WriteDelay = -10000000 / -10000.0;
+ static initonly double WriteDelay = WRITE_DELAY;
virtual ~ManagedAccel()
{
@@ -58,12 +176,13 @@ public:
return gcnew Tuple<double, double>(in_out_vec.x, in_out_vec.y);
}
- void UpdateFromSettings(IntPtr argsIn)
+ void UpdateFromSettings(DriverSettings^ args)
{
- *modifier_instance = {
- *reinterpret_cast<settings*>(argsIn.ToPointer())
- , vec2<si_pair*>{ lut_x, lut_y }
- };
+ update_modifier(
+ *modifier_instance,
+ args,
+ vec2<si_pair*>{ lut_x, lut_y }
+ );
}
static ManagedAccel^ GetActiveAccel()
diff --git a/writer/App.config b/writer/App.config
new file mode 100644
index 0000000..56efbc7
--- /dev/null
+++ b/writer/App.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
+ </startup>
+</configuration> \ No newline at end of file
diff --git a/writer/Program.cs b/writer/Program.cs
new file mode 100644
index 0000000..7f9c37c
--- /dev/null
+++ b/writer/Program.cs
@@ -0,0 +1,30 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+using System;
+using System.IO;
+
+namespace writer
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ try
+ {
+ var serializerSettings = new JsonSerializerSettings
+ {
+ MissingMemberHandling = MissingMemberHandling.Error,
+ };
+ var token = JObject.Parse(File.ReadAllText(args[0]))["AccelerationSettings"];
+ var settings = token.ToObject<DriverSettings>(JsonSerializer.Create(serializerSettings));
+ DriverInterop.SetActiveSettings(settings);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ Console.ReadLine();
+ }
+ }
+ }
+}
diff --git a/writer/Properties/AssemblyInfo.cs b/writer/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..37e79ad
--- /dev/null
+++ b/writer/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("writer")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("writer")]
+[assembly: AssemblyCopyright("Copyright © 2020")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("28acf254-e4ef-4a0e-9761-0fe22048d6fd")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/writer/writer.csproj b/writer/writer.csproj
new file mode 100644
index 0000000..4befc1a
--- /dev/null
+++ b/writer/writer.csproj
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{28ACF254-E4EF-4A0E-9761-0FE22048D6FD}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>writer</RootNamespace>
+ <AssemblyName>writer</AssemblyName>
+ <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+ <Deterministic>true</Deterministic>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+ <DebugSymbols>true</DebugSymbols>
+ <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DebugType>full</DebugType>
+ <PlatformTarget>x64</PlatformTarget>
+ <LangVersion>7.3</LangVersion>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <Prefer32Bit>true</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+ <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <Optimize>true</Optimize>
+ <DebugType>pdbonly</DebugType>
+ <PlatformTarget>x64</PlatformTarget>
+ <LangVersion>7.3</LangVersion>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <Prefer32Bit>true</Prefer32Bit>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>..\x64\Release\Newtonsoft.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\wrapper\wrapper.vcxproj">
+ <Project>{28a3656f-a1de-405c-b547-191c32ec555f}</Project>
+ <Name>wrapper</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project> \ No newline at end of file