ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
Loading...
Searching...
No Matches
Imago::ECS::CommandBuffer Class Reference

Queues structural changes to apply all at once when there is no iteration going on. More...

#include <Imago/ECS/CommandBuffer.hpp>

Public Member Functions

 CommandBuffer (Nexus &nexus)
 Construct a new Command Buffer object with the Nexus that it will apply its queued operations to.
void defer_destroy (Entity e)
 Queues an Entity for destruction.
template<typename T>
void defer_bind (Entity e, T component)
 Queues a bind_immediate command lambda.
template<typename T>
void defer_unbind (Entity e)
 Queues an unbind_immediate command lambda.
void flush ()
 Goes through all the defer queues and actually applies the operations to the associated Nexus.

Detailed Description

Queues structural changes to apply all at once when there is no iteration going on.

The Nexus will automatically route structural changes through the CommandBuffer when the user calls them during iteration.

Modyfing containers while iterating through them should generally be avoided and causes undefined behavior. Becuase ImagoECS is contantly iterating over several containers, this becomes a big issue. The CommandBuffer is used for structural changes in component pools (deleting Entity's, modyfing component data) to solve this problem. The CommandBuffer stores all changes in vectors and applies the operations in flush(). It does all binds, all unbinds, and then all destroys. Note that his means and unbind then bind of the same component in one frame leaves the entity without it.

Constructor & Destructor Documentation

◆ CommandBuffer()

Imago::ECS::CommandBuffer::CommandBuffer ( Nexus & nexus)
explicit

Construct a new Command Buffer object with the Nexus that it will apply its queued operations to.

Parameters
nexusThe Nexus this buffer will flush its operations into

Member Function Documentation

◆ defer_bind()

template<typename T>
void Imago::ECS::CommandBuffer::defer_bind ( Entity e,
T component )

Queues a bind_immediate command lambda.

Template Parameters
TThe component type that is being bound
Parameters
eThe entity to bind the component to
componentThe component data

◆ defer_destroy()

void Imago::ECS::CommandBuffer::defer_destroy ( Entity e)

Queues an Entity for destruction.

Parameters
eThe Entity to destroy

◆ defer_unbind()

template<typename T>
void Imago::ECS::CommandBuffer::defer_unbind ( Entity e)

Queues an unbind_immediate command lambda.

Template Parameters
TThe component type that is being unbound
Parameters
eThe entinty whose component of type T is being unbound

The documentation for this class was generated from the following files: