diff --git a/bakara/src/bakara/core/application.cpp b/bakara/src/bakara/core/application.cpp index 7e84ad8..eccade2 100644 --- a/bakara/src/bakara/core/application.cpp +++ b/bakara/src/bakara/core/application.cpp @@ -4,7 +4,7 @@ namespace Bk { Application::Application() { p_window = Window::create_window(); - p_window->set_event_callback(BK_BIND_EVENT_FN(Application::on_event)); + p_window->set_event_callback(BK_BIND_EVENT_FN(on_event)); } Application::~Application() { } @@ -12,19 +12,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)); + dispatcher.dispatch(BK_BIND_DISPACHER_FN(WindowCloseEvent, on_window_close)); + dispatcher.dispatch(BK_BIND_DISPACHER_FN(WindowResizeEvent, on_window_resize)); + BK_CORE_INFO("Event : {0}", GET_EVENT_STRING(e)); } - void Application::on_window_close(WindowCloseEvent& e) + bool Application::on_window_close(WindowCloseEvent& e) { - p_window.close(); + p_window->close(); + + return true; } - void Application::on_window_resize(WindowResizeEvent& e) + bool Application::on_window_resize(WindowResizeEvent& e) { - + BK_CORE_INFO("Event : {0}", GET_EVENT_STRING(e)); + return true; } void Application::run() @@ -32,6 +35,7 @@ namespace Bk { while (p_running) { p_window->on_update(); + if (!p_window->is_open()) p_window->open(); } } } diff --git a/bakara/src/bakara/core/application.h b/bakara/src/bakara/core/application.h index 69cae13..117c1a1 100644 --- a/bakara/src/bakara/core/application.h +++ b/bakara/src/bakara/core/application.h @@ -6,7 +6,8 @@ namespace Bk { - #define BK_BIND_EVENT_FN(fn) std::bind(&fn, this, std::placeholders::_1) + #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); } class Application { @@ -14,8 +15,8 @@ namespace Bk { Application(); virtual ~Application(); void on_event(Event& e); - void on_window_close(WindowCloseEvent& e); - void on_window_resize(WindowResizeEvent& e); + bool on_window_close(WindowCloseEvent& e); + bool on_window_resize(WindowResizeEvent& e); void run(); private: std::unique_ptr p_window; diff --git a/bakara/src/bakara/core/Layer.cpp b/bakara/src/bakara/core/layer.cpp similarity index 80% rename from bakara/src/bakara/core/Layer.cpp rename to bakara/src/bakara/core/layer.cpp index 3e65967..71ee4a0 100644 --- a/bakara/src/bakara/core/Layer.cpp +++ b/bakara/src/bakara/core/layer.cpp @@ -1,4 +1,4 @@ -#include "Layer.h" +#include "layer.h" namespace Bk { Layer::Layer(const std::string& name) diff --git a/bakara/src/bakara/core/Layer.h b/bakara/src/bakara/core/layer.h similarity index 100% rename from bakara/src/bakara/core/Layer.h rename to bakara/src/bakara/core/layer.h diff --git a/bakara/src/bakara/core/layer_stack.cpp b/bakara/src/bakara/core/layer_stack.cpp new file mode 100644 index 0000000..e69de29 diff --git a/bakara/src/bakara/core/layer_stack.h b/bakara/src/bakara/core/layer_stack.h new file mode 100644 index 0000000..2a03220 --- /dev/null +++ b/bakara/src/bakara/core/layer_stack.h @@ -0,0 +1,8 @@ +#pragma once + +namespace BK { + class LayerStack + { + + }; +} \ No newline at end of file diff --git a/bakara/src/bakara/events/event.h b/bakara/src/bakara/events/event.h index b80bf7a..d583edc 100644 --- a/bakara/src/bakara/events/event.h +++ b/bakara/src/bakara/events/event.h @@ -44,11 +44,11 @@ namespace Bk { #ifdef BK_DEBUG #define EVENT_STRINGIFY(str, ...) std::string to_string() const override { return format(str, __VA_ARGS__); } - #define EVENT_STRING(event) event.to_string() + #define GET_EVENT_STRING(event) event.to_string() #else #define EVENT_STRINGIFY(str, ...) - #define EVENT_STRING(event) + #define GET_EVENT_STRING(event) "" #endif class Event diff --git a/bakara/src/bakara/io/window.h b/bakara/src/bakara/io/window.h index effb362..2cc7c4b 100644 --- a/bakara/src/bakara/io/window.h +++ b/bakara/src/bakara/io/window.h @@ -30,7 +30,11 @@ namespace Bk { virtual bool is_vsync() const = 0; virtual void close() = 0; + virtual void open() = 0; + bool is_open() { return p_is_open; } static std::unique_ptr create_window(const WindowPros& props = WindowPros()); + protected: + bool p_is_open; }; } \ 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 acc54a0..072207b 100644 --- a/bakara/src/bakara/plaforms/window/glfw/win_glfw.cpp +++ b/bakara/src/bakara/plaforms/window/glfw/win_glfw.cpp @@ -16,7 +16,10 @@ namespace Bk { WinGLFW::WinGLFW(const WindowPros& props) { - init(props); + p_data.title = props.title; + p_data.width = props.width; + p_data.height = props.height; + init(); } WinGLFW::~WinGLFW() @@ -24,20 +27,17 @@ namespace Bk { close(); } - void WinGLFW::init(const WindowPros& props) + void WinGLFW::init() { - p_data.title = props.title; - p_data.width = props.width; - p_data.height = props.height; - - BK_CORE_INFO("Creating window : {0} ({1}, {2})", props.title, props.width, props.height); + p_is_open = true; + BK_CORE_INFO("Creating window : {0} ({1}, {2})", p_data.title, p_data.width, p_data.height); if (!p_glfw_initialized++) { int success = glfwInit(); BK_MSG_ASSERT(success, "Couldn't initialize glfw!") glfwSetErrorCallback(glfw_error_callback); } - p_window = glfwCreateWindow((int)props.width, (int)props.height, props.title.c_str(), nullptr, nullptr); + p_window = glfwCreateWindow((int)p_data.width, (int)p_data.height, p_data.title.c_str(), nullptr, nullptr); glfwMakeContextCurrent(p_window); glfwSetWindowUserPointer(p_window, &p_data); set_vsync(true); @@ -121,10 +121,14 @@ namespace Bk { void WinGLFW::on_update() { - glClearColor(1,0,0.5,1); - glClear(GL_COLOR_BUFFER_BIT); - glfwPollEvents(); - glfwSwapBuffers(p_window); + if (p_is_open) + { + glClearColor(1,0,0.5,1); + glClear(GL_COLOR_BUFFER_BIT); + glfwPollEvents(); + glfwSwapBuffers(p_window); + if (p_shutdown && p_is_open) { shutdown(); } + } } void WinGLFW::set_event_callback(const EventCallback callback) @@ -134,19 +138,38 @@ namespace Bk { void WinGLFW::set_vsync(bool enable) { - if (enable) { glfwSwapInterval(1); } - else { glfwSwapInterval(0); } - p_data.vsync = enable; + if (p_is_open) + { + if (enable) { glfwSwapInterval(1); } + else { glfwSwapInterval(0); } + p_data.vsync = enable; + } } bool WinGLFW::is_vsync() const { return p_data.vsync; } + + void WinGLFW::shutdown() + { + p_is_open = false; + p_shutdown = false; + glfwDestroyWindow(p_window); + } void WinGLFW::close() { - glfwDestroyWindow(p_window); + p_shutdown = true; } + + void WinGLFW::open() + { + if (!p_is_open) + { + init(); + } + } + } } diff --git a/bakara/src/bakara/plaforms/window/glfw/win_glfw.h b/bakara/src/bakara/plaforms/window/glfw/win_glfw.h index 9e2d402..6607a98 100644 --- a/bakara/src/bakara/plaforms/window/glfw/win_glfw.h +++ b/bakara/src/bakara/plaforms/window/glfw/win_glfw.h @@ -1,10 +1,8 @@ #pragma once #include #include -#include -#include -#include -#include +#include +#include #include @@ -25,9 +23,11 @@ namespace Bk::Plaform { bool is_vsync() const override; void close() override; + void open() override; private: GLFWwindow* p_window; + bool p_shutdown; struct WindowData { @@ -40,6 +40,7 @@ namespace Bk::Plaform { WindowData p_data; void init_event_callbacks(); - void init(const WindowPros& props); + void init(); + void shutdown(); }; } \ No newline at end of file