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
5#include <glm/glm.hpp>
6
7#include <utility>
8
9namespace pixelbullet
10{
11inline Node& operator<<(Node& node, const glm::vec2& value)
12{
13 node.set_type(NodeType::Array);
14 auto& properties = node.properties();
15 properties.clear();
16
17 Node x;
18 Node y;
19 x << value.x;
20 y << value.y;
21 properties.emplace_back("", std::move(x));
22 properties.emplace_back("", std::move(y));
23 return node;
24}
25
26inline void operator>>(const Node& node, glm::vec2& value)
27{
28 ASSERT(node.type() == NodeType::Array, "Node is not an array");
29 const auto& properties = node.properties();
30 ASSERT(properties.size() >= 2, "Insufficient elements for glm::vec2");
31 properties[0].second >> value.x;
32 properties[1].second >> value.y;
33}
34
35inline Node& operator<<(Node& node, const glm::vec3& value)
36{
37 node.set_type(NodeType::Array);
38 auto& properties = node.properties();
39 properties.clear();
40
41 Node x;
42 Node y;
43 Node z;
44 x << value.x;
45 y << value.y;
46 z << value.z;
47 properties.emplace_back("", std::move(x));
48 properties.emplace_back("", std::move(y));
49 properties.emplace_back("", std::move(z));
50 return node;
51}
52
53inline void operator>>(const Node& node, glm::vec3& value)
54{
55 ASSERT(node.type() == NodeType::Array, "Node is not an array");
56 const auto& properties = node.properties();
57 ASSERT(properties.size() >= 3, "Insufficient elements for glm::vec3");
58 properties[0].second >> value.x;
59 properties[1].second >> value.y;
60 properties[2].second >> value.z;
61}
62
63inline Node& operator<<(Node& node, const glm::vec4& value)
64{
65 node.set_type(NodeType::Array);
66 auto& properties = node.properties();
67 properties.clear();
68
69 Node x;
70 Node y;
71 Node z;
72 Node w;
73 x << value.x;
74 y << value.y;
75 z << value.z;
76 w << value.w;
77 properties.emplace_back("", std::move(x));
78 properties.emplace_back("", std::move(y));
79 properties.emplace_back("", std::move(z));
80 properties.emplace_back("", std::move(w));
81 return node;
82}
83
84inline void operator>>(const Node& node, glm::vec4& value)
85{
86 ASSERT(node.type() == NodeType::Array, "Node is not an array");
87 const auto& properties = node.properties();
88 ASSERT(properties.size() >= 4, "Insufficient elements for glm::vec4");
89 properties[0].second >> value.x;
90 properties[1].second >> value.y;
91 properties[2].second >> value.z;
92 properties[3].second >> value.w;
93}
94} // 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