Unravel Engine C++ Reference
Loading...
Searching...
No Matches
reflection_probe.cpp
Go to the documentation of this file.
3
6
7namespace unravel
8{
10{
11 auto box_predicate_entt = entt::property_predicate(
12 [](const entt::meta_any& obj)
13 {
14 auto data = obj.try_cast<reflection_probe>();
15 return data->type == probe_type::box;
16 });
17 auto sphere_predicate_entt = entt::property_predicate(
18 [](const entt::meta_any& obj)
19 {
20 auto data = obj.try_cast<reflection_probe>();
21 return data->type == probe_type::sphere;
22 });
23 // EnTT meta registration mirroring RTTR
24 entt::meta_factory<probe_type>{}
25 .type("probe_type"_hs)
27 entt::attribute{"name", "probe_type"},
28 entt::attribute{"pretty_name", "Probe Type"},
29 })
30 .data<probe_type::box>("box"_hs)
32 entt::attribute{"name", "box"},
33 entt::attribute{"pretty_name", "Box"}
34 })
35 .data<probe_type::sphere>("sphere"_hs)
37 entt::attribute{"name", "sphere"},
38 entt::attribute{"pretty_name", "Sphere"}
39 });
40
41 entt::meta_factory<reflect_method>{}
42 .type("reflect_method"_hs)
44 entt::attribute{"name", "reflect_method"},
45 entt::attribute{"pretty_name", "Reflect Method"},
46 })
47 .data<reflect_method::environment>("environment"_hs)
49 entt::attribute{"name", "environment"},
50 entt::attribute{"pretty_name", "Environment"}
51 })
52 .data<reflect_method::static_only>("static_only"_hs)
54 entt::attribute{"name", "static_only"},
55 entt::attribute{"pretty_name", "Static Only"}
56 });
57
58 entt::meta_factory<reflection_probe::box>{}
59 .type("box"_hs)
61 entt::attribute{"name", "box"},
62 entt::attribute{"pretty_name", "Box"},
63 })
64 .data<&reflection_probe::box::extents>("extents"_hs)
66 entt::attribute{"name", "extents"},
67 entt::attribute{"pretty_name", "Extents"}
68 })
69 .data<&reflection_probe::box::transition_distance>("transition_distance"_hs)
71 entt::attribute{"name", "transition_distance"},
72 entt::attribute{"pretty_name", "Transition Distance"},
73 entt::attribute{"min", 0.0f},
74 });
75
76 entt::meta_factory<reflection_probe::sphere>{}
77 .type("sphere"_hs)
79 entt::attribute{"name", "sphere"},
80 entt::attribute{"pretty_name", "Sphere"},
81 })
82 .data<&reflection_probe::sphere::range>("range"_hs)
84 entt::attribute{"name", "range"},
85 entt::attribute{"pretty_name", "Range"},
86 entt::attribute{"min", 0.0f},
87 });
88
89 entt::meta_factory<reflection_probe>{}
90 .type("reflection_probe"_hs)
92 entt::attribute{"name", "reflection_probe"},
93 entt::attribute{"pretty_name", "Reflection Probe"},
94 })
95 .data<&reflection_probe::type>("type"_hs)
97 entt::attribute{"name", "type"},
98 entt::attribute{"pretty_name", "Type"}
99 })
100 .data<&reflection_probe::method>("method"_hs)
102 entt::attribute{"name", "method"},
103 entt::attribute{"pretty_name", "Method"}
104 })
105 .data<&reflection_probe::intensity>("intensity"_hs)
107 entt::attribute{"name", "intensity"},
108 entt::attribute{"pretty_name", "Intensity"},
109 entt::attribute{"min", 0.1f},
110 entt::attribute{"max", 3.0f},
111 })
112 .data<&reflection_probe::box_data>("box_data"_hs)
114 entt::attribute{"name", "box_data"},
115 entt::attribute{"pretty_name", "Box"},
116 entt::attribute{"predicate", box_predicate_entt},
117 })
118 .data<&reflection_probe::sphere_data>("sphere_data"_hs)
120 entt::attribute{"name", "sphere_data"},
121 entt::attribute{"pretty_name", "Sphere"},
122 entt::attribute{"predicate", sphere_predicate_entt},
123 });
124}
125
127{
128 try_save(ar, ser20::make_nvp("type", obj.type));
129 try_save(ar, ser20::make_nvp("method", obj.method));
130 try_save(ar, ser20::make_nvp("intensity", obj.intensity));
131 if(obj.type == probe_type::box)
132 {
133 try_save(ar, ser20::make_nvp("extents", obj.box_data.extents));
134 try_save(ar, ser20::make_nvp("transition_distance", obj.box_data.transition_distance));
135 }
136 else
137 {
138 try_save(ar, ser20::make_nvp("range", obj.sphere_data.range));
139 }
140}
143
145{
146 try_load(ar, ser20::make_nvp("type", obj.type));
147 try_load(ar, ser20::make_nvp("method", obj.method));
148 try_load(ar, ser20::make_nvp("intensity", obj.intensity));
149 if(obj.type == probe_type::box)
150 {
151 try_load(ar, ser20::make_nvp("extents", obj.box_data.extents));
152 try_load(ar, ser20::make_nvp("transition_distance", obj.box_data.transition_distance));
153 }
154 else
155 {
156 try_load(ar, ser20::make_nvp("range", obj.sphere_data.range));
157 }
158}
161} // namespace unravel
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
auto property_predicate(property_predicate_t predicate) -> property_predicate_t
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
@ sphere
Sphere type reflection probe.
@ box
Box type reflection probe.
#define REFLECT(cls)
Definition reflection.h:133
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Structure representing a reflection probe.
probe_type type
Type of the reflection probe.