mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-08 10:35:47 +00:00
Core: add way to serialize and deserialize a 4x4 matrix to Json
This commit is contained in:
parent
ec5f7bbe93
commit
f58a133edc
2 changed files with 23 additions and 0 deletions
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
|
|
||||||
picojson::object ToJsonObject(const Common::Vec3& vec)
|
picojson::object ToJsonObject(const Common::Vec3& vec)
|
||||||
|
@ -23,6 +25,24 @@ void FromJson(const picojson::object& obj, Common::Vec3& vec)
|
||||||
vec.z = ReadNumericFromJson<float>(obj, "z").value_or(0.0f);
|
vec.z = ReadNumericFromJson<float>(obj, "z").value_or(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
picojson::object ToJsonObject(const Common::Matrix44& mat)
|
||||||
|
{
|
||||||
|
picojson::object obj;
|
||||||
|
for (std::size_t i = 0; i < mat.data.size(); i++)
|
||||||
|
{
|
||||||
|
obj.emplace(fmt::format("m{}", i), mat.data[i]);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FromJson(const picojson::object& obj, Common::Matrix44& mat)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < mat.data.size(); i++)
|
||||||
|
{
|
||||||
|
mat.data[i] = ReadNumericFromJson<float>(obj, fmt::format("m{}", i)).value_or(0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<std::string> ReadStringFromJson(const picojson::object& obj, const std::string& key)
|
std::optional<std::string> ReadStringFromJson(const picojson::object& obj, const std::string& key)
|
||||||
{
|
{
|
||||||
const auto it = obj.find(key);
|
const auto it = obj.find(key);
|
||||||
|
|
|
@ -56,5 +56,8 @@ std::optional<bool> ReadBoolFromJson(const picojson::object& obj, const std::str
|
||||||
picojson::object ToJsonObject(const Common::Vec3& vec);
|
picojson::object ToJsonObject(const Common::Vec3& vec);
|
||||||
void FromJson(const picojson::object& obj, Common::Vec3& vec);
|
void FromJson(const picojson::object& obj, Common::Vec3& vec);
|
||||||
|
|
||||||
|
picojson::object ToJsonObject(const Common::Matrix44& mat);
|
||||||
|
void FromJson(const picojson::object& obj, Common::Matrix44& mat);
|
||||||
|
|
||||||
bool JsonToFile(const std::string& filename, const picojson::value& root, bool prettify = false);
|
bool JsonToFile(const std::string& filename, const picojson::value& root, bool prettify = false);
|
||||||
bool JsonFromFile(const std::string& filename, picojson::value* root, std::string* error);
|
bool JsonFromFile(const std::string& filename, picojson::value* root, std::string* error);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue