cellSaveData: get rid of g_last_user_response

This commit is contained in:
Megamouse 2023-02-14 01:01:30 +01:00
parent 3d411431c6
commit 2885c8a4ab
6 changed files with 42 additions and 25 deletions

View file

@ -137,19 +137,21 @@ struct msg_dlg_thread_info
using msg_dlg_thread = named_thread<msg_dlg_thread_info>; using msg_dlg_thread = named_thread<msg_dlg_thread_info>;
// variable used to immediately get the response from auxiliary message dialogs (callbacks would be async)
atomic_t<s32> g_last_user_response = CELL_MSGDIALOG_BUTTON_NONE;
// forward declaration for open_msg_dialog // forward declaration for open_msg_dialog
error_code cellMsgDialogOpen2(u32 type, vm::cptr<char> msgString, vm::ptr<CellMsgDialogCallback> callback, vm::ptr<void> userData, vm::ptr<void> extParam); error_code cellMsgDialogOpen2(u32 type, vm::cptr<char> msgString, vm::ptr<CellMsgDialogCallback> callback, vm::ptr<void> userData, vm::ptr<void> extParam);
// wrapper to call for other hle dialogs // wrapper to call for other hle dialogs
error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString, vm::ptr<CellMsgDialogCallback> callback, vm::ptr<void> userData, vm::ptr<void> extParam) error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString, vm::ptr<CellMsgDialogCallback> callback, vm::ptr<void> userData, vm::ptr<void> extParam, s32* return_code)
{ {
cellSysutil.notice("open_msg_dialog(is_blocking=%d, type=0x%x, msgString=%s, callback=*0x%x, userData=*0x%x, extParam=*0x%x)", is_blocking, type, msgString, callback, userData, extParam); cellSysutil.notice("open_msg_dialog(is_blocking=%d, type=0x%x, msgString=%s, callback=*0x%x, userData=*0x%x, extParam=*0x%x, return_code=*0x%x)", is_blocking, type, msgString, callback, userData, extParam, return_code);
const MsgDialogType _type{ type }; const MsgDialogType _type{ type };
if (return_code)
{
*return_code = CELL_MSGDIALOG_BUTTON_NONE;
}
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>()) if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{ {
if (manager->get<rsx::overlays::message_dialog>()) if (manager->get<rsx::overlays::message_dialog>())
@ -162,10 +164,15 @@ error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString,
return CellSysutilError{ret + 0u}; return CellSysutilError{ret + 0u};
} }
g_last_user_response = CELL_MSGDIALOG_BUTTON_NONE; const auto notify = std::make_shared<atomic_t<bool>>(false);
const auto res = manager->create<rsx::overlays::message_dialog>()->show(is_blocking, msgString.get_ptr(), _type, [callback, userData](s32 status) const auto res = manager->create<rsx::overlays::message_dialog>()->show(is_blocking, msgString.get_ptr(), _type, [callback, userData, &return_code, is_blocking, &notify](s32 status)
{ {
if (return_code)
{
*return_code = status;
}
sysutil_send_system_cmd(CELL_SYSUTIL_DRAWING_END, 0); sysutil_send_system_cmd(CELL_SYSUTIL_DRAWING_END, 0);
if (callback) if (callback)
@ -176,8 +183,20 @@ error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString,
return CELL_OK; return CELL_OK;
}); });
} }
if (is_blocking && notify)
{
*notify = true;
notify->notify_one();
}
}); });
// Wait for on_close
while (is_blocking && !Emu.IsStopped() && !*notify)
{
notify->wait(false, atomic_wait_timeout{1'000'000});
}
return res; return res;
} }
@ -195,8 +214,13 @@ error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString,
dlg->type = _type; dlg->type = _type;
dlg->on_close = [callback, userData, wptr = std::weak_ptr<MsgDialogBase>(dlg)](s32 status) dlg->on_close = [callback, userData, &return_code, wptr = std::weak_ptr<MsgDialogBase>(dlg)](s32 status)
{ {
if (return_code)
{
*return_code = status;
}
const auto dlg = wptr.lock(); const auto dlg = wptr.lock();
if (dlg && dlg->state.compare_and_swap_test(MsgDialogState::Open, MsgDialogState::Close)) if (dlg && dlg->state.compare_and_swap_test(MsgDialogState::Open, MsgDialogState::Close))
@ -230,7 +254,6 @@ error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString,
// Run asynchronously in GUI thread // Run asynchronously in GUI thread
Emu.CallFromMainThread([&, msg_string = std::move(msg_string)]() Emu.CallFromMainThread([&, msg_string = std::move(msg_string)]()
{ {
g_last_user_response = CELL_MSGDIALOG_BUTTON_NONE;
dlg->Create(msg_string); dlg->Create(msg_string);
lv2_obj::awake(&ppu); lv2_obj::awake(&ppu);
}); });

View file

@ -89,10 +89,8 @@ enum class MsgDialogState
Close, Close,
}; };
extern atomic_t<s32> g_last_user_response;
void close_msg_dialog(); void close_msg_dialog();
error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString, vm::ptr<CellMsgDialogCallback> callback = vm::null, vm::ptr<void> userData = vm::null, vm::ptr<void> extParam = vm::null); error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString, vm::ptr<CellMsgDialogCallback> callback = vm::null, vm::ptr<void> userData = vm::null, vm::ptr<void> extParam = vm::null, s32* return_code = nullptr);
error_code open_exit_dialog(const std::string& message, bool is_exit_requested); error_code open_exit_dialog(const std::string& message, bool is_exit_requested);
class MsgDialogBase class MsgDialogBase

View file

@ -319,7 +319,8 @@ static error_code select_and_delete(ppu_thread& ppu)
lv2_obj::sleep(ppu); lv2_obj::sleep(ppu);
// Get user confirmation by opening a blocking dialog // Get user confirmation by opening a blocking dialog
error_code res = open_msg_dialog(true, CELL_MSGDIALOG_TYPE_SE_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_YESNO, vm::make_str(msg)); s32 return_code = CELL_MSGDIALOG_BUTTON_NONE;
error_code res = open_msg_dialog(true, CELL_MSGDIALOG_TYPE_SE_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_YESNO, vm::make_str(msg), vm::null, vm::null, vm::null, &return_code);
// Reschedule after a blocking dialog returns // Reschedule after a blocking dialog returns
if (ppu.check_state()) if (ppu.check_state())
@ -332,7 +333,7 @@ static error_code select_and_delete(ppu_thread& ppu)
return CELL_SAVEDATA_ERROR_INTERNAL; return CELL_SAVEDATA_ERROR_INTERNAL;
} }
if (g_last_user_response.load() == CELL_MSGDIALOG_BUTTON_YES) if (return_code == CELL_MSGDIALOG_BUTTON_YES)
{ {
// Remove directory // Remove directory
const std::string path = base_dir + save_entries[selected].escaped; const std::string path = base_dir + save_entries[selected].escaped;
@ -1157,7 +1158,8 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
lv2_obj::sleep(ppu); lv2_obj::sleep(ppu);
// Get user confirmation by opening a blocking dialog // Get user confirmation by opening a blocking dialog
error_code res = open_msg_dialog(true, CELL_MSGDIALOG_TYPE_SE_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_YESNO, vm::make_str(message)); s32 return_code = CELL_MSGDIALOG_BUTTON_NONE;
error_code res = open_msg_dialog(true, CELL_MSGDIALOG_TYPE_SE_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_YESNO, vm::make_str(message), vm::null, vm::null, vm::null, &return_code);
// Reschedule after a blocking dialog returns // Reschedule after a blocking dialog returns
if (ppu.check_state()) if (ppu.check_state())
@ -1170,7 +1172,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
return CELL_SAVEDATA_ERROR_INTERNAL; return CELL_SAVEDATA_ERROR_INTERNAL;
} }
if (g_last_user_response != CELL_MSGDIALOG_BUTTON_YES) if (return_code != CELL_MSGDIALOG_BUTTON_YES)
{ {
if (selected >= 0) if (selected >= 0)
{ {
@ -1287,7 +1289,8 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
lv2_obj::sleep(ppu); lv2_obj::sleep(ppu);
// Get user confirmation by opening a blocking dialog // Get user confirmation by opening a blocking dialog
error_code res = open_msg_dialog(true, CELL_MSGDIALOG_TYPE_SE_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_YESNO, vm::make_str(message)); s32 return_code = CELL_MSGDIALOG_BUTTON_NONE;
error_code res = open_msg_dialog(true, CELL_MSGDIALOG_TYPE_SE_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_YESNO, vm::make_str(message), vm::null, vm::null, vm::null, &return_code);
// Reschedule after a blocking dialog returns // Reschedule after a blocking dialog returns
if (ppu.check_state()) if (ppu.check_state())
@ -1300,7 +1303,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
return CELL_SAVEDATA_ERROR_INTERNAL; return CELL_SAVEDATA_ERROR_INTERNAL;
} }
if (g_last_user_response != CELL_MSGDIALOG_BUTTON_YES) if (return_code != CELL_MSGDIALOG_BUTTON_YES)
{ {
return CELL_CANCEL; return CELL_CANCEL;
} }

View file

@ -279,8 +279,6 @@ namespace rsx
} }
return error; return error;
} }
g_last_user_response = return_code;
} }
else else
{ {

View file

@ -398,7 +398,6 @@ namespace rsx
if (on_close && use_callback) if (on_close && use_callback)
{ {
g_last_user_response = return_code;
on_close(return_code); on_close(return_code);
} }

View file

@ -85,14 +85,12 @@ void msg_dialog_frame::Create(const std::string& msg, const std::string& title)
connect(m_button_yes, &QAbstractButton::clicked, [this]() connect(m_button_yes, &QAbstractButton::clicked, [this]()
{ {
g_last_user_response = CELL_MSGDIALOG_BUTTON_YES;
if (on_close) on_close(CELL_MSGDIALOG_BUTTON_YES); if (on_close) on_close(CELL_MSGDIALOG_BUTTON_YES);
m_dialog->accept(); m_dialog->accept();
}); });
connect(m_button_no, &QAbstractButton::clicked, [this]() connect(m_button_no, &QAbstractButton::clicked, [this]()
{ {
g_last_user_response = CELL_MSGDIALOG_BUTTON_NO;
if (on_close) on_close(CELL_MSGDIALOG_BUTTON_NO); if (on_close) on_close(CELL_MSGDIALOG_BUTTON_NO);
m_dialog->accept(); m_dialog->accept();
}); });
@ -117,7 +115,6 @@ void msg_dialog_frame::Create(const std::string& msg, const std::string& title)
connect(m_button_ok, &QAbstractButton::clicked, [this]() connect(m_button_ok, &QAbstractButton::clicked, [this]()
{ {
g_last_user_response = CELL_MSGDIALOG_BUTTON_OK;
if (on_close) on_close(CELL_MSGDIALOG_BUTTON_OK); if (on_close) on_close(CELL_MSGDIALOG_BUTTON_OK);
m_dialog->accept(); m_dialog->accept();
}); });
@ -129,7 +126,6 @@ void msg_dialog_frame::Create(const std::string& msg, const std::string& title)
{ {
if (!type.disable_cancel) if (!type.disable_cancel)
{ {
g_last_user_response = CELL_MSGDIALOG_BUTTON_ESCAPE;
if (on_close) on_close(CELL_MSGDIALOG_BUTTON_ESCAPE); if (on_close) on_close(CELL_MSGDIALOG_BUTTON_ESCAPE);
} }
}); });