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

Command buffer for deferred World operations. More...

#include <world_buffer.hpp>

Public Types

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

Public Member Functions

constexpr WorldCmdBuffer (CmdQueue< Allocator > &queue, allocator_type allocator=allocator_type{})
 Constructs a world command buffer with a custom allocator.
constexpr WorldCmdBuffer (CmdQueue< Allocator > &queue, std::pmr::memory_resource *resource)
 Constructs a world command buffer from a PMR memory resource.
 WorldCmdBuffer (CmdQueue< Allocator > &queue, std::nullptr_t)=delete
 WorldCmdBuffer (const WorldCmdBuffer &)=delete
 WorldCmdBuffer (WorldCmdBuffer &&)=delete
constexpr ~WorldCmdBuffer ()
WorldCmdBufferoperator= (const WorldCmdBuffer &)=delete
WorldCmdBufferoperator= (WorldCmdBuffer &&)=delete
void Clear () noexcept
 Clears all pending commands from the buffer.
constexpr void Reserve (size_type capacity)
 Reserves capacity for commands.
template<ResourceTrait T>
auto InsertResource (this auto &&self, T &&resource) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to insert a resource into the world.
template<ResourceTrait T>
auto TryInsertResource (this auto &&self, T &&resource) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to try to insert a resource if not present.
template<ResourceTrait T>
auto RemoveResource (this auto &&self) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to remove a resource from the world.
template<ResourceTrait T>
auto TryRemoveResource (this auto &&self) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to try to remove a resource.
template<typename F>
requires std::invocable<F, World&>
auto DeferredUpdate (this auto &&self, F &&command) -> decltype(std::forward< decltype(self)>(self))
 Enqueues a command to be executed during the next World::Update().
constexpr bool Empty () const noexcept
 Checks if the buffer is empty.
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::WorldCmdBuffer< Allocator >

Command buffer for deferred World 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 24 of file world_buffer.hpp.

Member Typedef Documentation

◆ allocator_type

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

Definition at line 27 of file world_buffer.hpp.

◆ size_type

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

Definition at line 26 of file world_buffer.hpp.

Constructor & Destructor Documentation

◆ WorldCmdBuffer() [1/5]

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

Constructs a world command buffer with a custom allocator.

Parameters
queueQueue to push commands into
allocatorAllocator instance

Definition at line 34 of file world_buffer.hpp.

◆ WorldCmdBuffer() [2/5]

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

Constructs a world command buffer from a PMR memory resource.

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

Parameters
queueQueue to push commands into
resourceMemory resource used to construct allocator

Definition at line 45 of file world_buffer.hpp.

◆ WorldCmdBuffer() [3/5]

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

◆ WorldCmdBuffer() [4/5]

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

◆ WorldCmdBuffer() [5/5]

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

◆ ~WorldCmdBuffer()

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::WorldCmdBuffer< Allocator >::~WorldCmdBuffer ( )
inlineconstexpr

Definition at line 54 of file world_buffer.hpp.

Member Function Documentation

◆ Clear()

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

Clears all pending commands from the buffer.

Removes all commands currently in the buffer.

Definition at line 63 of file world_buffer.hpp.

◆ DeferredUpdate()

template<typename Allocator>
requires std::invocable<F, World&>
template<typename F>
requires std::invocable<F, World&>
auto helios::ecs::WorldCmdBuffer< Allocator >::DeferredUpdate ( this auto && self,
F && command ) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to be executed during the next World::Update().

Equivalent to enqueueing a FunctionCmd with the given callable.

Note
Not thread-safe.
Template Parameters
FCallable type, must have signature void(World&)
Parameters
commandCommand to enqueue

Definition at line 192 of file world_buffer.hpp.

◆ Empty()

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

Checks if the buffer is empty.

Returns
True if buffer is empty, false otherwise

Definition at line 129 of file world_buffer.hpp.

◆ GetAllocator()

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

Gets the allocator used by the command storage.

Returns
Allocator instance

Definition at line 145 of file world_buffer.hpp.

◆ InsertResource()

template<typename Allocator>
template<ResourceTrait T>
auto helios::ecs::WorldCmdBuffer< Allocator >::InsertResource ( this auto && self,
T && resource ) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to insert a resource into the world.

Replaces existing resource if present.

Note
Not thread-safe.
Template Parameters
TResource type
Parameters
resourceResource to insert

Definition at line 157 of file world_buffer.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ RemoveResource()

template<typename Allocator>
template<ResourceTrait T>
auto helios::ecs::WorldCmdBuffer< Allocator >::RemoveResource ( this auto && self) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to remove a resource from the world.

Note
Not thread-safe.
Warning
Triggers assertion if resource does not exist.
Template Parameters
TResource type

Definition at line 175 of file world_buffer.hpp.

◆ Reserve()

template<typename Allocator = std::allocator<std::byte>>
void helios::ecs::WorldCmdBuffer< 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 71 of file world_buffer.hpp.

◆ Size()

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

Gets the number of commands in the buffer.

Returns
Number of commands in buffer

Definition at line 137 of file world_buffer.hpp.

◆ TryInsertResource()

template<typename Allocator>
template<ResourceTrait T>
auto helios::ecs::WorldCmdBuffer< Allocator >::TryInsertResource ( this auto && self,
T && resource ) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to try to insert a resource if not present.

Note
Not thread-safe.
Template Parameters
TResource type
Parameters
resourceResource to insert

Definition at line 166 of file world_buffer.hpp.

◆ TryRemoveResource()

template<typename Allocator>
template<ResourceTrait T>
auto helios::ecs::WorldCmdBuffer< Allocator >::TryRemoveResource ( this auto && self) -> decltype(std::forward< decltype(self)>(self))
inline

Enqueues a command to try to remove a resource.

Note
Not thread-safe.
Template Parameters
TResource type

Definition at line 183 of file world_buffer.hpp.