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 and returns it.
There are two kinds of possible entity identifiers:
- Newly created ones in case no entities have been previously destroyed.
- Recycled ones with updated versions.
- Returns
- A valid entity 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 / What is allowed and what is not
Source
Lines 443-445 in src/entt/entity/registry.hpp.
entity_type create() {
return available == null ? generate_identifier() : recycle_identifier();
}
Synopsis
#include <src/entt/entity/registry.hpp>
entity_type create(const entity_type hint)
Description
Creates a new entity and returns it.
- See
- create
- Parameters
hint
- A desired entity identifier.- Returns
- A valid entity 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 / What is allowed and what is not
Source
Lines 458-480 in src/entt/entity/registry.hpp.
[[nodiscard]] entity_type create(const entity_type hint) {
ENTT_ASSERT(hint != null);
entity_type entt;
if(const auto req = (to_integral(hint) & traits_type::entity_mask); !(req < entities.size())) {
entities.reserve(size_type(req) + 1u);
for(auto pos = entities.size(); pos < req; ++pos) {
release_entity(generate_identifier(), {});
}
entt = entities.emplace_back(hint);
} else if(const auto curr = (to_integral(entities[req]) & traits_type::entity_mask); req == curr) {
entt = create();
} else {
auto *it = &available;
for(; (to_integral(*it) & traits_type::entity_mask) != req; it = &entities[to_integral(*it) & traits_type::entity_mask]);
*it = entity_type{curr | (to_integral(*it) & (traits_type::version_mask << traits_type::entity_shift))};
entt = entities[req] = hint;
}
return entt;
}
Synopsis
#include <src/entt/entity/registry.hpp>
template <typename It>
void create(It first, It last)
Description
Assigns each element in a range an entity.
- 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 / What is allowed and what is not
Source
Lines 491-500 in src/entt/entity/registry.hpp.
template<typename It>
void create(It first, It last) {
for(; available != null && first != last; ++first) {
*first = recycle_identifier();
}
for(; first != last; ++first) {
*first = generate_identifier();
}
}