Skip to content

Commit

Permalink
Merge branch 'variant_exclusive' of https://github.com/kgorking/ecs i…
Browse files Browse the repository at this point in the history
…nto variant_exclusive
  • Loading branch information
kgorking committed Nov 21, 2023
2 parents a44c287 + 03edd28 commit f77e467
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
40 changes: 20 additions & 20 deletions include/ecs/ecs.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -4552,27 +4552,27 @@ namespace ecs {
static_assert((!std::is_pointer_v<std::remove_cvref_t<T>> && ...), "can not add pointers to entities; wrap them in a struct");
static_assert((!detail::is_variant_of_pack<T...>()), "Can not add more than one component from the same variant");

auto const adder = [this, range]<typename Type>(Type&& val) {
// Add it to the component pool
if constexpr (detail::is_parent<Type>::value) {
detail::component_pool<detail::parent_id>& pool = ctx.get_component_pool<detail::parent_id>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, detail::parent_id{val.id()});
} else if constexpr (std::is_reference_v<Type>) {
using DerefT = std::remove_cvref_t<Type>;
static_assert(std::copyable<DerefT>, "Type must be copyable");

detail::component_pool<DerefT>& pool = ctx.get_component_pool<DerefT>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, val);
} else {
static_assert(std::copyable<Type>, "Type must be copyable");
auto const adder = [this, range]<typename Type>(Type&& val) {
// Add it to the component pool
if constexpr (detail::is_parent<Type>::value) {
detail::component_pool<detail::parent_id>& pool = ctx.get_component_pool<detail::parent_id>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, detail::parent_id{val.id()});
} else if constexpr (std::is_reference_v<Type>) {
using DerefT = std::remove_cvref_t<Type>;
static_assert(std::copyable<DerefT>, "Type must be copyable");

detail::component_pool<DerefT>& pool = ctx.get_component_pool<DerefT>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, val);
} else {
static_assert(std::copyable<Type>, "Type must be copyable");

detail::component_pool<Type>& pool = ctx.get_component_pool<Type>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, std::forward<Type>(val));
}
};
detail::component_pool<Type>& pool = ctx.get_component_pool<Type>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, std::forward<Type>(val));
}
};

(adder(std::forward<T>(vals)), ...);
}
Expand Down
40 changes: 20 additions & 20 deletions include/ecs/ecs_sh.h
Original file line number Diff line number Diff line change
Expand Up @@ -4552,27 +4552,27 @@ namespace ecs {
static_assert((!std::is_pointer_v<std::remove_cvref_t<T>> && ...), "can not add pointers to entities; wrap them in a struct");
static_assert((!detail::is_variant_of_pack<T...>()), "Can not add more than one component from the same variant");

auto const adder = [this, range]<typename Type>(Type&& val) {
// Add it to the component pool
if constexpr (detail::is_parent<Type>::value) {
detail::component_pool<detail::parent_id>& pool = ctx.get_component_pool<detail::parent_id>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, detail::parent_id{val.id()});
} else if constexpr (std::is_reference_v<Type>) {
using DerefT = std::remove_cvref_t<Type>;
static_assert(std::copyable<DerefT>, "Type must be copyable");

detail::component_pool<DerefT>& pool = ctx.get_component_pool<DerefT>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, val);
} else {
static_assert(std::copyable<Type>, "Type must be copyable");
auto const adder = [this, range]<typename Type>(Type&& val) {
// Add it to the component pool
if constexpr (detail::is_parent<Type>::value) {
detail::component_pool<detail::parent_id>& pool = ctx.get_component_pool<detail::parent_id>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, detail::parent_id{val.id()});
} else if constexpr (std::is_reference_v<Type>) {
using DerefT = std::remove_cvref_t<Type>;
static_assert(std::copyable<DerefT>, "Type must be copyable");

detail::component_pool<DerefT>& pool = ctx.get_component_pool<DerefT>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, val);
} else {
static_assert(std::copyable<Type>, "Type must be copyable");

detail::component_pool<Type>& pool = ctx.get_component_pool<Type>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, std::forward<Type>(val));
}
};
detail::component_pool<Type>& pool = ctx.get_component_pool<Type>();
Pre(!pool.has_entity(range), "one- or more entities in the range already has this type");
pool.add(range, std::forward<Type>(val));
}
};

(adder(std::forward<T>(vals)), ...);
}
Expand Down

0 comments on commit f77e467

Please sign in to comment.