Seal cereal includes in util/cereal.cpp

This commit is contained in:
Nekotekina 2021-01-28 10:29:13 +03:00
parent 34274ec391
commit 67dd6754a6
7 changed files with 73 additions and 27 deletions

View file

@ -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

View file

@ -2,13 +2,9 @@
#include "Emu/CPU/CPUThread.h"
#include "Emu/RSX/rsx_methods.h"
#include <unordered_map>
#include <cereal/types/vector.hpp>
#include <cereal/types/array.hpp>
#include <cereal/types/string.hpp>
#include <cereal/types/utility.hpp>
#include <cereal/types/unordered_set.hpp>
#include <unordered_map>
#include <unordered_set>
namespace rsx
{

View file

@ -18,9 +18,7 @@
#include "Utilities/span.h"
#include "Utilities/StrUtil.h"
#include <cereal/archives/binary.hpp>
#include <cereal/types/unordered_map.hpp>
#include "util/cereal.hpp"
#include "util/asm.hpp"
#include <sstream>
@ -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();

View file

@ -34,9 +34,7 @@
#include "util/sysinfo.hpp"
#include "util/yaml.hpp"
#include "util/logs.hpp"
#include "cereal/archives/binary.hpp"
#include <cereal/types/unordered_map.hpp>
#include "util/cereal.hpp"
#include <thread>
#include <queue>
@ -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<rsx::frame_capture_data> frame = std::make_unique<rsx::frame_capture_data>();
archive(*frame);
cereal_deserialize(*frame, in_file.to_string());
in_file.close();
if (frame->magic != rsx::FRAME_CAPTURE_MAGIC)
{

View file

@ -107,6 +107,7 @@
</ClCompile>
<ClCompile Include="util\cereal.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
</ClCompile>
<ClCompile Include="util\fixed_typemap.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>

View file

@ -1,5 +1,18 @@
#include "util/cereal.hpp"
#include <string>
#include "Utilities/StrFmt.h"
#include "Emu/RSX/RSXThread.h"
#include "Emu/RSX/Capture/rsx_capture.h"
#include "cereal/archives/binary.hpp"
#include <cereal/types/vector.hpp>
#include <cereal/types/array.hpp>
#include <cereal/types/string.hpp>
#include <cereal/types/utility.hpp>
#include <cereal/types/unordered_set.hpp>
#include <cereal/types/unordered_map.hpp>
#include <sstream>
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<rsx::frame_capture_data>(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>(rsx::frame_capture_data& data, const std::string& src)
{
std::istringstream is(src);
cereal::BinaryInputArchive archive(is);
archive(data);
}

9
rpcs3/util/cereal.hpp Normal file
View file

@ -0,0 +1,9 @@
#pragma once
#include <string>
template <typename T>
std::string cereal_serialize(const T&);
template <typename T>
void cereal_deserialize(T& out, const std::string& data);