diff --git a/premake5.lua b/premake5.lua index d4c8b2d..ce40296 100644 --- a/premake5.lua +++ b/premake5.lua @@ -13,9 +13,6 @@ project "bakara" { "%{wks.location}/vendor/glm/glm/**.hpp", "%{wks.location}/vendor/glm/glm/**.inl", - "%{wks.location}/vendor/imgui/misc/cpp/imgui_stdlib.cpp", - "%{wks.location}/vendor/imgui/backends/imgui_impl_opengl3.cpp", - "%{wks.location}/vendor/imgui/backends/imgui_impl_glfw.cpp", "src/bakara/**.h", "src/bakara/**.cpp", "src/platforms/**.h", @@ -27,7 +24,6 @@ project "bakara" { "_CRT_SECURE_NO_WARNINGS", "GLFW_INCLUDE_NONE", - "IMGUI_IMPL_OPENGL_LOADER_GLAD", "BKMOD_ALL" } diff --git a/src/bakara/core/application.cpp b/src/bakara/core/application.cpp index ce4e630..c63f4e1 100644 --- a/src/bakara/core/application.cpp +++ b/src/bakara/core/application.cpp @@ -27,10 +27,15 @@ namespace Bk { } } - bool Application::on_window_close(WindowCloseEvent& e) + void Application::close() { h_window->close(); p_running = false; + } + + bool Application::on_window_close(WindowCloseEvent& e) + { + close(); return true; } diff --git a/src/bakara/core/application.h b/src/bakara/core/application.h index c6e23c7..dfa45bc 100644 --- a/src/bakara/core/application.h +++ b/src/bakara/core/application.h @@ -51,7 +51,7 @@ namespace Bk { /*! \fn Bk::Application::pop_overlay Pop's the layer on top of the layer stack */ - inline void pop_overlay() { p_layer_stack.pop_overlay(); } + inline void pop_overlay(Layer* layer) { p_layer_stack.pop_overlay(layer); } /*! \fn Bk::Application::push_overlay Push's the layer at the bottom of the layer stack @param layer : Layer pointer to push @@ -60,7 +60,7 @@ namespace Bk { /*! \fn Bk::Application::push_overlay Pop's the layer at the bottom of the layer stack */ - inline void pop_layer() { p_layer_stack.pop_layer(); } + inline void pop_layer(Layer* layer) { p_layer_stack.pop_layer(layer); } /*! \fn Bk::Application::run Starts the application and the update loop. @@ -74,6 +74,11 @@ namespace Bk { protected: std::shared_ptr h_window; //!< Pointer to the main window + /*! \fn Bk::Application::close + Stops the application and the update loop without creating an event. + */ + void close(); + private: LayerStack p_layer_stack; //!< Layer stack of the application bool p_running; //!< Flag that indicates if the update loop should stop or not diff --git a/src/bakara/core/base.h b/src/bakara/core/base.h deleted file mode 100644 index 33e47ff..0000000 --- a/src/bakara/core/base.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#define BK_STRINGIFY(x) #x -#define BIT_SHIFT(x) (1 << x) - -#define BK_BIND_EVENT_FN(fn) [this](Event& e) { fn(e); } -#define BK_BIND_DISPACHER_FN(event, fn) [this](event& e) -> bool{ return fn(e); } - - - diff --git a/src/bakara/core/layer_stack.cpp b/src/bakara/core/layer_stack.cpp index 8809348..513e7f8 100644 --- a/src/bakara/core/layer_stack.cpp +++ b/src/bakara/core/layer_stack.cpp @@ -1,10 +1,7 @@ #include "layer_stack.h" namespace Bk { - LayerStack::~LayerStack() - { - clear(); - } + LayerStack::~LayerStack() { clear(); } void LayerStack::push_overlay(Layer* layer) { @@ -12,29 +9,31 @@ namespace Bk { p_layers.emplace_back(layer); } - void LayerStack::pop_overlay() + void LayerStack::pop_overlay(Layer* layer) { - if(auto layer = p_layers.back()) - { + auto it = std::find(p_layers.begin() + p_layer_index, p_layers.end(), layer); + if (it != p_layers.end()) + { layer->on_detach(); - p_layers.pop_back(); - delete layer; + p_layers.erase(it); } } void LayerStack::push_layer(Layer* layer) { layer->on_attach(); - p_layers.emplace_front(layer); + p_layers.emplace(p_layers.begin() + p_layer_index, layer); + p_layer_index++; } - void LayerStack::pop_layer() + void LayerStack::pop_layer(Layer* layer) { - if(auto layer = p_layers.front()) - { + auto it = std::find(p_layers.begin(), p_layers.begin() + p_layer_index, layer); + if (it != p_layers.begin() + p_layer_index) + { layer->on_detach(); - p_layers.pop_front(); - delete layer; + p_layers.erase(it); + p_layer_index--; } } @@ -46,5 +45,6 @@ namespace Bk { delete layer; }); p_layers.clear(); + p_layer_index = 0; } } \ No newline at end of file diff --git a/src/bakara/core/layer_stack.h b/src/bakara/core/layer_stack.h index e2b6948..e919de7 100644 --- a/src/bakara/core/layer_stack.h +++ b/src/bakara/core/layer_stack.h @@ -11,19 +11,19 @@ namespace Bk { ~LayerStack(); void push_overlay(Layer* layer); - void pop_overlay(); + void pop_overlay(Layer* layer); void push_layer(Layer* layer); - void pop_layer(); + void pop_layer(Layer* layer); void clear(); - std::deque::iterator begin() { return p_layers.begin(); } - std::deque::iterator end() { return p_layers.end(); } + std::vector::iterator begin() { return p_layers.begin(); } + std::vector::iterator end() { return p_layers.end(); } - std::deque::reverse_iterator rbegin() { return p_layers.rbegin(); } - std::deque::reverse_iterator rend() { return p_layers.rend(); } + std::vector::reverse_iterator rbegin() { return p_layers.rbegin(); } + std::vector::reverse_iterator rend() { return p_layers.rend(); } private: - std::deque p_layers; + std::vector p_layers; uint p_layer_index = 0; }; } \ No newline at end of file diff --git a/src/bakara/events/event.h b/src/bakara/events/event.h index 8ce826c..474b5bc 100644 --- a/src/bakara/events/event.h +++ b/src/bakara/events/event.h @@ -1,8 +1,10 @@ #pragma once -#include #include +#define BK_BIND_EVENT_FN(fn) [this](Event& e) { fn(e); } +#define BK_BIND_DISPACHER_FN(event, fn) [this](event& e) -> bool{ return fn(e); } + namespace Bk { enum class EventType { @@ -27,11 +29,11 @@ namespace Bk { enum EventCategory { None = 0, - AppCategory = BIT_SHIFT(0), - InputCategory = BIT_SHIFT(1), - KeyboardCategory = BIT_SHIFT(2), - MouseCategory = BIT_SHIFT(3), - MouseButtonCategory = BIT_SHIFT(4) + AppCategory = BK_BIT_SHIFT(0), + InputCategory = BK_BIT_SHIFT(1), + KeyboardCategory = BK_BIT_SHIFT(2), + MouseCategory = BK_BIT_SHIFT(3), + MouseButtonCategory = BK_BIT_SHIFT(4) }; #define EVENT_CLASS_TYPE(type) static EventType get_static_type() { return EventType::type; }\ diff --git a/src/bakara/imgui/imgui_build.cpp b/src/bakara/imgui/imgui_build.cpp new file mode 100644 index 0000000..0edc408 --- /dev/null +++ b/src/bakara/imgui/imgui_build.cpp @@ -0,0 +1,5 @@ +#include + +#define IMGUI_IMPL_OPENGL_LOADER_GLAD +#include +#include \ No newline at end of file diff --git a/src/bakara/io/input.h b/src/bakara/io/input.h new file mode 100644 index 0000000..3d55ba5 --- /dev/null +++ b/src/bakara/io/input.h @@ -0,0 +1,12 @@ +#pragma once + +#include "bakarapch.h" +#include "io_codes.h" + +namespace Bk +{ + class Input + { + + }; +} \ No newline at end of file diff --git a/src/platforms/glfw/glfw_window.h b/src/platforms/glfw/glfw_window.h index 66d2e87..4c72ea8 100644 --- a/src/platforms/glfw/glfw_window.h +++ b/src/platforms/glfw/glfw_window.h @@ -2,7 +2,6 @@ #include #include #include -#include #include namespace Bk::Plaform {