Skip to content

Commit

Permalink
Fix continued_movement_magnitude_ calculation in game_pad_stick_conve…
Browse files Browse the repository at this point in the history
…rter
  • Loading branch information
tekezo committed Jan 9, 2024
1 parent e66f135 commit aa540ca
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
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);
}),
std::end(delta_magnitude_history_));
Expand All @@ -202,12 +203,9 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche

if (magnitude >= continued_movement_absolute_magnitude_threshold_) {
if (continued_movement_magnitude_ == 0.0) {
auto it = std::max_element(std::begin(delta_magnitude_history_),
std::end(delta_magnitude_history_),
[](auto&& a, auto&& b) {
return a.get_delta_magnitude() < b.get_delta_magnitude();
});
continued_movement_magnitude_ = it->get_delta_magnitude();
for (const auto& e : delta_magnitude_history_) {
continued_movement_magnitude_ += e.get_delta_magnitude();
}
}

delta_magnitude_ = continued_movement_magnitude_;
Expand Down Expand Up @@ -443,6 +441,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
post_xy_event();
}
},
// TODO: Replace hard-coded interval
std::chrono::milliseconds(300));
}
}
Expand Down Expand Up @@ -476,6 +475,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
post_wheels_event();
}
},
// TODO: Replace hard-coded interval
std::chrono::milliseconds(300));
}
}
Expand Down

0 comments on commit aa540ca

Please sign in to comment.