Skip to content

Commit 4306e7e

Browse files
authored
Merge pull request RawAccelOfficial#36 from a1xd/gain-conv-fix
fix gain cap conversion
2 parents 625ccbe + 4ec037a commit 4306e7e

File tree

6 files changed

+116
-107
lines changed

6 files changed

+116
-107
lines changed

converter/converter.cpp

+42-37
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <fstream>
55
#include <iostream>
66
#include <optional>
7+
#include <sstream>
78
#include <string>
89

910
#include <rawaccel-settings.h>
@@ -44,12 +45,16 @@ static inline void trim(std::string& s) {
4445
rtrim(s);
4546
}
4647

47-
bool yes() {
48-
for (;;) {
49-
wchar_t c = _getwch();
50-
if (c == 'y') return true;
51-
else if (c == 'n') return false;
52-
}
48+
bool ask(std::string_view question) {
49+
std::cout << question << " (Y/N)" << std::endl;
50+
wchar_t ch;
51+
bool yes;
52+
do
53+
{
54+
ch = towupper(_getwch());
55+
yes = ch == 'Y';
56+
} while (ch != 'N' && !yes);
57+
return yes;
5358
}
5459

5560
using ia_settings_t = std::vector<std::pair<std::string, double>>;
@@ -128,10 +133,10 @@ ra::accel_args convert_quake(const ia_settings_t& ia_settings, bool legacy) {
128133
double offset = get("Offset").value_or(0);
129134

130135
ra::accel_args args;
131-
132-
double accel_b = std::pow(accel * prescale, power - 1) / sens;
133-
double accel_e = 1 / (power - 1);
134-
args.accel = std::pow(accel_b, accel_e);
136+
double powm1 = power - 1;
137+
double rpowm1 = 1 / powm1;
138+
double accel_b = std::pow(accel * prescale, powm1) / sens;
139+
args.accel = std::pow(accel_b, rpowm1);
135140
args.exponent = power;
136141
args.legacy_offset = legacy;
137142
args.offset = offset;
@@ -142,9 +147,7 @@ ra::accel_args convert_quake(const ia_settings_t& ia_settings, bool legacy) {
142147
args.scale_cap = cap_converted;
143148
}
144149
else {
145-
double b = (cap_converted - 1) / power;
146-
double e = 1 / (power - 1);
147-
args.gain_cap = offset + (1 / accel) * std::pow(b, e);
150+
args.gain_cap = offset + std::pow(cap_converted - 1, rpowm1) / args.accel;
148151
}
149152

150153
return args;
@@ -165,16 +168,16 @@ bool try_convert(const ia_settings_t& ia_settings) {
165168

166169
switch (static_cast<IA_MODES_ENUM>(mode)) {
167170
case IA_QL: {
168-
std::cout << "We recommend trying out our new cap and offset styles.\n"
169-
"Use new cap and offset? (y|n)\n";
171+
bool legacy = !ask("We recommend trying out our new cap and offset styles.\n"
172+
"Use new cap and offset?");
170173
ra_settings.modes.x = ra::accel_mode::classic;
171-
ra_settings.argsv.x = convert_quake(ia_settings, !yes());
174+
ra_settings.argsv.x = convert_quake(ia_settings, legacy);
172175
break;
173176
}
174177
case IA_NAT: {
175-
std::cout << "Raw Accel offers a new mode that you might like more than Natural.\n"
176-
"Wanna try it out now? (y|n)\n";
177-
ra_settings.modes.x = yes() ? ra::accel_mode::naturalgain : ra::accel_mode::natural;
178+
bool nat_gain = ask("Raw Accel offers a new mode that you might like more than Natural.\n"
179+
"Wanna try it out now?");
180+
ra_settings.modes.x = nat_gain ? ra::accel_mode::naturalgain : ra::accel_mode::natural;
178181
ra_settings.argsv.x = convert_natural(ia_settings);
179182
break;
180183
}
@@ -223,29 +226,31 @@ int main()
223226
}
224227

225228
if (opt_path) {
226-
std::cout << "Found " << opt_path->filename() <<
227-
"\n\nConvert and send settings generated from " <<
228-
opt_path->filename() << "? (y|n)\n";
229-
if (!yes()) return 0;
230-
try {
231-
if (!try_convert(parse_ia_settings(opt_path.value())))
232-
std::cout << "Unable to convert settings.\n";
233-
}
234-
catch (DriverNotInstalledException^) {
235-
Console::WriteLine("\nDriver is not installed.");
236-
}
237-
catch (Exception^ e) {
238-
Console::WriteLine("\nError: " + e->ToString());
239-
}
240-
catch (const std::exception& e) {
241-
std::cout << "Error: " << e.what() << '\n';
229+
std::string path = opt_path->filename().generic_string();
230+
std::stringstream ss;
231+
ss << "Found " << path <<
232+
"\n\nConvert and send settings generated from " << path << '?';
233+
if (ask(ss.str())) {
234+
try {
235+
if (!try_convert(parse_ia_settings(opt_path.value())))
236+
std::cout << "Unable to convert settings.\n";
237+
}
238+
catch (DriverNotInstalledException^) {
239+
Console::WriteLine("\nDriver is not installed.");
240+
}
241+
catch (Exception^ e) {
242+
Console::WriteLine("\nError: " + e->ToString());
243+
}
244+
catch (const std::exception& e) {
245+
std::cout << "Error: " << e.what() << '\n';
246+
}
242247
}
243248
}
244249
else {
245250
std::cout << "Drop your InterAccel settings/profile into this directory.\n"
246251
"Then run this program to generate the equivalent Raw Accel settings.\n";
247252
}
248-
249-
std::cout << "Press any key to close this window . . .\n";
253+
254+
std::cout << "Press any key to close this window . . ." << std::endl;
250255
_getwch();
251256
}

0 commit comments

Comments
 (0)