stellarlib 0.1.0
Loading...
Searching...
No Matches
stellarlib::ecs::world Class Referencefinal

Stores and exposes operations on entities and components. More...

#include <world.hpp>

Public Member Functions

 world () noexcept
 Default constructor.
constexpr world (const world &) noexcept=delete
 Deleted copy constructor.
 world (world &&other) noexcept
 Move constructor.
constexpr auto operator= (const world &) noexcept -> world &=delete
 Deleted copy assignment operator.
auto operator= (world &&other) noexcept -> world &
 Move assignment operator.
 ~world () noexcept
 Destructor.
template<typename ... T>
constexpr auto spawn (T &&...components) noexcept
 Spawns an entity with the provided components.
template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
constexpr auto insert (const std::uint32_t entity, T &&...components) noexcept -> std::expected< void, std::tuple< T... > >
 Adds the provided components to an entity.
auto size () const noexcept -> std::size_t
 Returns the number of entities.
auto spawning (std::uint32_t entity) const noexcept -> bool
 Evaluates whether an entity will be spawned.
auto contains (std::uint32_t entity) const noexcept -> bool
 Evaluates whether an entity exists.
auto despawning (std::uint32_t entity) const noexcept -> bool
 Evaluates whether an entity will be despawned.
template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
constexpr auto contains (const std::uint32_t entity) const noexcept
 Evaluates whether an entity has the specified components.
auto at (std::uint32_t entity) const noexcept -> const archetype *
 Returns a pointer to the archetype of an entity.
template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
constexpr auto at (const std::uint32_t entity) const noexcept
 Returns a tuple of pointers to the specified components of an entity.
template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
constexpr auto at (const std::uint32_t entity) noexcept
 Returns a tuple of pointers to the specified components of an entity.
auto operator[] (std::uint32_t entity) const noexcept -> const archetype &
 Returns a reference to the archetype of an entity.
template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
constexpr auto operator[] (const std::uint32_t entity) const noexcept
 Returns a tuple of references to the specified components of an entity.
template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
constexpr auto operator[] (const std::uint32_t entity) noexcept
 Returns a tuple of references to the specified components of an entity.
constexpr auto query () noexcept
 Returns a view to all entities with their archetypes.
template<typename T>
constexpr auto query () noexcept
 Returns a view to entities with the specified components.
template<typename ... T>
requires (1 < sizeof...(T))
constexpr auto query () noexcept
 Returns a view to entities with the specified components.
template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
constexpr void erase (const std::uint32_t entity) noexcept
 Removes the specified components from an entity.
void despawn (std::uint32_t entity) noexcept
 Despawns an entity.
void clear () noexcept
 Despawns all entities.

Detailed Description

Stores and exposes operations on entities and components.

Examples
examples/example.cpp.

Constructor & Destructor Documentation

◆ world()

stellarlib::ecs::world::world ( world && other)
nodiscardnoexcept

Move constructor.

Parameters
otherOther instance

Member Function Documentation

◆ operator=()

auto stellarlib::ecs::world::operator= ( world && other) -> world &
noexcept

Move assignment operator.

Parameters
otherOther instance
Returns
Current instance

◆ spawn()

template<typename ... T>
auto stellarlib::ecs::world::spawn ( T &&... components)
inlineconstexprnoexcept

Spawns an entity with the provided components.

Template Parameters
TComponent types
Parameters
componentsComponent instances
Returns
ID of the spawned entity
Note
This action is deferred during iterations
Examples
examples/example.cpp.

◆ insert()

template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
auto stellarlib::ecs::world::insert ( const std::uint32_t entity,
T &&... components ) -> std::expected< void, std::tuple< T... > >
inlinenodiscardconstexprnoexcept

Adds the provided components to an entity.

Template Parameters
TComponents types
Parameters
entityID of the entity (can be invalid)
componentsComponent instances
Returns
Void, or a tuple of the provided component instances if the entity ID is invalid
Note
This action is deferred during iterations

◆ size()

auto stellarlib::ecs::world::size ( ) const -> std::size_t
nodiscardnoexcept

Returns the number of entities.

Returns
Number of entities

◆ spawning()

auto stellarlib::ecs::world::spawning ( std::uint32_t entity) const -> bool
nodiscardnoexcept

Evaluates whether an entity will be spawned.

Parameters
entityID of the entity
Returns
Whether the entity will be spawned

◆ contains() [1/2]

auto stellarlib::ecs::world::contains ( std::uint32_t entity) const -> bool
nodiscardnoexcept

Evaluates whether an entity exists.

Parameters
entityID of the entity
Returns
Whether the entity exists

◆ despawning()

auto stellarlib::ecs::world::despawning ( std::uint32_t entity) const -> bool
nodiscardnoexcept

Evaluates whether an entity will be despawned.

Parameters
entityID of the entity
Returns
Whether the entity will be despawned

◆ contains() [2/2]

template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
auto stellarlib::ecs::world::contains ( const std::uint32_t entity) const
inlinenodiscardconstexprnoexcept

Evaluates whether an entity has the specified components.

Template Parameters
TComponent types
Parameters
entityID of the entity (can be invalid)
Returns
Tuple of bools indicating the result for each component type

◆ at() [1/3]

auto stellarlib::ecs::world::at ( std::uint32_t entity) const -> const archetype *
nodiscardnoexcept

Returns a pointer to the archetype of an entity.

Parameters
entityID of the entity (can be invalid)
Returns
Pointer to the archetype of the entity, or nullptr if the entity ID is invalid

◆ at() [2/3]

template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
auto stellarlib::ecs::world::at ( const std::uint32_t entity) const
inlinenodiscardconstexprnoexcept

Returns a tuple of pointers to the specified components of an entity.

Template Parameters
TComponent types
Parameters
entityID of the entity (can be invalid)
Returns
Tuple of pointers to the specified components of the entity, invalid components are indicated with nullptrs

◆ at() [3/3]

template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
auto stellarlib::ecs::world::at ( const std::uint32_t entity)
inlinenodiscardconstexprnoexcept

Returns a tuple of pointers to the specified components of an entity.

Template Parameters
TComponent types
Parameters
entityID of the entity (can be invalid)
Returns
Tuple of pointers to the specified components of the entity, invalid components are indicated with nullptrs

◆ operator[]() [1/3]

auto stellarlib::ecs::world::operator[] ( std::uint32_t entity) const -> const archetype &
nodiscardnoexcept

Returns a reference to the archetype of an entity.

Parameters
entityID of the entity
Returns
Reference to the archetype of the entity
Warning
Invalid entity ID can lead to undefined behavior

◆ operator[]() [2/3]

template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
auto stellarlib::ecs::world::operator[] ( const std::uint32_t entity) const
inlinenodiscardconstexprnoexcept

Returns a tuple of references to the specified components of an entity.

Template Parameters
TComponent types
Parameters
entityID of the entity
Returns
Tuple of references to the specified components of the entity
Warning
Invalid entity ID or component types can lead to undefined behavior

◆ operator[]() [3/3]

template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
auto stellarlib::ecs::world::operator[] ( const std::uint32_t entity)
inlinenodiscardconstexprnoexcept

Returns a tuple of references to the specified components of an entity.

Template Parameters
TComponent types
Parameters
entityID of the entity
Returns
Tuple of references to the specified components of the entity
Warning
Invalid entity ID or component types can lead to undefined behavior

◆ query() [1/3]

auto stellarlib::ecs::world::query ( )
inlinenodiscardconstexprnoexcept

Returns a view to all entities with their archetypes.

Returns
View to all entities with their archetypes

◆ query() [2/3]

template<typename T>
auto stellarlib::ecs::world::query ( )
inlinenodiscardconstexprnoexcept

Returns a view to entities with the specified components.

Template Parameters
TComponent types
Returns
View to entities with the specified components

◆ query() [3/3]

template<typename ... T>
requires (1 < sizeof...(T))
auto stellarlib::ecs::world::query ( )
inlinenodiscardconstexprnoexcept

Returns a view to entities with the specified components.

Template Parameters
TComponent types
Returns
View to entities with the specified components

◆ erase()

template<typename ... T>
requires (static_cast<bool>(sizeof...(T)))
void stellarlib::ecs::world::erase ( const std::uint32_t entity)
inlineconstexprnoexcept

Removes the specified components from an entity.

Template Parameters
TComponents types
Parameters
entityID of the entity (can be invalid)
Note
This action is deferred during iterations

◆ despawn()

void stellarlib::ecs::world::despawn ( std::uint32_t entity)
noexcept

Despawns an entity.

Parameters
entityID of the entity (can be invalid)
Note
This action is deferred during iterations

◆ clear()

void stellarlib::ecs::world::clear ( )
noexcept

Despawns all entities.

Note
This action is deferred during iterations

The documentation for this class was generated from the following file: