minor changes

This commit is contained in:
Michele Caini
2019-05-15 15:53:35 +02:00
parent 2658ddf868
commit 1442a3853c
3 changed files with 13 additions and 10 deletions

2
TODO
View File

@@ -25,3 +25,5 @@
* multi component registry::remove and some others?
* move CONTRIBUTING.md within doc (for GitHub)
* reactive systems
* test snapshot for empty types

View File

@@ -64,8 +64,8 @@ class basic_registry {
template<typename Component>
struct pool_handler: storage<Entity, Component> {
sigh<void(basic_registry &, const Entity, Component &)> on_construct;
sigh<void(basic_registry &, const Entity, Component &)> on_replace;
sigh<void(basic_registry &, const Entity, std::conditional_t<std::is_empty_v<Component>, const Component &, Component &>)> on_construct;
sigh<void(basic_registry &, const Entity, std::conditional_t<std::is_empty_v<Component>, const Component &, Component &>)> on_replace;
sigh<void(basic_registry &, const Entity)> on_destroy;
void *group{};
@@ -78,10 +78,9 @@ class basic_registry {
template<typename... Args>
decltype(auto) assign(basic_registry &registry, const Entity entt, Args &&... args) {
if constexpr(std::is_empty_v<Component>) {
Component component{std::forward<Args>(args)...};
storage<Entity, Component>::construct(entt);
on_construct.publish(registry, entt, component);
return std::move(component);
on_construct.publish(registry, entt, Component{});
return Component{std::forward<Args>(args)...};
} else {
auto &component = storage<Entity, Component>::construct(entt, std::forward<Args>(args)...);
on_construct.publish(registry, entt, component);
@@ -120,13 +119,13 @@ class basic_registry {
}
template<typename... Args>
decltype(auto) replace(basic_registry &registry, const Entity entt, [[maybe_unused]] Args &&... args) {
Component component{std::forward<Args>(args)...};
on_replace.publish(registry, entt, component);
decltype(auto) replace(basic_registry &registry, const Entity entt, Args &&... args) {
if constexpr(std::is_empty_v<Component>) {
return std::move(component);
on_replace.publish(registry, entt, Component{});
return Component{std::forward<Args>(args)...};
} else {
Component component{std::forward<Args>(args)...};
on_replace.publish(registry, entt, component);
return (storage<Entity, Component>::get(entt) = std::move(component));
}
}

View File

@@ -1043,6 +1043,8 @@ TEST(Registry, CreateManyEntitiesAtOnce) {
TEST(Registry, CreateAnEntityWithComponents) {
entt::registry registry;
auto &&[entity, ivalue, cvalue, evalue] = registry.create<int, char, empty_type>();
// suppress warnings
(void)evalue;
ASSERT_FALSE(registry.empty<int>());
ASSERT_FALSE(registry.empty<char>());