Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d72472114 | ||
|
|
102350a125 | ||
|
|
1c650cb136 | ||
|
|
625e74653d | ||
|
|
5bad762293 |
@@ -4,7 +4,7 @@
|
||||
|
||||
#define ENTT_VERSION_MAJOR 3
|
||||
#define ENTT_VERSION_MINOR 5
|
||||
#define ENTT_VERSION_PATCH 0
|
||||
#define ENTT_VERSION_PATCH 1
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,32 +31,6 @@ struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
|
||||
{};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Entity traits for a 16 bits entity identifier.
|
||||
*
|
||||
* A 16 bits entity identifier guarantees:
|
||||
*
|
||||
* * 12 bits for the entity number (up to 4k entities).
|
||||
* * 4 bit for the version (resets in [0-15]).
|
||||
*/
|
||||
template<>
|
||||
struct entt_traits<std::uint16_t> {
|
||||
/*! @brief Underlying entity type. */
|
||||
using entity_type = std::uint16_t;
|
||||
/*! @brief Underlying version type. */
|
||||
using version_type = std::uint8_t;
|
||||
/*! @brief Difference type. */
|
||||
using difference_type = std::int16_t;
|
||||
|
||||
/*! @brief Mask to use to get the entity number out of an identifier. */
|
||||
static constexpr entity_type entity_mask = 0xFFF;
|
||||
/*! @brief Mask to use to get the version out of an identifier. */
|
||||
static constexpr entity_type version_mask = 0xF;
|
||||
/*! @brief Extent of the entity number within an identifier. */
|
||||
static constexpr std::size_t entity_shift = 12u;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Entity traits for a 32 bits entity identifier.
|
||||
*
|
||||
@@ -72,7 +46,7 @@ struct entt_traits<std::uint32_t> {
|
||||
/*! @brief Underlying version type. */
|
||||
using version_type = std::uint16_t;
|
||||
/*! @brief Difference type. */
|
||||
using difference_type = std::int32_t;
|
||||
using difference_type = std::int64_t;
|
||||
|
||||
/*! @brief Mask to use to get the entity number out of an identifier. */
|
||||
static constexpr entity_type entity_mask = 0xFFFFF;
|
||||
|
||||
@@ -212,9 +212,16 @@ class basic_observer {
|
||||
|
||||
template<typename... Reject, typename... Require, typename... NoneOf, typename... AllOf>
|
||||
struct matcher_handler<matcher<type_list<Reject...>, type_list<Require...>, type_list<NoneOf...>, AllOf...>> {
|
||||
template<std::size_t Index>
|
||||
template<std::size_t Index, typename... Ignore>
|
||||
static void maybe_valid_if(basic_observer &obs, const basic_registry<Entity> ®, const Entity entt) {
|
||||
if(reg.template has<AllOf..., Require...>(entt) && !reg.template any<NoneOf..., Reject...>(entt)) {
|
||||
if([®, entt]() {
|
||||
if constexpr(sizeof...(Ignore) == 0) {
|
||||
return reg.template has<AllOf..., Require...>(entt) && !reg.template any<NoneOf..., Reject...>(entt);
|
||||
} else {
|
||||
return reg.template has<AllOf..., Require...>(entt) && ((std::is_same_v<Ignore..., NoneOf> || !reg.template any<NoneOf>(entt)) && ...) && !reg.template any<Reject...>(entt);
|
||||
}
|
||||
}())
|
||||
{
|
||||
if(auto *comp = obs.view.try_get(entt); !comp) {
|
||||
obs.view.emplace(entt);
|
||||
}
|
||||
@@ -235,7 +242,7 @@ class basic_observer {
|
||||
(reg.template on_destroy<Require>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template on_construct<Reject>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template on_construct<AllOf>().template connect<&maybe_valid_if<Index>>(obs), ...);
|
||||
(reg.template on_destroy<NoneOf>().template connect<&maybe_valid_if<Index>>(obs), ...);
|
||||
(reg.template on_destroy<NoneOf>().template connect<&maybe_valid_if<Index, NoneOf>>(obs), ...);
|
||||
(reg.template on_destroy<AllOf>().template connect<&discard_if<Index>>(obs), ...);
|
||||
(reg.template on_construct<NoneOf>().template connect<&discard_if<Index>>(obs), ...);
|
||||
}
|
||||
|
||||
@@ -340,3 +340,30 @@ TEST(Observer, MultipleFilters) {
|
||||
|
||||
ASSERT_TRUE(observer.empty());
|
||||
}
|
||||
|
||||
TEST(Observer, GroupCornerCase) {
|
||||
constexpr auto add_collector = entt::collector.group<int>(entt::exclude<char>);
|
||||
constexpr auto remove_collector = entt::collector.group<int, char>();
|
||||
|
||||
entt::registry registry;
|
||||
entt::observer add_observer{registry, add_collector};
|
||||
entt::observer remove_observer{registry, remove_collector};
|
||||
|
||||
const auto entity = registry.create();
|
||||
registry.emplace<int>(entity);
|
||||
|
||||
ASSERT_FALSE(add_observer.empty());
|
||||
ASSERT_TRUE(remove_observer.empty());
|
||||
|
||||
add_observer.clear();
|
||||
registry.emplace<char>(entity);
|
||||
|
||||
ASSERT_TRUE(add_observer.empty());
|
||||
ASSERT_FALSE(remove_observer.empty());
|
||||
|
||||
remove_observer.clear();
|
||||
registry.remove<char>(entity);
|
||||
|
||||
ASSERT_FALSE(add_observer.empty());
|
||||
ASSERT_TRUE(remove_observer.empty());
|
||||
}
|
||||
@@ -11,7 +11,7 @@ int curried_by_ref(const int &i, int j) {
|
||||
}
|
||||
|
||||
int curried_by_ptr(const int *i, int j) {
|
||||
return (*i)+j;
|
||||
return (*i)*j;
|
||||
}
|
||||
|
||||
int non_const_reference(int &i) {
|
||||
@@ -181,16 +181,16 @@ TEST(Delegate, Comparison) {
|
||||
ASSERT_FALSE(lhs == rhs);
|
||||
ASSERT_NE(lhs, rhs);
|
||||
|
||||
lhs.connect([](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val); }, &functor);
|
||||
lhs.connect([](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val) * val; }, &functor);
|
||||
|
||||
ASSERT_NE(lhs, (entt::delegate<int(int)>{[](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val); }, &functor}));
|
||||
ASSERT_NE(lhs, (entt::delegate<int(int)>{[](const void *, int val) { return val + val; }, &functor}));
|
||||
ASSERT_TRUE(lhs != rhs);
|
||||
ASSERT_FALSE(lhs == rhs);
|
||||
ASSERT_NE(lhs, rhs);
|
||||
|
||||
rhs.connect([](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val); }, &functor);
|
||||
rhs.connect([](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val) + val; }, &functor);
|
||||
|
||||
ASSERT_NE(rhs, (entt::delegate<int(int)>{[](const void *ptr, int val) { return static_cast<const delegate_functor *>(ptr)->identity(val); }, &functor}));
|
||||
ASSERT_NE(rhs, (entt::delegate<int(int)>{[](const void *, int val) { return val * val; }, &functor}));
|
||||
ASSERT_TRUE(lhs != rhs);
|
||||
ASSERT_FALSE(lhs == rhs);
|
||||
ASSERT_NE(lhs, rhs);
|
||||
@@ -329,7 +329,7 @@ TEST(Delegate, CurriedFunction) {
|
||||
delegate.connect<&curried_by_ptr>(&value);
|
||||
|
||||
ASSERT_TRUE(delegate);
|
||||
ASSERT_EQ(delegate(2), 5);
|
||||
ASSERT_EQ(delegate(2), 6);
|
||||
}
|
||||
|
||||
TEST(Delegate, Constructors) {
|
||||
@@ -351,7 +351,7 @@ TEST(Delegate, Constructors) {
|
||||
ASSERT_EQ(5, ref(3));
|
||||
|
||||
ASSERT_TRUE(ptr);
|
||||
ASSERT_EQ(5, ref(3));
|
||||
ASSERT_EQ(6, ptr(3));
|
||||
|
||||
ASSERT_TRUE(member);
|
||||
ASSERT_EQ(6, member(3));
|
||||
|
||||
Reference in New Issue
Block a user