skypjack / entt

Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more
https://github.com/skypjack/entt/wiki
MIT License
10.04k stars 880 forks source link

[POC] Annotated meta-data #299

Closed Innokentiy-Alaytsev closed 4 years ago

Innokentiy-Alaytsev commented 5 years ago

The purpose of annotated meta-data is to provide better runtime-introspection abilities with less code. Annotations are just properties created with reusable function or functional object.

https://github.com/Innokentiy-Alaytsev/entt/tree/runtime-annotations

I've implemented one of the functions I think is useful. I've renamed the concept from 'decoration' to 'annotation' - I think the new word better represents the purpose. I've only implemented the function for registering meta-data without setter and getter. If you say everything is fine, I'll add implementations for annotated meta-data with setter and getter, annotated meta-type (reflect_annotated), maybe annotated meta-function (func_annotated). Also, I'll try to find a way to minimise the amount of the required code - it's very straight forward, but it may be a support burden.

Innokentiy-Alaytsev commented 4 years ago

I'll retest it a bit later - after new failed attempt to fix the duplicate bug. But previous testing showed that it works just fine.

skypjack commented 4 years ago

Trying to attach to properties for which both key and value have the same type results in duplicate assertion fail due to both properties using the same local static variables.

Is this true also on wip? I cannot reproduce it. Can you give me a hint in this sense?

Innokentiy-Alaytsev commented 4 years ago

I implemented yet another horrible duplicate bug fix. I need this fix to properly test my implementation of annotations and property tuples.

I used the following reflection for test:

        entt::meta<annotated_data_type>()
                .type("annotated_data"_hs)
                .data<&annotated_data_type::i, entt::as_alias_t>("i"_hs)
                    .prop (name_annotation{ std::string{"i"} })
                    .props (
                        int_value_range_annotation{-5, 5},
                        [](){
                            return std::pair{ "from_lambda"_hs, true};
                        },
                        std::pair{"int_prop"_hs, 42},
                        std::pair{"double_prop"_hs, 3.141592653},
                        "key_only"_hs,
                        std::tuple{1,2,3,4})
                    .prop (
                        std::tuple{
                            std::pair{"tup_1"_hs, 1},
                            & nesting_annotation,
                            std::pair{"tup_2"_hs, 2},
                            std::pair{"tup_3"_hs, 3} });

Annotations:

Direct use of a list of properties (std::tuple{1,2,3,4}) is present. Another instance of passing a list of properties in the form of a tuple is also present.

All tests are green.

Innokentiy-Alaytsev commented 4 years ago

Trying to attach to properties for which both key and value have the same type results in duplicate assertion fail due to both properties using the same local static variables.

Is this true also on wip? I cannot reproduce it. Can you give me a hint in this sense?

Yes, it is on wip. Here's how you can reproduce in:

         entt::meta<properties>()
                 .data<properties::prop_bool>("prop_bool"_hs)
                     .prop(properties::prop_int, 0)
+                    .prop(properties::prop_bool, 0)
                 .data<properties::prop_int>("prop_int"_hs)
                     .prop(std::make_tuple(std::make_pair(properties::prop_bool, true), std::make_pair(properties::prop_int, 0)))
skypjack commented 4 years ago

Ok, wip contains a version that shouldn't suffer anymore from this problem. Let me know if I'm wrong.

Innokentiy-Alaytsev commented 4 years ago

I think it's done now