diff --git a/YoggieEngine/src/Application.cpp b/YoggieEngine/src/Application.cpp index 9edab16..1b58cf2 100644 --- a/YoggieEngine/src/Application.cpp +++ b/YoggieEngine/src/Application.cpp @@ -38,7 +38,7 @@ namespace YoggieEngine { void Application::Run() { - std::cout << "No run function implemented!"; + } @@ -81,6 +81,12 @@ namespace YoggieEngine { } } + void Application::PushLayer(Layer* layer) + { + AppLayerstack.PushLayer(layer); + layer->OnAttach(); + } + Application::~Application() { ImGui_ImplOpenGL3_Shutdown(); diff --git a/YoggieEngine/src/Application.h b/YoggieEngine/src/Application.h index f6c5b19..efbf677 100644 --- a/YoggieEngine/src/Application.h +++ b/YoggieEngine/src/Application.h @@ -1,5 +1,6 @@ #pragma once #include "YoggieEngine.h" +#include "LayerStack.h" namespace YoggieEngine { @@ -17,11 +18,16 @@ namespace YoggieEngine { void GuiBegin(); void GuiEnd(); + void PushLayer(Layer* layer); + + protected: std::string m_AppName; NativeWindow* appWindow; - friend class ApplicationRuntime; + + LayerStack AppLayerstack; + }; }; diff --git a/YoggieEngine/src/Layer.h b/YoggieEngine/src/Layer.h new file mode 100644 index 0000000..adbdc65 --- /dev/null +++ b/YoggieEngine/src/Layer.h @@ -0,0 +1,29 @@ +#pragma once + +class Layer { + +public: + ~Layer() { OnDestroy(); } + Layer() { OnCreate(); } + + Layer(const std::string name ) + : Name(name) {} + + + virtual void OnUpdate(){} + virtual void OnUI(){} + virtual void OnStartup(){} + + virtual void OnAttach() {} + virtual void OnDetach() {} + + + virtual void OnCreate() {} + virtual void OnDestroy(){} + +private: + + std::string Name; + + +}; \ No newline at end of file diff --git a/YoggieEngine/src/LayerStack.cpp b/YoggieEngine/src/LayerStack.cpp new file mode 100644 index 0000000..77e90cc --- /dev/null +++ b/YoggieEngine/src/LayerStack.cpp @@ -0,0 +1,27 @@ +#include "YoggieEngine.h" +#include "LayerStack.h" + +LayerStack::~LayerStack() +{ + for (Layer* layer : layers) { + layer->OnDetach(); + delete layer; + } +} + + +void LayerStack::PushLayer(Layer* layer) { + layers.emplace(layers.begin() + insertion_index, layer); + insertion_index++; +} + + +void LayerStack::PopLayer(Layer* layer) { + auto it = std::find(layers.begin(), layers.begin() + insertion_index, layer); + if (it != layers.begin() + insertion_index) { + layer->OnDetach(); + layers.erase(it); + insertion_index--; + + } +} diff --git a/YoggieEngine/src/LayerStack.h b/YoggieEngine/src/LayerStack.h new file mode 100644 index 0000000..3b3a72b --- /dev/null +++ b/YoggieEngine/src/LayerStack.h @@ -0,0 +1,22 @@ +#pragma once +#include "Layer.h" +#include + +class LayerStack{ +public: + LayerStack() = default; + ~LayerStack(); + + void PushLayer(Layer* layer); + void PopLayer(Layer* layer); + + std::vector::iterator begin() { return layers.begin(); } + std::vector::iterator end() { return layers.end(); } + std::vector::reverse_iterator rbegin() { return layers.rbegin(); } + std::vector::reverse_iterator rend() { return layers.rend(); } + + +private: + std::vector layers; + int insertion_index = 0; +}; \ No newline at end of file