Skip to content

Commit

Permalink
IdManager.h: Savestate fix part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Oct 5, 2023
1 parent b2e969e commit d335d35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
13 changes: 9 additions & 4 deletions rpcs3/Emu/IdManager.h
Expand Up @@ -48,10 +48,13 @@ namespace id_manager
}

template <typename T>
concept IdmCompatible = requires () { T::id_base, T::id_step, T::id_count; };
concept IdmCompatible = requires () { +T::id_base, +T::id_step, +T::id_count; };

template <typename T>
concept IdmSavable = IdmCompatible<T> && T::savestate_init_pos != 0 && (requires () { std::declval<T>().save(std::declval<stx::exact_t<utils::serial&>>()); });
concept IdmBaseCompatible = (std::is_final_v<T> ? IdmCompatible<T> : !!(requires () { +T::id_step, +T::id_count; }));

template <typename T>
concept IdmSavable = IdmBaseCompatible<T> && T::savestate_init_pos != 0 && (requires () { std::declval<T>().save(std::declval<stx::exact_t<utils::serial&>>()); });

// Last allocated ID for constructors
extern thread_local u32 g_id;
Expand Down Expand Up @@ -103,7 +106,7 @@ namespace id_manager
template <typename T>
struct id_traits_load_func<T, std::void_t<decltype(&T::load)>>
{
static constexpr std::shared_ptr<void>(*load)(utils::serial&) = &T::load;
static constexpr std::shared_ptr<void>(*load)(utils::serial&) = [](utils::serial& ar) -> std::shared_ptr<void> { return T::load(stx::exact_t<utils::serial&>(ar)); };
};

template <typename T, typename = void>
Expand Down Expand Up @@ -172,7 +175,7 @@ namespace id_manager
{
typeinfo info{};

using C = std::conditional_t<IdmSavable<T>, T, dummy_construct>;
using C = std::conditional_t<IdmCompatible<T> && IdmSavable<T>, T, dummy_construct>;
using Type = std::conditional_t<IdmCompatible<T>, T, dummy_construct>;

if constexpr (std::is_same_v<C, T>)
Expand Down Expand Up @@ -248,6 +251,8 @@ namespace id_manager
template <typename T>
struct id_map
{
static_assert(IdmBaseCompatible<T>, "Please specify IDM compatible type.");

std::vector<std::pair<id_key, std::shared_ptr<void>>> vec{}, private_copy{};
shared_mutex mutex{}; // TODO: Use this instead of global mutex

Expand Down
10 changes: 0 additions & 10 deletions rpcs3/util/fixed_typemap.hpp
Expand Up @@ -117,13 +117,6 @@ namespace stx
*std::launder(static_cast<T*>(ptr)) = state;
}

#ifdef _MSC_VER
template <typename T>
static void call_save(void*, utils::serial&) noexcept
{
}
#endif

template <typename T> requires requires (T& a) { a.save(std::declval<stx::exact_t<utils::serial&>>()); }
static void call_save(void* ptr, utils::serial& ar) noexcept
{
Expand All @@ -144,10 +137,7 @@ namespace stx
r.stop = &call_stop<T>;
}

// TODO: Unconnement and remove call_save overload when MSVC implements it
#ifndef _MSC_VER
if constexpr (!!(requires (T& a) { a.save(std::declval<stx::exact_t<utils::serial&>>()); }))
#endif
{
r.save = &call_save<T>;
}
Expand Down

0 comments on commit d335d35

Please sign in to comment.