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

#include <world_command_buffer.hpp>

Public Types

using allocator_type = Allocator
 

Public Member Functions

 WorldCmdBuffer (details::SystemLocalStorage &local_storage, Allocator alloc=Allocator{}) noexcept
 Constructs a WorldCmdBuffer for recording commands.
 
 WorldCmdBuffer (const WorldCmdBuffer &)=delete
 
 WorldCmdBuffer (WorldCmdBuffer &&) noexcept=default
 
 ~WorldCmdBuffer () noexcept
 Destructor that automatically flushes pending commands.
 
WorldCmdBufferoperator= (const WorldCmdBuffer &)=delete
 
WorldCmdBufferoperator= (WorldCmdBuffer &&) noexcept=default
 
void Flush () noexcept
 Flushes all pending commands to the system local storage.
 
template<typename F >
requires std::invocable<F, World&>
void Push (F &&func)
 Pushes a custom command function to be executed on the world.
 
void Destroy (Entity entity)
 Enqueues destruction of a single entity.
 
template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, Entity>
void Destroy (const R &entities)
 Enqueues destruction of entities.
 
void TryDestroy (Entity entity)
 Enqueues try-destruction of a single entity.
 
template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, Entity>
void TryDestroy (const R &entities)
 Enqueues try-destruction of entities.
 
template<EventTrait T>
void ClearEvents ()
 Queues a command to clear all events of a specific type.
 
void ClearEvents ()
 Queues a command to clear all event queues without removing registration.
 
bool Empty () const noexcept
 Checks if there are no pending commands.
 
size_t Size () const noexcept
 Gets the number of pending commands.
 
allocator_type get_allocator () const noexcept
 Gets the allocator used by this buffer.
 

Detailed Description

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
class helios::ecs::WorldCmdBuffer< Allocator >

Definition at line 45 of file world_command_buffer.hpp.

Member Typedef Documentation

◆ allocator_type

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
using helios::ecs::WorldCmdBuffer< Allocator >::allocator_type = Allocator

Constructor & Destructor Documentation

◆ WorldCmdBuffer() [1/3]

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
helios::ecs::WorldCmdBuffer< Allocator >::WorldCmdBuffer ( details::SystemLocalStorage local_storage,
Allocator  alloc = Allocator{} 
)
inlineexplicitnoexcept

Constructs a WorldCmdBuffer for recording commands.

Parameters
local_storageReference to system local storage for command execution
allocAllocator instance for internal storage

Definition at line 54 of file world_command_buffer.hpp.

54 {}) noexcept
55 : local_storage_(local_storage), commands_(alloc), alloc_(alloc) {}
BasicQuery< World, Allocator, Components... > Query
Type alias for query with mutable world access.
Definition query.hpp:2481

◆ WorldCmdBuffer() [2/3]

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

◆ WorldCmdBuffer() [3/3]

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
helios::ecs::WorldCmdBuffer< Allocator >::WorldCmdBuffer ( WorldCmdBuffer< Allocator > &&  )
defaultnoexcept

◆ ~WorldCmdBuffer()

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
helios::ecs::WorldCmdBuffer< Allocator >::~WorldCmdBuffer ( )
inlinenoexcept

Destructor that automatically flushes pending commands.

Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/world_command_buffer.hpp.

Definition at line 63 of file world_command_buffer.hpp.

63{ Flush(); }
void Flush() noexcept
Flushes all pending commands to the system local storage.

Member Function Documentation

◆ ClearEvents() [1/2]

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
template<EventTrait T>
void helios::ecs::WorldCmdBuffer< Allocator >::ClearEvents ( )
inline

Queues a command to clear all events of a specific type.

Template Parameters
TEvent type to clear
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/world_command_buffer.hpp.

Definition at line 135 of file world_command_buffer.hpp.

135 {
136 commands_.push_back(std::make_unique<details::ClearEventsCmd<T>>());
137 }

◆ ClearEvents() [2/2]

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
void helios::ecs::WorldCmdBuffer< Allocator >::ClearEvents ( )
inline

Queues a command to clear all event queues without removing registration.

Events can still be written/read after this command executes.

Definition at line 143 of file world_command_buffer.hpp.

143{ commands_.push_back(std::make_unique<details::ClearAllEventsCmd>()); }

◆ Destroy() [1/2]

template<typename Allocator >
requires std::same_as<std::ranges::range_value_t<R>, Entity>
template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, Entity>
void helios::ecs::WorldCmdBuffer< Allocator >::Destroy ( const R entities)
inline

Enqueues destruction of entities.

Warning
Triggers assertion in next cases:
  • Any entity is invalid.
  • Any entity is not owned by world during command execution.
Template Parameters
RRange type containing Entity elements
Parameters
entitiesEntities to destroy

Definition at line 188 of file world_command_buffer.hpp.

188 {
189 HELIOS_ASSERT(std::ranges::all_of(entities, [](const auto& entity) { return entity.Valid(); }),
190 "Failed to destroy entities: All entities must be valid!");
191 commands_.push_back(std::make_unique<details::DestroyEntitiesCmd>(entities));
192}
#define HELIOS_ASSERT(condition,...)
Assertion macro that aborts execution in debug builds.
Definition assert.hpp:140

◆ Destroy() [2/2]

template<typename Allocator >
void helios::ecs::WorldCmdBuffer< Allocator >::Destroy ( Entity  entity)
inline

Enqueues destruction of a single entity.

Warning
Triggers assertion in next cases:
  • Entity is invalid.
  • Entity is not owned by world during command execution.
Parameters
entityEntity to destroy
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/world_command_buffer.hpp.

Definition at line 180 of file world_command_buffer.hpp.

180 {
181 HELIOS_ASSERT(entity.Valid(), "Failed to destroy entity: Entity is not valid!");
182 commands_.push_back(std::make_unique<details::DestroyEntityCmd>(entity));
183}

◆ Empty()

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
bool helios::ecs::WorldCmdBuffer< Allocator >::Empty ( ) const
inlinenoexcept

Checks if there are no pending commands.

Returns
True if no commands are buffered, false otherwise
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/world_command_buffer.hpp.

Definition at line 149 of file world_command_buffer.hpp.

149{ return commands_.empty(); }

◆ Flush()

template<typename Allocator >
void helios::ecs::WorldCmdBuffer< Allocator >::Flush ( )
inlinenoexcept

Flushes all pending commands to the system local storage.

Moves all locally buffered commands to SystemLocalStorage for later execution. Called automatically by destructor. Safe to call multiple times.

Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/world_command_buffer.hpp.

Definition at line 170 of file world_command_buffer.hpp.

170 {
171 for (auto& cmd : commands_) {
172 if (cmd != nullptr) [[likely]] {
173 local_storage_.AddCommand(std::move(cmd));
174 }
175 }
176 commands_.clear();
177}
void AddCommand(std::unique_ptr< Command > command)
Adds a pre-constructed command to the local buffer.

◆ get_allocator()

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
allocator_type helios::ecs::WorldCmdBuffer< Allocator >::get_allocator ( ) const
inlinenoexcept

Gets the allocator used by this buffer.

Returns
Copy of the allocator
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/world_command_buffer.hpp.

Definition at line 161 of file world_command_buffer.hpp.

161{ return alloc_; }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
WorldCmdBuffer & helios::ecs::WorldCmdBuffer< Allocator >::operator= ( WorldCmdBuffer< Allocator > &&  )
defaultnoexcept

◆ Push()

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
template<typename F >
requires std::invocable<F, World&>
void helios::ecs::WorldCmdBuffer< Allocator >::Push ( F &&  func)
inline

Pushes a custom command function to be executed on the world.

Template Parameters
FCallable type that accepts World&
Parameters
funcFunction to execute on the world
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/world_command_buffer.hpp.

Definition at line 82 of file world_command_buffer.hpp.

82 {
83 commands_.push_back(std::make_unique<details::FunctionCmd<F>>(std::forward<F>(func)));
84 }

◆ Size()

template<typename Allocator = std::allocator<std::unique_ptr<Command>>>
size_t helios::ecs::WorldCmdBuffer< Allocator >::Size ( ) const
inlinenoexcept

Gets the number of pending commands.

Returns
Number of commands in the buffer
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/world_command_buffer.hpp.

Definition at line 155 of file world_command_buffer.hpp.

155{ return commands_.size(); }

◆ TryDestroy() [1/2]

template<typename Allocator >
requires std::same_as<std::ranges::range_value_t<R>, Entity>
template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, Entity>
void helios::ecs::WorldCmdBuffer< Allocator >::TryDestroy ( const R entities)
inline

Enqueues try-destruction of entities.

Skips non-existing entities.

Warning
Triggers assertion in next cases:
  • Any entity is invalid.
  • Any entity is not owned by world during command execution.
Template Parameters
RRange type containing Entity elements
Parameters
entitiesEntities to try destroy

Definition at line 203 of file world_command_buffer.hpp.

203 {
204 HELIOS_ASSERT(std::ranges::all_of(entities, [](const auto& entity) { return entity.Valid(); }),
205 "Failed to destroy entities: All entities must be valid!");
206 commands_.push_back(std::make_unique<details::TryDestroyEntitiesCmd>(entities));
207}

◆ TryDestroy() [2/2]

template<typename Allocator >
void helios::ecs::WorldCmdBuffer< Allocator >::TryDestroy ( Entity  entity)
inline

Enqueues try-destruction of a single entity.

Skips non-existing entity.

Warning
Triggers assertion in next cases:
  • Entity is invalid.
  • Entity is not owned by world during command execution.
Parameters
entityEntity to try destroy
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/world_command_buffer.hpp.

Definition at line 195 of file world_command_buffer.hpp.

195 {
196 HELIOS_ASSERT(entity.Valid(), "Failed to try destroy entity: Entity is not valid!");
197 commands_.push_back(std::make_unique<details::TryDestroyEntityCmd>(entity));
198}