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

Source

Lines 384-386 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 and returns it.

See
create
If the requested entity isn't in use, the suggested identifier is created and returned. Otherwise, a new identifier is generated.
Parameters

hint - Required entity identifier.

Returns
A valid entity identifier.

Mentioned in

Source

Lines 399-420 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 = traits_type::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 = traits_type::to_entity(entities[req]); req == curr) {
        return create();
    } else {
        auto *it = &free_list;
        for(; traits_type::to_entity(*it) != req; it = &entities[traits_type::to_entity(*it)]);
        *it = traits_type::construct(curr, traits_type::to_version(*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 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 431-443 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);
    }
}





Add Discussion

Log in to comment