PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
glm_node.h
1#pragma once
2
3#include "pixelbullet/serialization/node.h"
4#include "pixelbullet/serialization/node_reader.h"
5
6#include <glm/glm.hpp>
7
8#include <utility>
9
10namespace pixelbullet
11{
12inline Node& operator<<(Node& node, const glm::vec2& value)
13{
14 node.set_type(NodeType::Array);
15 auto& properties = node.properties();
16 properties.clear();
17
18 Node x;
19 Node y;
20 x << value.x;
21 y << value.y;
22 properties.emplace_back("", std::move(x));
23 properties.emplace_back("", std::move(y));
24 return node;
25}
26
27inline void operator>>(const Node& node, glm::vec2& value)
28{
29 ASSERT(node.type() == NodeType::Array, "Node is not an array");
30 const auto& properties = node.properties();
31 ASSERT(properties.size() >= 2, "Insufficient elements for glm::vec2");
32 properties[0].second >> value.x;
33 properties[1].second >> value.y;
34}
35
36inline Node& operator<<(Node& node, const glm::vec3& value)
37{
38 node.set_type(NodeType::Array);
39 auto& properties = node.properties();
40 properties.clear();
41
42 Node x;
43 Node y;
44 Node z;
45 x << value.x;
46 y << value.y;
47 z << value.z;
48 properties.emplace_back("", std::move(x));
49 properties.emplace_back("", std::move(y));
50 properties.emplace_back("", std::move(z));
51 return node;
52}
53
54inline void operator>>(const Node& node, glm::vec3& value)
55{
56 ASSERT(node.type() == NodeType::Array, "Node is not an array");
57 const auto& properties = node.properties();
58 ASSERT(properties.size() >= 3, "Insufficient elements for glm::vec3");
59 properties[0].second >> value.x;
60 properties[1].second >> value.y;
61 properties[2].second >> value.z;
62}
63
64inline Node& operator<<(Node& node, const glm::vec4& value)
65{
66 node.set_type(NodeType::Array);
67 auto& properties = node.properties();
68 properties.clear();
69
70 Node x;
71 Node y;
72 Node z;
73 Node w;
74 x << value.x;
75 y << value.y;
76 z << value.z;
77 w << value.w;
78 properties.emplace_back("", std::move(x));
79 properties.emplace_back("", std::move(y));
80 properties.emplace_back("", std::move(z));
81 properties.emplace_back("", std::move(w));
82 return node;
83}
84
85inline void operator>>(const Node& node, glm::vec4& value)
86{
87 ASSERT(node.type() == NodeType::Array, "Node is not an array");
88 const auto& properties = node.properties();
89 ASSERT(properties.size() >= 4, "Insufficient elements for glm::vec4");
90 properties[0].second >> value.x;
91 properties[1].second >> value.y;
92 properties[2].second >> value.z;
93 properties[3].second >> value.w;
94}
95
96} // namespace pixelbullet
#define ASSERT(condition,...)
Asserts that a condition is true.
Definition assert.h:142
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:49