1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 20:22:30 +01:00

input: list actual nodes instead of button ids

This commit is contained in:
Megamouse 2023-05-21 14:54:05 +02:00
parent 1a98682ea0
commit fc76d2df38
6 changed files with 22 additions and 22 deletions

View File

@ -658,9 +658,9 @@ static void ds3_input_to_pad(const u32 port_no, be_t<u16>& digital_buttons, be_t
continue; continue;
} }
if (const auto btn = cfg->find_button(button.m_offset, button.m_outKeyCode)) if (const auto btn = cfg->find_button(button.m_offset, button.m_outKeyCode); btn.has_value() && btn.value())
{ {
switch (btn.value()) switch (btn.value()->btn_id())
{ {
case gem_btn::start: case gem_btn::start:
digital_buttons |= CELL_GEM_CTRL_START; digital_buttons |= CELL_GEM_CTRL_START;

View File

@ -92,9 +92,9 @@ void usb_device_buzz::interrupt_transfer(u32 buf_size, u8* buf, u32 /*endpoint*/
continue; continue;
} }
if (const auto btn = cfg->find_button(button.m_offset, button.m_outKeyCode)) if (const auto btn = cfg->find_button(button.m_offset, button.m_outKeyCode); btn.has_value() && btn.value())
{ {
switch (btn.value()) switch (btn.value()->btn_id())
{ {
case buzz_btn::red: case buzz_btn::red:
buf[2 + (0 + 5 * index) / 8] |= 1 << ((0 + 5 * index) % 8); // Red buf[2 + (0 + 5 * index) / 8] |= 1 << ((0 + 5 * index) % 8); // Red

View File

@ -125,9 +125,9 @@ void usb_device_ghltar::interrupt_transfer(u32 buf_size, u8* buf, u32 /*endpoint
continue; continue;
} }
if (const auto btn = cfg->find_button(button.m_offset, button.m_outKeyCode)) if (const auto btn = cfg->find_button(button.m_offset, button.m_outKeyCode); btn.has_value() && btn.value())
{ {
switch (btn.value()) switch (btn.value()->btn_id())
{ {
case ghltar_btn::w1: case ghltar_btn::w1:
buf[0] += 0x01; // W1 buf[0] += 0x01; // W1

View File

@ -134,9 +134,9 @@ void usb_device_turntable::interrupt_transfer(u32 buf_size, u8* buf, u32 /*endpo
if (!button.m_pressed) if (!button.m_pressed)
continue; continue;
if (const auto btn = cfg->find_button(button.m_offset, button.m_outKeyCode)) if (const auto btn = cfg->find_button(button.m_offset, button.m_outKeyCode); btn.has_value() && btn.value())
{ {
switch (btn.value()) switch (btn.value()->btn_id())
{ {
case turntable_btn::blue: case turntable_btn::blue:
buf[0] |= 0x01; // Square Button buf[0] |= 0x01; // Square Button

View File

@ -32,13 +32,13 @@ struct emulated_pad_config : cfg::node
{ {
using cfg::node::node; using cfg::node::node;
std::map<u32, std::map<u32, T>> buttons; std::map<u32, std::map<u32, const cfg_pad_btn<T>*>> button_map;
std::optional<T> find_button(u32 offset, u32 keycode) const std::optional<const cfg_pad_btn<T>*> find_button(u32 offset, u32 keycode) const
{ {
if (const auto it = buttons.find(offset); it != buttons.cend()) if (const auto it = button_map.find(offset); it != button_map.cend())
{ {
if (const auto it2 = it->second.find(keycode); it2 != it->second.cend()) if (const auto it2 = it->second.find(keycode); it2 != it->second.cend() && it2->second)
{ {
return it2->second; return it2->second;
} }
@ -47,19 +47,19 @@ struct emulated_pad_config : cfg::node
return std::nullopt; return std::nullopt;
} }
void set_button(const cfg_pad_btn<T>& pbtn, T bbtn) void init_button(cfg_pad_btn<T>* pbtn)
{ {
const u32 offset = pad_button_offset(pbtn); if (!pbtn) return;
const u32 keycode = pad_button_keycode(pbtn); const u32 offset = pad_button_offset(pbtn->get());
buttons[(offset >> 8) & 0xFF][keycode & 0xFF] = bbtn; const u32 keycode = pad_button_keycode(pbtn->get());
button_map[(offset >> 8) & 0xFF][keycode & 0xFF] = std::as_const(pbtn);
} }
void set_buttons() void init_buttons()
{ {
for (const auto& n : get_nodes()) for (const auto& n : get_nodes())
{ {
const auto& node = static_cast<cfg_pad_btn<T>*>(n); init_button(static_cast<cfg_pad_btn<T>*>(n));
set_button(*node, node->btn_id());
} }
} }
}; };
@ -108,7 +108,7 @@ struct emulated_pads_config : cfg::node
for (T* player : players) for (T* player : players)
{ {
player->set_buttons(); player->init_buttons();
} }
return result; return result;

View File

@ -173,9 +173,9 @@ void usb_device_usio::translate_input()
for (const Button& button : pad->m_buttons) for (const Button& button : pad->m_buttons)
{ {
if (const auto btn = cfg->find_button(button.m_offset, button.m_outKeyCode)) if (const auto btn = cfg->find_button(button.m_offset, button.m_outKeyCode); btn.has_value() && btn.value())
{ {
switch (btn.value()) switch (btn.value()->btn_id())
{ {
case usio_btn::test: case usio_btn::test:
if (player != 0) break; if (player != 0) break;