From fdce82fc24651555eaee5f824b0f2a944ff30b84 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 15 May 2026 00:02:45 +0200 Subject: [PATCH] input: Use smaller external structs for button and stick access outside of the pad_thread This needs less memory and hides unwanted members from client code. --- rpcs3/Emu/Cell/Modules/cellGem.cpp | 4 ++-- rpcs3/Emu/Cell/Modules/cellPad.cpp | 4 ++-- rpcs3/Emu/Io/GameTablet.cpp | 2 +- rpcs3/Emu/Io/emulated_pad_config.h | 4 ++-- rpcs3/Emu/Io/pad_types.h | 18 ++++++++++++++++-- rpcs3/Emu/RSX/Overlays/overlays.cpp | 4 ++-- rpcs3/Input/pad_thread.cpp | 8 ++++---- 7 files changed, 29 insertions(+), 15 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellGem.cpp b/rpcs3/Emu/Cell/Modules/cellGem.cpp index f9f5ea4100..24d0ef60d9 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGem.cpp @@ -2183,7 +2183,7 @@ static void ds3_input_to_ext(u32 gem_num, gem_config::gem_controller& controller ext.status = controller.ext_status; - for (const AnalogStick& stick : pad->m_sticks_external) + for (const AnalogStickExternal& stick : pad->m_sticks_external) { switch (stick.m_offset) { @@ -2195,7 +2195,7 @@ static void ds3_input_to_ext(u32 gem_num, gem_config::gem_controller& controller } } - for (const Button& button : pad->m_buttons_external) + for (const ButtonExternal& button : pad->m_buttons_external) { if (!button.m_pressed) continue; diff --git a/rpcs3/Emu/Cell/Modules/cellPad.cpp b/rpcs3/Emu/Cell/Modules/cellPad.cpp index 9c8e05f74f..b2fbe187f9 100644 --- a/rpcs3/Emu/Cell/Modules/cellPad.cpp +++ b/rpcs3/Emu/Cell/Modules/cellPad.cpp @@ -418,7 +418,7 @@ void pad_get_data(u32 port_no, CellPadData* data, bool get_periph_data = false) } }; - for (const Button& button : pad->m_buttons_external) + for (const ButtonExternal& button : pad->m_buttons_external) { // here we check btns, and set pad accordingly, // if something changed, set btnChanged @@ -497,7 +497,7 @@ void pad_get_data(u32 port_no, CellPadData* data, bool get_periph_data = false) } } - for (const AnalogStick& stick : pad->m_sticks_external) + for (const AnalogStickExternal& stick : pad->m_sticks_external) { switch (stick.m_offset) { diff --git a/rpcs3/Emu/Io/GameTablet.cpp b/rpcs3/Emu/Io/GameTablet.cpp index 1d0fcf24fe..f72c108ae1 100644 --- a/rpcs3/Emu/Io/GameTablet.cpp +++ b/rpcs3/Emu/Io/GameTablet.cpp @@ -200,7 +200,7 @@ void usb_device_gametablet::interrupt_transfer(u32 buf_size, u8* buf, u32 /*endp const auto& pad = ::at32(pads, m_controller_index); if (pad->is_connected() && !pad->is_copilot()) { - for (Button& button : pad->m_buttons_external) + for (ButtonExternal& button : pad->m_buttons_external) { if (!button.m_pressed) { diff --git a/rpcs3/Emu/Io/emulated_pad_config.h b/rpcs3/Emu/Io/emulated_pad_config.h index b9bf68a223..eb54966583 100644 --- a/rpcs3/Emu/Io/emulated_pad_config.h +++ b/rpcs3/Emu/Io/emulated_pad_config.h @@ -93,7 +93,7 @@ public: if (!pad || pad->is_copilot()) return; - for (const Button& button : pad->m_buttons_external) + for (const ButtonExternal& button : pad->m_buttons_external) { if (button.m_pressed || !press_only) { @@ -104,7 +104,7 @@ public: } } - for (const AnalogStick& stick : pad->m_sticks_external) + for (const AnalogStickExternal& stick : pad->m_sticks_external) { if (handle_input(func, stick.m_offset, get_axis_keycode(stick.m_offset, stick.m_value), stick.m_value, true, true)) { diff --git a/rpcs3/Emu/Io/pad_types.h b/rpcs3/Emu/Io/pad_types.h index d2b1535a1a..685d5ba59f 100644 --- a/rpcs3/Emu/Io/pad_types.h +++ b/rpcs3/Emu/Io/pad_types.h @@ -421,6 +421,14 @@ struct Button } }; +struct ButtonExternal +{ + u32 m_offset = 0; + u32 m_outKeyCode = 0; + u16 m_value = 0; + bool m_pressed = false; +}; + struct AnalogStick { u32 m_offset = 0; @@ -442,6 +450,12 @@ struct AnalogStick {} }; +struct AnalogStickExternal +{ + u32 m_offset = 0; + u16 m_value = 128; +}; + struct AnalogSensor { u32 m_offset = 0; @@ -519,8 +533,8 @@ struct Pad std::array m_sensors{}; std::array m_vibrate_motors{}; - std::vector