Skip to content

Commit

Permalink
Use stick_stroke_release_detection_threshold_milliseconds, stick_stro…
Browse files Browse the repository at this point in the history
…ke_acceleration_measurement_duration_milliseconds
  • Loading branch information
tekezo committed Oct 19, 2023
1 parent 8ccd7d3 commit 2d0d0b0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
radian_(0.0),
magnitude_(0.0),
stroke_acceleration_(0.0),
remain_deadzone_threshold_milliseconds_(0),
stroke_acceleration_measurement_milliseconds_(0) {
stick_stroke_release_detection_threshold_milliseconds_(0),
stick_stroke_acceleration_measurement_duration_milliseconds_(0) {
auto now = pqrs::osx::chrono::mach_absolute_time_point();
deadzone_entered_at_ = now;
deadzone_left_at_ = now;
Expand Down Expand Up @@ -97,9 +97,8 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche

void update_configurations(const core_configuration::core_configuration& core_configuration,
const device_identifiers& device_identifiers) {
// TODO: Add config
remain_deadzone_threshold_milliseconds_ = 100;
stroke_acceleration_measurement_milliseconds_ = 50;
stick_stroke_release_detection_threshold_milliseconds_ = core_configuration.get_selected_profile().get_device_game_pad_stick_stroke_release_detection_threshold_milliseconds(device_identifiers);
stick_stroke_acceleration_measurement_duration_milliseconds_ = core_configuration.get_selected_profile().get_device_game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_(device_identifiers);

xy_stick_interval_milliseconds_formula_string_ = core_configuration.get_selected_profile().get_device_game_pad_xy_stick_interval_milliseconds_formula(device_identifiers);
wheels_stick_interval_milliseconds_formula_string_ = core_configuration.get_selected_profile().get_device_game_pad_wheels_stick_interval_milliseconds_formula(device_identifiers);
Expand Down Expand Up @@ -209,7 +208,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
deadzone_entered_at_ = now;
stroke_acceleration_ = 0.0;
},
std::chrono::milliseconds(remain_deadzone_threshold_milliseconds_));
std::chrono::milliseconds(stick_stroke_release_detection_threshold_milliseconds_));
}
} else {
deadzone_timer_.stop();
Expand All @@ -219,7 +218,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
}
}

if (pqrs::osx::chrono::make_milliseconds(now - deadzone_left_at_).count() < stroke_acceleration_measurement_milliseconds_) {
if (pqrs::osx::chrono::make_milliseconds(now - deadzone_left_at_).count() < stick_stroke_acceleration_measurement_duration_milliseconds_) {
stroke_acceleration_ = std::max(stroke_acceleration_, magnitude_);
}
}
Expand Down Expand Up @@ -252,8 +251,8 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
absolute_time_point deadzone_entered_at_;
absolute_time_point deadzone_left_at_;

int remain_deadzone_threshold_milliseconds_;
int stroke_acceleration_measurement_milliseconds_;
int stick_stroke_release_detection_threshold_milliseconds_;
int stick_stroke_acceleration_measurement_duration_milliseconds_;
std::string xy_stick_interval_milliseconds_formula_string_;
std::string wheels_stick_interval_milliseconds_formula_string_;
std::string x_formula_string_;
Expand Down
10 changes: 5 additions & 5 deletions src/share/core_configuration/details/profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,24 +504,24 @@ class profile final {
}
}

int get_device_game_pad_stick_release_detection_threshold_milliseconds(const device_identifiers& identifiers) const {
int get_device_game_pad_stick_stroke_release_detection_threshold_milliseconds(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
if (auto value = d.get_game_pad_stick_release_detection_threshold_milliseconds()) {
if (auto value = d.get_game_pad_stick_stroke_release_detection_threshold_milliseconds()) {
return *value;
}
}
}
return device::game_pad_stick_release_detection_threshold_milliseconds_default_value;
return device::game_pad_stick_stroke_release_detection_threshold_milliseconds_default_value;
}

void set_device_game_pad_stick_release_detection_threshold_milliseconds(const device_identifiers& identifiers,
void set_device_game_pad_stick_stroke_release_detection_threshold_milliseconds(const device_identifiers& identifiers,
std::optional<int> value) {
add_device(identifiers);

for (auto&& device : devices_) {
if (device.get_identifiers() == identifiers) {
device.set_game_pad_stick_release_detection_threshold_milliseconds(value);
device.set_game_pad_stick_stroke_release_detection_threshold_milliseconds(value);
return;
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/share/core_configuration/details/profile/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace core_configuration {
namespace details {
class device final {
public:
static constexpr int game_pad_stick_release_detection_threshold_milliseconds_default_value = 100;
static constexpr int game_pad_stick_stroke_release_detection_threshold_milliseconds_default_value = 100;
static constexpr int game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_default_value = 50;

static constexpr double game_pad_xy_stick_deadzone_default_value = 0.1;
Expand Down Expand Up @@ -140,10 +140,10 @@ class device final {

game_pad_swap_sticks_ = value.get<bool>();

} else if (key == "game_pad_stick_release_detection_threshold_milliseconds") {
} else if (key == "game_pad_stick_stroke_release_detection_threshold_milliseconds") {
pqrs::json::requires_number(value, "`" + key + "`");

game_pad_stick_release_detection_threshold_milliseconds_ = value.get<int>();
game_pad_stick_stroke_release_detection_threshold_milliseconds_ = value.get<int>();

} else if (key == "game_pad_stick_stroke_acceleration_measurement_duration_milliseconds") {
pqrs::json::requires_number(value, "`" + key + "`");
Expand Down Expand Up @@ -252,8 +252,8 @@ class device final {
j["mouse_swap_xy"] = mouse_swap_xy_;
j["mouse_swap_wheels"] = mouse_swap_wheels_;
j["game_pad_swap_sticks"] = game_pad_swap_sticks_;
if (game_pad_stick_release_detection_threshold_milliseconds_ != std::nullopt) {
j["game_pad_stick_release_detection_threshold_milliseconds"] = *game_pad_stick_release_detection_threshold_milliseconds_;
if (game_pad_stick_stroke_release_detection_threshold_milliseconds_ != std::nullopt) {
j["game_pad_stick_stroke_release_detection_threshold_milliseconds"] = *game_pad_stick_stroke_release_detection_threshold_milliseconds_;
}
if (game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_ != std::nullopt) {
j["game_pad_stick_stroke_acceleration_measurement_duration_milliseconds"] = *game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_;
Expand Down Expand Up @@ -390,11 +390,11 @@ class device final {
coordinate_between_properties();
}

std::optional<int> get_game_pad_stick_release_detection_threshold_milliseconds(void) const {
return game_pad_stick_release_detection_threshold_milliseconds_;
std::optional<int> get_game_pad_stick_stroke_release_detection_threshold_milliseconds(void) const {
return game_pad_stick_stroke_release_detection_threshold_milliseconds_;
}
void set_game_pad_stick_release_detection_threshold_milliseconds(std::optional<int> value) {
game_pad_stick_release_detection_threshold_milliseconds_ = value;
void set_game_pad_stick_stroke_release_detection_threshold_milliseconds(std::optional<int> value) {
game_pad_stick_stroke_release_detection_threshold_milliseconds_ = value;

coordinate_between_properties();
}
Expand Down Expand Up @@ -562,7 +562,7 @@ class device final {
bool mouse_swap_xy_;
bool mouse_swap_wheels_;
bool game_pad_swap_sticks_;
std::optional<int> game_pad_stick_release_detection_threshold_milliseconds_;
std::optional<int> game_pad_stick_stroke_release_detection_threshold_milliseconds_;
std::optional<int> game_pad_stick_stroke_acceleration_measurement_duration_milliseconds_;
std::optional<double> game_pad_xy_stick_deadzone_;
std::optional<double> game_pad_wheels_stick_deadzone_;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core_configuration/src/device_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ void run_device_test(void) {
{"mouse_flip_x", true},
{"mouse_swap_wheels", true},
{"game_pad_swap_sticks", true},
{"game_pad_stick_release_detection_threshold_milliseconds", 200},
{"game_pad_stick_stroke_release_detection_threshold_milliseconds", 200},
{"game_pad_stick_stroke_acceleration_measurement_duration_milliseconds", 100},
{"game_pad_xy_stick_deadzone", 0.08},
{"game_pad_wheels_stick_deadzone", 0.08},
Expand Down Expand Up @@ -398,7 +398,7 @@ void run_device_test(void) {
}},
{"ignore", true},
{"game_pad_swap_sticks", true},
{"game_pad_stick_release_detection_threshold_milliseconds", 200},
{"game_pad_stick_stroke_release_detection_threshold_milliseconds", 200},
{"game_pad_stick_stroke_acceleration_measurement_duration_milliseconds", 100},
{"game_pad_xy_stick_deadzone", 0.08},
{"game_pad_wheels_stick_deadzone", 0.08},
Expand Down

0 comments on commit 2d0d0b0

Please sign in to comment.