From 1f0a314e9c81753351571de0a133459b4089af82 Mon Sep 17 00:00:00 2001 From: ambigipathyv Date: Mon, 22 Jan 2024 16:20:17 +0100 Subject: [PATCH] Refactoring code and working directory --- bakara/src/bakara.h | 2 +- bakara/src/bakara/core/Layer.cpp | 6 ++++++ bakara/src/bakara/core/Layer.h | 18 ++++++++++++++++++ bakara/src/bakara/core/application.cpp | 13 +++++++++++++ bakara/src/bakara/core/application.h | 6 ++++-- bakara/src/bakara/events/event.h | 2 +- bakara/src/bakara/events/events.h | 7 +++++++ bakara/src/bakara/events/key_event.h | 2 +- bakara/src/bakara/events/mouse_event.h | 2 +- bakara/src/bakara/{core => io}/io_codes.h | 0 bakara/src/bakara/{core => io}/window.h | 4 +++- .../bakara/plaforms/window/glfw/win_glfw.cpp | 5 ++--- .../src/bakara/plaforms/window/glfw/win_glfw.h | 5 +++-- sandbox/src/sandbox.cpp | 4 ++-- 14 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 bakara/src/bakara/core/Layer.cpp create mode 100644 bakara/src/bakara/core/Layer.h create mode 100644 bakara/src/bakara/events/events.h rename bakara/src/bakara/{core => io}/io_codes.h (100%) rename bakara/src/bakara/{core => io}/window.h (92%) diff --git a/bakara/src/bakara.h b/bakara/src/bakara.h index 5644225..a20d1d0 100644 --- a/bakara/src/bakara.h +++ b/bakara/src/bakara.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/bakara/src/bakara/core/Layer.cpp b/bakara/src/bakara/core/Layer.cpp new file mode 100644 index 0000000..3e65967 --- /dev/null +++ b/bakara/src/bakara/core/Layer.cpp @@ -0,0 +1,6 @@ +#include "Layer.h" + +namespace Bk { + Layer::Layer(const std::string& name) + : name(name) {} +} \ No newline at end of file diff --git a/bakara/src/bakara/core/Layer.h b/bakara/src/bakara/core/Layer.h new file mode 100644 index 0000000..00edf42 --- /dev/null +++ b/bakara/src/bakara/core/Layer.h @@ -0,0 +1,18 @@ +#pragma once +#include + +namespace Bk { + class Layer + { + public: + Layer(const std::string& name = "Layer"); + virtual ~Layer() {} + + virtual void on_attach() {} + virtual void on_detach() {} + virtual void on_event() {} + virtual void on_update() {} + private: + std::string name; + }; +} \ No newline at end of file diff --git a/bakara/src/bakara/core/application.cpp b/bakara/src/bakara/core/application.cpp index f056186..7e84ad8 100644 --- a/bakara/src/bakara/core/application.cpp +++ b/bakara/src/bakara/core/application.cpp @@ -11,9 +11,22 @@ namespace Bk { void Application::on_event(Event& e) { + EventDispatcher dispatcher(e); + dispatcher.dispatch(BK_BIND_EVENT_FN(Application::on_window_close)); + dispatcher.dispatch(BK_BIND_EVENT_FN(Application::on_window_resize)); BK_CORE_INFO("Event : {0}", EVENT_STRING(e)); } + void Application::on_window_close(WindowCloseEvent& e) + { + p_window.close(); + } + + void Application::on_window_resize(WindowResizeEvent& e) + { + + } + void Application::run() { while (p_running) diff --git a/bakara/src/bakara/core/application.h b/bakara/src/bakara/core/application.h index aff369a..69cae13 100644 --- a/bakara/src/bakara/core/application.h +++ b/bakara/src/bakara/core/application.h @@ -1,8 +1,8 @@ #pragma once #include -#include "window.h" -#include +#include +#include namespace Bk { @@ -14,6 +14,8 @@ namespace Bk { Application(); virtual ~Application(); void on_event(Event& e); + void on_window_close(WindowCloseEvent& e); + void on_window_resize(WindowResizeEvent& e); void run(); private: std::unique_ptr p_window; diff --git a/bakara/src/bakara/events/event.h b/bakara/src/bakara/events/event.h index dc51a9b..b80bf7a 100644 --- a/bakara/src/bakara/events/event.h +++ b/bakara/src/bakara/events/event.h @@ -66,7 +66,7 @@ namespace Bk { bool is_in_category(EventCategory category) { - return (get_category_flags() & (int)category) == get_category_flags(); + return get_category_flags() & category; } }; diff --git a/bakara/src/bakara/events/events.h b/bakara/src/bakara/events/events.h new file mode 100644 index 0000000..538fd03 --- /dev/null +++ b/bakara/src/bakara/events/events.h @@ -0,0 +1,7 @@ +#pragma once + +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/bakara/src/bakara/events/key_event.h b/bakara/src/bakara/events/key_event.h index 9de7ba1..4ad8cc8 100644 --- a/bakara/src/bakara/events/key_event.h +++ b/bakara/src/bakara/events/key_event.h @@ -1,7 +1,7 @@ #pragma once -#include +#include #include "event.h" namespace Bk { diff --git a/bakara/src/bakara/events/mouse_event.h b/bakara/src/bakara/events/mouse_event.h index 1fc3c64..40746f5 100644 --- a/bakara/src/bakara/events/mouse_event.h +++ b/bakara/src/bakara/events/mouse_event.h @@ -2,7 +2,7 @@ #include "event.h" #include -#include +#include namespace Bk { diff --git a/bakara/src/bakara/core/io_codes.h b/bakara/src/bakara/io/io_codes.h similarity index 100% rename from bakara/src/bakara/core/io_codes.h rename to bakara/src/bakara/io/io_codes.h diff --git a/bakara/src/bakara/core/window.h b/bakara/src/bakara/io/window.h similarity index 92% rename from bakara/src/bakara/core/window.h rename to bakara/src/bakara/io/window.h index a9abdd0..effb362 100644 --- a/bakara/src/bakara/core/window.h +++ b/bakara/src/bakara/io/window.h @@ -18,7 +18,7 @@ namespace Bk { { public: using EventCallback = std::function; - virtual ~Window(){} + virtual ~Window() {} virtual uint get_width() const = 0; virtual uint get_height() const = 0; @@ -29,6 +29,8 @@ namespace Bk { virtual void set_vsync(bool enable) = 0; virtual bool is_vsync() const = 0; + virtual void close() = 0; + static std::unique_ptr create_window(const WindowPros& props = WindowPros()); }; } \ No newline at end of file diff --git a/bakara/src/bakara/plaforms/window/glfw/win_glfw.cpp b/bakara/src/bakara/plaforms/window/glfw/win_glfw.cpp index 56076f5..acc54a0 100644 --- a/bakara/src/bakara/plaforms/window/glfw/win_glfw.cpp +++ b/bakara/src/bakara/plaforms/window/glfw/win_glfw.cpp @@ -21,7 +21,7 @@ namespace Bk { WinGLFW::~WinGLFW() { - shutdown(); + close(); } void WinGLFW::init(const WindowPros& props) @@ -53,7 +53,6 @@ namespace Bk { WindowResizeEvent e((uint)width, (uint)height); data.callback(e); }); - glfwSetWindowCloseCallback(p_window, [](GLFWwindow* window) { WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); @@ -145,7 +144,7 @@ namespace Bk { return p_data.vsync; } - void WinGLFW::shutdown() + void WinGLFW::close() { glfwDestroyWindow(p_window); } diff --git a/bakara/src/bakara/plaforms/window/glfw/win_glfw.h b/bakara/src/bakara/plaforms/window/glfw/win_glfw.h index df414c0..9e2d402 100644 --- a/bakara/src/bakara/plaforms/window/glfw/win_glfw.h +++ b/bakara/src/bakara/plaforms/window/glfw/win_glfw.h @@ -1,6 +1,6 @@ #pragma once #include -#include +#include #include #include #include @@ -23,6 +23,8 @@ namespace Bk::Plaform { void set_vsync(bool enable) override; bool is_vsync() const override; + + void close() override; private: GLFWwindow* p_window; @@ -39,6 +41,5 @@ namespace Bk::Plaform { void init_event_callbacks(); void init(const WindowPros& props); - void shutdown(); }; } \ No newline at end of file diff --git a/sandbox/src/sandbox.cpp b/sandbox/src/sandbox.cpp index fcf08a2..dfc916f 100644 --- a/sandbox/src/sandbox.cpp +++ b/sandbox/src/sandbox.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -9,8 +10,7 @@ class Sandbox : public Bk::Application public: Sandbox() { - Bk::Vec2 vec(2.0f, 2.0f); - BK_INFO("My Vec 2 ({0}, {1})", vec.x, vec.y); + } ~Sandbox()