Savestate/IDM: Do not save unsavable containers

This commit is contained in:
Eladash 2023-06-11 23:45:47 +03:00 committed by Ivan
parent a560121775
commit 5f2f084091
3 changed files with 12 additions and 7 deletions

View File

@ -84,6 +84,11 @@ private:
public: public:
SAVESTATE_INIT_POS(4); // Dependency on PPUs SAVESTATE_INIT_POS(4); // Dependency on PPUs
lv2_obj() noexcept = default;
lv2_obj(u32 i) noexcept : exists{ i } {}
lv2_obj(utils::serial&) noexcept {}
void save(utils::serial&) {}
// Existence validation (workaround for shared-ptr ref-counting) // Existence validation (workaround for shared-ptr ref-counting)
atomic_t<u32> exists = 0; atomic_t<u32> exists = 0;

View File

@ -248,16 +248,17 @@ namespace id_manager
std::vector<std::pair<id_key, std::shared_ptr<void>>> vec{}, private_copy{}; std::vector<std::pair<id_key, std::shared_ptr<void>>> vec{}, private_copy{};
shared_mutex mutex{}; // TODO: Use this instead of global mutex shared_mutex mutex{}; // TODO: Use this instead of global mutex
id_map() id_map() noexcept
{ {
// Preallocate memory // Preallocate memory
vec.reserve(T::id_count); vec.reserve(T::id_count);
} }
// Order it directly before the source type's position // Order it directly before the source type's position
static constexpr double savestate_init_pos = std::bit_cast<double>(std::bit_cast<u64>(T::savestate_init_pos) - 1); static constexpr double savestate_init_pos_original = T::savestate_init_pos;
static constexpr double savestate_init_pos = std::bit_cast<double>(std::bit_cast<u64>(savestate_init_pos_original) - 1);
id_map(utils::serial& ar) id_map(utils::serial& ar) noexcept requires (savestate_init_pos_original != 0 && std::is_constructible_v<T, stx::exact_t<utils::serial&>>)
{ {
vec.resize(T::id_count); vec.resize(T::id_count);
@ -297,7 +298,7 @@ namespace id_manager
} }
} }
void save(utils::serial& ar) void save(utils::serial& ar) requires (savestate_init_pos_original != 0 && std::is_constructible_v<T, stx::exact_t<utils::serial&>>)
{ {
u32 obj_count = 0; u32 obj_count = 0;
usz obj_count_offs = ar.data.size(); usz obj_count_offs = ar.data.size();
@ -334,8 +335,7 @@ namespace id_manager
std::memcpy(ar.data.data() + obj_count_offs, &obj_count, sizeof(obj_count)); std::memcpy(ar.data.data() + obj_count_offs, &obj_count, sizeof(obj_count));
} }
template <bool dummy = false> requires (std::is_assignable_v<T&, thread_state>) id_map& operator=(thread_state state) noexcept requires (std::is_assignable_v<T&, thread_state>)
id_map& operator=(thread_state state)
{ {
if (private_copy.empty()) if (private_copy.empty())
{ {

View File

@ -1353,4 +1353,4 @@ extern bool serialize(utils::serial& ar, T& obj);
}() }()
#define ENABLE_BITWISE_SERIALIZATION using enable_bitcopy = std::true_type; #define ENABLE_BITWISE_SERIALIZATION using enable_bitcopy = std::true_type;
#define SAVESTATE_INIT_POS(x) static constexpr double savestate_init_pos = (x) #define SAVESTATE_INIT_POS(...) static constexpr double savestate_init_pos = (__VA_ARGS__)