SDEngine
Game Engine
Loading...
Searching...
No Matches
Layer.hpp
Go to the documentation of this file.
1// TODO(docs): Add file-level Doxygen header
2// - @file Layer.hpp
3// - @brief Layer system architecture - the core abstraction for engine functionality
4// - Explain the three layer subtypes: System, RenderStage, Panel
5// - Layer lifecycle and event flow
6// - When to use each subtype
7#pragma once
8
9#include <vulkan/vulkan.hpp>
10
11#include "SD/core/id_types.hpp"
12#include "SD/export.hpp"
13#include "Scene.hpp"
14#include "events/Event.hpp"
15
16namespace sd {
17class View;
18class Layer;
19template<typename T> concept IsLayer = std::is_base_of_v<Layer, T>;
20
21// TODO(docs): Document Layer base class
22// - Purpose: Base abstraction for all game/engine functionality
23// - Virtual methods and when to override each
24// - mActive flag usage
25// - Scene association
26// - Example custom layer implementation
29public:
30 virtual ~Layer() = default;
31
32 explicit Layer(const std::string& name = "Layer", Scene* scene = nullptr) :
33 m_debug_name(name), m_scene(scene), m_stage_id(0), m_view_id{} {}
34
35 virtual void on_attach() {}
36 virtual void on_detach() {}
37
38 virtual void on_activate() {}
39 virtual void on_deactivate() {}
40
41 virtual void on_swapchain_recreated() {}
42
43 const std::string& get_name() const { return m_debug_name; }
44
45 void set_scene(Scene* scene) { m_scene = scene; }
46 [[nodiscard]] Scene* get_scene() const { return m_scene; }
47
48 virtual void on_event(Event&) {}
49 virtual void on_fixed_update([[maybe_unused]] double fixedDelta) {}
50 virtual void on_update([[maybe_unused]] float dt) { (void)dt; }
51 virtual void on_render([[maybe_unused]] vk::CommandBuffer cmd) {}
52 virtual void on_gui_render() {}
53 virtual void on_im_gui_menu_bar() {}
54
55 [[nodiscard]] bool is_active() const noexcept { return m_is_active; }
56
57protected:
58 bool m_is_active = true;
59 std::string m_debug_name;
60 Scene* m_scene = nullptr;
63 View* m_view = nullptr;
64
65 friend class View;
66};
67
68// ---------------------------------------------------------------------------
69// Focused layer subtypes — use these instead of raw Layer
70// ---------------------------------------------------------------------------
71
73class SD_EXPORT System : public Layer {
74public:
75 using Layer::Layer;
76
77 // --- Available for override ---
78 // OnEvent, OnUpdate, OnFixedUpdate, OnAttach, OnDetach
79
80 // --- Sealed (not for Systems) ---
81 void on_render(vk::CommandBuffer) final {}
85};
86
88class SD_EXPORT RenderStage : public Layer {
89public:
90 using Layer::Layer;
91
92 // --- Available for override ---
93 // OnRender, OnSwapchainRecreated, OnAttach, OnDetach
94
95 // --- Sealed (not for RenderStages) ---
96 void on_update(float) final {}
97 void on_fixed_update(double) final {}
100};
101
103class SD_EXPORT Panel : public Layer {
104public:
105 using Layer::Layer;
106
107 // --- Available for override ---
108 // OnGuiRender, OnImGuiMenuBar, OnUpdate, OnEvent, OnAttach, OnDetach
109
110 // --- Sealed (not for Panels) ---
111 void on_render(vk::CommandBuffer) final {}
113};
114
115} // namespace sd
Definition Event.hpp:56
Base class for all layers. Prefer using System, RenderStage, or Panel instead.
Definition Layer.hpp:28
virtual void on_event(Event &)
Definition Layer.hpp:48
virtual void on_im_gui_menu_bar()
Definition Layer.hpp:53
ViewId m_view_id
Definition Layer.hpp:62
int m_stage_id
Definition Layer.hpp:61
Layer(const std::string &name="Layer", Scene *scene=nullptr)
Definition Layer.hpp:32
virtual void on_fixed_update(double fixedDelta)
Definition Layer.hpp:49
const std::string & get_name() const
Definition Layer.hpp:43
bool is_active() const noexcept
Definition Layer.hpp:55
virtual void on_activate()
Definition Layer.hpp:38
virtual ~Layer()=default
virtual void on_update(float dt)
Definition Layer.hpp:50
std::string m_debug_name
Definition Layer.hpp:59
virtual void on_deactivate()
Definition Layer.hpp:39
virtual void on_render(vk::CommandBuffer cmd)
Definition Layer.hpp:51
virtual void on_attach()
Definition Layer.hpp:35
void set_scene(Scene *scene)
Definition Layer.hpp:45
Scene * get_scene() const
Definition Layer.hpp:46
virtual void on_swapchain_recreated()
Definition Layer.hpp:41
virtual void on_detach()
Definition Layer.hpp:36
virtual void on_gui_render()
Definition Layer.hpp:52
ImGui UI layer: panels, inspectors, debug tools. No GPU rendering.
Definition Layer.hpp:103
void on_swapchain_recreated() final
Definition Layer.hpp:112
void on_render(vk::CommandBuffer) final
Definition Layer.hpp:111
GPU command recording layer: bound to a View + render stage. No logic or UI.
Definition Layer.hpp:88
void on_gui_render() final
Definition Layer.hpp:98
void on_update(float) final
Definition Layer.hpp:96
void on_fixed_update(double) final
Definition Layer.hpp:97
void on_im_gui_menu_bar() final
Definition Layer.hpp:99
Definition Scene.hpp:18
Logic-only layer: events, update, fixed update. No rendering or UI.
Definition Layer.hpp:73
void on_render(vk::CommandBuffer) final
Definition Layer.hpp:81
void on_swapchain_recreated() final
Definition Layer.hpp:84
void on_gui_render() final
Definition Layer.hpp:82
void on_im_gui_menu_bar() final
Definition Layer.hpp:83
Definition View.hpp:54
Definition Layer.hpp:19
Definition Application.hpp:28
Definition id_types.hpp:7
constexpr T g_type_max
Definition types.hpp:21