Mar. 25, 2019
Hi.
RTTR has ability to register classes, data members, functions, enumerators and much more.
- Registration
RTTR_REGISTRATION
{
rttr::registration::class_("Transform")
.constructor()
.property("Position", &Transform::mPos)
.property("Scale", &Transform::mScale)
.property("Rotation", &Transform::mRotate);
.method("Init", &Transform::Init);
}
- Use
rttr::type component = rttr::type::get_by_name("Transform");
rttr::constructor ctor = component.get_constructor();
rttr::variant obj = ctor.invoke();
Component* tr = &(obj.convert());
obj->AddComponent(tr);
rttr::instance inst = *tr;
for (auto prop : component.get_properties())
{
if(prop.get_type() == rttr::type::get())
{
float data = json["property_name"].GetFloat();
prop.set_value(tr, data);
}
}
This is just an idea of how type reflections can ease everything. I will upload my whole work on github soon.
I have set up Deserialization and Serialization using rttr such as I don't have to rewrite any of my code again even if I add new components. You still need to register every components and their properties if you want them to be Deserialized and Serialized. I also have Enumeration reflected which removes string to enum if conditions.
Moreover, you can use rttr for method invoking, which can be pretty useful. In my case, I use them for component pool constructors and destructors. So I don't have to write initialization of my components each time I add new.
If you want an example of how you can use it, check out my github repo. Feel free to go through Reflection and Editor code to see rttr references.
That's about it. Cheers!