summaryrefslogtreecommitdiff
path: root/converter/converter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'converter/converter.cpp')
-rw-r--r--converter/converter.cpp70
1 files changed, 30 insertions, 40 deletions
diff --git a/converter/converter.cpp b/converter/converter.cpp
index 230e1be..ad92f8c 100644
--- a/converter/converter.cpp
+++ b/converter/converter.cpp
@@ -1,3 +1,5 @@
+#include <rawaccel-base.hpp>
+
#include <array>
#include <charconv>
#include <filesystem>
@@ -7,9 +9,8 @@
#include <sstream>
#include <string>
-#include <rawaccel-settings.h>
-
using namespace System;
+using namespace System::IO;
using namespace System::Runtime::InteropServices;
using namespace Newtonsoft::Json;
@@ -108,7 +109,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 +118,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.decay_rate = accel * prescale / sens;
+ args.offset = get("Offset").value_or(0);
+ args.mode = ra::accel_mode::natural;
+ args.legacy = legacy;
+
return args;
}
@@ -130,25 +136,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;
}
@@ -156,7 +153,7 @@ ra::accel_args convert_quake(const ia_settings_t& ia_settings, bool legacy) {
bool try_convert(const ia_settings_t& ia_settings) {
auto get = make_extractor(ia_settings);
- ra::settings ra_settings;
+ ra::settings& ra_settings = *(new ra::settings());
ra_settings.degrees_rotation = get("Angle", "AngleAdjustment").value_or(0);
ra_settings.sens = {
@@ -168,17 +165,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: {
@@ -187,9 +182,9 @@ bool try_convert(const ia_settings_t& ia_settings) {
}
default: return false;
}
-
+
DriverSettings^ new_settings = Marshal::PtrToStructure<DriverSettings^>((IntPtr)&ra_settings);
- auto errors = DriverInterop::GetSettingsErrors(new_settings);
+ SettingsErrors^ errors = gcnew SettingsErrors(new_settings);
if (!errors->Empty()) {
Console::WriteLine("Bad settings: {0}", errors);
@@ -197,21 +192,16 @@ bool try_convert(const ia_settings_t& ia_settings) {
}
Console::Write("Sending to driver... ");
- DriverInterop::Write(new_settings);
+ (gcnew ManagedAccel(gcnew ExtendedSettings(new_settings)))->Activate();
Console::WriteLine("done");
Console::Write("Generating settings.json... ");
- auto json = JsonConvert::SerializeObject(new_settings, Formatting::Indented);
- System::IO::File::WriteAllText("settings.json", json);
+ File::WriteAllText("settings.json", RaConvert::Settings(new_settings));
Console::WriteLine("done");
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;
- }
+ }
}
}