Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
example.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <string_view>
9
10namespace helios::example {
11
12/**
13 * @brief Example component to demonstrate module components.
14 */
16 int value = 0;
17};
18
19/**
20 * @brief Example resource to demonstrate module resources.
21 */
23 int counter = 0;
24
25 /**
26 * @brief Returns the name of the resource.
27 * @return Resource name.
28 */
29 static constexpr std::string_view GetName() noexcept { return "ExampleResource"; }
30};
31
32/**
33 * @brief Example system that increments the counter in ExampleResource.
34 *
35 * This system demonstrates how to create a system that operates on resources.
36 */
37struct ExampleSystem final : public ecs::System {
38 /**
39 * @brief Returns the name of the system.
40 * @return System name.
41 */
42 static constexpr std::string_view GetName() noexcept { return "ExampleSystem"; }
43
44 /**
45 * @brief Returns the access policy for this system.
46 * @return Access policy declaring resource writes.
47 */
48 static constexpr auto GetAccessPolicy() noexcept { return app::AccessPolicy().WriteResources<ExampleResource>(); }
49
50 /**
51 * @brief Updates the system, incrementing the example resource counter.
52 * @param ctx The system context providing access to resources.
53 */
54 void Update(app::SystemContext& ctx) override;
55};
56
57/**
58 * @brief Example module that demonstrates module structure.
59 *
60 * This module can be added to an App to demonstrate the module system.
61 * It registers the ExampleResource and ExampleSystem.
62 *
63 * @example
64 * @code
65 * helios::app::App app;
66 * app.AddModule<helios::example::ExampleModule>();
67 * @endcode
68 */
69struct ExampleModule final : public app::Module {
70 /**
71 * @brief Returns the name of the module.
72 * @return Module name.
73 */
74 static constexpr std::string_view GetName() noexcept { return "Example"; }
75
76 /**
77 * @brief Builds the module, adding resources and systems to the app.
78 * @param app The application to configure.
79 */
80 void Build(app::App& app) override;
81
82 /**
83 * @brief Destroys the module, performing cleanup.
84 * @param app The application to clean up.
85 */
86 void Destroy(app::App& app) override;
87};
88
89} // namespace helios::example
constexpr auto WriteResources(this auto &&self) -> decltype(std::forward< decltype(self)>(self))
Declares write access to resource types.
Application class.
Definition app.hpp:97
Base class for all modules.
Definition module.hpp:25
Per-system execution context with validated access.
Example component to demonstrate module components.
Definition example.hpp:15
static constexpr std::string_view GetName() noexcept
Returns the name of the module.
Definition example.hpp:74
void Build(app::App &app) override
Builds the module, adding resources and systems to the app.
Definition example.cpp:13
void Destroy(app::App &app) override
Destroys the module, performing cleanup.
Definition example.cpp:18
Example resource to demonstrate module resources.
Definition example.hpp:22
static constexpr std::string_view GetName() noexcept
Returns the name of the resource.
Definition example.hpp:29
Example system that increments the counter in ExampleResource.
Definition example.hpp:37
static constexpr std::string_view GetName() noexcept
Returns the name of the system.
Definition example.hpp:42
static constexpr auto GetAccessPolicy() noexcept
Returns the access policy for this system.
Definition example.hpp:48
void Update(app::SystemContext &ctx) override
Updates the system, incrementing the example resource counter.
Definition example.cpp:8