diff options
| author | a1xd <[email protected]> | 2021-04-01 01:51:31 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-04-01 01:51:31 -0400 |
| commit | 14bde56daf188bfc027dc8ead5b45ec0aa1109d6 (patch) | |
| tree | 6c674efea62c4e945e4d8ed3e947189742486015 /converter/converter.cpp | |
| parent | refactor lut/motivity (diff) | |
| download | rawaccel-14bde56daf188bfc027dc8ead5b45ec0aa1109d6.tar.xz rawaccel-14bde56daf188bfc027dc8ead5b45ec0aa1109d6.zip | |
update rest
grapher is still broken
refactored io / error handling a bit
Diffstat (limited to 'converter/converter.cpp')
| -rw-r--r-- | converter/converter.cpp | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/converter/converter.cpp b/converter/converter.cpp index 230e1be..7b71af3 100644 --- a/converter/converter.cpp +++ b/converter/converter.cpp @@ -1,3 +1,5 @@ +#include <rawaccel-base.hpp> + #include <array> #include <charconv> #include <filesystem> @@ -7,8 +9,6 @@ #include <sstream> #include <string> -#include <rawaccel-settings.h> - using namespace System; using namespace System::Runtime::InteropServices; using namespace Newtonsoft::Json; @@ -108,7 +108,7 @@ auto make_extractor(const ia_settings_t& ia_settings) { }; } -ra::accel_args convert_natural(const ia_settings_t& ia_settings) { +ra::accel_args convert_natural(const ia_settings_t& ia_settings, bool legacy) { auto get = make_extractor(ia_settings); double accel = get("Acceleration").value_or(0); @@ -117,8 +117,13 @@ ra::accel_args convert_natural(const ia_settings_t& ia_settings) { double prescale = get("Pre-ScaleX").value_or(1); ra::accel_args args; + args.limit = 1 + std::abs(cap - sens) / sens; - args.accel = accel * prescale / sens; + args.accel_natural = accel * prescale / sens; + args.offset = get("Offset").value_or(0); + args.mode = ra::accel_mode::natural; + args.legacy = legacy; + return args; } @@ -130,25 +135,16 @@ ra::accel_args convert_quake(const ia_settings_t& ia_settings, bool legacy) { double cap = get("SensitivityCap").value_or(0); double sens = get("Sensitivity").value_or(1); double prescale = get("Pre-ScaleX").value_or(1); - double offset = get("Offset").value_or(0); - - ra::accel_args args; - double powm1 = power - 1; - double rpowm1 = 1 / powm1; - double accel_b = std::pow(accel * prescale, powm1) / sens; - args.accel = std::pow(accel_b, rpowm1); - args.exponent = power; - args.legacy_offset = legacy; - args.offset = offset; - double cap_converted = cap / sens; + ra::accel_args args; - if (legacy || cap_converted <= 1) { - args.scale_cap = cap_converted; - } - else { - args.gain_cap = offset + std::pow(cap_converted - 1, rpowm1) / args.accel; - } + double accel_b = std::pow(accel * prescale, power - 1) / sens; + args.accel_classic = std::pow(accel_b, 1 / (power - 1)); + args.cap = cap / sens; + args.power = power; + args.offset = get("Offset").value_or(0); + args.mode = ra::accel_mode::classic; + args.legacy = legacy; return args; } @@ -168,17 +164,15 @@ bool try_convert(const ia_settings_t& ia_settings) { switch (static_cast<IA_MODES_ENUM>(mode)) { case IA_QL: { - bool legacy = !ask("We recommend trying out our new cap and offset styles.\n" - "Use new cap and offset?"); - ra_settings.modes.x = ra::accel_mode::classic; + bool legacy = !ask("We recommend trying out a new smooth cap style.\n" + "Use new cap style?"); ra_settings.argsv.x = convert_quake(ia_settings, legacy); break; } case IA_NAT: { - bool nat_gain = ask("Raw Accel offers a new mode that you might like more than Natural.\n" + bool legacy = !ask("Raw Accel offers a new mode that you might like more than Natural.\n" "Wanna try it out now?"); - ra_settings.modes.x = nat_gain ? ra::accel_mode::naturalgain : ra::accel_mode::natural; - ra_settings.argsv.x = convert_natural(ia_settings); + ra_settings.argsv.x = convert_natural(ia_settings, legacy); break; } case IA_LOG: { @@ -189,7 +183,7 @@ bool try_convert(const ia_settings_t& ia_settings) { } DriverSettings^ new_settings = Marshal::PtrToStructure<DriverSettings^>((IntPtr)&ra_settings); - auto errors = DriverInterop::GetSettingsErrors(new_settings); + auto errors = gcnew SettingsErrors(new_settings); if (!errors->Empty()) { Console::WriteLine("Bad settings: {0}", errors); @@ -197,7 +191,7 @@ bool try_convert(const ia_settings_t& ia_settings) { } Console::Write("Sending to driver... "); - DriverInterop::Write(new_settings); + (gcnew ManagedAccel(new_settings))->Activate(); Console::WriteLine("done"); Console::Write("Generating settings.json... "); @@ -208,10 +202,6 @@ bool try_convert(const ia_settings_t& ia_settings) { return true; } -public ref struct ASSEMBLY { - static initonly Version^ VERSION = ASSEMBLY::typeid->Assembly->GetName()->Version; -}; - int main() { auto close_prompt = [] { @@ -221,9 +211,9 @@ int main() }; try { - VersionHelper::ValidateAndGetDriverVersion(ASSEMBLY::VERSION); + VersionHelper::ValidOrThrow(); } - catch (VersionException^ ex) { + catch (InteropException^ ex) { Console::WriteLine(ex->Message); close_prompt(); } @@ -239,7 +229,7 @@ int main() entry.path().extension() == IA_PROFILE_EXT) { opt_path = entry; break; - } + } } } |