Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement reflection for Entity #689

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Check warning on line 17 in core/src/cubos/core/ecs/entity/entity.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/ecs/entity/entity.cpp#L17

Added line #L17 was not covered by tests
{
return Type::create("cubos::core::ecs::Entity")
.with(ConstructibleTrait::typed<Entity>()
.withCopyConstructor()
.withMoveConstructor()
.withDefaultConstructor()

Check warning on line 23 in core/src/cubos/core/ecs/entity/entity.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/ecs/entity/entity.cpp#L19-L23

Added lines #L19 - L23 were not covered by tests
.build())
.with(FieldsTrait().withField("index", &Entity::index).withField("generation", &Entity::generation));

Check warning on line 25 in core/src/cubos/core/ecs/entity/entity.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/ecs/entity/entity.cpp#L25

Added line #L25 was not covered by tests
}

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