From ed2764c5fa73a49207ebe3d9eff142a78d62260f Mon Sep 17 00:00:00 2001 From: Diogo Miranda Date: Sat, 3 Feb 2024 18:18:44 +0000 Subject: [PATCH] feat(core): Add name component to spawned entities from blueprints --- core/include/cubos/core/ecs/world.hpp | 6 ++++++ core/src/cubos/core/ecs/blueprint.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/core/include/cubos/core/ecs/world.hpp b/core/include/cubos/core/ecs/world.hpp index e2a2a8b6dd..d47f0c94ce 100644 --- a/core/include/cubos/core/ecs/world.hpp +++ b/core/include/cubos/core/ecs/world.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -27,6 +28,11 @@ namespace cubos::core::ecs class World { public: + /// @brief World constructor. + World() { + this->registerComponent(); + } + /// @brief Used to access the components in an entity. class Components; diff --git a/core/src/cubos/core/ecs/blueprint.cpp b/core/src/cubos/core/ecs/blueprint.cpp index d26421ba7c..8a6273ea19 100644 --- a/core/src/cubos/core/ecs/blueprint.cpp +++ b/core/src/cubos/core/ecs/blueprint.cpp @@ -1,7 +1,9 @@ #include +#include #include #include #include +#include #include #include #include @@ -11,9 +13,11 @@ using cubos::core::ecs::Blueprint; using cubos::core::ecs::Entity; using cubos::core::ecs::EntityHash; +using cubos::core::ecs::Name; using cubos::core::memory::AnyValue; using cubos::core::memory::UnorderedBimap; using cubos::core::reflection::ConstructibleTrait; +using cubos::core::reflection::reflect; using cubos::core::reflection::Type; Blueprint::Blueprint() = default; @@ -159,6 +163,8 @@ void Blueprint::instantiate(void* userData, Create create, Add add, Relate relat std::unordered_map thisToInstance{}; for (const auto& [entity, name] : mBimap) { + Name nameComponent{name}; + add(userData, entity, AnyValue::moveConstruct(reflect(), (void*)&nameComponent)); thisToInstance.emplace(entity, create(userData, name)); }