Warning!
The version you're viewing is not the latest.
Go to the latest version
Function create
Summary
#include <src/entt/entity/registry.hpp>
(1) entity_type create()
(2) entity_type create(const entity_type hint)
(3) template <typename It>
void create(It first, It last)
Function overload
Synopsis
#include <src/entt/entity/registry.hpp>
entity_type create()
Description
Creates a new entity or recycles a destroyed one.
- Returns
- A valid identifier.
Mentioned in
- Getting Started / Code Example
- Entity Component System / The Registry, the Entity and the Component
- Entity Component System / Null entity
- Entity Component System / Tombstone
- Entity Component System / What is allowed and what is not
Source
Lines 558-560 in src/entt/entity/registry.hpp.
[[nodiscard]] entity_type create() {
return (free_list == null) ? entities.emplace_back(generate_identifier(entities.size())) : recycle_identifier();
}
Synopsis
#include <src/entt/entity/registry.hpp>
entity_type create(const entity_type hint)
Description
Creates a new entity or recycles a destroyed one.
If the requested entity isn't in use, the suggested identifier is used. Otherwise, a new identifier is generated.
- Parameters
hint
- Required identifier.- Returns
- A valid identifier.
Mentioned in
- Getting Started / Code Example
- Entity Component System / The Registry, the Entity and the Component
- Entity Component System / Null entity
- Entity Component System / Tombstone
- Entity Component System / What is allowed and what is not
Source
Lines 571-592 in src/entt/entity/registry.hpp.
[[nodiscard]] entity_type create(const entity_type hint) {
const auto length = entities.size();
if(hint == null || hint == tombstone) {
return create();
} else if(const auto req = entity_traits::to_entity(hint); !(req < length)) {
entities.resize(size_type(req) + 1u, null);
for(auto pos = length; pos < req; ++pos) {
release_entity(generate_identifier(pos), {});
}
return (entities[req] = hint);
} else if(const auto curr = entity_traits::to_entity(entities[req]); req == curr) {
return create();
} else {
auto *it = &free_list;
for(; entity_traits::to_entity(*it) != req; it = &entities[entity_traits::to_entity(*it)]) {}
*it = entity_traits::combine(curr, entity_traits::to_integral(*it));
return (entities[req] = hint);
}
}
Synopsis
#include <src/entt/entity/registry.hpp>
template <typename It>
void create(It first, It last)
Description
Assigns each element in a range an identifier.
- See
- create
- Template Parameters
It
- Type of forward iterator.- Parameters
first
- An iterator to the first element of the range to generate.last
- An iterator past the last element of the range to generate.
Mentioned in
- Getting Started / Code Example
- Entity Component System / The Registry, the Entity and the Component
- Entity Component System / Null entity
- Entity Component System / Tombstone
- Entity Component System / What is allowed and what is not
Source
Lines 603-615 in src/entt/entity/registry.hpp.
template<typename It>
void create(It first, It last) {
for(; free_list != null && first != last; ++first) {
*first = recycle_identifier();
}
const auto length = entities.size();
entities.resize(length + std::distance(first, last), null);
for(auto pos = length; first != last; ++first, ++pos) {
*first = entities[pos] = generate_identifier(pos);
}
}