Skip to content

Commit

Permalink
feat(ecs): add untyped World::registerComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Nov 26, 2023
1 parent 81faddb commit bbef379
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
19 changes: 9 additions & 10 deletions core/include/cubos/core/ecs/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ namespace cubos::core::ecs
void registerResource(TArgs... args);

/// @brief Registers a component type.
/// @note Should be called before other operations, aside from @ref registerResource().
/// @param type Component type.
void registerComponent(const reflection::Type& type);

/// @brief Registers a component type.
/// @tparam T Component type.
template <typename T>
void registerComponent();
template <reflection::Reflectable T>
void registerComponent()
{
this->registerComponent(reflection::reflect<T>());
}

/// @brief Locks a resource for reading and returns it.
/// @tparam T Resource type.
Expand Down Expand Up @@ -376,13 +382,6 @@ namespace cubos::core::ecs
mResourceManager.add<T>(args...);
}

template <typename T>
void World::registerComponent()
{
CUBOS_TRACE("Registered component '{}'", reflection::reflect<T>().name());
mComponentManager.registerType(reflection::reflect<T>());
}

template <typename T>
ReadResource<T> World::read() const
{
Expand Down
6 changes: 6 additions & 0 deletions core/src/cubos/core/ecs/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ World::World(std::size_t initialCapacity)
// Edu: BAH!
}

void World::registerComponent(const reflection::Type& type)
{
CUBOS_TRACE("Registered component '{}'", type.name());
mComponentManager.registerType(type);
}

Entity World::create()
{
Entity::Mask mask{};
Expand Down

0 comments on commit bbef379

Please sign in to comment.