diff --git a/rpcs3/Emu/CMakeLists.txt b/rpcs3/Emu/CMakeLists.txt index 1b9c412733..f860462abe 100644 --- a/rpcs3/Emu/CMakeLists.txt +++ b/rpcs3/Emu/CMakeLists.txt @@ -74,6 +74,11 @@ else() set_source_files_properties("../util/yaml.cpp" PROPERTIES COMPILE_FLAGS -fexceptions) endif() +if (MSVC) + set_source_files_properties("../util/cereal.cpp" PROPERTIES COMPILE_FLAGS /GR) +else() + set_source_files_properties("../util/cereal.cpp" PROPERTIES COMPILE_FLAGS -frtti) +endif() # Crypto target_sources(rpcs3_emu PRIVATE diff --git a/rpcs3/Emu/RSX/Capture/rsx_replay.h b/rpcs3/Emu/RSX/Capture/rsx_replay.h index ff3422f2d1..951388fbb7 100644 --- a/rpcs3/Emu/RSX/Capture/rsx_replay.h +++ b/rpcs3/Emu/RSX/Capture/rsx_replay.h @@ -2,13 +2,9 @@ #include "Emu/CPU/CPUThread.h" #include "Emu/RSX/rsx_methods.h" -#include -#include -#include -#include -#include -#include +#include +#include namespace rsx { diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 40165f8b74..b4521f9d3b 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -18,9 +18,7 @@ #include "Utilities/span.h" #include "Utilities/StrUtil.h" -#include -#include - +#include "util/cereal.hpp" #include "util/asm.hpp" #include @@ -2899,17 +2897,19 @@ namespace rsx else if (capture_current_frame) { capture_current_frame = false; - std::stringstream os; - cereal::BinaryOutputArchive archive(os); - const std::string& filePath = fs::get_config_dir() + "captures/" + Emu.GetTitleID() + "_" + date_time::current_time_narrow() + "_capture.rrc"; - archive(frame_capture); - { - // todo: may want to compress this data? - fs::file f(filePath, fs::rewrite); - f.write(os.str()); - } - rsx_log.success("capture successful: %s", filePath.c_str()); + const std::string file_path = fs::get_config_dir() + "captures/" + Emu.GetTitleID() + "_" + date_time::current_time_narrow() + "_capture.rrc"; + const std::string file_data = cereal_serialize(frame_capture); + + // todo: may want to compress this data? + if (fs::write_file(file_path, fs::rewrite, file_data)) + { + rsx_log.success("Capture successful: %s", file_path); + } + else + { + rsx_log.fatal("Capture failed: %s (%s)", file_path, fs::g_tls_error); + } frame_capture.reset(); Emu.Pause(); diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 240b306661..52fda9fdff 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -34,9 +34,7 @@ #include "util/sysinfo.hpp" #include "util/yaml.hpp" #include "util/logs.hpp" - -#include "cereal/archives/binary.hpp" -#include +#include "util/cereal.hpp" #include #include @@ -521,14 +519,16 @@ std::string Emulator::PPUCache() const bool Emulator::BootRsxCapture(const std::string& path) { - if (!fs::is_file(path)) + fs::file in_file(path); + + if (!in_file) + { return false; + } - std::fstream f(path, std::ios::in | std::ios::binary); - - cereal::BinaryInputArchive archive(f); std::unique_ptr frame = std::make_unique(); - archive(*frame); + cereal_deserialize(*frame, in_file.to_string()); + in_file.close(); if (frame->magic != rsx::FRAME_CAPTURE_MAGIC) { diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index feeb22e99d..f1f9f2481a 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -107,6 +107,7 @@ NotUsing + true NotUsing diff --git a/rpcs3/util/cereal.cpp b/rpcs3/util/cereal.cpp index fe120f29a6..750ae334f3 100644 --- a/rpcs3/util/cereal.cpp +++ b/rpcs3/util/cereal.cpp @@ -1,5 +1,18 @@ +#include "util/cereal.hpp" #include #include "Utilities/StrFmt.h" +#include "Emu/RSX/RSXThread.h" +#include "Emu/RSX/Capture/rsx_capture.h" + +#include "cereal/archives/binary.hpp" +#include +#include +#include +#include +#include +#include + +#include namespace cereal { @@ -7,4 +20,26 @@ namespace cereal { fmt::throw_exception("%s", err); } + + [[noreturn]] void throw_exception(const char* err) + { + fmt::throw_exception("%s", err); + } +} + +template <> +std::string cereal_serialize(const rsx::frame_capture_data& data) +{ + std::ostringstream os; + cereal::BinaryOutputArchive archive(os); + archive(data); + return os.str(); +} + +template <> +void cereal_deserialize(rsx::frame_capture_data& data, const std::string& src) +{ + std::istringstream is(src); + cereal::BinaryInputArchive archive(is); + archive(data); } diff --git a/rpcs3/util/cereal.hpp b/rpcs3/util/cereal.hpp new file mode 100644 index 0000000000..28329f72ec --- /dev/null +++ b/rpcs3/util/cereal.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +template +std::string cereal_serialize(const T&); + +template +void cereal_deserialize(T& out, const std::string& data);