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

Source

Lines 624-626 in src/entt/entity/registry.hpp.

[[nodiscard]] entity_type create() {
    return (free_list == null) ? epool.emplace_back(generate_identifier(epool.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

Source

Lines 637-658 in src/entt/entity/registry.hpp.

[[nodiscard]] entity_type create(const entity_type hint) {
    const auto length = epool.size();
    if(hint == null || hint == tombstone) {
        return create();
    } else if(const auto req = entity_traits::to_entity(hint); !(req < length)) {
        epool.resize(size_type(req) + 1u, null);
        for(auto pos = length; pos < req; ++pos) {
            release_entity(generate_identifier(pos), {});
        }
        return (epool[req] = hint);
    } else if(const auto curr = entity_traits::to_entity(epool[req]); req == curr) {
        return create();
    } else {
        auto *it = &free_list;
        for(; entity_traits::to_entity(*it) != req; it = &epool[entity_traits::to_entity(*it)]) {}
        *it = entity_traits::combine(curr, entity_traits::to_integral(*it));
        return (epool[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

Source

Lines 669-681 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 = epool.size();
    epool.resize(length + std::distance(first, last), null);
    for(auto pos = length; first != last; ++first, ++pos) {
        *first = epool[pos] = generate_identifier(pos);
    }
}





Add Discussion

Log in to comment