diff --git a/SakuraCore/src/Application.cpp b/SakuraCore/src/Application.cpp index 080547c..b98e89c 100644 --- a/SakuraCore/src/Application.cpp +++ b/SakuraCore/src/Application.cpp @@ -73,8 +73,10 @@ bool Application::Init() { SDL_SetRenderVSync(m_Renderer, 1); - m_ImGuiLayer = new SakuraVNE::ImGuiLayer(); - PushOverlay(m_ImGuiLayer); + // m_ImGuiLayer = new SakuraVNE::ImGuiLayer(); + // PushOverlay(m_ImGuiLayer); + + this->PushOverlay(); return true; } @@ -148,12 +150,3 @@ void Application::Shutdown() { SDL_Quit(); } - -void Application::PushLayer(SakuraVNE::Layer *layer) { - m_LayerStack.PushLayer(layer); - layer->OnAttach(); -} -void Application::PushOverlay(SakuraVNE::Layer *layer) { - m_LayerStack.PushOverLay(layer); - layer->OnAttach(); -} diff --git a/SakuraCore/src/Application.h b/SakuraCore/src/Application.h index de04075..c5bb136 100644 --- a/SakuraCore/src/Application.h +++ b/SakuraCore/src/Application.h @@ -5,6 +5,8 @@ #include "SDL3/SDL_render.h" #include "SDL3/SDL_video.h" #include "imguilayer.h" +#include +#include struct WindowData { int width = 1280; @@ -28,8 +30,38 @@ public: void Run(); void Shutdown(); - void PushLayer(SakuraVNE::Layer *); - void PushOverlay(SakuraVNE::Layer *); + template + requires(std::is_base_of_v) + void PushLayer() { + auto newLayer = std::make_unique(); + SakuraVNE::Layer *layer = newLayer.get(); + + m_LayerStack.PushLayer(std::move(newLayer)); + + layer->OnAttach(); + } + + template + requires(std::is_base_of_v) + TLayer *GetLayer() { + for (const auto &layer : m_LayerStack) { + if (auto casted = dynamic_cast(layer.get())) { + return casted; + } + } + return nullptr; + } + + template + requires(std::is_base_of_v) + void PushOverlay() { + auto newOverlay = std::make_unique(); + SakuraVNE::Layer *layer = newOverlay.get(); + + m_LayerStack.PushOverLay(std::move(newOverlay)); + + layer->OnAttach(); + } inline AppData &GetAppData() { return m_AppData; } inline SDL_Window *GetSDLWindow() { return m_Window; }