Skip to content

Commit

Permalink
Add game_pad_xy_stick_flicking_input_window_milliseconds_, game_pad_w…
Browse files Browse the repository at this point in the history
…heels_stick_flicking_input_window_milliseconds_
  • Loading branch information
tekezo committed Jan 10, 2024
1 parent 58f64cf commit 09cef27
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
continued_movement_magnitude_(0.0),
previous_magnitude_(0.0),
event_origin_(event_origin::none),
continued_movement_absolute_magnitude_threshold_(1.0) {
continued_movement_absolute_magnitude_threshold_(1.0),
flicking_input_window_milliseconds_(0) {
}

~stick(void) {
Expand Down Expand Up @@ -150,9 +151,11 @@ 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);
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);
flicking_input_window_milliseconds_ = core_configuration.get_selected_profile().get_device_game_pad_wheels_stick_flicking_input_window_milliseconds(device_identifiers);
break;
}

Expand Down Expand Up @@ -191,9 +194,8 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
delta_magnitude_history_.push_back(delta_magnitude_history_entry(now, dm));
delta_magnitude_history_.erase(std::remove_if(std::begin(delta_magnitude_history_),
std::end(delta_magnitude_history_),
[now](auto&& e) {
// TODO: Replace hard-coded threshold
return pqrs::osx::chrono::make_milliseconds(now - e.get_time()) > std::chrono::milliseconds(100);
[this, now](auto&& e) {
return pqrs::osx::chrono::make_milliseconds(now - e.get_time()) > std::chrono::milliseconds(flicking_input_window_milliseconds_);
}),
std::end(delta_magnitude_history_));

Expand Down Expand Up @@ -354,6 +356,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
//

double continued_movement_absolute_magnitude_threshold_;
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_;
Expand Down
84 changes: 84 additions & 0 deletions src/share/core_configuration/details/profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ class profile final {
}
}

//
// game_pad_xy_stick_continued_movement_absolute_magnitude_threshold
//

bool has_device_game_pad_xy_stick_continued_movement_absolute_magnitude_threshold(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
Expand Down Expand Up @@ -534,6 +538,48 @@ class profile final {
}
}

//
// game_pad_xy_stick_flicking_input_window_milliseconds
//

bool has_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()) {
return true;
}
}
}
return false;
}

double 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()) {
return *value;
}
}
}
return device::game_pad_xy_stick_flicking_input_window_milliseconds_default_value;
}

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

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

//
// game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold
//

bool has_device_game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
Expand Down Expand Up @@ -568,6 +614,44 @@ class profile final {
}
}

//
// 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_wheels_stick_flicking_input_window_milliseconds()) {
return true;
}
}
}
return false;
}

double 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_flicking_input_window_milliseconds()) {
return *value;
}
}
}
return device::game_pad_wheels_stick_flicking_input_window_milliseconds_default_value;
}

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

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

std::string get_device_game_pad_xy_stick_interval_milliseconds_formula(const device_identifiers& identifiers) const {
for (const auto& d : devices_) {
if (d.get_identifiers() == identifiers) {
Expand Down
35 changes: 35 additions & 0 deletions src/share/core_configuration/details/profile/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace details {
class device final {
public:
static constexpr double game_pad_xy_stick_continued_movement_absolute_magnitude_threshold_default_value = 1.0;
static constexpr int game_pad_xy_stick_flicking_input_window_milliseconds_default_value = 50;

static constexpr double game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold_default_value = 1.0;
static constexpr int game_pad_wheels_stick_flicking_input_window_milliseconds_default_value = 50;

static constexpr std::string_view game_pad_xy_stick_interval_milliseconds_formula_default_value =
"20";
Expand Down Expand Up @@ -137,11 +140,21 @@ class device final {

game_pad_xy_stick_continued_movement_absolute_magnitude_threshold_ = value.get<double>();

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

game_pad_xy_stick_flicking_input_window_milliseconds_ = value.get<int>();

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

game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold_ = value.get<double>();

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

game_pad_wheels_stick_flicking_input_window_milliseconds_ = value.get<int>();

} else if (key == "game_pad_xy_stick_interval_milliseconds_formula") {
game_pad_xy_stick_interval_milliseconds_formula_ = unmarshal_formula(value, key);

Expand Down Expand Up @@ -245,7 +258,9 @@ class device final {
}

OPTIONAL_SETTING(game_pad_xy_stick_continued_movement_absolute_magnitude_threshold);
OPTIONAL_SETTING(game_pad_xy_stick_flicking_input_window_milliseconds);
OPTIONAL_SETTING(game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold);
OPTIONAL_SETTING(game_pad_wheels_stick_flicking_input_window_milliseconds);

#undef OPTIONAL_SETTING

Expand Down Expand Up @@ -384,6 +399,15 @@ class device final {
coordinate_between_properties();
}

std::optional<double> get_game_pad_xy_stick_flicking_input_window_milliseconds(void) const {
return game_pad_xy_stick_flicking_input_window_milliseconds_;
}
void set_game_pad_xy_stick_flicking_input_window_milliseconds(std::optional<double> value) {
game_pad_xy_stick_flicking_input_window_milliseconds_ = value;

coordinate_between_properties();
}

std::optional<double> get_game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold(void) const {
return game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold_;
}
Expand All @@ -393,6 +417,15 @@ class device final {
coordinate_between_properties();
}

std::optional<double> get_game_pad_wheels_stick_flicking_input_window_milliseconds(void) const {
return game_pad_wheels_stick_flicking_input_window_milliseconds_;
}
void set_game_pad_wheels_stick_flicking_input_window_milliseconds(std::optional<double> value) {
game_pad_wheels_stick_flicking_input_window_milliseconds_ = value;

coordinate_between_properties();
}

const std::optional<std::string>& get_game_pad_xy_stick_interval_milliseconds_formula(void) const {
return game_pad_xy_stick_interval_milliseconds_formula_;
}
Expand Down Expand Up @@ -530,7 +563,9 @@ class device final {
bool mouse_swap_wheels_;
bool game_pad_swap_sticks_;
std::optional<double> game_pad_xy_stick_continued_movement_absolute_magnitude_threshold_;
std::optional<int> game_pad_xy_stick_flicking_input_window_milliseconds_;
std::optional<double> game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold_;
std::optional<int> game_pad_wheels_stick_flicking_input_window_milliseconds_;
std::optional<std::string> game_pad_xy_stick_interval_milliseconds_formula_;
std::optional<std::string> game_pad_wheels_stick_interval_milliseconds_formula_;
std::optional<std::string> game_pad_stick_x_formula_;
Expand Down

0 comments on commit 09cef27

Please sign in to comment.