Skip to content

Commit

Permalink
Add game_pad_stick_converter::update_timer_
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Oct 27, 2023
1 parent d9bde19 commit 855cc9d
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
stick(void)
: dispatcher_client(),
deadzone_timer_(*this),
update_timer_(*this),
radian_(0.0),
magnitude_(0.0),
stroke_acceleration_(0.0),
Expand All @@ -73,6 +74,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
~stick(void) {
detach_from_dispatcher([this] {
deadzone_timer_.stop();
update_timer_.stop();
});
}

Expand All @@ -83,7 +85,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
horizontal_stick_sensor_.update_stick_sensor_value(logical_max,
logical_min,
integer_value);
update_values(deadzone);
set_update_timer(deadzone);
}

void update_vertical_stick_sensor_value(CFIndex logical_max,
Expand All @@ -93,7 +95,17 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
vertical_stick_sensor_.update_stick_sensor_value(logical_max,
logical_min,
integer_value);
update_values(deadzone);
set_update_timer(deadzone);
}

void set_update_timer(double deadzone) {
if (!update_timer_.enabled()) {
update_timer_.start(
[this, deadzone] {
update_values(deadzone);
},
std::chrono::milliseconds(20));
}
}

void update_configurations(const core_configuration::core_configuration& core_configuration,
Expand Down Expand Up @@ -210,6 +222,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
[this, now] {
deadzone_entered_at_ = now;
stroke_acceleration_ = 0.0;
update_timer_.stop();
},
std::chrono::milliseconds(stick_stroke_release_detection_threshold_milliseconds_));
}
Expand Down Expand Up @@ -244,6 +257,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
}

pqrs::dispatcher::extra::timer deadzone_timer_;
pqrs::dispatcher::extra::timer update_timer_;

stick_sensor horizontal_stick_sensor_;
stick_sensor vertical_stick_sensor_;
Expand Down

0 comments on commit 855cc9d

Please sign in to comment.