![]() |
ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
|
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. | |
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.
|
explicit |
| void Imago::ECS::CommandBuffer::defer_bind | ( | Entity | e, |
| T | component ) |
Queues a bind_immediate command lambda.
| T | The component type that is being bound |
| e | The entity to bind the component to |
| component | The component data |
| void Imago::ECS::CommandBuffer::defer_destroy | ( | Entity | e | ) |
| void Imago::ECS::CommandBuffer::defer_unbind | ( | Entity | e | ) |
Queues an unbind_immediate command lambda.
| T | The component type that is being unbound |
| e | The entinty whose component of type T is being unbound |