3#include <vulkan/vulkan.hpp>
9#include "SD/export.hpp"
26 other.m_arena =
nullptr;
27 other.m_layers.clear();
33 m_arena =
other.m_arena;
34 m_layers =
other.m_layers;
35 other.m_arena =
nullptr;
36 other.m_layers.clear();
49 template<
typename T,
typename...
Args>
50 requires std::is_base_of_v<Layer, T>
52 T* data = m_arena->push_array<T>(1);
53 if constexpr (!std::is_trivially_constructible_v<T,
Args...>)
54 new (data) T(std::forward<Args>(
args)...);
59 node.is_active = data->is_active;
60 node.debug_name = data->debug_name;
61 node.scene = data->scene;
63 node.stage_id = data->stage_id;
64 node.view_id = data->view_id;
65 node.view = data->view;
69 m_layers.push(m_arena,
node);
74 template<
typename T,
typename...
Args>
75 requires std::is_base_of_v<Layer, T>
77 T* data = m_arena->push_array<T>(1);
78 if constexpr (!std::is_trivially_constructible_v<T,
Args...>)
79 new (data) T(std::forward<Args>(
args)...);
84 node.is_active = data->is_active;
85 node.debug_name = data->debug_name;
86 node.scene = data->scene;
88 node.stage_id = data->stage_id;
89 node.view_id = data->view_id;
90 node.view = data->view;
94 m_layers.push(m_arena,
node);
100 requires std::is_base_of_v<Layer, T>
103 for (
U64 i = 0;
i < m_layers.count; ++
i) {
104 if (m_layers[
i].type_id ==
tid)
105 return static_cast<T*
>(m_layers[
i].data);
111 requires std::is_base_of_v<Layer, T>
114 for (
I64 i =
static_cast<I64>(m_layers.count) - 1;
i >= 0; --
i) {
115 if (m_layers[
i].type_id ==
tid) {
116 m_layers[
i].on_detach();
117 T*
result =
static_cast<T*
>(m_layers[
i].data);
118 for (
U64 j =
static_cast<U64>(
i);
j < m_layers.count - 1; ++
j)
119 m_layers[
j] = m_layers[
j + 1];
128 for (
I64 i =
static_cast<I64>(m_layers.count) - 1;
i >= 0; --
i) {
129 m_layers[
i].on_detach();
130 if (m_layers[
i].destroy_fn)
131 m_layers[
i].destroy_fn(m_layers[
i].data);
139 for (
U64 i = 0;
i < m_layers.count; ++
i) {
140 if (m_layers[
i].is_active)
141 m_layers[
i].on_update(
dt);
146 for (
U64 i = 0;
i < m_layers.count; ++
i) {
147 if (m_layers[
i].is_active)
148 m_layers[
i].on_fixed_update(
dt);
153 for (
U64 i = 0;
i < m_layers.count; ++
i) {
154 if (m_layers[
i].is_active)
155 m_layers[
i].on_gui_render();
160 for (
U64 i = 0;
i < m_layers.count; ++
i) {
161 if (m_layers[
i].is_active)
162 m_layers[
i].on_im_gui_menu_bar();
167 for (
I64 i =
static_cast<I64>(m_layers.count) - 1;
i >= 0; --
i) {
168 if (m_layers[
i].is_active) {
169 m_layers[
i].on_event(
e);
177 for (
U64 i = 0;
i < m_layers.count; ++
i) {
178 if (m_layers[
i].is_active)
179 m_layers[
i].on_swapchain_recreated();
184 for (
U64 i = 0;
i < m_layers.count; ++
i) {
185 if (m_layers[
i].is_active)
186 m_layers[
i].on_shader_reload();
191 for (
U64 i = 0;
i < m_layers.count; ++
i) {
192 if (m_layers[
i].is_active)
193 m_layers[
i].on_render(
cmd);
202 if constexpr (!std::is_trivially_destructible_v<T>)
203 node.destroy_fn = [](
void*
d) {
204 static_cast<T*
>(
d)->~T();
208 static_cast<T*
>(
d)->on_event(
e);
210 if constexpr (
requires(T&
t,
float dt) {
t.on_update(
dt); })
211 node.on_update_fn = [](
void*
d,
float dt) {
212 static_cast<T*
>(
d)->on_update(
dt);
214 if constexpr (
requires(T&
t,
double dt) {
t.on_fixed_update(
dt); })
215 node.on_fixed_update_fn = [](
void*
d,
double dt) {
216 static_cast<T*
>(
d)->on_fixed_update(
dt);
218 if constexpr (
requires(T&
t, vk::CommandBuffer
cmd) {
t.on_render(
cmd); })
219 node.on_render_fn = [](
void*
d, vk::CommandBuffer
cmd) {
220 static_cast<T*
>(
d)->on_render(
cmd);
222 if constexpr (
requires(T&
t) {
t.on_gui_render(); })
223 node.on_gui_render_fn = [](
void*
d) {
224 static_cast<T*
>(
d)->on_gui_render();
226 if constexpr (
requires(T&
t) {
t.on_im_gui_menu_bar(); })
227 node.on_im_gui_menu_bar_fn = [](
void*
d) {
228 static_cast<T*
>(
d)->on_im_gui_menu_bar();
230 if constexpr (
requires(T&
t) {
t.on_attach(); })
231 node.on_attach_fn = [](
void*
d) {
232 static_cast<T*
>(
d)->on_attach();
234 if constexpr (
requires(T&
t) {
t.on_detach(); })
235 node.on_detach_fn = [](
void*
d) {
236 static_cast<T*
>(
d)->on_detach();
238 if constexpr (
requires(T&
t) {
t.on_activate(); })
239 node.on_activate_fn = [](
void*
d) {
240 static_cast<T*
>(
d)->on_activate();
242 if constexpr (
requires(T&
t) {
t.on_deactivate(); })
243 node.on_deactivate_fn = [](
void*
d) {
244 static_cast<T*
>(
d)->on_deactivate();
246 if constexpr (
requires(T&
t) {
t.on_swapchain_recreated(); })
247 node.on_swapchain_recreated_fn = [](
void*
d) {
248 static_cast<T*
>(
d)->on_swapchain_recreated();
250 if constexpr (
requires(T&
t) {
t.on_shader_reload(); })
251 node.on_shader_reload_fn = [](
void*
d) {
252 static_cast<T*
>(
d)->on_shader_reload();
SD_EXPORT Arena * arena_alloc(ArenaParams params={})
Definition arena.cpp:91
consteval U64 kb(U64 n)
Definition arena.hpp:16
SD_EXPORT void arena_release(Arena *arena)
Definition arena.cpp:142
Definition Application.hpp:22
U64 reserve_size
Definition arena.hpp:69
Definition arena_vec.hpp:6
Definition EventVariant.hpp:19
Definition LayerList.hpp:15
void on_swapchain_recreated() const
Definition LayerList.hpp:176
LayerList(LayerList &&other) noexcept
Definition LayerList.hpp:25
void on_fixed_update(double dt) const
Definition LayerList.hpp:145
iterator begin()
Definition LayerList.hpp:44
iterator end()
Definition LayerList.hpp:45
LayerList & operator=(const LayerList &)=delete
void update(float dt) const
Definition LayerList.hpp:138
void on_event(EventVariant &e)
Definition LayerList.hpp:166
T & push_layer(Args &&... args)
Definition LayerList.hpp:51
T * pop_layer()
Definition LayerList.hpp:112
T * Get()
Definition LayerList.hpp:101
LayerList(const LayerList &)=delete
void gui_render() const
Definition LayerList.hpp:152
LayerList & operator=(LayerList &&other) noexcept
Definition LayerList.hpp:29
LayerList()
Definition LayerList.hpp:16
void on_shader_reload() const
Definition LayerList.hpp:183
void on_imGui_menu_bar() const
Definition LayerList.hpp:159
ArenaVec< LayerNode > m_layers
Definition LayerList.hpp:257
T & push_bottom(Args &&... args)
Definition LayerList.hpp:76
void on_render(vk::CommandBuffer cmd) const
Definition LayerList.hpp:190
U64 size() const
Definition LayerList.hpp:197
static void setup_fn_ptrs(LayerNode &node)
Definition LayerList.hpp:201
const_iterator begin() const
Definition LayerList.hpp:46
const_iterator end() const
Definition LayerList.hpp:47
~LayerList()
Definition LayerList.hpp:19
void clear()
Definition LayerList.hpp:127
Definition LayerNode.hpp:15
void * data
Definition LayerNode.hpp:16
consteval U64 type_id_of()
Definition type_id.hpp:6
std::uint64_t U64
Definition types.hpp:16
std::int64_t I64
Definition types.hpp:11