Skip to content

Commit

Permalink
Use shared_ptr to game_pad_stick_converter::states_
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Oct 9, 2023
1 parent dc0e438 commit 0068da5
Showing 1 changed file with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,17 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche

if (auto c = core_configuration_.lock()) {
for (auto&& [device_id, state] : states_) {
state.update_formula(*c);
state->update_formula(*c);
}
}
}

void register_device(const device_properties& device_properties) {
if (auto is_game_pad = device_properties.get_is_game_pad()) {
if (*is_game_pad) {
auto s = state(device_properties.get_device_identifiers());
auto s = std::make_shared<state>(device_properties.get_device_identifiers());
if (auto c = core_configuration_.lock()) {
s.update_formula(*c);
s->update_formula(*c);
}

states_[device_properties.get_device_id()] = s;
Expand Down Expand Up @@ -355,57 +355,57 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
if (v.conforms_to(pqrs::hid::usage_page::generic_desktop,
pqrs::hid::usage::generic_desktop::x)) {
if (flip_sticks) {
it->second.wheels.update_horizontal_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
right_stick_deadzone);
it->second->wheels.update_horizontal_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
right_stick_deadzone);
} else {
it->second.xy.update_horizontal_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
left_stick_deadzone);
it->second->xy.update_horizontal_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
left_stick_deadzone);
}

} else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop,
pqrs::hid::usage::generic_desktop::y)) {
if (flip_sticks) {
it->second.wheels.update_vertical_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
right_stick_deadzone);
it->second->wheels.update_vertical_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
right_stick_deadzone);
} else {
it->second.xy.update_vertical_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
left_stick_deadzone);
it->second->xy.update_vertical_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
left_stick_deadzone);
}

} else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop,
pqrs::hid::usage::generic_desktop::rz)) {
if (flip_sticks) {
it->second.xy.update_vertical_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
left_stick_deadzone);
it->second->xy.update_vertical_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
left_stick_deadzone);
} else {
it->second.wheels.update_vertical_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
right_stick_deadzone);
it->second->wheels.update_vertical_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
right_stick_deadzone);
}

} else if (v.conforms_to(pqrs::hid::usage_page::generic_desktop,
pqrs::hid::usage::generic_desktop::z)) {
if (flip_sticks) {
it->second.xy.update_horizontal_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
left_stick_deadzone);
it->second->xy.update_horizontal_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
left_stick_deadzone);
} else {
it->second.wheels.update_horizontal_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
right_stick_deadzone);
it->second->wheels.update_horizontal_stick_sensor_value(*logical_max,
*logical_min,
v.get_integer_value(),
right_stick_deadzone);
}
}
}
Expand All @@ -416,16 +416,16 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
}

for (auto&& [device_id, state] : states_) {
if (!state.xy.get_active() &&
state.xy.xy_interval().count() > 0) {
state.xy.set_active(true);
if (!state->xy.get_active() &&
state->xy.xy_interval().count() > 0) {
state->xy.set_active(true);
emit_xy_event(device_id,
event_origin);
}

if (!state.wheels.get_active() &&
state.wheels.wheels_interval().count() > 0) {
state.wheels.set_active(true);
if (!state->wheels.get_active() &&
state->wheels.wheels_interval().count() > 0) {
state->wheels.set_active(true);
emit_wheels_event(device_id,
event_origin);
}
Expand All @@ -450,14 +450,14 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
return;
}

auto interval = get_interval(it->second);
auto interval = get_interval(*(it->second));

if (interval <= std::chrono::milliseconds(0)) {
unset_active(it->second);
unset_active(*(it->second));
return;
}

auto m = make_pointing_motion(it->second);
auto m = make_pointing_motion(*(it->second));

event_queue::event_time_stamp event_time_stamp(pqrs::osx::chrono::mach_absolute_time_point());
event_queue::event event(m);
Expand Down Expand Up @@ -535,7 +535,7 @@ class game_pad_stick_converter final : public pqrs::dispatcher::extra::dispatche
}

std::weak_ptr<const core_configuration::core_configuration> core_configuration_;
std::unordered_map<device_id, state> states_;
std::unordered_map<device_id, std::shared_ptr<state>> states_;
};
} // namespace device_grabber_details
} // namespace grabber
Expand Down

0 comments on commit 0068da5

Please sign in to comment.