TypeIndexedDoubleBuffer Class Template
Central hub for publishing and consuming typed messages. More...
Declaration
Public Constructors Index
template <typename Indexer> | |
| TypeIndexedDoubleBuffer ()=default | |
|
Default constructor. More... | |
Public Destructor Index
template <typename Indexer> | |
| ~TypeIndexedDoubleBuffer ()=default | |
|
Default destructor. More... | |
Public Member Functions Index
template <typename T, typename... Args> | |
| void | push (Args &&... args) |
|
Pushes a message of type T to the write buffer. More... | |
template <typename T> | |
| auto | read () const noexcept -> std::span< const T > |
|
Returns a read-only view of all messages of type T. More... | |
template <typename T> | |
| void | reserve (size_t size) |
|
Pre-allocates capacity for messages of type T. More... | |
template <typename T> | |
| auto | getOrCreateBuffer () -> ReadWriteDoubleBuffer< T > & |
|
Gets or creates the buffer for message type T. More... | |
template <typename Indexer> | |
| void | swapBuffers () |
|
Swaps read and write buffers for all message types. More... | |
template <typename Indexer> | |
| void | clearReadBuffers () |
|
Clears all read buffers. More... | |
template <typename Indexer> | |
| void | clearWriteBuffers () |
|
Clears all write buffers without swapping. More... | |
template <typename Indexer> | |
| void | clearAll () |
|
Clears both read and write buffers for all message types. More... | |
template <typename Indexer> | |
| WriteSink | writeSink () noexcept |
template <typename Indexer> | |
| ReadSource | readSource () noexcept |
|
Creates a ReadSource handle for this buffer. More... | |
Private Member Attributes Index
template <typename Indexer> | |
| std::vector< std::unique_ptr< DoubleBuffer > > | buffers_ |
|
Type-erased storage for message buffers, indexed by type. More... | |
Private Static Functions Index
template <typename T> | |
| static size_t | index () |
|
Returns the buffer index for message type T. More... | |
Description
Central hub for publishing and consuming typed messages.
TypeIndexedDoubleBuffer provides a double-buffered, type-indexed message system for decoupled inter-system communication. Systems push messages during their update phase, then at frame boundaries swapBuffers() is called to make those messages available for reading.
Each message type T gets its own dedicated ReadWriteDoubleBuffer, indexed via TypeIndexer for O(1) access. This design enables efficient, allocation-friendly inter-system communication.
Example usage:
- Template Parameters
-
Indexer The TypeIndexer used for mapping message types to buffer indices.
Definition at line 59 of file TypeIndexedDoubleBuffer.ixx.
Public Constructors
TypeIndexedDoubleBuffer()
| default |
Default constructor.
Definition at line 88 of file TypeIndexedDoubleBuffer.ixx.
Public Destructor
~TypeIndexedDoubleBuffer()
| default |
Default destructor.
Definition at line 83 of file TypeIndexedDoubleBuffer.ixx.
Public Member Functions
clearAll()
| inline |
Clears both read and write buffers for all message types.
Completely resets the buffer state, discarding all messages.
Definition at line 207 of file TypeIndexedDoubleBuffer.ixx.
References helios::engine::core::container::buffer::TypeIndexedDoubleBuffer< Indexer >::clearReadBuffers and helios::engine::core::container::buffer::TypeIndexedDoubleBuffer< Indexer >::clearWriteBuffers.
Referenced by helios::engine::runtime::gameloop::GameLoop::phaseCommit.
clearReadBuffers()
| inline |
Clears all read buffers.
Typically not needed as swapBuffers() clears read buffers automatically.
Definition at line 180 of file TypeIndexedDoubleBuffer.ixx.
Referenced by helios::engine::core::container::buffer::TypeIndexedDoubleBuffer< Indexer >::clearAll.
clearWriteBuffers()
| inline |
Clears all write buffers without swapping.
Use to discard messages that were pushed but should not be processed.
Definition at line 193 of file TypeIndexedDoubleBuffer.ixx.
Referenced by helios::engine::core::container::buffer::TypeIndexedDoubleBuffer< Indexer >::clearAll.
getOrCreateBuffer()
| inline |
Gets or creates the buffer for message type T.
- Template Parameters
-
T The message type.
- Returns
Reference to the ReadWriteDoubleBuffer for type T.
Definition at line 147 of file TypeIndexedDoubleBuffer.ixx.
Reference helios::engine::core::registerComponents.
push()
| inline |
Pushes a message of type T to the write buffer.
- Template Parameters
-
T The message type.
Args Constructor argument types for T.
- Parameters
-
args Arguments forwarded to T's constructor.
Definition at line 99 of file TypeIndexedDoubleBuffer.ixx.
Reference helios::engine::core::registerComponents.
read()
| inline noexcept |
Returns a read-only view of all messages of type T.
Returns messages that were written before the last swapBuffers() call. If no messages of type T exist, returns an empty span.
- Template Parameters
-
T The message type to read.
- Returns
A span over all messages of type T in the read buffer.
Definition at line 114 of file TypeIndexedDoubleBuffer.ixx.
References helios::engine::core::container::buffer::TypeIndexedDoubleBuffer< Indexer >::read and helios::engine::core::registerComponents.
Referenced by helios::engine::core::container::buffer::TypeIndexedDoubleBuffer< Indexer >::read.
readSource()
| inline noexcept |
Creates a ReadSource handle for this buffer.
- Returns
A ReadSource that can read messages from this buffer.
Definition at line 308 of file TypeIndexedDoubleBuffer.ixx.
reserve()
| inline |
Pre-allocates capacity for messages of type T.
Call during initialization to avoid allocations during gameplay.
- Template Parameters
-
T The message type.
- Parameters
-
size The number of messages to reserve capacity for.
Definition at line 135 of file TypeIndexedDoubleBuffer.ixx.
Reference helios::engine::core::registerComponents.
swapBuffers()
| inline |
Swaps read and write buffers for all message types.
Call once per frame at a consistent point (e.g., end of update phase). After this call, messages pushed in the current frame become readable.
Definition at line 167 of file TypeIndexedDoubleBuffer.ixx.
Referenced by helios::engine::runtime::gameloop::GameLoop::onPassCommit, helios::engine::runtime::gameloop::GameLoop::phaseCommit and helios::engine::runtime::gameloop::GameLoop::update.
writeSink()
| inline noexcept |
Private Member Attributes
buffers_
|
Type-erased storage for message buffers, indexed by type.
Definition at line 64 of file TypeIndexedDoubleBuffer.ixx.
Private Static Functions
index()
| inline static |
Returns the buffer index for message type T.
- Template Parameters
-
T The message type.
- Returns
The index assigned to type T by the Indexer.
Definition at line 74 of file TypeIndexedDoubleBuffer.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.