diff --git a/TODO b/TODO
index 3038e1d00..41e29dc21 100644
--- a/TODO
+++ b/TODO
@@ -19,6 +19,7 @@
* any-of rule for views/groups (eg entity has A and any of B/C/D)
- get -> all, exclude -> none
* deprecate sigh::publish, use operator()
+* merge entity/helper and entt/utility
* WIP: snapshot rework/deprecation
- remove snapshot/loader from registry, make them external (faster) tools
diff --git a/docs/md/entity.md b/docs/md/entity.md
index e9849a3f2..f513b559a 100644
--- a/docs/md/entity.md
+++ b/docs/md/entity.md
@@ -333,7 +333,7 @@ The function type of a listener for the construction and destruction signals
should be equivalent to the following:
```cpp
-void(entt::entity, entt::registry &);
+void(entt::registry &, entt::entity);
```
In both cases, listeners are provided with the registry that triggered the
@@ -342,7 +342,7 @@ The function type of a listener that observes changes to components is slightly
different instead:
```cpp
-void(entt::entity, entt::registry &, Component &);
+void(entt::registry &, entt::entity, Component &);
```
In this case, `Component` is intuitively the type of component of interest. The
@@ -600,26 +600,27 @@ the other things.
### Dependencies
-The `registry` class is designed to create short circuits between its functions.
-This makes easy to define dependencies between different operations.
+The `registry` class is designed to be able to create short circuits between its
+functions. This simplifies the definition of _dependencies_ between different
+operations.
For example, the following adds (or replaces) the component `a_type` whenever
`my_type` is assigned to an entity:
```cpp
-registry.on_construct().connect<&entt::registry::assign_or_replace>(registry);
+registry.on_construct().connect<&entt::registry::assign_or_replace>();
```
Similarly, the code shown below removes `a_type` from an entity whenever
`my_type` is assigned to it:
```cpp
-registry.on_construct().connect<&entt::registry::remove>(registry);
+registry.on_construct().connect<&entt::registry::remove>();
```
A dependency can also be easily broken as follows:
```cpp
-registry.on_construct().disconnect<&entt::registry::assign_or_replace>(registry);
+registry.on_construct().disconnect<&entt::registry::assign_or_replace>();
```
There are many other types of dependencies. In general, all functions that
diff --git a/src/entt/entity/helper.hpp b/src/entt/entity/helper.hpp
index e20ae4589..f9b02a45f 100644
--- a/src/entt/entity/helper.hpp
+++ b/src/entt/entity/helper.hpp
@@ -4,7 +4,6 @@
#include
#include "../config/config.h"
-#include "../signal/sigh.hpp"
#include "registry.hpp"
diff --git a/src/entt/entity/observer.hpp b/src/entt/entity/observer.hpp
index 5e0ec89fc..6b15d640e 100644
--- a/src/entt/entity/observer.hpp
+++ b/src/entt/entity/observer.hpp
@@ -177,7 +177,7 @@ class basic_observer {
template
struct matcher_handler, type_list, AnyOf>> {
template
- static void maybe_valid_if(basic_observer &obs, const Entity entt, const basic_registry ®) {
+ static void maybe_valid_if(basic_observer &obs, const basic_registry ®, const Entity entt) {
if(reg.template has(entt) && !(reg.template has(entt) || ...)) {
if(auto *comp = obs.view.try_get(entt); !comp) {
obs.view.construct(entt);
@@ -188,7 +188,7 @@ class basic_observer {
}
template
- static void discard_if(basic_observer &obs, const Entity entt) {
+ static void discard_if(basic_observer &obs, const basic_registry &, const Entity entt) {
if(auto *value = obs.view.try_get(entt); value && !(*value &= (~(1 << Index)))) {
obs.view.destroy(entt);
}
@@ -213,7 +213,7 @@ class basic_observer {
template
struct matcher_handler, type_list, type_list, AllOf...>> {
template
- static void maybe_valid_if(basic_observer &obs, const Entity entt, const basic_registry ®) {
+ static void maybe_valid_if(basic_observer &obs, const basic_registry ®, const Entity entt) {
if(reg.template has(entt) && !(reg.template has(entt) || ...) && !(reg.template has(entt) || ...)) {
if(auto *comp = obs.view.try_get(entt); !comp) {
obs.view.construct(entt);
@@ -224,7 +224,7 @@ class basic_observer {
}
template
- static void discard_if(basic_observer &obs, const Entity entt) {
+ static void discard_if(basic_observer &obs, const basic_registry &, const Entity entt) {
if(auto *value = obs.view.try_get(entt); value && !(*value &= (~(1 << Index)))) {
obs.view.destroy(entt);
}
diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp
index e5b7b3cdd..d55ea57ea 100644
--- a/src/entt/entity/registry.hpp
+++ b/src/entt/entity/registry.hpp
@@ -69,7 +69,7 @@ class basic_registry {
template
decltype(auto) assign(basic_registry &owner, const Entity entt, Args &&... args) {
this->construct(entt, std::forward(args)...);
- construction.publish(entt, owner);
+ construction.publish(owner, entt);
return this->get(entt);
}
@@ -80,12 +80,12 @@ class basic_registry {
(func(this->raw() + this->size() - std::distance(first, last)), ...);
if(!construction.empty()) {
- std::for_each(first, last, [this, &owner](const auto entt) { construction.publish(entt, owner); });
+ std::for_each(first, last, [this, &owner](const auto entt) { construction.publish(owner, entt); });
}
}
void remove(basic_registry &owner, const Entity entt) {
- destruction.publish(entt, owner);
+ destruction.publish(owner, entt);
this->destroy(entt);
}
@@ -93,7 +93,7 @@ class basic_registry {
void remove(basic_registry &owner, It first, It last) {
if(std::distance(first, last) == std::distance(this->begin(), this->end())) {
if(!destruction.empty()) {
- std::for_each(first, last, [this, &owner](const auto entt) { destruction.publish(entt, owner); });
+ std::for_each(first, last, [this, &owner](const auto entt) { destruction.publish(owner, entt); });
}
this->clear();
@@ -106,14 +106,14 @@ class basic_registry {
template
decltype(auto) replace(basic_registry &owner, const Entity entt, Args &&... args) {
Component component{std::forward(args)...};
- update.publish(entt, owner, component);
+ update.publish(owner, entt, component);
return (this->get(entt) = std::move(component));
}
private:
- sigh construction{};
- sigh destruction{};
- sigh>().get({})))> update{};
+ sigh construction{};
+ sigh destruction{};
+ sigh>().get({})))> update{};
};
struct pool_data {
@@ -133,7 +133,7 @@ class basic_registry {
std::conditional_t, std::size_t> current{};
template
- void maybe_valid_if(const Entity entt, basic_registry &owner) {
+ void maybe_valid_if(basic_registry &owner, const Entity entt) {
static_assert(std::disjunction_v>..., std::is_same>..., std::is_same>...>);
[[maybe_unused]] const auto cpools = std::forward_as_tuple(owner.assure()...);
@@ -153,7 +153,7 @@ class basic_registry {
}
}
- void discard_if(const Entity entt, basic_registry &owner) {
+ void discard_if([[maybe_unused]] basic_registry &owner, const Entity entt) {
if constexpr(sizeof...(Owned) == 0) {
if(current.has(entt)) {
current.destroy(entt);
@@ -1021,7 +1021,7 @@ public:
* The function type for a listener is equivalent to:
*
* @code{.cpp}
- * void(Entity, registry &);
+ * void(registry &, Entity);
* @endcode
*
* Listeners are invoked **after** the component has been assigned to the
@@ -1052,7 +1052,7 @@ public:
* The function type for a listener is equivalent to:
*
* @code{.cpp}
- * void(Entity, registry &, Component &);
+ * void(registry &, Entity, Component &);
* @endcode
*
* Listeners are invoked **before** the component has been replaced.
@@ -1083,7 +1083,7 @@ public:
* The function type for a listener is equivalent to:
*
* @code{.cpp}
- * void(Entity, registry &);
+ * void(registry &, Entity);
* @endcode
*
* Listeners are invoked **before** the component has been removed from the
diff --git a/test/entt/entity/group.cpp b/test/entt/entity/group.cpp
index f27cd9fde..4cdc24cbc 100644
--- a/test/entt/entity/group.cpp
+++ b/test/entt/entity/group.cpp
@@ -492,7 +492,7 @@ TEST(NonOwningGroup, Less) {
TEST(NonOwningGroup, SignalRace) {
entt::registry registry;
- registry.on_construct().connect<&entt::registry::assign_or_replace>(registry);
+ registry.on_construct().connect<&entt::registry::assign_or_replace>();
registry.group(entt::get);
auto entity = registry.create();
@@ -1068,7 +1068,7 @@ TEST(OwningGroup, Less) {
TEST(OwningGroup, SignalRace) {
entt::registry registry;
- registry.on_construct().connect<&entt::registry::assign_or_replace>(registry);
+ registry.on_construct().connect<&entt::registry::assign_or_replace>();
registry.group(entt::get);
auto entity = registry.create();
diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp
index 3fd0ac16f..03fcc0456 100644
--- a/test/entt/entity/registry.cpp
+++ b/test/entt/entity/registry.cpp
@@ -14,12 +14,12 @@ struct empty_type {};
struct listener {
template
- static void sort(entt::entity, entt::registry ®istry) {
+ static void sort(entt::registry ®istry) {
registry.sort([](auto lhs, auto rhs) { return lhs < rhs; });
}
template
- void incr(entt::entity entity, entt::registry ®istry) {
+ void incr(const entt::registry ®istry, entt::entity entity) {
ASSERT_TRUE(registry.valid(entity));
ASSERT_TRUE(registry.has(entity));
last = entity;
@@ -27,7 +27,7 @@ struct listener {
}
template
- void decr(entt::entity entity, entt::registry ®istry) {
+ void decr(const entt::registry ®istry, entt::entity entity) {
ASSERT_TRUE(registry.valid(entity));
ASSERT_TRUE(registry.has(entity));
last = entity;
@@ -1562,8 +1562,8 @@ TEST(Registry, Dependencies) {
constexpr auto assign_or_replace = &entt::registry::assign_or_replace;
constexpr auto remove = &entt::registry::remove;
- registry.on_construct().connect(registry);
- registry.on_destroy().connect(registry);
+ registry.on_construct().connect();
+ registry.on_destroy().connect();
registry.assign(entity, .3);
ASSERT_FALSE(registry.has(entity));
@@ -1579,8 +1579,8 @@ TEST(Registry, Dependencies) {
ASSERT_FALSE(registry.has(entity));
ASSERT_FALSE(registry.has(entity));
- registry.on_construct().disconnect(registry);
- registry.on_destroy().disconnect(registry);
+ registry.on_construct().disconnect();
+ registry.on_destroy().disconnect();
registry.assign(entity);
ASSERT_TRUE(registry.has(entity));