Make compilation fail if ecs::entity_container::create is called with several equal component types
This commit is contained in:
parent
c59a28433a
commit
9f36dfc0e4
2 changed files with 28 additions and 0 deletions
24
libs/ecs/include/psemek/ecs/detail/all_different_types.hpp
Normal file
24
libs/ecs/include/psemek/ecs/detail/all_different_types.hpp
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace psemek::ecs::detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename ... Ts>
|
||||||
|
struct all_different_types;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct all_different_types<>
|
||||||
|
: std::true_type
|
||||||
|
{};
|
||||||
|
|
||||||
|
template <typename T, typename ... Ts>
|
||||||
|
struct all_different_types<T, Ts...>
|
||||||
|
: std::bool_constant<(!std::is_same_v<T, Ts> && ...) && all_different_types<Ts...>::value>
|
||||||
|
{};
|
||||||
|
|
||||||
|
template <typename ... Ts>
|
||||||
|
constexpr bool all_different_types_v = all_different_types<Ts...>::value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <psemek/ecs/detail/table_container.hpp>
|
#include <psemek/ecs/detail/table_container.hpp>
|
||||||
#include <psemek/ecs/detail/query_cache_container.hpp>
|
#include <psemek/ecs/detail/query_cache_container.hpp>
|
||||||
#include <psemek/ecs/detail/apply_helper.hpp>
|
#include <psemek/ecs/detail/apply_helper.hpp>
|
||||||
|
#include <psemek/ecs/detail/all_different_types.hpp>
|
||||||
#include <psemek/ecs/entity_accessor.hpp>
|
#include <psemek/ecs/entity_accessor.hpp>
|
||||||
#include <psemek/util/span.hpp>
|
#include <psemek/util/span.hpp>
|
||||||
|
|
||||||
|
|
@ -18,6 +19,7 @@ namespace psemek::ecs
|
||||||
// Create an entity with the specified components
|
// Create an entity with the specified components
|
||||||
// NB: equivalent to create() followed by a
|
// NB: equivalent to create() followed by a
|
||||||
// series of attach() calls, but faster
|
// series of attach() calls, but faster
|
||||||
|
// All components must be unique
|
||||||
template <typename ... Components>
|
template <typename ... Components>
|
||||||
entity_handle create(Components && ... components);
|
entity_handle create(Components && ... components);
|
||||||
|
|
||||||
|
|
@ -57,6 +59,8 @@ namespace psemek::ecs
|
||||||
template <typename ... Components>
|
template <typename ... Components>
|
||||||
entity_handle entity_container::create(Components && ... components)
|
entity_handle entity_container::create(Components && ... components)
|
||||||
{
|
{
|
||||||
|
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
||||||
|
|
||||||
detail::component_uuid_holder<Components...> uuids;
|
detail::component_uuid_holder<Components...> uuids;
|
||||||
detail::component_mask mask = component_index_.make_component_mask(uuids.get());
|
detail::component_mask mask = component_index_.make_component_mask(uuids.get());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue