|
|
@@ -265,20 +265,26 @@ protected:
|
|
|
}
|
|
|
|
|
|
/*! @copydoc basic_sparse_set::swap_and_pop */
|
|
|
- void swap_and_pop(const std::size_t pos) final {
|
|
|
- const auto length = underlying_type::size();
|
|
|
+ void swap_and_pop(const Entity entt, void *ud) {
|
|
|
+ const auto pos = underlying_type::index(entt);
|
|
|
+ const auto length = underlying_type::size() - 1u;
|
|
|
+
|
|
|
auto &&elem = packed[page(pos)][offset(pos)];
|
|
|
auto &&last = packed[page(length)][offset(length)];
|
|
|
|
|
|
// support for nosy destructors
|
|
|
[[maybe_unused]] auto unused = std::move(elem);
|
|
|
elem = std::move(last);
|
|
|
+
|
|
|
alloc_traits::destroy(allocator, std::addressof(last));
|
|
|
+ underlying_type::swap_and_pop(entt, ud);
|
|
|
}
|
|
|
|
|
|
/*! @copydoc basic_sparse_set::in_place_pop */
|
|
|
- void in_place_pop(const std::size_t pos) final {
|
|
|
+ void in_place_pop(const Entity entt, void *ud) {
|
|
|
+ const auto pos = underlying_type::index(entt);
|
|
|
alloc_traits::destroy(allocator, std::addressof(packed[page(pos)][offset(pos)]));
|
|
|
+ underlying_type::in_place_pop(entt, ud);
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
@@ -543,13 +549,13 @@ public:
|
|
|
/**
|
|
|
* @brief Updates the instance assigned to a given entity in-place.
|
|
|
* @tparam Func Types of the function objects to invoke.
|
|
|
- * @param entity A valid entity identifier.
|
|
|
+ * @param entt A valid entity identifier.
|
|
|
* @param func Valid function objects.
|
|
|
* @return A reference to the updated instance.
|
|
|
*/
|
|
|
template<typename... Func>
|
|
|
- decltype(auto) patch(const entity_type entity, Func &&... func) {
|
|
|
- const auto idx = underlying_type::index(entity);
|
|
|
+ decltype(auto) patch(const entity_type entt, Func &&... func) {
|
|
|
+ const auto idx = underlying_type::index(entt);
|
|
|
auto &&elem = packed[page(idx)][offset(idx)];
|
|
|
(std::forward<Func>(func)(elem), ...);
|
|
|
return elem;
|
|
|
@@ -748,12 +754,12 @@ public:
|
|
|
/**
|
|
|
* @brief Updates the instance assigned to a given entity in-place.
|
|
|
* @tparam Func Types of the function objects to invoke.
|
|
|
- * @param entity A valid entity identifier.
|
|
|
+ * @param entt A valid entity identifier.
|
|
|
* @param func Valid function objects.
|
|
|
*/
|
|
|
template<typename... Func>
|
|
|
- void patch([[maybe_unused]] const entity_type entity, Func &&... func) {
|
|
|
- ENTT_ASSERT(underlying_type::contains(entity), "Storage does not contain entity");
|
|
|
+ void patch([[maybe_unused]] const entity_type entt, Func &&... func) {
|
|
|
+ ENTT_ASSERT(underlying_type::contains(entt), "Storage does not contain entity");
|
|
|
(std::forward<Func>(func)(), ...);
|
|
|
}
|
|
|
|
|
|
@@ -794,13 +800,13 @@ struct storage_adapter_mixin: Type {
|
|
|
/**
|
|
|
* @brief Assigns entities to a storage.
|
|
|
* @tparam Args Types of arguments to use to construct the object.
|
|
|
- * @param entity A valid entity identifier.
|
|
|
+ * @param entt A valid entity identifier.
|
|
|
* @param args Parameters to use to initialize the object.
|
|
|
* @return A reference to the newly created object.
|
|
|
*/
|
|
|
template<typename... Args>
|
|
|
- decltype(auto) emplace(basic_registry<entity_type> &, const entity_type entity, Args &&... args) {
|
|
|
- return Type::emplace(entity, std::forward<Args>(args)...);
|
|
|
+ decltype(auto) emplace(basic_registry<entity_type> &, const entity_type entt, Args &&... args) {
|
|
|
+ return Type::emplace(entt, std::forward<Args>(args)...);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -821,13 +827,13 @@ struct storage_adapter_mixin: Type {
|
|
|
/**
|
|
|
* @brief Patches the given instance for an entity.
|
|
|
* @tparam Func Types of the function objects to invoke.
|
|
|
- * @param entity A valid entity identifier.
|
|
|
+ * @param entt A valid entity identifier.
|
|
|
* @param func Valid function objects.
|
|
|
* @return A reference to the patched instance.
|
|
|
*/
|
|
|
template<typename... Func>
|
|
|
- decltype(auto) patch(basic_registry<entity_type> &, const entity_type entity, Func &&... func) {
|
|
|
- return Type::patch(entity, std::forward<Func>(func)...);
|
|
|
+ decltype(auto) patch(basic_registry<entity_type> &, const entity_type entt, Func &&... func) {
|
|
|
+ return Type::patch(entt, std::forward<Func>(func)...);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -838,11 +844,18 @@ struct storage_adapter_mixin: Type {
|
|
|
*/
|
|
|
template<typename Type>
|
|
|
class sigh_storage_mixin final: public Type {
|
|
|
- /*! @copydoc basic_sparse_set::about_to_pop */
|
|
|
- void about_to_pop(const typename Type::entity_type entity, void *ud) final {
|
|
|
+ /*! @copydoc basic_sparse_set::swap_and_pop */
|
|
|
+ void swap_and_pop(const typename Type::entity_type entt, void *ud) final {
|
|
|
ENTT_ASSERT(ud != nullptr, "Invalid pointer to registry");
|
|
|
- destruction.publish(*static_cast<basic_registry<typename Type::entity_type> *>(ud), entity);
|
|
|
- Type::about_to_pop(entity, ud);
|
|
|
+ destruction.publish(*static_cast<basic_registry<typename Type::entity_type> *>(ud), entt);
|
|
|
+ Type::swap_and_pop(entt, ud);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*! @copydoc basic_sparse_set::in_place_pop */
|
|
|
+ void in_place_pop(const typename Type::entity_type entt, void *ud) final {
|
|
|
+ ENTT_ASSERT(ud != nullptr, "Invalid pointer to registry");
|
|
|
+ destruction.publish(*static_cast<basic_registry<typename Type::entity_type> *>(ud), entt);
|
|
|
+ Type::in_place_pop(entt, ud);
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
@@ -923,15 +936,15 @@ public:
|
|
|
* @brief Assigns entities to a storage.
|
|
|
* @tparam Args Types of arguments to use to construct the object.
|
|
|
* @param owner The registry that issued the request.
|
|
|
- * @param entity A valid entity identifier.
|
|
|
+ * @param entt A valid entity identifier.
|
|
|
* @param args Parameters to use to initialize the object.
|
|
|
* @return A reference to the newly created object.
|
|
|
*/
|
|
|
template<typename... Args>
|
|
|
- decltype(auto) emplace(basic_registry<entity_type> &owner, const entity_type entity, Args &&... args) {
|
|
|
- Type::emplace(entity, std::forward<Args>(args)...);
|
|
|
- construction.publish(owner, entity);
|
|
|
- return this->get(entity);
|
|
|
+ decltype(auto) emplace(basic_registry<entity_type> &owner, const entity_type entt, Args &&... args) {
|
|
|
+ Type::emplace(entt, std::forward<Args>(args)...);
|
|
|
+ construction.publish(owner, entt);
|
|
|
+ return this->get(entt);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -960,15 +973,15 @@ public:
|
|
|
* @brief Patches the given instance for an entity.
|
|
|
* @tparam Func Types of the function objects to invoke.
|
|
|
* @param owner The registry that issued the request.
|
|
|
- * @param entity A valid entity identifier.
|
|
|
+ * @param entt A valid entity identifier.
|
|
|
* @param func Valid function objects.
|
|
|
* @return A reference to the patched instance.
|
|
|
*/
|
|
|
template<typename... Func>
|
|
|
- decltype(auto) patch(basic_registry<entity_type> &owner, const entity_type entity, Func &&... func) {
|
|
|
- Type::patch(entity, std::forward<Func>(func)...);
|
|
|
- update.publish(owner, entity);
|
|
|
- return this->get(entity);
|
|
|
+ decltype(auto) patch(basic_registry<entity_type> &owner, const entity_type entt, Func &&... func) {
|
|
|
+ Type::patch(entt, std::forward<Func>(func)...);
|
|
|
+ update.publish(owner, entt);
|
|
|
+ return this->get(entt);
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
@@ -1006,17 +1019,17 @@ struct storage_traits {
|
|
|
* @brief Gets the element assigned to an entity from a storage, if any.
|
|
|
* @tparam Type Storage type.
|
|
|
* @param container A valid instance of a storage class.
|
|
|
- * @param entity A valid entity identifier.
|
|
|
+ * @param entt A valid entity identifier.
|
|
|
* @return A possibly empty tuple containing the requested element.
|
|
|
*/
|
|
|
template<typename Type>
|
|
|
-[[nodiscard]] auto get_as_tuple([[maybe_unused]] Type &container, [[maybe_unused]] const typename Type::entity_type entity) {
|
|
|
+[[nodiscard]] auto get_as_tuple([[maybe_unused]] Type &container, [[maybe_unused]] const typename Type::entity_type entt) {
|
|
|
static_assert(std::is_same_v<std::remove_const_t<Type>, typename storage_traits<typename Type::entity_type, typename Type::value_type>::storage_type>, "Invalid storage");
|
|
|
|
|
|
if constexpr(std::is_void_v<decltype(container.get({}))>) {
|
|
|
return std::make_tuple();
|
|
|
} else {
|
|
|
- return std::forward_as_tuple(container.get(entity));
|
|
|
+ return std::forward_as_tuple(container.get(entt));
|
|
|
}
|
|
|
}
|
|
|
|