|
|
@ -8,37 +8,37 @@
|
|
|
|
namespace InputCommon {
|
|
|
|
namespace InputCommon {
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::PreSetController(const PadIdentifier& identifier) {
|
|
|
|
void InputEngine::PreSetController(const PadIdentifier& identifier) {
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
controller_list.try_emplace(identifier);
|
|
|
|
controller_list.try_emplace(identifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::PreSetButton(const PadIdentifier& identifier, int button) {
|
|
|
|
void InputEngine::PreSetButton(const PadIdentifier& identifier, int button) {
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
controller.buttons.try_emplace(button, false);
|
|
|
|
controller.buttons.try_emplace(button, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::PreSetHatButton(const PadIdentifier& identifier, int button) {
|
|
|
|
void InputEngine::PreSetHatButton(const PadIdentifier& identifier, int button) {
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
controller.hat_buttons.try_emplace(button, u8{0});
|
|
|
|
controller.hat_buttons.try_emplace(button, u8{0});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::PreSetAxis(const PadIdentifier& identifier, int axis) {
|
|
|
|
void InputEngine::PreSetAxis(const PadIdentifier& identifier, int axis) {
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
controller.axes.try_emplace(axis, 0.0f);
|
|
|
|
controller.axes.try_emplace(axis, 0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::PreSetMotion(const PadIdentifier& identifier, int motion) {
|
|
|
|
void InputEngine::PreSetMotion(const PadIdentifier& identifier, int motion) {
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
controller.motions.try_emplace(motion);
|
|
|
|
controller.motions.try_emplace(motion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool value) {
|
|
|
|
void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool value) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
if (!configuring) {
|
|
|
|
if (!configuring) {
|
|
|
|
controller.buttons.insert_or_assign(button, value);
|
|
|
|
controller.buttons.insert_or_assign(button, value);
|
|
|
@ -49,7 +49,7 @@ void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool va
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::SetHatButton(const PadIdentifier& identifier, int button, u8 value) {
|
|
|
|
void InputEngine::SetHatButton(const PadIdentifier& identifier, int button, u8 value) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
if (!configuring) {
|
|
|
|
if (!configuring) {
|
|
|
|
controller.hat_buttons.insert_or_assign(button, value);
|
|
|
|
controller.hat_buttons.insert_or_assign(button, value);
|
|
|
@ -60,7 +60,7 @@ void InputEngine::SetHatButton(const PadIdentifier& identifier, int button, u8 v
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) {
|
|
|
|
void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
if (!configuring) {
|
|
|
|
if (!configuring) {
|
|
|
|
controller.axes.insert_or_assign(axis, value);
|
|
|
|
controller.axes.insert_or_assign(axis, value);
|
|
|
@ -71,7 +71,7 @@ void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value)
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value) {
|
|
|
|
void InputEngine::SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
if (!configuring) {
|
|
|
|
if (!configuring) {
|
|
|
|
controller.battery = value;
|
|
|
|
controller.battery = value;
|
|
|
@ -82,7 +82,7 @@ void InputEngine::SetBattery(const PadIdentifier& identifier, Common::Input::Bat
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value) {
|
|
|
|
void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
ControllerData& controller = controller_list.at(identifier);
|
|
|
|
if (!configuring) {
|
|
|
|
if (!configuring) {
|
|
|
|
controller.motions.insert_or_assign(motion, value);
|
|
|
|
controller.motions.insert_or_assign(motion, value);
|
|
|
@ -92,7 +92,7 @@ void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const B
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const {
|
|
|
|
bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const {
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
const auto controller_iter = controller_list.find(identifier);
|
|
|
|
const auto controller_iter = controller_list.find(identifier);
|
|
|
|
if (controller_iter == controller_list.cend()) {
|
|
|
|
if (controller_iter == controller_list.cend()) {
|
|
|
|
LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(),
|
|
|
|
LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(),
|
|
|
@ -109,7 +109,7 @@ bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const {
|
|
|
|
bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const {
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
const auto controller_iter = controller_list.find(identifier);
|
|
|
|
const auto controller_iter = controller_list.find(identifier);
|
|
|
|
if (controller_iter == controller_list.cend()) {
|
|
|
|
if (controller_iter == controller_list.cend()) {
|
|
|
|
LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(),
|
|
|
|
LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(),
|
|
|
@ -126,7 +126,7 @@ bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const {
|
|
|
|
f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const {
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
const auto controller_iter = controller_list.find(identifier);
|
|
|
|
const auto controller_iter = controller_list.find(identifier);
|
|
|
|
if (controller_iter == controller_list.cend()) {
|
|
|
|
if (controller_iter == controller_list.cend()) {
|
|
|
|
LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(),
|
|
|
|
LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(),
|
|
|
@ -143,7 +143,7 @@ f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Common::Input::BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const {
|
|
|
|
Common::Input::BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const {
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
const auto controller_iter = controller_list.find(identifier);
|
|
|
|
const auto controller_iter = controller_list.find(identifier);
|
|
|
|
if (controller_iter == controller_list.cend()) {
|
|
|
|
if (controller_iter == controller_list.cend()) {
|
|
|
|
LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(),
|
|
|
|
LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(),
|
|
|
@ -155,7 +155,7 @@ Common::Input::BatteryLevel InputEngine::GetBattery(const PadIdentifier& identif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const {
|
|
|
|
BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const {
|
|
|
|
std::lock_guard lock{mutex};
|
|
|
|
std::scoped_lock lock{mutex};
|
|
|
|
const auto controller_iter = controller_list.find(identifier);
|
|
|
|
const auto controller_iter = controller_list.find(identifier);
|
|
|
|
if (controller_iter == controller_list.cend()) {
|
|
|
|
if (controller_iter == controller_list.cend()) {
|
|
|
|
LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(),
|
|
|
|
LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(),
|
|
|
@ -186,7 +186,7 @@ void InputEngine::ResetAnalogState() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value) {
|
|
|
|
void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value) {
|
|
|
|
std::lock_guard lock{mutex_callback};
|
|
|
|
std::scoped_lock lock{mutex_callback};
|
|
|
|
for (const auto& poller_pair : callback_list) {
|
|
|
|
for (const auto& poller_pair : callback_list) {
|
|
|
|
const InputIdentifier& poller = poller_pair.second;
|
|
|
|
const InputIdentifier& poller = poller_pair.second;
|
|
|
|
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Button, button)) {
|
|
|
|
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Button, button)) {
|
|
|
@ -214,7 +214,7 @@ void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int but
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value) {
|
|
|
|
void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value) {
|
|
|
|
std::lock_guard lock{mutex_callback};
|
|
|
|
std::scoped_lock lock{mutex_callback};
|
|
|
|
for (const auto& poller_pair : callback_list) {
|
|
|
|
for (const auto& poller_pair : callback_list) {
|
|
|
|
const InputIdentifier& poller = poller_pair.second;
|
|
|
|
const InputIdentifier& poller = poller_pair.second;
|
|
|
|
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::HatButton, button)) {
|
|
|
|
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::HatButton, button)) {
|
|
|
@ -243,7 +243,7 @@ void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value) {
|
|
|
|
void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value) {
|
|
|
|
std::lock_guard lock{mutex_callback};
|
|
|
|
std::scoped_lock lock{mutex_callback};
|
|
|
|
for (const auto& poller_pair : callback_list) {
|
|
|
|
for (const auto& poller_pair : callback_list) {
|
|
|
|
const InputIdentifier& poller = poller_pair.second;
|
|
|
|
const InputIdentifier& poller = poller_pair.second;
|
|
|
|
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Analog, axis)) {
|
|
|
|
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Analog, axis)) {
|
|
|
@ -270,7 +270,7 @@ void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis,
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier,
|
|
|
|
void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier,
|
|
|
|
[[maybe_unused]] Common::Input::BatteryLevel value) {
|
|
|
|
[[maybe_unused]] Common::Input::BatteryLevel value) {
|
|
|
|
std::lock_guard lock{mutex_callback};
|
|
|
|
std::scoped_lock lock{mutex_callback};
|
|
|
|
for (const auto& poller_pair : callback_list) {
|
|
|
|
for (const auto& poller_pair : callback_list) {
|
|
|
|
const InputIdentifier& poller = poller_pair.second;
|
|
|
|
const InputIdentifier& poller = poller_pair.second;
|
|
|
|
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Battery, 0)) {
|
|
|
|
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Battery, 0)) {
|
|
|
@ -284,7 +284,7 @@ void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier,
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion,
|
|
|
|
void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion,
|
|
|
|
const BasicMotion& value) {
|
|
|
|
const BasicMotion& value) {
|
|
|
|
std::lock_guard lock{mutex_callback};
|
|
|
|
std::scoped_lock lock{mutex_callback};
|
|
|
|
for (const auto& poller_pair : callback_list) {
|
|
|
|
for (const auto& poller_pair : callback_list) {
|
|
|
|
const InputIdentifier& poller = poller_pair.second;
|
|
|
|
const InputIdentifier& poller = poller_pair.second;
|
|
|
|
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Motion, motion)) {
|
|
|
|
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Motion, motion)) {
|
|
|
@ -346,18 +346,18 @@ const std::string& InputEngine::GetEngineName() const {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InputEngine::SetCallback(InputIdentifier input_identifier) {
|
|
|
|
int InputEngine::SetCallback(InputIdentifier input_identifier) {
|
|
|
|
std::lock_guard lock{mutex_callback};
|
|
|
|
std::scoped_lock lock{mutex_callback};
|
|
|
|
callback_list.insert_or_assign(last_callback_key, std::move(input_identifier));
|
|
|
|
callback_list.insert_or_assign(last_callback_key, std::move(input_identifier));
|
|
|
|
return last_callback_key++;
|
|
|
|
return last_callback_key++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::SetMappingCallback(MappingCallback callback) {
|
|
|
|
void InputEngine::SetMappingCallback(MappingCallback callback) {
|
|
|
|
std::lock_guard lock{mutex_callback};
|
|
|
|
std::scoped_lock lock{mutex_callback};
|
|
|
|
mapping_callback = std::move(callback);
|
|
|
|
mapping_callback = std::move(callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputEngine::DeleteCallback(int key) {
|
|
|
|
void InputEngine::DeleteCallback(int key) {
|
|
|
|
std::lock_guard lock{mutex_callback};
|
|
|
|
std::scoped_lock lock{mutex_callback};
|
|
|
|
const auto& iterator = callback_list.find(key);
|
|
|
|
const auto& iterator = callback_list.find(key);
|
|
|
|
if (iterator == callback_list.end()) {
|
|
|
|
if (iterator == callback_list.end()) {
|
|
|
|
LOG_ERROR(Input, "Tried to delete non-existent callback {}", key);
|
|
|
|
LOG_ERROR(Input, "Tried to delete non-existent callback {}", key);
|
|
|
|