stellarlib 0.1.0
Loading...
Searching...
No Matches
context.hpp
1/* clang-format off */
2
3/*
4 stellarlib
5 Copyright (C) 2025-2026 Domán Zana
6
7 This software is provided 'as-is', without any express or implied
8 warranty. In no event will the authors be held liable for any damages
9 arising from the use of this software.
10
11 Permission is granted to anyone to use this software for any purpose,
12 including commercial applications, and to alter it and redistribute it
13 freely, subject to the following restrictions:
14
15 1. The origin of this software must not be misrepresented; you must not
16 claim that you wrote the original software. If you use this software
17 in a product, an acknowledgment in the product documentation would be
18 appreciated but is not required.
19 2. Altered source versions must be plainly marked as such, and must not be
20 misrepresented as being the original software.
21 3. This notice may not be removed or altered from any source distribution.
22*/
23
24#ifndef STELLARLIB_APP_CONTEXT_HPP
25#define STELLARLIB_APP_CONTEXT_HPP
26
27#include <stellarlib/app/clock.hpp>
28#include <stellarlib/app/lifecycle.hpp>
29#include <stellarlib/app/metadata.hpp>
30#include <stellarlib/app/scene.hpp>
31#include <stellarlib/app/window.hpp>
32#include <stellarlib/ecs/ecs.hpp>
33
34#include <SDL3/SDL_events.h>
35#include <SDL3/SDL_init.h>
36
37#include <cstdint>
38#include <functional>
39#include <memory>
40#include <variant>
41
42/**
43 * @brief Application runtime
44 */
45namespace stellarlib::app
46{
47/**
48 * @brief Application context
49 */
50class context final
51{
52friend internal::lifecycle<class host>;
53
54public:
55 /**
56 * @brief Context initialization descriptor
57 */
58 struct info final
59 {
60 /**
61 * @brief Metadata initialization descriptor
62 */
64
65 /**
66 * @brief Clock initialization descriptor
67 */
69
70 /**
71 * @brief Window initialization descriptor
72 */
74
75 /**
76 * @brief Explicit padding
77 */
78 std::uint64_t padding;
79
80 /**
81 * @brief Initial scene, application termination, or deferred scene factory
82 */
83 std::variant<std::unique_ptr<scene>, std::function<std::unique_ptr<scene> (context &)>> entry;
84 };
85
86 /**
87 * @brief Deleted copy constructor
88 */
89 [[nodiscard]]
90 constexpr context(const context &) noexcept = delete;
91
92 /**
93 * @brief Deleted move constructor
94 */
95 [[nodiscard]]
96 constexpr context(context &&) noexcept = delete;
97
98 /**
99 * @brief Deleted copy assignment operator
100 */
101 constexpr auto operator=(const context &) noexcept
102 -> context & = delete;
103
104 /**
105 * @brief Deleted move assignment operator
106 */
107 constexpr auto operator=(context &&) noexcept
108 -> context & = delete;
109
110 /**
111 * @brief Destructor
112 */
114
115 /**
116 * @brief Returns a reference to the metadata subsystem
117 * @return Reference to the metadata subsystem
118 */
119 [[nodiscard]]
120 auto metadata() const
121 -> const app::metadata &;
122
123 /**
124 * @brief Returns a reference to the metadata subsystem
125 * @return Reference to the metadata subsystem
126 */
127 [[nodiscard]]
128 auto metadata()
129 -> app::metadata &;
130
131 /**
132 * @brief Returns a reference to the clock subsystem
133 * @return Reference to the clock subsystem
134 */
135 [[nodiscard]]
136 auto clock() const
137 -> const app::clock &;
138
139 /**
140 * @brief Returns a reference to the clock subsystem
141 * @return Reference to the clock subsystem
142 */
143 [[nodiscard]]
144 auto clock()
145 -> app::clock &;
146
147 /**
148 * @brief Returns a reference to the window subsystem
149 * @return Reference to the window subsystem
150 */
151 [[nodiscard]]
152 auto window() const
153 -> const app::window &;
154
155 /**
156 * @brief Returns a reference to the window subsystem
157 * @return Reference to the window subsystem
158 */
159 [[nodiscard]]
160 auto window()
161 -> app::window &;
162
163 /**
164 * @brief Returns a reference to the ECS subsystem
165 * @return Reference to the ECS subsystem
166 */
167 [[nodiscard]]
168 auto world() const
169 -> const ecs::world &;
170
171 /**
172 * @brief Returns a reference to the ECS subsystem
173 * @return Reference to the ECS subsystem
174 */
175 [[nodiscard]]
176 auto world()
177 -> ecs::world &;
178
179private:
180 [[no_unique_address]] app::metadata _metadata;
181 app::clock _clock;
182 std::uint32_t _padding1;
183 app::window _window;
184 ecs::world _world;
185 std::unique_ptr<scene> _scene;
186 std::uint64_t _padding2;
187
188 [[nodiscard]]
189 explicit context(info info);
190
191 [[nodiscard]]
192 auto iterate()
193 -> SDL_AppResult;
194
195 [[nodiscard]]
196 auto event(const SDL_Event &event) const
197 -> SDL_AppResult;
198};
199}
200
201#endif
auto window() const -> const app::window &
Returns a reference to the window subsystem.
auto world() const -> const ecs::world &
Returns a reference to the ECS subsystem.
auto clock() const -> const app::clock &
Returns a reference to the clock subsystem.
auto metadata() const -> const app::metadata &
Returns a reference to the metadata subsystem.
constexpr context(context &&) noexcept=delete
Deleted move constructor.
constexpr context(const context &) noexcept=delete
Deleted copy constructor.
Application scene interface.
Definition scene.hpp:39
Application runtime.
Definition clock.hpp:33
Entity component system.
Definition any_set.hpp:28
Clock initialization descriptor.
Definition clock.hpp:46
Context initialization descriptor.
Definition context.hpp:59
std::variant< std::unique_ptr< scene >, std::function< std::unique_ptr< scene >(context &)> > entry
Initial scene, application termination, or deferred scene factory.
Definition context.hpp:83
app::metadata::info metadata
Metadata initialization descriptor.
Definition context.hpp:63
app::clock::info clock
Clock initialization descriptor.
Definition context.hpp:68
app::window::info window
Window initialization descriptor.
Definition context.hpp:73
std::uint64_t padding
Explicit padding.
Definition context.hpp:78
Metadata initialization descriptor.
Definition metadata.hpp:48
Window initialization descriptor.
Definition window.hpp:52