Savestates: Rename DeferDeserialization, add some asserts

This commit is contained in:
Eladash 2023-12-31 21:10:51 +02:00 committed by Elad Ashkenazi
parent f5d39ef7f2
commit ce5f7bd4ff
9 changed files with 35 additions and 16 deletions

View File

@ -46,7 +46,7 @@ KeyboardHandlerBase::KeyboardHandlerBase(utils::serial* ar)
if (m_info.max_connect)
{
Emu.DeferDeserialization([this]()
Emu.PostponeInitCode([this]()
{
Init(m_info.max_connect);
auto lk = init.init();

View File

@ -46,7 +46,7 @@ MouseHandlerBase::MouseHandlerBase(utils::serial* ar)
if (m_info.max_connect)
{
Emu.DeferDeserialization([this]()
Emu.PostponeInitCode([this]()
{
Init(m_info.max_connect);
auto lk = init.init();

View File

@ -45,7 +45,7 @@ CellError lv2_cond::on_id_create()
ensure(!!Emu.DeserialManager());
Emu.DeferDeserialization([this]()
Emu.PostponeInitCode([this]()
{
if (!mutex)
{

View File

@ -77,7 +77,7 @@ std::shared_ptr<lv2_event_queue> lv2_event_queue::load_ptr(utils::serial& ar, st
fmt::throw_exception("Failed in event queue pointer deserialization (invalid ID): location: %s, id=0x%x", msg, id);
}
Emu.DeferDeserialization([id, &queue, msg_str = std::string{msg}]()
Emu.PostponeInitCode([id, &queue, msg_str = std::string{msg}]()
{
// Defer resolving
queue = idm::get_unlocked<lv2_obj, lv2_event_queue>(id);

View File

@ -28,7 +28,7 @@ lv2_int_tag::lv2_int_tag(utils::serial& ar) noexcept
if (!ptr && id)
{
Emu.DeferDeserialization([id, &handler = this->handler]()
Emu.PostponeInitCode([id, &handler = this->handler]()
{
handler = ensure(idm::get_unlocked<lv2_obj, lv2_int_serv>(id));
});

View File

@ -105,7 +105,7 @@ u64 lv2_timer::check_unlocked(u64 _now) noexcept
lv2_timer_thread::lv2_timer_thread()
{
Emu.DeferDeserialization([this]()
Emu.PostponeInitCode([this]()
{
idm::select<lv2_obj, lv2_timer>([&](u32 id, lv2_timer&)
{

View File

@ -202,22 +202,36 @@ void init_fxo_for_exec(utils::serial* ar, bool full = false)
Emu.ConfigurePPUCache();
g_fxo->init(false, ar);
g_fxo->init(false, ar, [](){ Emu.ExecPostponedInitCode(); });
Emu.GetCallbacks().init_gs_render(ar);
Emu.GetCallbacks().init_pad_handler(Emu.GetTitleID());
Emu.GetCallbacks().init_kb_handler();
Emu.GetCallbacks().init_mouse_handler();
usz pos = 0;
if (ar)
{
Emu.ExecDeserializationRemnants();
pos = ar->pos;
}
[[maybe_unused]] auto flags = (*ar)(Emu.m_savestate_extension_flags1);
// TODO: Remove second call when possible
Emu.ExecPostponedInitCode();
if (ar)
{
ensure(pos == ar->pos);
(*ar)(Emu.m_savestate_extension_flags1);
const usz advance = (Emu.m_savestate_extension_flags1 & Emulator::SaveStateExtentionFlags1::SupportsMenuOpenResume ? 32 : 31);
load_and_check_reserved(*ar, advance); // Reserved area
// Reserved area
if (!load_and_check_reserved(*ar, advance))
{
sys_log.error("Potential failure to load savestate: padding buyes are not 0. %s", *ar);
}
}
}

View File

@ -145,11 +145,11 @@ class Emulator final
std::vector<std::shared_ptr<atomic_t<u32>>> m_pause_msgs_refs;
std::vector<std::function<void()>> deferred_deserialization;
std::vector<std::function<void()>> m_postponed_init_code;
void ExecDeserializationRemnants()
void ExecPostponedInitCode()
{
for (auto&& func : ::as_rvalue(std::move(deferred_deserialization)))
for (auto&& func : ::as_rvalue(std::move(m_postponed_init_code)))
{
func();
}
@ -200,9 +200,9 @@ public:
CallFromMainThread(std::move(func), nullptr, true, static_cast<u64>(counter));
}
void DeferDeserialization(std::function<void()>&& func)
void PostponeInitCode(std::function<void()>&& func)
{
deferred_deserialization.emplace_back(std::move(func));
m_postponed_init_code.emplace_back(std::move(func));
}
/** Set emulator mode to running unconditionnaly.

View File

@ -242,7 +242,7 @@ namespace stx
*m_info++ = nullptr;
}
void init(bool reset = true, utils::serial* ar = nullptr)
void init(bool reset = true, utils::serial* ar = nullptr, std::function<void()> func = {})
{
if (reset)
{
@ -297,6 +297,11 @@ namespace stx
}
}
if (func)
{
func();
}
// Launch threads
for (auto it = m_info; it != info_before; it--)
{