Moving on to cubemaps.
This commit is contained in:
parent
9c75238461
commit
87c513b9f0
113 changed files with 15511 additions and 0 deletions
59
24-cubemaps/src/json.hpp
Normal file
59
24-cubemaps/src/json.hpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#pragma once
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <optional>
|
||||
#include <glm/glm.hpp>
|
||||
#include <vector>
|
||||
|
||||
#define ENROLL_COMPONENT(COMPONENT, ...) \
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(COMPONENT, __VA_ARGS__); \
|
||||
template <> struct NameOf<COMPONENT> { \
|
||||
static constexpr const char *name = #COMPONENT; \
|
||||
};
|
||||
|
||||
// partial specialization (full specialization works too)
|
||||
namespace nlohmann {
|
||||
|
||||
template <>
|
||||
struct adl_serializer<glm::vec3> {
|
||||
static void to_json(json& j, const glm::vec3& opt) {
|
||||
|
||||
}
|
||||
|
||||
static void from_json(const json& j, glm::vec3& opt) {
|
||||
opt = glm::vec3(j[0], j[1], j[2]);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct adl_serializer<std::optional<T>> {
|
||||
static void to_json(json& j, const std::optional<T>& opt) {
|
||||
if (opt == std::nullopt) {
|
||||
j = nullptr;
|
||||
} else {
|
||||
j = *opt; // this will call adl_serializer<T>::to_json which will
|
||||
// find the free function to_json in T's namespace!
|
||||
}
|
||||
}
|
||||
|
||||
static void from_json(const json& j, std::optional<T>& opt) {
|
||||
if (j.is_null() || j == false) {
|
||||
opt = std::nullopt;
|
||||
} else {
|
||||
opt = std::make_optional<T>(j.template get<T>());
|
||||
// same as above, but with adl_serializer<T>::from_json
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct adl_serializer<std::chrono::milliseconds> {
|
||||
static void to_json(json& j, const std::chrono::milliseconds& opt) {
|
||||
j = opt.count();
|
||||
}
|
||||
|
||||
static void from_json(const json& j, std::chrono::milliseconds& opt) {
|
||||
opt = std::chrono::milliseconds{int(j)};
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue