diff --git a/Utilities/Timer.h b/Utilities/Timer.h index 3908b8643c..581a95304f 100644 --- a/Utilities/Timer.h +++ b/Utilities/Timer.h @@ -49,4 +49,11 @@ public: return std::chrono::duration_cast(now - m_start).count(); } + + u64 GetMsSince(std::chrono::steady_clock::time_point timestamp) + { + std::chrono::steady_clock::time_point now = m_stopped ? m_end : std::chrono::steady_clock::now(); + + return std::chrono::duration_cast(now - timestamp).count(); + } }; diff --git a/rpcs3/Emu/RSX/Overlays/overlay_controls.h b/rpcs3/Emu/RSX/Overlays/overlay_controls.h index 1737e346b2..1fc9dde301 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_controls.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_controls.h @@ -1479,12 +1479,11 @@ namespace rsx m_accept_btn->set_pos(30, height + 20); m_cancel_btn->set_pos(180, height + 20); - m_accept_btn->text = "Select"; - m_cancel_btn->text = "Cancel"; + m_accept_btn->set_text("Select"); + m_cancel_btn->set_text("Cancel"); - auto fnt = fontmgr::get("Arial", 16); - m_accept_btn->font_ref = fnt; - m_cancel_btn->font_ref = fnt; + m_accept_btn->set_font("Arial", 16); + m_cancel_btn->set_font("Arial", 16); auto_resize = false; back_color = { 0.15f, 0.15f, 0.15f, 0.8f }; diff --git a/rpcs3/Emu/RSX/Overlays/overlays.h b/rpcs3/Emu/RSX/Overlays/overlays.h index 64e53e4acf..44c7d1a27a 100644 --- a/rpcs3/Emu/RSX/Overlays/overlays.h +++ b/rpcs3/Emu/RSX/Overlays/overlays.h @@ -64,8 +64,8 @@ namespace rsx cross }; - u64 input_timestamp = 0; - bool exit = false; + Timer input_timer; + bool exit = false; s32 return_code = CELL_OK; std::function on_close; @@ -93,8 +93,16 @@ namespace rsx if (rinfo.max_connect == 0) return selection_code::error; - std::array button_state; - button_state.fill(true); + std::array timestamp; + timestamp.fill(std::chrono::steady_clock::now()); + + std::array, CELL_PAD_MAX_PORT_NUM> button_state; + for (auto& state : button_state) + { + state.fill(true); + } + + input_timer.Start(); while (!exit) { @@ -107,8 +115,15 @@ namespace rsx continue; } + int pad_index = -1; for (const auto &pad : handler->GetPads()) { + if (++pad_index >= CELL_PAD_MAX_PORT_NUM) + { + LOG_FATAL(RSX, "The native overlay cannot handle more than 7 pads! Current number of pads: %d", pad_index + 1); + continue; + } + for (auto &button : pad->m_buttons) { u8 button_id = 255; @@ -151,10 +166,25 @@ namespace rsx if (button_id < 255) { - if (button.m_pressed != button_state[button_id]) - if (button.m_pressed) on_button_pressed(static_cast(button_id)); + if (button.m_pressed) + { + if (button_id < 4) // d-pad button + { + if (!button_state[pad_index][button_id] || input_timer.GetMsSince(timestamp[pad_index]) > 400) + { + // d-pad button was not pressed, or was pressed more than 400ms ago + timestamp[pad_index] = std::chrono::steady_clock::now(); + on_button_pressed(static_cast(button_id)); + } + } + else if (!button_state[pad_index][button_id]) + { + // button was not pressed + on_button_pressed(static_cast(button_id)); + } + } - button_state[button_id] = button.m_pressed; + button_state[pad_index][button_id] = button.m_pressed; } if (button.m_flush)