From 901d9f3f6e030c7ad1d27edee7c74e81b74075e5 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Mon, 13 Feb 2023 22:21:07 +0300 Subject: [PATCH] rsx/overlays: Simplify attach-thread-input API - Restructure the inputs to encourage shorter input signature. --- .../Overlays/HomeMenu/overlay_home_menu.cpp | 15 +---- rpcs3/Emu/RSX/Overlays/overlay_manager.cpp | 25 +++++++- rpcs3/Emu/RSX/Overlays/overlay_manager.h | 4 +- .../RSX/Overlays/overlay_message_dialog.cpp | 60 ++++++++++--------- rpcs3/Emu/RSX/Overlays/overlay_osk.cpp | 13 +--- .../RSX/Overlays/overlay_user_list_dialog.cpp | 13 +--- 6 files changed, 60 insertions(+), 70 deletions(-) diff --git a/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu.cpp b/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu.cpp index 45c10c1eca..67ce422c59 100644 --- a/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu.cpp +++ b/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu.cpp @@ -170,19 +170,8 @@ namespace rsx auto& overlayman = g_fxo->get(); overlayman.attach_thread_input( - uid, // Target - [](s32 error) // What to do with the result - { - if (error && error != selection_code::canceled) - { - rsx_log.error("Home menu dialog input loop exited with error code=%d", error); - } - }, - [¬ify]() // What to do before starting the loop - { - *notify = true; - notify->notify_one(); - } + uid, + [¬ify]() { *notify = true; notify->notify_one(); } ); if (g_cfg.misc.pause_during_home_menu) diff --git a/rpcs3/Emu/RSX/Overlays/overlay_manager.cpp b/rpcs3/Emu/RSX/Overlays/overlay_manager.cpp index ac90872c36..064c9f50a6 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_manager.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_manager.cpp @@ -11,6 +11,8 @@ namespace rsx if (m_input_thread) { m_input_thread_abort.store(true); + + *m_input_thread = thread_state::aborting; while (*m_input_thread <= thread_state::aborting) { _mm_pause(); @@ -152,13 +154,18 @@ namespace rsx void display_manager::attach_thread_input( u32 uid, + std::function on_input_loop_enter, std::function on_input_loop_exit, - std::function on_input_loop_enter) + std::function input_loop_override) { if (auto iface = std::dynamic_pointer_cast(get(uid))) { std::lock_guard lock(m_input_thread_lock); - m_input_token_stack.emplace_front(std::move(iface), on_input_loop_enter, on_input_loop_exit); + m_input_token_stack.emplace_front( + std::move(iface), + on_input_loop_enter, + on_input_loop_exit, + input_loop_override); } } @@ -209,12 +216,24 @@ namespace rsx input_context.input_loop_prologue(); } - const auto result = input_context.target->run_input_loop(); + s32 result = 0; + if (!input_context.input_loop_override) [[ likely ]] + { + result = input_context.target->run_input_loop(); + } + else + { + result = input_context.input_loop_override(); + } if (input_context.input_loop_epilogue) { input_context.input_loop_epilogue(result); } + else if (result && result != user_interface::selection_code::canceled) + { + rsx_log.error("Input loop exited with error code=%d", result); + } } else { diff --git a/rpcs3/Emu/RSX/Overlays/overlay_manager.h b/rpcs3/Emu/RSX/Overlays/overlay_manager.h index f58d141e36..e93b1cc8f1 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_manager.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_manager.h @@ -158,8 +158,9 @@ namespace rsx // Enable input thread attach to the specified interface void attach_thread_input( u32 uid, // The input target + std::function on_input_loop_enter = nullptr, // [optional] What to do before running the input routine std::function on_input_loop_exit = nullptr, // [optional] What to do with the result if any - std::function on_input_loop_enter = nullptr); // [optional] What to do before running the input routine + std::function input_loop_override = nullptr); // [optional] What to do during the input loop. By default calls user_interface::run_input_loop private: struct overlay_input_thread @@ -172,6 +173,7 @@ namespace rsx std::shared_ptr target; std::function input_loop_prologue = nullptr; std::function input_loop_epilogue = nullptr; + std::function input_loop_override = nullptr; }; std::deque m_input_token_stack; diff --git a/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.cpp b/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.cpp index ebe40f4dc4..de99d33857 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.cpp @@ -303,37 +303,39 @@ namespace rsx const auto notify = std::make_shared>(false); auto& overlayman = g_fxo->get(); - overlayman.attach_thread_input( - uid, - [](s32 error) - { - if (error && error != selection_code::canceled) - { - rsx_log.error("Message dialog input loop exited with error code=%d", error); - } - }, - [¬ify]() - { - *notify = true; - notify->notify_one(); - } - ); - -#if 0 - while (!m_stop_input_loop && thread_ctrl::state() != thread_state::aborting) + if (interactive) { - refresh(); - - // Only update the screen at about 60fps since updating it everytime slows down the process - std::this_thread::sleep_for(16ms); - - if (!g_fxo->is_init()) - { - rsx_log.fatal("display_manager was improperly destroyed"); - break; - } + overlayman.attach_thread_input( + uid, + [¬ify]() { *notify = true; notify->notify_one(); } + ); + } + else + { + overlayman.attach_thread_input( + uid, + [¬ify]() { *notify = true; notify->notify_one(); }, + nullptr, + [&]() + { + while (!m_stop_input_loop && thread_ctrl::state() != thread_state::aborting) + { + refresh(); + + // Only update the screen at about 60fps since updating it everytime slows down the process + std::this_thread::sleep_for(16ms); + + if (!g_fxo->is_init()) + { + rsx_log.fatal("display_manager was improperly destroyed"); + break; + } + } + + return 0; + } + ); } -#endif while (!Emu.IsStopped() && !*notify) { diff --git a/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp b/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp index 32f0e821cd..de1a844324 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp @@ -1630,18 +1630,7 @@ namespace rsx overlayman.attach_thread_input( uid, - [](s32 error) - { - if (error && error != selection_code::canceled) - { - rsx_log.error("Osk input loop exited with error code=%d", error); - } - }, - [¬ify]() - { - *notify = true; - notify->notify_one(); - } + [¬ify]() { *notify = true; notify->notify_one(); } ); while (!Emu.IsStopped() && !*notify) diff --git a/rpcs3/Emu/RSX/Overlays/overlay_user_list_dialog.cpp b/rpcs3/Emu/RSX/Overlays/overlay_user_list_dialog.cpp index 0cd336fd23..67073127eb 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_user_list_dialog.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_user_list_dialog.cpp @@ -249,18 +249,7 @@ namespace rsx overlayman.attach_thread_input( uid, - [](s32 error) - { - if (error && error != selection_code::canceled) - { - rsx_log.error("User list dialog input loop exited with error code=%d", error); - } - }, - [¬ify]() - { - *notify = true; - notify->notify_one(); - } + [¬ify]() { *notify = true; notify->notify_one(); } ); while (!Emu.IsStopped() && !*notify)