/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #include "Base/UUID.hpp" #include "Math/Math.hpp" #include "Math/AABB.hpp" #include "Math/Pose.hpp" #include "Math/DenseVector3i.hpp" #include "Math/Int24.hpp" #include "Math/Range.hpp" #include "Math/RGB10A2.hpp" #include "Math/RGB565.hpp" #include "Math/RGBA5551.hpp" #include "Math/Timestamp.hpp" #include "Base/Version.hpp" #include #include #include namespace c4 { template size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Vector2& v) { return ryml::format(buf, "({},{})", v.x, v.y); } template size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Vector3& v) { return ryml::format(buf, "({},{},{})", v.x, v.y, v.z); } template size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Vector4& v) { return ryml::format(buf, "({},{},{},{})", v.x, v.y, v.z, v.w); } template size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Vector2_SIMD& v) { return ryml::format(buf, "({},{})", v.x, v.y); } template size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Vector3_SIMD& v) { return ryml::format(buf, "({},{},{})", v.x, v.y, v.z); } template size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Matrix3& m) { return ryml::format(buf, "({},{},{}),({},{},{}),({},{},{})", m[0][0], m[1][0], m[2][0], m[0][1], m[1][1], m[2][1], m[0][2], m[1][2], m[2][2]); } template size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Matrix3_SIMD& m) { return ryml::format(buf, "({},{},{}),({},{},{}),({},{},{})", m[0][0], m[1][0], m[2][0], m[0][1], m[1][1], m[2][1], m[0][2], m[1][2], m[2][2]); } template size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Matrix4& m) { return ryml::format(buf, "({},{},{},{}),({},{},{},{}),({},{},{},{}),({},{},{},{})", m[0][0], m[1][0], m[2][0], m[3][0], m[0][1], m[1][1], m[2][1], m[3][1], m[0][2], m[1][2], m[2][2], m[3][2], m[0][3], m[1][3], m[2][3], m[3][3]); } inline size_t to_chars(ryml::substr buf, const OpenVulkano::Math::AABB& bbox) { return ryml::format(buf, "({},{},{}),({},{},{})", bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z); } template size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Pose& pose) { return ryml::format(buf, "({},{},{}),({},{},{},{})", pose.GetPosition().x, pose.GetPosition().y, pose.GetPosition().z, pose.GetOrientation().x, pose.GetOrientation().y, pose.GetOrientation().z, pose.GetOrientation().w); } template bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector2* v) { size_t ret = ryml::unformat(buf, "({},{})", v->x, v->y); return ret != ryml::yml::npos; } template bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector3* v) { size_t ret = ryml::unformat(buf, "({},{},{})", v->x, v->y, v->z); return ret != ryml::yml::npos; } template bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector4* v) { size_t ret = ryml::unformat(buf, "({},{},{},{})", v->x, v->y, v->z, v->w); return ret != ryml::yml::npos; } template bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector2_SIMD* v) { size_t ret = ryml::unformat(buf, "({},{})", v->x, v->y); return ret != ryml::yml::npos; } template bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector3_SIMD* v) { size_t ret = ryml::unformat(buf, "({},{},{})", v->x, v->y, v->z); return ret != ryml::yml::npos; } template size_t from_chars(ryml::csubstr buf, OpenVulkano::Math::Matrix3* mp) { auto& m = *mp; size_t ret = ryml::unformat(buf, "({},{},{}),({},{},{}),({},{},{})", m[0][0], m[1][0], m[2][0], m[0][1], m[1][1], m[2][1], m[0][2], m[1][2], m[2][2]); return ret != ryml::yml::npos; } template size_t from_chars(ryml::csubstr buf, OpenVulkano::Math::Matrix3_SIMD* mp) { auto& m = *mp; size_t ret = ryml::unformat(buf, "({},{},{}),({},{},{}),({},{},{})", m[0][0], m[1][0], m[2][0], m[0][1], m[1][1], m[2][1], m[0][2], m[1][2], m[2][2]); return ret != ryml::yml::npos; } template size_t from_chars(ryml::csubstr buf, OpenVulkano::Math::Matrix4* mp) { auto& m = *mp; size_t ret = ryml::unformat(buf, "({},{},{},{}),({},{},{},{}),({},{},{},{}),({},{},{},{})", m[0][0], m[1][0], m[2][0], m[3][0], m[0][1], m[1][1], m[2][1], m[3][1], m[0][2], m[1][2], m[2][2], m[3][2], m[0][3], m[1][3], m[2][3], m[3][3]); return ret != ryml::yml::npos; } inline bool from_chars(ryml::csubstr buf, OpenVulkano::Math::AABB* bbox) { size_t ret = ryml::unformat(buf, "({},{},{}),({},{},{})", bbox->min.x, bbox->min.y, bbox->min.z, bbox->max.x, bbox->max.y, bbox->max.z); return ret != ryml::yml::npos; } template bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Pose* pose) { size_t ret = ryml::unformat(buf, "({},{},{}),({},{},{},{})", pose->GetPosition().x, pose->GetPosition().y, pose->GetPosition().z, pose->GetOrientation().x, pose->GetOrientation().y, pose->GetOrientation().z, pose->GetOrientation().w); return ret != ryml::yml::npos; } inline size_t to_chars(ryml::substr buf, const OpenVulkano::UUID& uuid) { return ryml::format(buf, "{}", uuid.string()); } inline bool from_chars(ryml::csubstr buf, OpenVulkano::UUID* uuid) { uuid->assign(buf.str); return true; } inline size_t to_chars(ryml::substr buf, const OpenVulkano::Version& version) { return ryml::format(buf, "{}", static_cast(version)); } inline bool from_chars(ryml::csubstr buf, OpenVulkano::Version* version) { *version = OpenVulkano::Version(buf.str); return true; } template inline size_t to_chars( ryml::substr buf, const OpenVulkano::Math::DenseVector3i& vec) { return ryml::format(buf, "({},{},{})", vec.X(), vec.Y(), vec.Z()); } template inline bool from_chars(ryml::csubstr buf, OpenVulkano::Math::DenseVector3i* vec) { int x, y, z; size_t ret = ryml::unformat(buf, "({},{},{})", x, y, z); if (ret != ryml::yml::npos) { *vec = OpenVulkano::Math::DenseVector3i(x, y, z); return true; } return false; } inline size_t to_chars(c4::substr buf, const OpenVulkano::int24& value) { int intValue = static_cast(value); return ryml::format(buf, "{}", intValue); } inline bool from_chars(c4::csubstr buf, OpenVulkano::int24* value) { int intValue; size_t ret = ryml::unformat(buf, "{}", intValue); if (ret != ryml::yml::npos) { *value = OpenVulkano::int24(intValue); return true; } return false; } template size_t to_chars(c4::substr buf, const OpenVulkano::Math::Range& range) { return ryml::format(buf, "[{},{}]", range.GetMin(), range.GetMax()); } template bool from_chars(c4::csubstr buf, OpenVulkano::Math::Range* range) { T minVal, maxVal; size_t ret = ryml::unformat(buf, "[{},{}]", minVal, maxVal); if (ret != ryml::yml::npos) { *range = OpenVulkano::Math::Range(minVal, maxVal); return true; } return false; } template size_t to_chars(c4::substr buf, const OpenVulkano::Math::RGB10A2& color) { return ryml::format(buf, "[{},{},{},{}]", color.r, color.g, color.b, color.a); } template bool from_chars(c4::csubstr buf, OpenVulkano::Math::RGB10A2* color) { T r, g, b, a; size_t ret = ryml::unformat(buf, "[{},{},{},{}]", r, g, b, a); if (ret != ryml::yml::npos) { color->r = r; color->g = g; color->b = b; color->a = a; return true; } return false; } inline size_t to_chars(ryml::substr buf, const OpenVulkano::Math::RGB565& rgb) { return ryml::format(buf, "[{},{},{}]", rgb.r, rgb.g, rgb.b); } inline bool from_chars(ryml::csubstr buf, OpenVulkano::Math::RGB565* rgb) { int r, g, b; size_t ret = ryml::unformat (buf, "[{},{},{}]", r, g, b); rgb->r = r; rgb->g = g; rgb->b = b; return ret != ryml::yml::npos; } inline size_t to_chars(c4::substr buf, const OpenVulkano::Math::RGBA5551& color) { return ryml::format(buf, "[{},{},{},{}]", color.r, color.g, color.b, color.a); } inline bool from_chars(c4::csubstr buf, OpenVulkano::Math::RGBA5551* color) { int r, g, b, a; size_t ret = ryml::unformat(buf, "[{},{},{},{}]", r, g, b, a); if (ret != ryml::yml::npos) { color->r = r; color->g = g; color->b = b; color->a = a; return true; } return false; } inline size_t to_chars(c4::substr buf, const OpenVulkano::Math::Timestamp& ts) { return ryml::format(buf, "{}", ts.GetNanos()); } inline bool from_chars(c4::csubstr buf, OpenVulkano::Math::Timestamp* ts) { uint64_t nanos; size_t ret = ryml::unformat(buf, "{}", nanos); if (ret != ryml::yml::npos) { *ts = OpenVulkano::Math::Timestamp(nanos); return true; } return false; } }