From 8f7192f1a04324f51bb507ab42aa6d18edb55be3 Mon Sep 17 00:00:00 2001 From: Ricardo Antunes Date: Sat, 7 Oct 2023 15:55:04 +0100 Subject: [PATCH] feat(ecs): implement reflection for Entity --- core/include/cubos/core/ecs/entity/entity.hpp | 4 ++++ core/src/cubos/core/ecs/entity/entity.cpp | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/core/include/cubos/core/ecs/entity/entity.hpp b/core/include/cubos/core/ecs/entity/entity.hpp index 7726166cf..8f3de15d9 100644 --- a/core/include/cubos/core/ecs/entity/entity.hpp +++ b/core/include/cubos/core/ecs/entity/entity.hpp @@ -7,6 +7,8 @@ #include #include +#include + namespace cubos::core::ecs { /// @brief Identifies an entity. @@ -19,6 +21,8 @@ namespace cubos::core::ecs /// @ingroup core-ecs-entity struct Entity { + CUBOS_REFLECT; + /// @brief Type used to store which components an entity has. using Mask = std::bitset; diff --git a/core/src/cubos/core/ecs/entity/entity.cpp b/core/src/cubos/core/ecs/entity/entity.cpp index c787c0bf0..bafeb63b8 100644 --- a/core/src/cubos/core/ecs/entity/entity.cpp +++ b/core/src/cubos/core/ecs/entity/entity.cpp @@ -3,9 +3,27 @@ #include #include #include +#include +#include +#include +#include using cubos::core::ecs::Entity; using cubos::core::ecs::EntityHash; +using cubos::core::reflection::ConstructibleTrait; +using cubos::core::reflection::FieldsTrait; +using cubos::core::reflection::Type; + +CUBOS_REFLECT_IMPL(Entity) +{ + return Type::create("cubos::core::ecs::Entity") + .with(ConstructibleTrait::typed() + .withCopyConstructor() + .withMoveConstructor() + .withDefaultConstructor() + .build()) + .with(FieldsTrait().withField("index", &Entity::index).withField("generation", &Entity::generation)); +} template <> void cubos::core::data::old::serialize(Serializer& ser, const Entity& obj, const char* name)