Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::ecs::EntityCmdBuffer< Allocator > Class Template Reference

Command buffer for deferred entity operations. More...

#include <entity_buffer.hpp>

Public Types

using size_type = CmdQueue<Allocator>::size_type
using allocator_type = CmdQueue<Allocator>::allocator_type

Public Member Functions

constexpr EntityCmdBuffer (Entity entity, CmdQueue< Allocator > &queue, allocator_type allocator=allocator_type{})
 Constructs aa entity command buffer with a custom allocator.
constexpr EntityCmdBuffer (Entity entity, CmdQueue< Allocator > &queue, std::pmr::memory_resource *resource)
 Constructs an entity command buffer from a PMR memory resource.
 EntityCmdBuffer (Entity entity, CmdQueue< Allocator > &queue, std::nullptr_t)=delete
 EntityCmdBuffer (const EntityCmdBuffer &)=delete
 EntityCmdBuffer (EntityCmdBuffer &&)=delete
 ~EntityCmdBuffer ()
EntityCmdBufferoperator= (const EntityCmdBuffer &)=delete
EntityCmdBufferoperator= (EntityCmdBuffer &&)=delete
void Clear () noexcept
 Clears all pending commands from the buffer.
constexpr void Reserve (size_type capacity)
 Reserves capacity for commands.
auto Destroy (this auto &&self) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to destroy entity and removes it from the world.
auto TryDestroy (this auto &&self) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to try destroy entity if it exists in the world.
template<ComponentTrait... Ts>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
auto AddComponents (this auto &&self, Ts &&... components) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to add components to the entity.
template<ComponentTrait... Ts>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
auto TryAddComponents (this auto &&self, Ts &&... components) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to try to add components to the entity if they don't exist.
template<ComponentTrait... Ts>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
auto RemoveComponents (this auto &&self) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to remove components from the entity.
template<ComponentTrait... Ts>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
auto TryRemoveComponents (this auto &&self) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to try to remove components from the entity if they exist.
auto ClearComponents (this auto &&self) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to remove all components from the entity.
constexpr bool Empty () const noexcept
 Checks if the buffer is empty.
constexpr Entity GetEntity () const noexcept
 Gets the entity associated with this buffer.
constexpr size_type Size () const noexcept
 Gets the number of commands in the buffer.
constexpr allocator_type GetAllocator () const noexcept(std::is_nothrow_copy_constructible_v< allocator_type >)
 Gets the allocator used by the command storage.

Detailed Description

template<typename Allocator = std::allocator<std::byte>>
class helios::ecs::EntityCmdBuffer< Allocator >

Command buffer for deferred entity operations.

Collects commands and then pushes them into a queue. Commands are enqueued in the order they were added, ensuring predictable behavior.

Note
Not thread-safe.
Template Parameters
AllocatorAllocator type for command storage (default: std::allocator<std::byte>)

Definition at line 26 of file entity_buffer.hpp.

Member Typedef Documentation

◆ allocator_type

template<typename Allocator = std::allocator<std::byte>>
using helios::ecs::EntityCmdBuffer< Allocator >::allocator_type = CmdQueue<Allocator>::allocator_type

Definition at line 29 of file entity_buffer.hpp.

◆ size_type

template<typename Allocator = std::allocator<std::byte>>
using helios::ecs::EntityCmdBuffer< Allocator >::size_type = CmdQueue<Allocator>::size_type

Definition at line 28 of file entity_buffer.hpp.

Constructor & Destructor Documentation

◆ EntityCmdBuffer() [1/5]

template<typename Allocator>
helios::ecs::EntityCmdBuffer< Allocator >::EntityCmdBuffer ( Entity entity,
CmdQueue< Allocator > & queue,
allocator_type allocator = allocator_type{} )
constexpr

Constructs aa entity command buffer with a custom allocator.

Warning
Triggers assertion if entity is invalid.
Parameters
entityEntity associated with this buffer
queueQueue to push commands into
allocatorAllocator instance

Definition at line 203 of file entity_buffer.hpp.

◆ EntityCmdBuffer() [2/5]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::EntityCmdBuffer< Allocator >::EntityCmdBuffer ( Entity entity,
CmdQueue< Allocator > & queue,
std::pmr::memory_resource * resource )
inlineconstexpr

Constructs an entity command buffer from a PMR memory resource.

Enabled only when allocator_type is constructible from std::pmr::memory_resource*.

Parameters
entityEntity associated with this buffer
queueQueue to push commands into
resourceMemory resource used to construct allocator

Definition at line 49 of file entity_buffer.hpp.

◆ EntityCmdBuffer() [3/5]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::EntityCmdBuffer< Allocator >::EntityCmdBuffer ( Entity entity,
CmdQueue< Allocator > & queue,
std::nullptr_t  )
delete

◆ EntityCmdBuffer() [4/5]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::EntityCmdBuffer< Allocator >::EntityCmdBuffer ( const EntityCmdBuffer< Allocator > & )
delete

◆ EntityCmdBuffer() [5/5]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::EntityCmdBuffer< Allocator >::EntityCmdBuffer ( EntityCmdBuffer< Allocator > && )
delete

◆ ~EntityCmdBuffer()

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::EntityCmdBuffer< Allocator >::~EntityCmdBuffer ( )
inline

Definition at line 59 of file entity_buffer.hpp.

Member Function Documentation

◆ AddComponents()

template<typename Allocator>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
template<ComponentTrait... Ts>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
auto helios::ecs::EntityCmdBuffer< Allocator >::AddComponents ( this auto && self,
Ts &&... components ) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to add components to the entity.

If entity already has component of provided type then it will be replaced.

Note
Not thread-safe.
Warning
Triggers assertion in next cases:
Template Parameters
TsComponents types to add
Parameters
componentsComponents to add

Definition at line 226 of file entity_buffer.hpp.

◆ Clear()

template<typename Allocator = std::allocator<std::byte>>
void helios::ecs::EntityCmdBuffer< Allocator >::Clear ( )
inlinenoexcept

Clears all pending commands from the buffer.

Removes all commands currently in the buffer.

Definition at line 68 of file entity_buffer.hpp.

◆ ClearComponents()

template<typename Allocator>
auto helios::ecs::EntityCmdBuffer< Allocator >::ClearComponents ( this auto && self) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to remove all components from the entity.

Note
Not thread-safe.
Warning
Triggers assertion in next cases:

Definition at line 264 of file entity_buffer.hpp.

◆ Destroy()

template<typename Allocator>
auto helios::ecs::EntityCmdBuffer< Allocator >::Destroy ( this auto && self) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to destroy entity and removes it from the world.

Note
Not thread-safe.
Warning
Triggers assertion in next cases:

Definition at line 210 of file entity_buffer.hpp.

◆ Empty()

template<typename Allocator = std::allocator<std::byte>>
bool helios::ecs::EntityCmdBuffer< Allocator >::Empty ( ) const
inlinenodiscardconstexprnoexcept

Checks if the buffer is empty.

Returns
True if buffer is empty, false otherwise

Definition at line 169 of file entity_buffer.hpp.

◆ GetAllocator()

template<typename Allocator = std::allocator<std::byte>>
allocator_type helios::ecs::EntityCmdBuffer< Allocator >::GetAllocator ( ) const
inlinenodiscardconstexprnoexcept

Gets the allocator used by the command storage.

Returns
Allocator instance

Definition at line 191 of file entity_buffer.hpp.

◆ GetEntity()

template<typename Allocator = std::allocator<std::byte>>
Entity helios::ecs::EntityCmdBuffer< Allocator >::GetEntity ( ) const
inlinenodiscardconstexprnoexcept

Gets the entity associated with this buffer.

Returns
Entity instance

Definition at line 177 of file entity_buffer.hpp.

◆ operator=() [1/2]

template<typename Allocator = std::allocator<std::byte>>
EntityCmdBuffer & helios::ecs::EntityCmdBuffer< Allocator >::operator= ( const EntityCmdBuffer< Allocator > & )
delete

◆ operator=() [2/2]

template<typename Allocator = std::allocator<std::byte>>
EntityCmdBuffer & helios::ecs::EntityCmdBuffer< Allocator >::operator= ( EntityCmdBuffer< Allocator > && )
delete

◆ RemoveComponents()

template<typename Allocator>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
template<ComponentTrait... Ts>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
auto helios::ecs::EntityCmdBuffer< Allocator >::RemoveComponents ( this auto && self) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to remove components from the entity.

Note
Not thread-safe.
Warning
Triggers assertion in next cases:
  • Entity is invalid.
  • World does not own entity.
  • Entity does not have any of the components.
Template Parameters
TsComponents types to remove

Definition at line 248 of file entity_buffer.hpp.

◆ Reserve()

template<typename Allocator = std::allocator<std::byte>>
void helios::ecs::EntityCmdBuffer< Allocator >::Reserve ( size_type capacity)
inlineconstexpr

Reserves capacity for commands.

Pre-allocates memory to avoid reallocations during enqueue operations.

Parameters
capacityNumber of commands to reserve space for

Definition at line 76 of file entity_buffer.hpp.

◆ Size()

template<typename Allocator = std::allocator<std::byte>>
size_type helios::ecs::EntityCmdBuffer< Allocator >::Size ( ) const
inlinenodiscardconstexprnoexcept

Gets the number of commands in the buffer.

Returns
Number of commands in buffer

Definition at line 183 of file entity_buffer.hpp.

◆ TryAddComponents()

template<typename Allocator>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
template<ComponentTrait... Ts>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
auto helios::ecs::EntityCmdBuffer< Allocator >::TryAddComponents ( this auto && self,
Ts &&... components ) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to try to add components to the entity if they don't exist.

Note
Not thread-safe.
Warning
Triggers assertion in next cases:
Template Parameters
TsComponents types to add
Parameters
componentsComponents to add

Definition at line 237 of file entity_buffer.hpp.

◆ TryDestroy()

template<typename Allocator>
auto helios::ecs::EntityCmdBuffer< Allocator >::TryDestroy ( this auto && self) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to try destroy entity if it exists in the world.

Note
Not thread-safe.
Warning
Triggers assertion if entity is invalid.

Definition at line 217 of file entity_buffer.hpp.

◆ TryRemoveComponents()

template<typename Allocator>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
template<ComponentTrait... Ts>
requires utils::UniqueTypes<Ts...> && (sizeof...(Ts) > 0)
auto helios::ecs::EntityCmdBuffer< Allocator >::TryRemoveComponents ( this auto && self) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to try to remove components from the entity if they exist.

Note
Not thread-safe.
Warning
Triggers assertion in next cases:
Template Parameters
TsComponents types to remove

Definition at line 257 of file entity_buffer.hpp.