stellarlib 0.1.0
Loading...
Searching...
No Matches
scene.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_SCENE_HPP
25#define STELLARLIB_APP_SCENE_HPP
26
27#include <memory>
28#include <optional>
29
30/**
31 * @brief Application runtime
32 */
33namespace stellarlib::app
34{
35/**
36 * @brief Application scene interface
37 */
38class scene
39{
40friend class context;
41
42public:
43 /**
44 * @brief Destructor
45 */
46 virtual ~scene() noexcept = 0;
47
48protected:
49 /**
50 * @brief Default constructor
51 */
52 [[nodiscard]]
53 scene() noexcept;
54
55 /**
56 * @brief Copy constructor
57 * @param other Other instance
58 */
59 [[nodiscard]]
60 scene(const scene &other) noexcept;
61
62 /**
63 * @brief Move constructor
64 * @param other Other instance
65 */
66 [[nodiscard]]
67 scene(scene &&other) noexcept;
68
69 /**
70 * @brief Copy assignment operator
71 * @param other Other instance
72 * @return Current instance
73 */
74 auto operator=(const scene &other) noexcept
75 -> scene &;
76
77 /**
78 * @brief Move assignment operator
79 * @param other Other instance
80 * @return Current instance
81 */
82 auto operator=(scene &&other) noexcept
83 -> scene &;
84
85 /**
86 * @brief Called after the previous scene has finished deactivation and before the first update
87 * @param ctx Global application context
88 */
89 virtual void begin(class context &ctx);
90
91 /**
92 * @brief Called once per frame
93 * @param ctx Global application context
94 * @return std::nullopt to continue execution, a scene instance to request a transition or nullptr to terminate the application
95 */
96 [[nodiscard]]
97 virtual constexpr auto update(class context &ctx)
98 -> std::optional<std::unique_ptr<scene>> = 0;
99
100 /**
101 * @brief Called after the last update and before the next scene begins activation
102 * @param ctx Global application context
103 */
104 virtual void end(class context &ctx);
105};
106}
107
108#endif
virtual ~scene() noexcept=0
Destructor.
virtual constexpr auto update(class context &ctx) -> std::optional< std::unique_ptr< scene > >=0
Called once per frame.
virtual void end(class context &ctx)
Called after the last update and before the next scene begins activation.
virtual void begin(class context &ctx)
Called after the previous scene has finished deactivation and before the first update.
scene() noexcept
Default constructor.
Application runtime.
Definition clock.hpp:33