diff options
| author | a1xd <[email protected]> | 2021-03-29 18:01:20 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-03-29 18:01:20 -0400 |
| commit | ed0bbc22681681a16b7d45b05133c38a0b82006f (patch) | |
| tree | 3c883ad3c85608cd167efded8cce09733527f835 /common | |
| parent | refactor common/settings (diff) | |
| download | rawaccel-ed0bbc22681681a16b7d45b05133c38a0b82006f.tar.xz rawaccel-ed0bbc22681681a16b7d45b05133c38a0b82006f.zip | |
formatting + file renames
Diffstat (limited to 'common')
| -rw-r--r-- | common/accel-classic.hpp | 16 | ||||
| -rw-r--r-- | common/accel-motivity.hpp | 17 | ||||
| -rw-r--r-- | common/accel-natural.hpp | 10 | ||||
| -rw-r--r-- | common/accel-noaccel.hpp | 4 | ||||
| -rw-r--r-- | common/accel-power.hpp | 7 | ||||
| -rw-r--r-- | common/accel-union.hpp | 98 | ||||
| -rw-r--r-- | common/common.vcxitems | 5 | ||||
| -rw-r--r-- | common/rawaccel-base.hpp (renamed from common/rawaccel-settings.h) | 0 | ||||
| -rw-r--r-- | common/rawaccel-io.hpp | 14 | ||||
| -rw-r--r-- | common/rawaccel.hpp | 94 | ||||
| -rw-r--r-- | common/utility-rawinput.hpp | 15 | ||||
| -rw-r--r-- | common/utility.hpp (renamed from common/x64-util.hpp) | 0 |
12 files changed, 156 insertions, 124 deletions
diff --git a/common/accel-classic.hpp b/common/accel-classic.hpp index c7d6519..4385897 100644 --- a/common/accel-classic.hpp +++ b/common/accel-classic.hpp @@ -1,10 +1,11 @@ #pragma once +#include "rawaccel-base.hpp" +#include "utility.hpp" + #include <math.h> #include <float.h> -#include "rawaccel-settings.h" - namespace rawaccel { /// <summary> Struct to hold "classic" (linear raised to power) acceleration implementation. </summary> @@ -18,7 +19,8 @@ namespace rawaccel { power(args.power), accel_raised(pow(args.accel_classic, power - 1)) {} - double base_fn(double x) const { + double base_fn(double x) const + { return accel_raised * pow(x - offset, power) / x; } }; @@ -40,7 +42,8 @@ namespace rawaccel { } } - inline double operator()(double x) const { + double operator()(double x) const + { if (x <= offset) return 1; return sign * minsd(base_fn(x), sens_cap) + 1; } @@ -67,7 +70,8 @@ namespace rawaccel { } } - double operator()(double x) const { + double operator()(double x) const + { double output; if (x <= offset) return 1; @@ -81,7 +85,7 @@ namespace rawaccel { return sign * output + 1; } - + static double gain(double x, double accel, double power, double offset) { return power * pow(accel * (x - offset), power - 1); diff --git a/common/accel-motivity.hpp b/common/accel-motivity.hpp index abeedf1..a3cb027 100644 --- a/common/accel-motivity.hpp +++ b/common/accel-motivity.hpp @@ -1,8 +1,8 @@ #pragma once -#include <math.h> +#include "rawaccel-base.hpp" -#include "rawaccel-settings.h" +#include <math.h> #define RA_LOOKUP @@ -23,24 +23,27 @@ namespace rawaccel { double subtractive_constant; motivity(const accel_args& args) : - rate(pow(10,args.accel_motivity)), limit(2*log10(args.limit)), midpoint(log10(args.midpoint)) + rate(pow(10,args.accel_motivity)), + limit(2*log10(args.limit)), + midpoint(log10(args.midpoint)) { subtractive_constant = limit / 2; } - inline double operator()(double speed) const { + double operator()(double speed) const + { double log_speed = log10(speed); return pow(10, limit / (exp(-rate * (log_speed - midpoint)) + 1) - subtractive_constant); } - inline double apply(si_pair* lookup, double speed) const + double apply(si_pair* lookup, double speed) const { si_pair pair = lookup[map(speed)]; return pair.slope + pair.intercept / speed; } - inline int map(double speed) const + int map(double speed) const { int index = speed > 0 ? (int)(100 * log10(speed) + 201) : 0; @@ -50,7 +53,7 @@ namespace rawaccel { return index; } - inline void fill(si_pair* lookup) const + void fill(si_pair* lookup) const { double lookup_speed = 0; double integral_interval = 0; diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp index 2939dbd..31ed190 100644 --- a/common/accel-natural.hpp +++ b/common/accel-natural.hpp @@ -1,8 +1,8 @@ #pragma once -#include <math.h> +#include "rawaccel-base.hpp" -#include "rawaccel-settings.h" +#include <math.h> namespace rawaccel { @@ -22,7 +22,8 @@ namespace rawaccel { struct natural_legacy : natural_base { - double operator()(double x) const { + double operator()(double x) const + { if (x <= offset) return 1; double offset_x = x - offset; @@ -36,7 +37,8 @@ namespace rawaccel { struct natural : natural_base { double constant; - double operator()(double x) const { + double operator()(double x) const + { if (x <= offset) return 1; double offset_x = x - offset; diff --git a/common/accel-noaccel.hpp b/common/accel-noaccel.hpp index b4f1704..8d1e758 100644 --- a/common/accel-noaccel.hpp +++ b/common/accel-noaccel.hpp @@ -1,6 +1,6 @@ #pragma once -#include "rawaccel-settings.h" +#include "rawaccel-base.hpp" namespace rawaccel { @@ -10,7 +10,7 @@ namespace rawaccel { accel_noaccel(const accel_args&) {} accel_noaccel() = default; - inline double operator()(double) const { return 1; } + double operator()(double) const { return 1; } }; } diff --git a/common/accel-power.hpp b/common/accel-power.hpp index 17977a0..c8faabb 100644 --- a/common/accel-power.hpp +++ b/common/accel-power.hpp @@ -1,8 +1,8 @@ #pragma once -#include <math.h> +#include "rawaccel-base.hpp" -#include "rawaccel-settings.h" +#include <math.h> namespace rawaccel { @@ -17,7 +17,8 @@ namespace rawaccel { exponent(args.exponent), post_scale(args.weight) {} - inline double operator()(double speed) const { + double operator()(double speed) const + { // f(x) = (mx)^k return post_scale * pow(speed * pre_scale, exponent); } diff --git a/common/accel-union.hpp b/common/accel-union.hpp new file mode 100644 index 0000000..86d0cf4 --- /dev/null +++ b/common/accel-union.hpp @@ -0,0 +1,98 @@ +#pragma once + +#include "accel-classic.hpp" +#include "accel-natural.hpp" +#include "accel-power.hpp" +#include "accel-motivity.hpp" +#include "accel-noaccel.hpp" + +namespace rawaccel { + + enum class internal_mode { + classic_lgcy, + classic_gain, + natural_lgcy, + natural_gain, + power, + motivity, + noaccel + }; + + constexpr internal_mode make_mode(accel_mode m, bool legacy) + { + switch (m) { + case accel_mode::classic: + return legacy ? internal_mode::classic_lgcy : internal_mode::classic_gain; + case accel_mode::natural: + return legacy ? internal_mode::natural_lgcy : internal_mode::natural_gain; + case accel_mode::power: + return internal_mode::power; + case accel_mode::motivity: + return internal_mode::motivity; + default: + return internal_mode::noaccel; + } + } + + constexpr internal_mode make_mode(const accel_args& args) + { + return make_mode(args.mode, args.legacy); + } + + template <typename Visitor, typename Variant> + inline auto visit_accel(Visitor vis, Variant&& var) + { + switch (var.tag) { + case internal_mode::classic_lgcy: return vis(var.u.classic_l); + case internal_mode::classic_gain: return vis(var.u.classic_g); + case internal_mode::natural_lgcy: return vis(var.u.natural_l); + case internal_mode::natural_gain: return vis(var.u.natural_g); + case internal_mode::power: return vis(var.u.power); + case internal_mode::motivity: return vis(var.u.motivity); + default: return vis(var.u.noaccel); + } + } + + struct accel_variant { + si_pair* lookup; + + internal_mode tag = internal_mode::noaccel; + + union union_t { + classic classic_g; + classic_legacy classic_l; + natural natural_g; + natural_legacy natural_l; + power power; + motivity motivity; + accel_noaccel noaccel = {}; + } u = {}; + + accel_variant(const accel_args& args, si_pair* lut = nullptr) : + tag(make_mode(args)), lookup(lut) + { + visit_accel([&](auto& impl) { + impl = { args }; + }, *this); + + if (lookup && tag == internal_mode::motivity) { + u.motivity.fill(lookup); + } + + } + + double apply(double speed) const + { + if (lookup && tag == internal_mode::motivity) { + return u.motivity.apply(lookup, speed); + } + + return visit_accel([=](auto&& impl) { + return impl(speed); + }, *this); + } + + accel_variant() = default; + }; + +} diff --git a/common/common.vcxitems b/common/common.vcxitems index 7600755..9e0d971 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -19,15 +19,16 @@ <ClInclude Include="$(MSBuildThisFileDirectory)accel-natural.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-noaccel.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-power.hpp" /> + <ClInclude Include="$(MSBuildThisFileDirectory)accel-union.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-error.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-io-def.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-io.hpp" /> - <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-settings.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-base.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-version.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)utility-install.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)utility-rawinput.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)vec2.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)x64-util.hpp" /> + <ClInclude Include="$(MSBuildThisFileDirectory)utility.hpp" /> </ItemGroup> </Project>
\ No newline at end of file diff --git a/common/rawaccel-settings.h b/common/rawaccel-base.hpp index 308a3fc..308a3fc 100644 --- a/common/rawaccel-settings.h +++ b/common/rawaccel-base.hpp diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp index 703ea92..0d3ddee 100644 --- a/common/rawaccel-io.hpp +++ b/common/rawaccel-io.hpp @@ -6,7 +6,7 @@ #include <Windows.h> #include "rawaccel-io-def.h" -#include "rawaccel-settings.h" +#include "rawaccel-base.hpp" #include "rawaccel-version.h" #include "rawaccel-error.hpp" @@ -15,7 +15,8 @@ namespace rawaccel { - void io_control(DWORD code, void* in, DWORD in_size, void* out, DWORD out_size) { + inline void io_control(DWORD code, void* in, DWORD in_size, void* out, DWORD out_size) + { HANDLE ra_handle = INVALID_HANDLE_VALUE; ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0); @@ -44,19 +45,22 @@ namespace rawaccel { } } - settings read() { + inline settings read() + { settings args; io_control(RA_READ, NULL, 0, &args, sizeof(settings)); return args; } - void write(const settings& args) { + inline void write(const settings& args) + { auto in_ptr = const_cast<settings*>(&args); io_control(RA_WRITE, in_ptr, sizeof(settings), NULL, 0); } - version_t get_version() { + inline version_t get_version() + { version_t ver; io_control(RA_GET_VERSION, NULL, 0, &ver, sizeof(version_t)); return ver; diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index cb30820..67b4e61 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -1,16 +1,11 @@ #pragma once +#include "accel-union.hpp" +#include "utility.hpp" + #define _USE_MATH_DEFINES #include <math.h> -#include "x64-util.hpp" - -#include "accel-classic.hpp" -#include "accel-natural.hpp" -#include "accel-power.hpp" -#include "accel-motivity.hpp" -#include "accel-noaccel.hpp" - namespace rawaccel { /// <summary> Struct to hold vector rotation details. </summary> @@ -66,89 +61,6 @@ namespace rawaccel { v.y *= ratio; } - enum class internal_mode { - classic_lgcy, - classic_gain, - natural_lgcy, - natural_gain, - power, - motivity, - noaccel - }; - - constexpr internal_mode make_mode(accel_mode m, bool legacy) { - switch (m) { - case accel_mode::classic: - return legacy ? internal_mode::classic_lgcy : internal_mode::classic_gain; - case accel_mode::natural: - return legacy ? internal_mode::natural_lgcy : internal_mode::natural_gain; - case accel_mode::power: - return internal_mode::power; - case accel_mode::motivity: - return internal_mode::motivity; - default: - return internal_mode::noaccel; - } - } - - constexpr internal_mode make_mode(const accel_args& args) { - return make_mode(args.mode, args.legacy); - } - - template <typename Visitor, typename Variant> - inline auto visit_accel(Visitor vis, Variant&& var) { - switch (var.tag) { - case internal_mode::classic_lgcy: return vis(var.u.classic_l); - case internal_mode::classic_gain: return vis(var.u.classic_g); - case internal_mode::natural_lgcy: return vis(var.u.natural_l); - case internal_mode::natural_gain: return vis(var.u.natural_g); - case internal_mode::power: return vis(var.u.power); - case internal_mode::motivity: return vis(var.u.motivity); - default: return vis(var.u.noaccel); - } - } - - struct accel_variant { - si_pair* lookup; - - internal_mode tag = internal_mode::noaccel; - - union union_t { - classic classic_g; - classic_legacy classic_l; - natural natural_g; - natural_legacy natural_l; - power power; - motivity motivity; - accel_noaccel noaccel = {}; - } u = {}; - - accel_variant(const accel_args& args, si_pair* lut = nullptr) : - tag(make_mode(args)), lookup(lut) - { - visit_accel([&](auto& impl) { - impl = { args }; - }, *this); - - if (lookup && tag == internal_mode::motivity) { - u.motivity.fill(lookup); - } - - } - - inline double apply(double speed) const { - if (lookup && tag == internal_mode::motivity) { - return u.motivity.apply(lookup, speed); - } - - return visit_accel([=](auto&& impl) { - return impl(speed); - }, *this); - } - - accel_variant() = default; - }; - struct weighted_distance { double p = 2.0; double p_inverse = 0.5; diff --git a/common/utility-rawinput.hpp b/common/utility-rawinput.hpp index c43084b..eaa23db 100644 --- a/common/utility-rawinput.hpp +++ b/common/utility-rawinput.hpp @@ -11,7 +11,9 @@ #include <initguid.h> // needed for devpkey.h to parse properly #include <devpkey.h> -std::wstring dev_prop_wstr_from_interface(const WCHAR* interface_name, const DEVPROPKEY* key) { +inline +std::wstring dev_prop_wstr_from_interface(const WCHAR* interface_name, const DEVPROPKEY* key) +{ ULONG size = 0; DEVPROPTYPE type; CONFIGRET cm_res; @@ -37,14 +39,17 @@ std::wstring dev_prop_wstr_from_interface(const WCHAR* interface_name, const DEV return prop; } -std::wstring dev_id_from_interface(const WCHAR* interface_name) { +inline +std::wstring dev_id_from_interface(const WCHAR* interface_name) +{ auto id = dev_prop_wstr_from_interface(interface_name, &DEVPKEY_Device_InstanceId); id.resize(id.find_last_of('\\')); return id; } template <typename Func> -void rawinput_foreach_with_interface(Func fn, DWORD input_type = RIM_TYPEMOUSE) { +void rawinput_foreach_with_interface(Func fn, DWORD input_type = RIM_TYPEMOUSE) +{ const UINT RI_ERROR = -1; UINT num_devs = 0; @@ -75,7 +80,9 @@ void rawinput_foreach_with_interface(Func fn, DWORD input_type = RIM_TYPEMOUSE) // returns device handles corresponding to a "device id" // https://docs.microsoft.com/en-us/windows-hardware/drivers/install/device-ids -std::vector<HANDLE> rawinput_handles_from_dev_id(const std::wstring& device_id, DWORD input_type = RIM_TYPEMOUSE) { +inline +std::vector<HANDLE> rawinput_handles_from_dev_id(const std::wstring& device_id, DWORD input_type = RIM_TYPEMOUSE) +{ std::vector<HANDLE> handles; rawinput_foreach_with_interface([&](const auto& dev, const WCHAR* name) { diff --git a/common/x64-util.hpp b/common/utility.hpp index 40bc7c4..40bc7c4 100644 --- a/common/x64-util.hpp +++ b/common/utility.hpp |