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.
Return
A valid entity identifier.

Mentioned in

Source

Lines 413-415 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
If the requested entity isn't in use, the suggested identifier is created and returned. Otherwise, a new one will be generated for this purpose.
Parameters

hint - A desired entity identifier.

Return
A valid entity identifier.

Mentioned in

Source

Lines 428-450 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

Source

Lines 461-470 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();
    }
}





Add Discussion

Log in to comment