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

Command queue for deferred ECS operations. More...

#include <queue.hpp>

Public Types

using size_type = CommandStorage::size_type
using allocator_type = CommandStorage::allocator_type

Public Member Functions

constexpr CmdQueue (allocator_type allocator=allocator_type{})
 Constructs a command queue with a custom allocator.
constexpr CmdQueue (std::pmr::memory_resource *resource)
 Constructs a command queue from a PMR memory resource.
 CmdQueue (std::nullptr_t)=delete
 CmdQueue (const CmdQueue &)=delete
constexpr CmdQueue (CmdQueue &&) noexcept=default
 ~CmdQueue ()=default
CmdQueueoperator= (const CmdQueue &)=delete
CmdQueueoperator= (CmdQueue &&) noexcept=default
void Clear () noexcept
 Clears all pending commands from the queue.
constexpr void Reserve (size_type capacity)
 Reserves capacity for commands.
constexpr void Merge (CmdQueue &&other)
 Merges another queue into this one by moving its commands.
template<CommandTrait T>
void Enqueue (T &&command)
 Enqueues a command by moving it into the queue.
template<std::ranges::input_range R>
requires CommandTrait<std::ranges::range_value_t<R>>
void EnqueueBulk (R &&commands)
 Enqueues multiple commands in bulk.
void ExecuteAll (World &world)
 Executes all commands in the queue and clears the queue.
constexpr bool Empty () const noexcept
 Checks if the queue is empty.
constexpr size_type Size () const noexcept
 Gets the number of commands in the queue.
constexpr allocator_type GetAllocator () const
 Gets the allocator used by the command storage.

Detailed Description

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

Command queue for deferred ECS operations.

Provides a queue for commands that will be executed during World::Update(). Commands are executed in the order they were enqueued, 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 queue.hpp.

Member Typedef Documentation

◆ allocator_type

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

Definition at line 33 of file queue.hpp.

◆ size_type

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

Definition at line 32 of file queue.hpp.

Constructor & Destructor Documentation

◆ CmdQueue() [1/5]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::CmdQueue< Allocator >::CmdQueue ( allocator_type allocator = allocator_type{})
inlineexplicitconstexpr

Constructs a command queue with a custom allocator.

Parameters
allocatorAllocator instance

Definition at line 39 of file queue.hpp.

◆ CmdQueue() [2/5]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::CmdQueue< Allocator >::CmdQueue ( std::pmr::memory_resource * resource)
inlineexplicitconstexpr

Constructs a command queue from a PMR memory resource.

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

Parameters
resourceMemory resource used to construct allocator

Definition at line 48 of file queue.hpp.

◆ CmdQueue() [3/5]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::CmdQueue< Allocator >::CmdQueue ( std::nullptr_t )
delete

◆ CmdQueue() [4/5]

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

◆ CmdQueue() [5/5]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::CmdQueue< Allocator >::CmdQueue ( CmdQueue< Allocator > && )
constexprdefaultnoexcept

◆ ~CmdQueue()

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::CmdQueue< Allocator >::~CmdQueue ( )
default

Member Function Documentation

◆ Clear()

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

Clears all pending commands from the queue.

Removes all commands currently in the queue.

Definition at line 65 of file queue.hpp.

◆ Empty()

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

Checks if the queue is empty.

Returns
True if queue is empty, false otherwise

Definition at line 113 of file queue.hpp.

◆ Enqueue()

template<typename Allocator>
template<CommandTrait T>
void helios::ecs::CmdQueue< Allocator >::Enqueue ( T && command)
inline

Enqueues a command by moving it into the queue.

Moves a command into the queue.

Template Parameters
TCommand type
Parameters
commandCommand to enqueue

Definition at line 139 of file queue.hpp.

◆ EnqueueBulk()

template<typename Allocator>
requires CommandTrait<std::ranges::range_value_t<R>>
template<std::ranges::input_range R>
requires CommandTrait<std::ranges::range_value_t<R>>
void helios::ecs::CmdQueue< Allocator >::EnqueueBulk ( R && commands)
inline

Enqueues multiple commands in bulk.

Moves a range of commands into the queue in a single operation.

Template Parameters
RRange type
Parameters
commandsRange of commands to enqueue

Definition at line 147 of file queue.hpp.

◆ ExecuteAll()

template<typename Allocator>
void helios::ecs::CmdQueue< Allocator >::ExecuteAll ( World & world)
inline

Executes all commands in the queue and clears the queue.

Parameters
worldReference to the World instance

Definition at line 158 of file queue.hpp.

◆ GetAllocator()

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

Gets the allocator used by the command storage.

Returns
Allocator instance

Definition at line 129 of file queue.hpp.

◆ Merge()

template<typename Allocator = std::allocator<std::byte>>
void helios::ecs::CmdQueue< Allocator >::Merge ( CmdQueue< Allocator > && other)
inlineconstexpr

Merges another queue into this one by moving its commands.

Moves all commands from the other queue into this one.

Parameters
otherQueue to merge

Definition at line 80 of file queue.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ Reserve()

template<typename Allocator = std::allocator<std::byte>>
void helios::ecs::CmdQueue< 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 73 of file queue.hpp.

◆ Size()

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

Gets the number of commands in the queue.

Returns
Number of commands in queue

Definition at line 121 of file queue.hpp.