summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authora1xd <[email protected]>2020-10-14 19:56:11 -0400
committerGitHub <[email protected]>2020-10-14 19:56:11 -0400
commit625ccbe552183c7cb6a3e332bb0ab8c182929810 (patch)
tree78f8704c7a74113b09d4a49e76317bc7ac40add8
parentMerge pull request #33 from a1xd/1.1 (diff)
parentfix non-standard access of template base members (diff)
downloadrawaccel-625ccbe552183c7cb6a3e332bb0ab8c182929810.tar.xz
rawaccel-625ccbe552183c7cb6a3e332bb0ab8c182929810.zip
Merge pull request #35 from a1xd/1.1.1
1.1.1
-rw-r--r--common/accel-base.hpp18
-rw-r--r--common/rawaccel.hpp2
-rw-r--r--converter/converter.cpp195
-rw-r--r--converter/converter.vcxproj2
-rw-r--r--grapher/Layouts/MotivityLayout.cs2
5 files changed, 124 insertions, 95 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp
index 67a1b8f..ac7ac4d 100644
--- a/common/accel-base.hpp
+++ b/common/accel-base.hpp
@@ -1,7 +1,7 @@
#pragma once
namespace rawaccel {
-
+
/// <summary> Struct to hold arguments for an acceleration function. </summary>
struct accel_args {
double offset = 0;
@@ -31,16 +31,16 @@ namespace rawaccel {
struct additive_accel : accel_val_base<Func> {
additive_accel(const accel_args& args) : accel_val_base(args) {
- legacy_offset = args.legacy_offset;
- offset = args.offset;
- weight = args.weight;
+ this->legacy_offset = args.legacy_offset;
+ this->offset = args.offset;
+ this->weight = args.weight;
}
inline double operator()(double speed) const {
- double offset_speed = speed - offset;
+ double offset_speed = speed - this->offset;
if (offset_speed <= 0) return 1;
- if (legacy_offset) return 1 + fn.legacy_offset(offset_speed) * weight;
- return 1 + fn(offset_speed) * weight;
+ if (this->legacy_offset) return 1 + this->fn.legacy_offset(offset_speed) * this->weight;
+ return 1 + this->fn(offset_speed) * this->weight;
}
};
@@ -48,11 +48,11 @@ namespace rawaccel {
struct nonadditive_accel : accel_val_base<Func> {
nonadditive_accel(const accel_args& args) : accel_val_base(args) {
- if (args.weight > 0) weight = args.weight;
+ if (args.weight > 0) this->weight = args.weight;
}
inline double operator()(double speed) const {
- return fn(speed) * weight;
+ return this->fn(speed) * this->weight;
}
};
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index d325abe..ecd3850 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -45,7 +45,7 @@ namespace rawaccel {
/// <summary> Struct to hold clamp (min and max) details for acceleration application </summary>
struct accel_scale_clamp {
double lo = 0;
- double hi = 9;
+ double hi = 128;
/// <summary>
/// Clamps given input to min at lo, max at hi.
diff --git a/converter/converter.cpp b/converter/converter.cpp
index 3aff02c..e282ca4 100644
--- a/converter/converter.cpp
+++ b/converter/converter.cpp
@@ -45,137 +45,163 @@ static inline void trim(std::string& s) {
}
bool yes() {
- bool b;
- while (wchar_t c = _getwch()) {
- if (c == 'y') {
- b = true;
- break;
- }
- else if (c == 'n') {
- b = false;
- break;
- }
+ for (;;) {
+ wchar_t c = _getwch();
+ if (c == 'y') return true;
+ else if (c == 'n') return false;
}
- return b;
}
-bool try_convert(const fs::path& fp) {
- std::vector<std::pair<std::string, double>> kv_pairs;
+using ia_settings_t = std::vector<std::pair<std::string, double>>;
+
+ia_settings_t parse_ia_settings(const fs::path fp) {
+ ia_settings_t kv_pairs;
- {
- std::ifstream ifs(fp);
- std::string line;
+ std::ifstream ifs(fp);
+ std::string line;
- while (std::getline(ifs, line)) {
- if (line.empty()) continue;
+ while (std::getline(ifs, line)) {
+ if (line.empty()) continue;
- auto delim_pos = line.find('=');
- if (delim_pos == std::string::npos) continue;
+ auto delim_pos = line.find('=');
+ if (delim_pos == std::string::npos) continue;
- std::string key(line.substr(0, delim_pos));
- trim(key);
+ std::string key(line.substr(0, delim_pos));
+ trim(key);
- auto val_pos = line.find_first_not_of(" \t", delim_pos + 1);
- if (val_pos == std::string::npos) continue;
+ auto val_pos = line.find_first_not_of(" \t", delim_pos + 1);
+ if (val_pos == std::string::npos) continue;
- double val = 0;
+ double val = 0;
- auto [p, ec] = std::from_chars(&line[val_pos], &line[0] + line.size(), val);
+ auto [p, ec] = std::from_chars(&line[val_pos], &line[0] + line.size(), val);
- if (ec == std::errc()) {
+ if (ec == std::errc()) {
+ kv_pairs.emplace_back(key, val);
+ }
+ else if (key == "AccelMode") {
+ std::string mode_val = line.substr(val_pos);
+ rtrim(mode_val);
+ auto it = std::find(IA_MODES.begin(), IA_MODES.end(), mode_val);
+ if (it != IA_MODES.end()) {
+ val = static_cast<double>(std::distance(IA_MODES.begin(), it));
kv_pairs.emplace_back(key, val);
}
- else if (key == "AccelMode") {
- std::string mode_val = line.substr(val_pos);
- rtrim(mode_val);
- auto it = std::find(IA_MODES.begin(), IA_MODES.end(), mode_val);
- if (it != IA_MODES.end()) {
- val = static_cast<double>(std::distance(IA_MODES.begin(), it));
- kv_pairs.emplace_back(key, val);
- }
- }
}
}
- auto get = [&](auto... keys) -> std::optional<double> {
- auto it = std::find_if(kv_pairs.begin(), kv_pairs.end(), [=](auto&& p) {
+ return kv_pairs;
+}
+
+auto make_extractor(const ia_settings_t& ia_settings) {
+ return [&](auto... keys) -> std::optional<double> {
+ auto it = std::find_if(ia_settings.begin(), ia_settings.end(), [=](auto&& p) {
return ((p.first == keys) || ...);
});
- if (it == kv_pairs.end()) return std::nullopt;
+ if (it == ia_settings.end()) return std::nullopt;
return it->second;
};
+}
- ra::settings ra_settings;
- ra::accel_args& args = ra_settings.argsv.x;
-
- auto opt_mode = get("AccelMode");
- if (!opt_mode) opt_mode = 0.0;
+ra::accel_args convert_natural(const ia_settings_t& ia_settings) {
+ auto get = make_extractor(ia_settings);
- double accel = std::max(get("Acceleration").value_or(0), 0.0);
+ double accel = get("Acceleration").value_or(0);
+ double cap = get("SensitivityCap").value_or(0);
double sens = get("Sensitivity").value_or(1);
+ 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;
+ return args;
+}
+
+ra::accel_args convert_quake(const ia_settings_t& ia_settings, bool legacy) {
+ auto get = make_extractor(ia_settings);
+
+ double power = get("Power").value_or(2);
+ double accel = get("Acceleration").value_or(0);
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 accel_b = std::pow(accel * prescale, power - 1) / sens;
+ double accel_e = 1 / (power - 1);
+ args.accel = std::pow(accel_b, accel_e);
+ args.exponent = power;
+ args.legacy_offset = legacy;
+ args.offset = offset;
+
+ double cap_converted = cap / sens;
- std::cout << "We recommend trying out our new cap and offset styles.\n"
- "Use new cap and offset? (y|n)\n";
+ if (legacy || cap_converted <= 1) {
+ args.scale_cap = cap_converted;
+ }
+ else {
+ double b = (cap_converted - 1) / power;
+ double e = 1 / (power - 1);
+ args.gain_cap = offset + (1 / accel) * std::pow(b, e);
+ }
+
+ return args;
+}
- args.legacy_offset = !yes();
- args.offset = get("Offset").value_or(0);
- args.accel = accel / sens * get("Pre-ScaleX").value_or(1);
- args.limit = 1 + std::abs(cap - sens);
+bool try_convert(const ia_settings_t& ia_settings) {
+ auto get = make_extractor(ia_settings);
+
+ ra::settings ra_settings;
ra_settings.degrees_rotation = get("Angle", "AngleAdjustment").value_or(0);
ra_settings.sens = {
- get("Post-ScaleX").value_or(1),
- get("Post-ScaleY").value_or(1)
+ get("Post-ScaleX").value_or(1) * get("Pre-ScaleX").value_or(1),
+ get("Post-ScaleY").value_or(1) * get("Pre-ScaleY").value_or(1)
};
- switch (static_cast<IA_MODES_ENUM>(opt_mode.value())) {
+ double mode = get("AccelMode").value_or(IA_QL);
+
+ switch (static_cast<IA_MODES_ENUM>(mode)) {
case IA_QL: {
- auto opt_pow = get("Power");
- if (!opt_pow || opt_pow.value() <= 1) return false;
- args.exponent = opt_pow.value();
-
- if (args.legacy_offset || cap <= 1) {
- args.scale_cap = cap;
- }
- else {
- double b = (cap - 1) / args.exponent;
- double e = 1 / (args.exponent - 1);
- args.gain_cap = args.offset + (1 / accel) * std::pow(b, e);
- }
+ std::cout << "We recommend trying out our new cap and offset styles.\n"
+ "Use new cap and offset? (y|n)\n";
ra_settings.modes.x = ra::accel_mode::classic;
+ ra_settings.argsv.x = convert_quake(ia_settings, !yes());
break;
}
case IA_NAT: {
std::cout << "Raw Accel offers a new mode that you might like more than Natural.\n"
"Wanna try it out now? (y|n)\n";
ra_settings.modes.x = yes() ? ra::accel_mode::naturalgain : ra::accel_mode::natural;
+ ra_settings.argsv.x = convert_natural(ia_settings);
break;
}
case IA_LOG: {
std::cout << "Logarithmic accel mode is not supported.\n";
return true;
- }
+ }
default: return false;
}
-
+
DriverSettings^ new_settings = Marshal::PtrToStructure<DriverSettings^>((IntPtr)&ra_settings);
auto errors = DriverInterop::GetSettingsErrors(new_settings);
- if (errors->Empty()) {
- Console::Write("Sending to driver... ");
- DriverInterop::Write(new_settings);
- Console::WriteLine("done");
-
- Console::Write("Generating settings.json... ");
- auto json = JsonConvert::SerializeObject(new_settings, Formatting::Indented);
- System::IO::File::WriteAllText("settings.json", json);
- Console::WriteLine("done");
- }
- else {
- Console::WriteLine("Bad settings:\n" + errors->x->ToArray()[0]);
+ if (!errors->Empty()) {
+ Console::WriteLine("Bad settings: " + errors->x->ToArray()[0]);
+ return false;
}
+ Console::Write("Sending to driver... ");
+ DriverInterop::Write(new_settings);
+ Console::WriteLine("done");
+
+ Console::Write("Generating settings.json... ");
+ auto json = JsonConvert::SerializeObject(new_settings, Formatting::Indented);
+ System::IO::File::WriteAllText("settings.json", json);
+ Console::WriteLine("done");
+
return true;
}
@@ -202,14 +228,17 @@ int main()
opt_path->filename() << "? (y|n)\n";
if (!yes()) return 0;
try {
- if (!try_convert(opt_path.value()))
+ if (!try_convert(parse_ia_settings(opt_path.value())))
std::cout << "Unable to convert settings.\n";
}
catch (DriverNotInstalledException^) {
- std::cout << "\nDriver is not installed\n";
+ Console::WriteLine("\nDriver is not installed.");
+ }
+ catch (Exception^ e) {
+ Console::WriteLine("\nError: " + e->ToString());
}
catch (const std::exception& e) {
- std::cout << "Error: \n" << e.what() << '\n';
+ std::cout << "Error: " << e.what() << '\n';
}
}
else {
diff --git a/converter/converter.vcxproj b/converter/converter.vcxproj
index 3cbe7bf..2bc5080 100644
--- a/converter/converter.vcxproj
+++ b/converter/converter.vcxproj
@@ -65,7 +65,7 @@
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
- <GenerateDebugInformation>true</GenerateDebugInformation>
+ <GenerateDebugInformation>DebugFull</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
diff --git a/grapher/Layouts/MotivityLayout.cs b/grapher/Layouts/MotivityLayout.cs
index 839de58..b06e4fc 100644
--- a/grapher/Layouts/MotivityLayout.cs
+++ b/grapher/Layouts/MotivityLayout.cs
@@ -19,7 +19,7 @@ namespace grapher.Layouts
AccelLayout = new OptionLayout(true, Acceleration);
ScaleLayout = new OptionLayout(false, string.Empty);
CapLayout = new OptionLayout(false, string.Empty);
- WeightLayout = new OptionLayout(true, Weight);
+ WeightLayout = new OptionLayout(false, string.Empty);
OffsetLayout = new OptionLayout(false, string.Empty);
LimitLayout = new OptionLayout(true, Motivity);
ExponentLayout = new OptionLayout(false, string.Empty);