Fixed TAS movie serialization

This commit is contained in:
Hamish Milne 2020-04-06 21:23:39 +01:00
parent ac37de10fc
commit 7ff985cef9
5 changed files with 39 additions and 37 deletions

View File

@ -534,6 +534,17 @@ void System::Reset() {
template <class Archive>
void System::serialize(Archive& ar, const unsigned int file_version) {
if (Archive::is_loading::value) {
// When loading, we want to make sure any lingering state gets cleared out before we begin.
// Shutdown, but persist a few things between loads...
Shutdown(true);
// Re-initialize everything like it was before
auto system_mode = this->app_loader->LoadKernelSystemMode();
auto n3ds_mode = this->app_loader->LoadKernelN3dsMode();
Init(*m_emu_window, *system_mode.first, *n3ds_mode.first);
}
u32 num_cores;
if (Archive::is_saving::value) {
num_cores = this->GetNumCores();
@ -565,11 +576,14 @@ void System::serialize(Archive& ar, const unsigned int file_version) {
ar&* memory.get();
ar&* kernel.get();
VideoCore::serialize(ar, file_version);
ar& Movie::GetInstance();
// This needs to be set from somewhere - might as well be here!
if (Archive::is_loading::value) {
Service::GSP::SetGlobalModule(*this);
memory->SetDSP(*dsp_core);
cheat_engine->Connect();
}
}

View File

@ -5,6 +5,7 @@
#pragma once
#include <functional>
#include <boost/serialization/vector.hpp>
#include "common/common_types.h"
namespace Service {
@ -41,8 +42,8 @@ public:
return s_instance;
}
void StartPlayback(const std::string& movie_file,
std::function<void()> completion_callback = [] {});
void StartPlayback(
const std::string& movie_file, std::function<void()> completion_callback = [] {});
void StartRecording(const std::string& movie_file);
/// Prepare to override the clock before playing back movies
@ -132,5 +133,16 @@ private:
u64 init_time;
std::function<void()> playback_completion_callback;
std::size_t current_byte = 0;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
// Only serialize what's needed to make savestates useful for TAS:
u64 _current_byte = static_cast<u64>(current_byte);
ar& _current_byte;
current_byte = static_cast<std::size_t>(_current_byte);
ar& recorded_input;
ar& init_time;
}
friend class boost::serialization::access;
};
} // namespace Core

View File

@ -84,13 +84,8 @@ std::vector<SaveStateInfo> ListSaveStates(u64 program_id) {
void System::SaveState(u32 slot) const {
std::ostringstream sstream{std::ios_base::binary};
try {
{
oarchive oa{sstream};
oa&* this;
}
VideoCore::Save(sstream);
} catch (const std::exception& e) {
LOG_ERROR(Core, "Error saving: {}", e.what());
}
@ -159,24 +154,9 @@ void System::LoadState(u32 slot) {
std::ios_base::binary};
decompressed.clear();
// When loading, we want to make sure any lingering state gets cleared out before we begin.
// Shutdown, but persist a few things between loads...
Shutdown(true);
// Re-initialize everything like it was before
auto system_mode = this->app_loader->LoadKernelSystemMode();
auto n3ds_mode = this->app_loader->LoadKernelN3dsMode();
Init(*m_emu_window, *system_mode.first, *n3ds_mode.first);
cheat_engine->Connect();
try {
{
iarchive ia{sstream};
ia&* this;
}
VideoCore::Load(sstream);
} catch (const std::exception& e) {
LOG_ERROR(Core, "Error loading: {}", e.what());
}

View File

@ -88,15 +88,11 @@ u16 GetResolutionScaleFactor() {
}
}
void Save(std::ostream& stream) {
oarchive oa{stream};
oa& Pica::g_state;
}
void Load(std::istream& stream) {
iarchive ia{stream};
ia& Pica::g_state;
// TODO: Flush/reset things
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& Pica::g_state;
}
} // namespace VideoCore
SERIALIZE_IMPL(VideoCore)

View File

@ -62,7 +62,7 @@ void RequestScreenshot(void* data, std::function<void()> callback,
u16 GetResolutionScaleFactor();
void Save(std::ostream& stream);
void Load(std::istream& stream);
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version);
} // namespace VideoCore