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

Per-system registry for tracking consumed message indices. More...

#include <consumed_registry.hpp>

Public Types

using size_type = size_t
using allocator_type = Alloc

Public Member Functions

constexpr ConsumedMessagesRegistry (allocator_type alloc={})
constexpr ConsumedMessagesRegistry (std::pmr::memory_resource *resource)
 Constructs a ConsumedMessagesRegistry from a PMR memory resource.
 ConsumedMessagesRegistry (std::nullptr_t)=delete
 ConsumedMessagesRegistry (const ConsumedMessagesRegistry &)=default
 ConsumedMessagesRegistry (ConsumedMessagesRegistry &&) noexcept=default
 ~ConsumedMessagesRegistry ()=default
ConsumedMessagesRegistryoperator= (const ConsumedMessagesRegistry &)=default
ConsumedMessagesRegistryoperator= (ConsumedMessagesRegistry &&) noexcept=default
template<ConsumableMessageTrait T>
constexpr void MarkConsumed (size_type global_index)
 Marks an message as consumed by its type and global index.
constexpr void MarkConsumed (MessageTypeIndex type_index, size_type global_index)
 Marks an message as consumed by its type index and global index.
template<typename OtherAlloc>
constexpr void MergeFrom (const ConsumedMessagesRegistry< OtherAlloc > &other)
 Merges consumed entries from another registry into this one.
template<typename OtherAlloc>
constexpr void MergeFrom (ConsumedMessagesRegistry< OtherAlloc > &&other)
 Merges consumed entries from another registry into this one.
constexpr void Clear () noexcept
 Clears all consumed entries.
template<ConsumableMessageTrait T>
constexpr void Clear () noexcept
 Clears consumed entries for a specific message type.
constexpr void Clear (MessageTypeIndex type_index) noexcept
 Clears consumed entries for a specific message type.
template<ConsumableMessageTrait T>
constexpr bool IsConsumed (size_type global_index) const noexcept
 Checks if a specific message is marked as consumed.
constexpr bool IsConsumed (MessageTypeIndex type_index, size_type global_index) const noexcept
 Checks if a specific message is marked as consumed.
template<ConsumableMessageTrait T>
constexpr auto ConsumedIndicesFor () const noexcept -> std::span< const size_type >
 Gets the sorted consumed indices for a specific message type.
constexpr auto ConsumedIndicesFor (MessageTypeIndex type_index) const noexcept -> std::span< const size_type >
 Gets the sorted consumed indices for a specific message type.
constexpr bool Empty () const noexcept
 Checks if any message type has consumed entries.
template<ConsumableMessageTrait T>
constexpr bool HasConsumed () const noexcept
 Checks if a specific message type has consumed entries.
constexpr bool HasConsumed (MessageTypeIndex type_index) const noexcept
 Checks if a specific message type has consumed entries.
constexpr size_type TotalConsumedCount () const noexcept
 Gets the total number of consumed messages across all types.
template<ConsumableMessageTrait T>
constexpr size_type ConsumedCount () const noexcept
 Gets the number of consumed messages for a specific type.
constexpr size_type ConsumedCount (MessageTypeIndex type_index) const noexcept
 Gets the number of consumed messages for a specific type.
constexpr const ConsumedMap & Data () const noexcept
 Provides direct access to the underlying consumed map.

Detailed Description

template<typename Alloc = std::allocator<std::byte>>
class helios::ecs::ConsumedMessagesRegistry< Alloc >

Per-system registry for tracking consumed message indices.

Each system running in parallel gets its own ConsumedMessagesRegistry instance. Systems mark messages as consumed by writing indices into their registry, avoiding data races. At Update time, all registries are merged and applied to message queues in MessageManager.

Indices are global within the combined (previous + current) message view for a given type. For a type with P previous messages and C current messages:

  • Indices [0, P) refer to previous messages
  • Indices [P, P + C) refer to current messages
Note
Not therad-safe.
Template Parameters
AllocAllocator type for internal storage (default: std::allocator<std::byte>)

Definition at line 42 of file consumed_registry.hpp.

Member Typedef Documentation

◆ allocator_type

template<typename Alloc = std::allocator<std::byte>>
using helios::ecs::ConsumedMessagesRegistry< Alloc >::allocator_type = Alloc

Definition at line 45 of file consumed_registry.hpp.

◆ size_type

template<typename Alloc = std::allocator<std::byte>>
using helios::ecs::ConsumedMessagesRegistry< Alloc >::size_type = size_t

Definition at line 44 of file consumed_registry.hpp.

Constructor & Destructor Documentation

◆ ConsumedMessagesRegistry() [1/5]

template<typename Alloc = std::allocator<std::byte>>
helios::ecs::ConsumedMessagesRegistry< Alloc >::ConsumedMessagesRegistry ( allocator_type alloc = {})
inlineexplicitconstexpr

Definition at line 81 of file consumed_registry.hpp.

◆ ConsumedMessagesRegistry() [2/5]

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

Constructs a ConsumedMessagesRegistry 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 91 of file consumed_registry.hpp.

◆ ConsumedMessagesRegistry() [3/5]

template<typename Alloc = std::allocator<std::byte>>
helios::ecs::ConsumedMessagesRegistry< Alloc >::ConsumedMessagesRegistry ( std::nullptr_t )
delete

◆ ConsumedMessagesRegistry() [4/5]

template<typename Alloc = std::allocator<std::byte>>
helios::ecs::ConsumedMessagesRegistry< Alloc >::ConsumedMessagesRegistry ( const ConsumedMessagesRegistry< Alloc > & )
default

◆ ConsumedMessagesRegistry() [5/5]

template<typename Alloc = std::allocator<std::byte>>
helios::ecs::ConsumedMessagesRegistry< Alloc >::ConsumedMessagesRegistry ( ConsumedMessagesRegistry< Alloc > && )
defaultnoexcept

◆ ~ConsumedMessagesRegistry()

template<typename Alloc = std::allocator<std::byte>>
helios::ecs::ConsumedMessagesRegistry< Alloc >::~ConsumedMessagesRegistry ( )
default

Member Function Documentation

◆ Clear() [1/3]

template<typename Alloc = std::allocator<std::byte>>
template<ConsumableMessageTrait T>
void helios::ecs::ConsumedMessagesRegistry< Alloc >::Clear ( )
inlineconstexprnoexcept

Clears consumed entries for a specific message type.

Template Parameters
TConsumable message type

Definition at line 154 of file consumed_registry.hpp.

◆ Clear() [2/3]

template<typename Alloc = std::allocator<std::byte>>
void helios::ecs::ConsumedMessagesRegistry< Alloc >::Clear ( )
inlineconstexprnoexcept

Clears all consumed entries.

Definition at line 147 of file consumed_registry.hpp.

◆ Clear() [3/3]

template<typename Alloc = std::allocator<std::byte>>
void helios::ecs::ConsumedMessagesRegistry< Alloc >::Clear ( MessageTypeIndex type_index)
inlineconstexprnoexcept

Clears consumed entries for a specific message type.

Parameters
type_indexType index to clear

Definition at line 162 of file consumed_registry.hpp.

◆ ConsumedCount() [1/2]

template<typename Alloc = std::allocator<std::byte>>
template<ConsumableMessageTrait T>
size_type helios::ecs::ConsumedMessagesRegistry< Alloc >::ConsumedCount ( ) const
inlinenodiscardconstexprnoexcept

Gets the number of consumed messages for a specific type.

Template Parameters
TConsumable message type
Returns
Number of consumed messages for this type

Definition at line 244 of file consumed_registry.hpp.

◆ ConsumedCount() [2/2]

template<typename Alloc>
auto helios::ecs::ConsumedMessagesRegistry< Alloc >::ConsumedCount ( MessageTypeIndex type_index) const
nodiscardconstexprnoexcept

Gets the number of consumed messages for a specific type.

Parameters
type_indexType index to query
Returns
Number of consumed messages for this type

Definition at line 395 of file consumed_registry.hpp.

◆ ConsumedIndicesFor() [1/2]

template<typename Alloc = std::allocator<std::byte>>
template<ConsumableMessageTrait T>
auto helios::ecs::ConsumedMessagesRegistry< Alloc >::ConsumedIndicesFor ( ) const -> std::span< const size_type >
inlinenodiscardconstexprnoexcept

Gets the sorted consumed indices for a specific message type.

Template Parameters
TConsumable message type
Returns
Span of sorted consumed indices, or empty span if none

Definition at line 193 of file consumed_registry.hpp.

◆ ConsumedIndicesFor() [2/2]

template<typename Alloc>
auto helios::ecs::ConsumedMessagesRegistry< Alloc >::ConsumedIndicesFor ( MessageTypeIndex type_index) const -> std::span< const size_type >
nodiscardconstexprnoexcept

Gets the sorted consumed indices for a specific message type.

Parameters
type_indexType index of the message
Returns
Span of sorted consumed indices, or empty span if none

Definition at line 368 of file consumed_registry.hpp.

◆ Data()

template<typename Alloc = std::allocator<std::byte>>
const ConsumedMap & helios::ecs::ConsumedMessagesRegistry< Alloc >::Data ( ) const
inlinenodiscardconstexprnoexcept

Provides direct access to the underlying consumed map.

Returns
Const reference to the consumed map

Definition at line 260 of file consumed_registry.hpp.

◆ Empty()

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

Checks if any message type has consumed entries.

Returns
True if no consumed entries exist, false otherwise

Definition at line 210 of file consumed_registry.hpp.

◆ HasConsumed() [1/2]

template<typename Alloc = std::allocator<std::byte>>
template<ConsumableMessageTrait T>
bool helios::ecs::ConsumedMessagesRegistry< Alloc >::HasConsumed ( ) const
inlinenodiscardconstexprnoexcept

Checks if a specific message type has consumed entries.

Template Parameters
TConsumable message type
Returns
True if consumed entries exist for this type, false otherwise

Definition at line 220 of file consumed_registry.hpp.

◆ HasConsumed() [2/2]

template<typename Alloc>
bool helios::ecs::ConsumedMessagesRegistry< Alloc >::HasConsumed ( MessageTypeIndex type_index) const
nodiscardconstexprnoexcept

Checks if a specific message type has consumed entries.

Parameters
type_indexType index to check
Returns
True if consumed entries exist for this type, false otherwise

Definition at line 378 of file consumed_registry.hpp.

◆ IsConsumed() [1/2]

template<typename Alloc>
bool helios::ecs::ConsumedMessagesRegistry< Alloc >::IsConsumed ( MessageTypeIndex type_index,
size_type global_index ) const
nodiscardconstexprnoexcept

Checks if a specific message is marked as consumed.

Parameters
type_indexType index of the message
global_indexGlobal index of the message
Returns
True if the message is consumed, false otherwise

Definition at line 358 of file consumed_registry.hpp.

◆ IsConsumed() [2/2]

template<typename Alloc = std::allocator<std::byte>>
template<ConsumableMessageTrait T>
bool helios::ecs::ConsumedMessagesRegistry< Alloc >::IsConsumed ( size_type global_index) const
inlinenodiscardconstexprnoexcept

Checks if a specific message is marked as consumed.

Template Parameters
TConsumable message type
Parameters
global_indexGlobal index of the message
Returns
True if the message is consumed, false otherwise

Definition at line 173 of file consumed_registry.hpp.

◆ MarkConsumed() [1/2]

template<typename Alloc>
void helios::ecs::ConsumedMessagesRegistry< Alloc >::MarkConsumed ( MessageTypeIndex type_index,
size_type global_index )
constexpr

Marks an message as consumed by its type index and global index.

Parameters
type_indexType index of the message
global_indexIndex of the message in the combined (previous + current) view

Definition at line 288 of file consumed_registry.hpp.

◆ MarkConsumed() [2/2]

template<typename Alloc = std::allocator<std::byte>>
template<ConsumableMessageTrait T>
void helios::ecs::ConsumedMessagesRegistry< Alloc >::MarkConsumed ( size_type global_index)
inlineconstexpr

Marks an message as consumed by its type and global index.

Template Parameters
TConsumable message type
Parameters
global_indexIndex of the message in the combined (previous + current) view

Definition at line 114 of file consumed_registry.hpp.

◆ MergeFrom() [1/2]

template<typename Alloc>
template<typename OtherAlloc>
void helios::ecs::ConsumedMessagesRegistry< Alloc >::MergeFrom ( const ConsumedMessagesRegistry< OtherAlloc > & other)
constexpr

Merges consumed entries from another registry into this one.

Performs a sorted union of consumed indices for each type. Avoids additional heap allocation by appending and using in-place merge.

Template Parameters
OtherAllocAllocator type of the source registry
Parameters
otherRegistry to merge from

Definition at line 300 of file consumed_registry.hpp.

◆ MergeFrom() [2/2]

template<typename Alloc>
template<typename OtherAlloc>
void helios::ecs::ConsumedMessagesRegistry< Alloc >::MergeFrom ( ConsumedMessagesRegistry< OtherAlloc > && other)
constexpr

Merges consumed entries from another registry into this one.

Rvalue overload that consumes the source registry.

Template Parameters
OtherAllocAllocator type of the source registry
Parameters
otherRegistry to merge from

Definition at line 330 of file consumed_registry.hpp.

◆ operator=() [1/2]

template<typename Alloc = std::allocator<std::byte>>
ConsumedMessagesRegistry & helios::ecs::ConsumedMessagesRegistry< Alloc >::operator= ( const ConsumedMessagesRegistry< Alloc > & )
default

◆ operator=() [2/2]

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

◆ TotalConsumedCount()

template<typename Alloc>
auto helios::ecs::ConsumedMessagesRegistry< Alloc >::TotalConsumedCount ( ) const
nodiscardconstexprnoexcept

Gets the total number of consumed messages across all types.

Returns
Total consumed message count

Definition at line 385 of file consumed_registry.hpp.