rsx/overlays: Simplify attach-thread-input API

- Restructure the inputs to encourage shorter input signature.
This commit is contained in:
kd-11 2023-02-13 22:21:07 +03:00 committed by kd-11
parent ddc9e74aa8
commit 901d9f3f6e
6 changed files with 60 additions and 70 deletions

View file

@ -170,19 +170,8 @@ namespace rsx
auto& overlayman = g_fxo->get<display_manager>(); auto& overlayman = g_fxo->get<display_manager>();
overlayman.attach_thread_input( overlayman.attach_thread_input(
uid, // Target uid,
[](s32 error) // What to do with the result [&notify]() { *notify = true; notify->notify_one(); }
{
if (error && error != selection_code::canceled)
{
rsx_log.error("Home menu dialog input loop exited with error code=%d", error);
}
},
[&notify]() // What to do before starting the loop
{
*notify = true;
notify->notify_one();
}
); );
if (g_cfg.misc.pause_during_home_menu) if (g_cfg.misc.pause_during_home_menu)

View file

@ -11,6 +11,8 @@ namespace rsx
if (m_input_thread) if (m_input_thread)
{ {
m_input_thread_abort.store(true); m_input_thread_abort.store(true);
*m_input_thread = thread_state::aborting;
while (*m_input_thread <= thread_state::aborting) while (*m_input_thread <= thread_state::aborting)
{ {
_mm_pause(); _mm_pause();
@ -152,13 +154,18 @@ namespace rsx
void display_manager::attach_thread_input( void display_manager::attach_thread_input(
u32 uid, u32 uid,
std::function<void()> on_input_loop_enter,
std::function<void(s32)> on_input_loop_exit, std::function<void(s32)> on_input_loop_exit,
std::function<void()> on_input_loop_enter) std::function<s32()> input_loop_override)
{ {
if (auto iface = std::dynamic_pointer_cast<user_interface>(get(uid))) if (auto iface = std::dynamic_pointer_cast<user_interface>(get(uid)))
{ {
std::lock_guard lock(m_input_thread_lock); 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(); 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) if (input_context.input_loop_epilogue)
{ {
input_context.input_loop_epilogue(result); 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 else
{ {

View file

@ -158,8 +158,9 @@ namespace rsx
// Enable input thread attach to the specified interface // Enable input thread attach to the specified interface
void attach_thread_input( void attach_thread_input(
u32 uid, // The input target u32 uid, // The input target
std::function<void()> on_input_loop_enter = nullptr, // [optional] What to do before running the input routine
std::function<void(s32)> on_input_loop_exit = nullptr, // [optional] What to do with the result if any std::function<void(s32)> on_input_loop_exit = nullptr, // [optional] What to do with the result if any
std::function<void()> on_input_loop_enter = nullptr); // [optional] What to do before running the input routine std::function<s32()> input_loop_override = nullptr); // [optional] What to do during the input loop. By default calls user_interface::run_input_loop
private: private:
struct overlay_input_thread struct overlay_input_thread
@ -172,6 +173,7 @@ namespace rsx
std::shared_ptr<user_interface> target; std::shared_ptr<user_interface> target;
std::function<void()> input_loop_prologue = nullptr; std::function<void()> input_loop_prologue = nullptr;
std::function<void(s32)> input_loop_epilogue = nullptr; std::function<void(s32)> input_loop_epilogue = nullptr;
std::function<s32()> input_loop_override = nullptr;
}; };
std::deque<input_thread_context_t> m_input_token_stack; std::deque<input_thread_context_t> m_input_token_stack;

View file

@ -303,37 +303,39 @@ namespace rsx
const auto notify = std::make_shared<atomic_t<bool>>(false); const auto notify = std::make_shared<atomic_t<bool>>(false);
auto& overlayman = g_fxo->get<display_manager>(); auto& overlayman = g_fxo->get<display_manager>();
overlayman.attach_thread_input( if (interactive)
uid,
[](s32 error)
{
if (error && error != selection_code::canceled)
{
rsx_log.error("Message dialog input loop exited with error code=%d", error);
}
},
[&notify]()
{
*notify = true;
notify->notify_one();
}
);
#if 0
while (!m_stop_input_loop && thread_ctrl::state() != thread_state::aborting)
{ {
refresh(); overlayman.attach_thread_input(
uid,
// Only update the screen at about 60fps since updating it everytime slows down the process [&notify]() { *notify = true; notify->notify_one(); }
std::this_thread::sleep_for(16ms); );
}
if (!g_fxo->is_init<display_manager>()) else
{ {
rsx_log.fatal("display_manager was improperly destroyed"); overlayman.attach_thread_input(
break; uid,
} [&notify]() { *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<display_manager>())
{
rsx_log.fatal("display_manager was improperly destroyed");
break;
}
}
return 0;
}
);
} }
#endif
while (!Emu.IsStopped() && !*notify) while (!Emu.IsStopped() && !*notify)
{ {

View file

@ -1630,18 +1630,7 @@ namespace rsx
overlayman.attach_thread_input( overlayman.attach_thread_input(
uid, uid,
[](s32 error) [&notify]() { *notify = true; notify->notify_one(); }
{
if (error && error != selection_code::canceled)
{
rsx_log.error("Osk input loop exited with error code=%d", error);
}
},
[&notify]()
{
*notify = true;
notify->notify_one();
}
); );
while (!Emu.IsStopped() && !*notify) while (!Emu.IsStopped() && !*notify)

View file

@ -249,18 +249,7 @@ namespace rsx
overlayman.attach_thread_input( overlayman.attach_thread_input(
uid, uid,
[](s32 error) [&notify]() { *notify = true; notify->notify_one(); }
{
if (error && error != selection_code::canceled)
{
rsx_log.error("User list dialog input loop exited with error code=%d", error);
}
},
[&notify]()
{
*notify = true;
notify->notify_one();
}
); );
while (!Emu.IsStopped() && !*notify) while (!Emu.IsStopped() && !*notify)