Skip to content

Commit

Permalink
game_pad_xy_stick_interval_milliseconds_formula_ -> game_pad_xy_stick…
Browse files Browse the repository at this point in the history
…_continued_movement_interval_milliseconds_, game_pad_wheels_stick_interval_milliseconds_formula_ -> game_pad_wheels_stick_continued_movement_interval_milliseconds_
  • Loading branch information
tekezo committed Jan 15, 2024
1 parent 8f33ab1 commit 3175fbf
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,21 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
switch (stick_type_) {
case stick_type::xy:
continued_movement_absolute_magnitude_threshold_ = core_configuration.get_selected_profile().get_device_game_pad_xy_stick_continued_movement_absolute_magnitude_threshold(device_identifiers);
continued_movement_interval_milliseconds_ = core_configuration.get_selected_profile().get_device_game_pad_xy_stick_continued_movement_interval_milliseconds(device_identifiers);
flicking_input_window_milliseconds_ = core_configuration.get_selected_profile().get_device_game_pad_xy_stick_flicking_input_window_milliseconds(device_identifiers);
break;
case stick_type::wheels:
continued_movement_absolute_magnitude_threshold_ = core_configuration.get_selected_profile().get_device_game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold(device_identifiers);
continued_movement_interval_milliseconds_ = core_configuration.get_selected_profile().get_device_game_pad_wheels_stick_continued_movement_interval_milliseconds(device_identifiers);
flicking_input_window_milliseconds_ = core_configuration.get_selected_profile().get_device_game_pad_wheels_stick_flicking_input_window_milliseconds(device_identifiers);
break;
}

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);
x_formula_string_ = core_configuration.get_selected_profile().get_device_game_pad_stick_x_formula(device_identifiers);
y_formula_string_ = core_configuration.get_selected_profile().get_device_game_pad_stick_y_formula(device_identifiers);
vertical_wheel_formula_string_ = core_configuration.get_selected_profile().get_device_game_pad_stick_vertical_wheel_formula(device_identifiers);
horizontal_wheel_formula_string_ = core_configuration.get_selected_profile().get_device_game_pad_stick_horizontal_wheel_formula(device_identifiers);

xy_stick_interval_milliseconds_formula_ = make_formula_expression(xy_stick_interval_milliseconds_formula_string_);
wheels_stick_interval_milliseconds_formula_ = make_formula_expression(wheels_stick_interval_milliseconds_formula_string_);
x_formula_ = make_formula_expression(x_formula_string_);
y_formula_ = make_formula_expression(y_formula_string_);
vertical_wheel_formula_ = make_formula_expression(vertical_wheel_formula_string_);
Expand Down Expand Up @@ -234,13 +232,13 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
switch (stick_type_) {
case stick_type::xy: {
auto [x, y] = xy_hid_values();
auto interval = xy_stick_interval();
auto interval = continued_movement_interval_milliseconds();
hid_values_updated(x, y, interval, event_origin_);
break;
}
case stick_type::wheels: {
auto [h, v] = wheels_hid_values();
auto interval = wheels_stick_interval();
auto interval = continued_movement_interval_milliseconds();
hid_values_updated(h, -v, interval, event_origin_);
break;
}
Expand Down Expand Up @@ -300,38 +298,12 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
return std::make_pair(h, v);
}

std::chrono::milliseconds xy_stick_interval(void) const {
std::chrono::milliseconds continued_movement_interval_milliseconds(void) const {
if (continued_movement_magnitude_ == 0.0) {
return std::chrono::milliseconds(0);
}

auto interval = xy_stick_interval_milliseconds_formula_.value();
if (std::isnan(interval)) {
logger::get_logger()->error("game_pad_stick_converter xy_stick_interval_milliseconds_formula_ returns nan: {0} (radian: {1}, magnitude: {2})",
xy_stick_interval_milliseconds_formula_string_,
radian_,
delta_magnitude_);
interval = 0;
}

return std::chrono::milliseconds(static_cast<int>(interval));
}

std::chrono::milliseconds wheels_stick_interval(void) const {
if (continued_movement_magnitude_ == 0.0) {
return std::chrono::milliseconds(0);
}

auto interval = wheels_stick_interval_milliseconds_formula_.value();
if (std::isnan(interval)) {
logger::get_logger()->error("game_pad_stick_converter wheels_stick_interval_milliseconds_formula_ returns nan: {0} (radian: {1}, magnitude: {2})",
wheels_stick_interval_milliseconds_formula_string_,
radian_,
delta_magnitude_);
interval = 0;
}

return std::chrono::milliseconds(static_cast<int>(interval));
return std::chrono::milliseconds(continued_movement_interval_milliseconds_);
}

exprtk_utility::expression_t make_formula_expression(const std::string& formula) {
Expand Down Expand Up @@ -362,15 +334,12 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
//

double continued_movement_absolute_magnitude_threshold_;
int continued_movement_interval_milliseconds_;
int flicking_input_window_milliseconds_;
std::string xy_stick_interval_milliseconds_formula_string_;
std::string wheels_stick_interval_milliseconds_formula_string_;
std::string x_formula_string_;
std::string y_formula_string_;
std::string vertical_wheel_formula_string_;
std::string horizontal_wheel_formula_string_;
exprtk_utility::expression_t xy_stick_interval_milliseconds_formula_;
exprtk_utility::expression_t wheels_stick_interval_milliseconds_formula_;
exprtk_utility::expression_t x_formula_;
exprtk_utility::expression_t y_formula_;
exprtk_utility::expression_t vertical_wheel_formula_;
Expand Down
112 changes: 79 additions & 33 deletions src/share/core_configuration/details/profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,44 @@ class profile final {
}
}

//
// game_pad_xy_stick_continued_movement_interval_milliseconds
//

bool has_device_game_pad_xy_stick_continued_movement_interval_milliseconds(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
if (auto value = d.get_game_pad_xy_stick_continued_movement_interval_milliseconds()) {
return true;
}
}
}
return false;
}

int get_device_game_pad_xy_stick_continued_movement_interval_milliseconds(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
if (auto value = d.get_game_pad_xy_stick_continued_movement_interval_milliseconds()) {
return *value;
}
}
}
return device::game_pad_xy_stick_continued_movement_interval_milliseconds_default_value;
}

void set_device_game_pad_xy_stick_continued_movement_interval_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_xy_stick_continued_movement_interval_milliseconds(value);
return;
}
}
}

//
// game_pad_xy_stick_flicking_input_window_milliseconds
//
Expand All @@ -553,7 +591,7 @@ class profile final {
return false;
}

double get_device_game_pad_xy_stick_flicking_input_window_milliseconds(const device_identifiers& identifiers) const {
int get_device_game_pad_xy_stick_flicking_input_window_milliseconds(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
if (auto value = d.get_game_pad_xy_stick_flicking_input_window_milliseconds()) {
Expand All @@ -565,7 +603,7 @@ class profile final {
}

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

for (auto&& device : devices_) {
Expand Down Expand Up @@ -615,89 +653,85 @@ class profile final {
}

//
// game_pad_wheels_stick_flicking_input_window_milliseconds
// game_pad_wheels_stick_continued_movement_interval_milliseconds
//

bool has_device_game_pad_wheels_stick_flicking_input_window_milliseconds(const device_identifiers& identifiers) const {
bool has_device_game_pad_wheels_stick_continued_movement_interval_milliseconds(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
if (auto value = d.get_game_pad_wheels_stick_flicking_input_window_milliseconds()) {
if (auto value = d.get_game_pad_wheels_stick_continued_movement_interval_milliseconds()) {
return true;
}
}
}
return false;
}

double get_device_game_pad_wheels_stick_flicking_input_window_milliseconds(const device_identifiers& identifiers) const {
int get_device_game_pad_wheels_stick_continued_movement_interval_milliseconds(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
if (auto value = d.get_game_pad_wheels_stick_flicking_input_window_milliseconds()) {
if (auto value = d.get_game_pad_wheels_stick_continued_movement_interval_milliseconds()) {
return *value;
}
}
}
return device::game_pad_wheels_stick_flicking_input_window_milliseconds_default_value;
return device::game_pad_wheels_stick_continued_movement_interval_milliseconds_default_value;
}

void set_device_game_pad_wheels_stick_flicking_input_window_milliseconds(const device_identifiers& identifiers,
std::optional<double> value) {
void set_device_game_pad_wheels_stick_continued_movement_interval_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_wheels_stick_flicking_input_window_milliseconds(value);
device.set_game_pad_wheels_stick_continued_movement_interval_milliseconds(value);
return;
}
}
}

std::string get_device_game_pad_xy_stick_interval_milliseconds_formula(const device_identifiers& identifiers) const {
//
// game_pad_wheels_stick_flicking_input_window_milliseconds
//

bool has_device_game_pad_wheels_stick_flicking_input_window_milliseconds(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
if (auto value = d.get_game_pad_xy_stick_interval_milliseconds_formula()) {
return *value;
if (auto value = d.get_game_pad_wheels_stick_flicking_input_window_milliseconds()) {
return true;
}
}
}
return std::string(device::game_pad_xy_stick_interval_milliseconds_formula_default_value);
}

void set_device_game_pad_xy_stick_interval_milliseconds_formula(const device_identifiers& identifiers,
const std::optional<std::string>& value) {
add_device(identifiers);

for (auto&& device : devices_) {
if (device.get_identifiers() == identifiers) {
device.set_game_pad_xy_stick_interval_milliseconds_formula(value);
return;
}
}
return false;
}

std::string get_device_game_pad_wheels_stick_interval_milliseconds_formula(const device_identifiers& identifiers) const {
int get_device_game_pad_wheels_stick_flicking_input_window_milliseconds(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
if (auto value = d.get_game_pad_wheels_stick_interval_milliseconds_formula()) {
if (auto value = d.get_game_pad_wheels_stick_flicking_input_window_milliseconds()) {
return *value;
}
}
}
return std::string(device::game_pad_wheels_stick_interval_milliseconds_formula_default_value);
return device::game_pad_wheels_stick_flicking_input_window_milliseconds_default_value;
}

void set_device_game_pad_wheels_stick_interval_milliseconds_formula(const device_identifiers& identifiers,
const std::optional<std::string>& value) {
void set_device_game_pad_wheels_stick_flicking_input_window_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_wheels_stick_interval_milliseconds_formula(value);
device.set_game_pad_wheels_stick_flicking_input_window_milliseconds(value);
return;
}
}
}

//
// game_pad_stick_x_formula
//

std::string get_device_game_pad_stick_x_formula(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
Expand All @@ -721,6 +755,10 @@ class profile final {
}
}

//
// game_pad_stick_y_formula
//

std::string get_device_game_pad_stick_y_formula(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
Expand All @@ -744,6 +782,10 @@ class profile final {
}
}

//
// game_pad_stick_vertical_wheel_formula
//

std::string get_device_game_pad_stick_vertical_wheel_formula(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
Expand All @@ -767,6 +809,10 @@ class profile final {
}
}

//
// game_pad_stick_horizontal_wheel_formula
//

std::string get_device_game_pad_stick_horizontal_wheel_formula(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
Expand Down
Loading

0 comments on commit 3175fbf

Please sign in to comment.