Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
builtin_events.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <helios/core_pch.hpp>
4
7
8#include <cstdint>
9#include <string_view>
10
11namespace helios::ecs {
12
13/**
14 * @brief Event emitted when an entity is spawned/created.
15 * @details This event is automatically emitted by World::CreateEntity() and World::ReserveEntity()
16 * if the event is registered via AddEvent<EntitySpawnedEvent>().
17 * @note Must be trivially copyable for event storage requirements.
18 */
20 Entity entity; ///< The spawned entity
21
22 /**
23 * @brief Gets the event name.
24 * @return Event name string
25 */
26 static constexpr std::string_view GetName() noexcept { return "EntitySpawnedEvent"; }
27
28 /**
29 * @brief Gets the clear policy for this event.
30 * @return Event clear policy (automatic)
31 */
33};
34
35/**
36 * @brief Event emitted when an entity is destroyed.
37 * @details This event is automatically emitted by World::DestroyEntity() and related methods
38 * if the event is registered via AddEvent<EntityDestroyedEvent>().
39 * @note Must be trivially copyable for event storage requirements.
40 */
42 Entity entity; ///< The destroyed entity
43
44 /**
45 * @brief Gets the event name.
46 * @return Event name string
47 */
48 static constexpr std::string_view GetName() noexcept { return "EntityDestroyedEvent"; }
49
50 /**
51 * @brief Gets the clear policy for this event.
52 * @return Event clear policy (automatic)
53 */
55};
56
57/**
58 * @brief Exit code for application shutdown.
59 */
61 Success = 0, ///< Normal shutdown
62 Failure = 1, ///< Shutdown due to error
63};
64
65/**
66 * @brief Event emitted to request application shutdown.
67 * @details This event is read by the default runner to gracefully stop the application loop.
68 * Systems can emit this event to request shutdown with an optional exit code.
69 * @note Must be trivially copyable for event storage requirements.
70 *
71 * @example
72 * @code
73 * void QuitSystem(SystemContext& ctx) {
74 * const auto& input = ctx.ReadResource<Input>();
75 * if (input.IsKeyPressed(Key::Escape)) {
76 * ctx.EmitEvent(ShutdownEvent{});
77 * }
78 * }
79 * @endcode
80 */
82 ShutdownExitCode exit_code = ShutdownExitCode::Success; ///< Exit code for the shutdown
83
84 /**
85 * @brief Gets the event name.
86 * @return Event name string
87 */
88 static constexpr std::string_view GetName() noexcept { return "ShutdownEvent"; }
89
90 /**
91 * @brief Gets the clear policy for this event.
92 * @details Uses manual clear policy since shutdown should persist until processed.
93 * @return Event clear policy (manual)
94 */
96};
97
98// Static assertions to ensure events meet requirements
101static_assert(EventTrait<ShutdownEvent>);
102
103} // namespace helios::ecs
Unique identifier for entities with generation counter to handle recycling.
Definition entity.hpp:21
EventClearPolicy
Policy for event clearing behavior.
Definition event.hpp:23
@ kAutomatic
Events are automatically cleared after double buffer cycle.
@ kManual
Events persist until manually cleared via ManualClear()
ShutdownExitCode
Exit code for application shutdown.
@ Failure
Shutdown due to error.
BasicQuery< World, Allocator, Components... > Query
Type alias for query with mutable world access.
Definition query.hpp:2481
Event emitted when an entity is destroyed.
static constexpr std::string_view GetName() noexcept
Gets the event name.
static constexpr EventClearPolicy GetClearPolicy() noexcept
Gets the clear policy for this event.
Entity entity
The destroyed entity.
Event emitted when an entity is spawned/created.
Entity entity
The spawned entity.
static constexpr std::string_view GetName() noexcept
Gets the event name.
static constexpr EventClearPolicy GetClearPolicy() noexcept
Gets the clear policy for this event.
static constexpr std::string_view GetName() noexcept
Gets the event name.
static constexpr EventClearPolicy GetClearPolicy() noexcept
Gets the clear policy for this event.
ShutdownExitCode exit_code
Exit code for the shutdown.