|
|
@@ -139,6 +139,104 @@ typename Registry::entity_type to_entity(const Registry ®, const Component &i
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+/*! @brief Primary template isn't defined on purpose. */
|
|
|
+template<typename...>
|
|
|
+struct sigh_helper;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Signal connection helper for registries.
|
|
|
+ * @tparam Registry Basic registry type.
|
|
|
+ */
|
|
|
+template<typename Registry>
|
|
|
+struct sigh_helper<Registry> {
|
|
|
+ /*! @brief Registry type. */
|
|
|
+ using registry_type = Registry;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Constructs a helper for a given registry.
|
|
|
+ * @param ref A valid reference to a registry.
|
|
|
+ */
|
|
|
+ sigh_helper(registry_type &ref)
|
|
|
+ : bucket{&ref} {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Binds a properly initialized helper to a given signal type.
|
|
|
+ * @tparam Type Type of signal to bind the helper to.
|
|
|
+ * @return A helper for a given registry and signal type.
|
|
|
+ */
|
|
|
+ template<typename Type>
|
|
|
+ auto with() noexcept {
|
|
|
+ return sigh_helper<registry_type, Type>{*bucket};
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Returns a reference to the underlying registry.
|
|
|
+ * @return A reference to the underlying registry.
|
|
|
+ */
|
|
|
+ [[nodiscard]] registry_type ®istry() noexcept {
|
|
|
+ return *bucket;
|
|
|
+ }
|
|
|
+
|
|
|
+private:
|
|
|
+ registry_type *bucket;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Signal connection helper for registries.
|
|
|
+ * @tparam Registry Basic registry type.
|
|
|
+ * @tparam Type Type of signal to connect listeners to.
|
|
|
+ */
|
|
|
+template<typename Registry, typename Type>
|
|
|
+struct sigh_helper<Registry, Type> final: sigh_helper<Registry> {
|
|
|
+ using sigh_helper<Registry>::sigh_helper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Forwards the call to `on_construct` on the underlying registry.
|
|
|
+ * @tparam Candidate Function or member to connect.
|
|
|
+ * @tparam Args Type of class or type of payload, if any.
|
|
|
+ * @param args A valid object that fits the purpose, if any.
|
|
|
+ * @return This helper.
|
|
|
+ */
|
|
|
+ template<auto Candidate, typename... Args>
|
|
|
+ auto on_construct(Args &&...args) {
|
|
|
+ this->registry().on_construct<Type>().connect<Candidate>(std::forward<Args>(args)...);
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Forwards the call to `on_update` on the underlying registry.
|
|
|
+ * @tparam Candidate Function or member to connect.
|
|
|
+ * @tparam Args Type of class or type of payload, if any.
|
|
|
+ * @param args A valid object that fits the purpose, if any.
|
|
|
+ * @return This helper.
|
|
|
+ */
|
|
|
+ template<auto Candidate, typename... Args>
|
|
|
+ auto on_update(Args &&...args) {
|
|
|
+ this->registry().on_update<Type>().connect<Candidate>(std::forward<Args>(args)...);
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Forwards the call to `on_destroy` on the underlying registry.
|
|
|
+ * @tparam Candidate Function or member to connect.
|
|
|
+ * @tparam Args Type of class or type of payload, if any.
|
|
|
+ * @param args A valid object that fits the purpose, if any.
|
|
|
+ * @return This helper.
|
|
|
+ */
|
|
|
+ template<auto Candidate, typename... Args>
|
|
|
+ auto on_destroy(Args &&...args) {
|
|
|
+ this->registry().on_destroy<Type>().connect<Candidate>(std::forward<Args>(args)...);
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Deduction guide.
|
|
|
+ * @tparam Registry Basic registry type.
|
|
|
+ */
|
|
|
+template<typename Registry>
|
|
|
+sigh_helper(Registry &) -> sigh_helper<Registry>;
|
|
|
+
|
|
|
} // namespace entt
|
|
|
|
|
|
#endif
|