Skip to content

Commit

Permalink
entity: return vertex indices from emplace
Browse files Browse the repository at this point in the history
  • Loading branch information
cjhowedev committed Sep 20, 2023
1 parent 598b296 commit 51a0738
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/entt/entity/organizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ class basic_organizer final {
* @tparam Candidate Function to add to the task list.
* @tparam Req Additional requirements and/or override resource access mode.
* @param name Optional name to associate with the task.
* @return The index of the created vertex
*/
template<auto Candidate, typename... Req>
void emplace(const char *name = nullptr) {
size_t emplace(const char *name = nullptr) {
using resource_type = decltype(internal::free_function_to_resource_traits<Req...>(Candidate));
constexpr auto requires_registry = type_list_contains_v<typename resource_type::args, registry_type>;

Expand All @@ -329,8 +330,10 @@ class basic_organizer final {
+[](registry_type &reg) { void(to_args(reg, typename resource_type::args{})); },
&type_id<std::integral_constant<decltype(Candidate), Candidate>>()};

track_dependencies(vertices.size(), requires_registry, typename resource_type::ro{}, typename resource_type::rw{});
size_t index = vertices.size();
track_dependencies(index, requires_registry, typename resource_type::ro{}, typename resource_type::rw{});
vertices.push_back(std::move(vdata));
return index;
}

/**
Expand All @@ -341,9 +344,10 @@ class basic_organizer final {
* @tparam Type Type of class or type of payload.
* @param value_or_instance A valid object that fits the purpose.
* @param name Optional name to associate with the task.
* @return The index of the created vertex
*/
template<auto Candidate, typename... Req, typename Type>
void emplace(Type &value_or_instance, const char *name = nullptr) {
size_t emplace(Type &value_or_instance, const char *name = nullptr) {
using resource_type = decltype(internal::constrained_function_to_resource_traits<Req...>(Candidate));
constexpr auto requires_registry = type_list_contains_v<typename resource_type::args, registry_type>;

Expand All @@ -362,8 +366,10 @@ class basic_organizer final {
+[](registry_type &reg) { void(to_args(reg, typename resource_type::args{})); },
&type_id<std::integral_constant<decltype(Candidate), Candidate>>()};

track_dependencies(vertices.size(), requires_registry, typename resource_type::ro{}, typename resource_type::rw{});
size_t index = vertices.size();
track_dependencies(index, requires_registry, typename resource_type::ro{}, typename resource_type::rw{});
vertices.push_back(std::move(vdata));
return index;
}

/**
Expand All @@ -373,11 +379,13 @@ class basic_organizer final {
* @param func Function to add to the task list.
* @param payload User defined arbitrary data.
* @param name Optional name to associate with the task.
* @return The index of the created vertex
*/
template<typename... Req>
void emplace(function_type *func, const void *payload = nullptr, const char *name = nullptr) {
size_t emplace(function_type *func, const void *payload = nullptr, const char *name = nullptr) {
using resource_type = internal::resource_traits<type_list<>, type_list<Req...>>;
track_dependencies(vertices.size(), true, typename resource_type::ro{}, typename resource_type::rw{});
size_t index = vertices.size();
track_dependencies(index, true, typename resource_type::ro{}, typename resource_type::rw{});

vertex_data vdata{
resource_type::ro::size,
Expand All @@ -390,6 +398,7 @@ class basic_organizer final {
&type_id<void>()};

vertices.push_back(std::move(vdata));
return index;
}

/**
Expand Down

0 comments on commit 51a0738

Please sign in to comment.