Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
command_buffer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <helios/core_pch.hpp>
4
9
10#include <concepts>
11#include <memory>
12#include <utility>
13
14namespace helios::ecs::details {
15
16/**
17 * @brief Command buffer to record operations to be executed later.
18 * @details All operations are recorded to system local storage and executed
19 * in the order they were recorded when World::Update() is called.
20 * @note Command buffer is not thread-safe but doesn't need to be since each system has its own local storage.
21 */
22class CmdBuffer {
23public:
24 explicit CmdBuffer(SystemLocalStorage& local_storage) noexcept : local_storage_(local_storage) {}
25 CmdBuffer(const CmdBuffer&) = delete;
26 CmdBuffer(CmdBuffer&&) = delete;
28
31
32 /**
33 * @brief Pushes a pre-constructed command to the buffer.
34 * @param command Unique pointer to command
35 */
36 void Push(std::unique_ptr<Command> command);
37
38 /**
39 * @brief Constructs and pushes a command to the buffer.
40 * @tparam T Command type
41 * @tparam Args Constructor argument types
42 * @param args Arguments to forward to command constructor
43 */
44 template <CommandTrait T, typename... Args>
46 void Emplace(Args&&... args) {
47 local_storage_.EmplaceCommand<T>(std::forward<Args>(args)...);
48 }
49
50private:
51 SystemLocalStorage& local_storage_;
52};
53
54inline void CmdBuffer::Push(std::unique_ptr<Command> command) {
55 HELIOS_ASSERT(command != nullptr, "Failed to push command to command buffer: command is nullptr!");
56 local_storage_.AddCommand(std::move(command));
57}
58
59} // namespace helios::ecs::details
#define HELIOS_ASSERT(condition,...)
Assertion macro that aborts execution in debug builds.
Definition assert.hpp:140
Base class for all commands to be executed in the world.
Definition command.hpp:12
Command buffer to record operations to be executed later.
void Push(std::unique_ptr< Command > command)
Pushes a pre-constructed command to the buffer.
CmdBuffer(SystemLocalStorage &local_storage) noexcept
CmdBuffer(const CmdBuffer &)=delete
CmdBuffer(CmdBuffer &&)=delete
~CmdBuffer() noexcept=default
void Emplace(Args &&... args)
Constructs and pushes a command to the buffer.
Local storage for system-specific data (commands, events, and temporary allocations).
void EmplaceCommand(Args &&... args)
Adds a command to the local command buffer.
void AddCommand(std::unique_ptr< Command > command)
Adds a pre-constructed command to the local buffer.
BasicQuery< World, Allocator, Components... > Query
Type alias for query with mutable world access.
Definition query.hpp:2481
STL namespace.