Skip to content

Commit

Permalink
feat(core): Add name component to spawned entities from blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
diogomsmiranda committed Feb 3, 2024
1 parent 76cbed2 commit ed2764c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/include/cubos/core/ecs/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cassert>
#include <cstddef>

#include <cubos/core/ecs/name.hpp>
#include <cubos/core/ecs/entity/archetype_graph.hpp>
#include <cubos/core/ecs/entity/pool.hpp>
#include <cubos/core/ecs/resource/manager.hpp>
Expand All @@ -27,6 +28,11 @@ namespace cubos::core::ecs
class World
{
public:
/// @brief World constructor.
World() {
this->registerComponent<Name>();
}

/// @brief Used to access the components in an entity.
class Components;

Expand Down
6 changes: 6 additions & 0 deletions core/src/cubos/core/ecs/blueprint.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <cubos/core/ecs/blueprint.hpp>
#include <cubos/core/ecs/name.hpp>
#include <cubos/core/ecs/reflection.hpp>
#include <cubos/core/log.hpp>
#include <cubos/core/reflection/external/string.hpp>
#include <cubos/core/reflection/reflect.hpp>
#include <cubos/core/reflection/traits/array.hpp>
#include <cubos/core/reflection/traits/constructible.hpp>
#include <cubos/core/reflection/traits/dictionary.hpp>
Expand All @@ -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;
Expand Down Expand Up @@ -159,6 +163,8 @@ void Blueprint::instantiate(void* userData, Create create, Add add, Relate relat
std::unordered_map<Entity, Entity, EntityHash> thisToInstance{};
for (const auto& [entity, name] : mBimap)
{
Name nameComponent{name};
add(userData, entity, AnyValue::moveConstruct(reflect<Name>(), (void*)&nameComponent));
thisToInstance.emplace(entity, create(userData, name));
}

Expand Down

0 comments on commit ed2764c

Please sign in to comment.