Skip to content

Commit

Permalink
feat(ecs): implement reflection for Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Oct 7, 2023
1 parent 273f8d8 commit 8f7192f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/include/cubos/core/ecs/entity/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <bitset>
#include <cstdint>

#include <cubos/core/reflection/reflect.hpp>

namespace cubos::core::ecs
{
/// @brief Identifies an entity.
Expand All @@ -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<CUBOS_CORE_ECS_MAX_COMPONENTS + 1>;

Expand Down
18 changes: 18 additions & 0 deletions core/src/cubos/core/ecs/entity/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@
#include <cubos/core/data/old/serializer.hpp>
#include <cubos/core/ecs/entity/entity.hpp>
#include <cubos/core/ecs/entity/hash.hpp>
#include <cubos/core/reflection/external/primitives.hpp>
#include <cubos/core/reflection/traits/constructible.hpp>
#include <cubos/core/reflection/traits/fields.hpp>
#include <cubos/core/reflection/type.hpp>

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<Entity>()
.withCopyConstructor()
.withMoveConstructor()
.withDefaultConstructor()
.build())
.with(FieldsTrait().withField("index", &Entity::index).withField("generation", &Entity::generation));
}

template <>
void cubos::core::data::old::serialize<Entity>(Serializer& ser, const Entity& obj, const char* name)
Expand Down

0 comments on commit 8f7192f

Please sign in to comment.