diff --git a/bakara/src/bakara/core/application.cpp b/bakara/src/bakara/core/application.cpp index ddcbad1..753b1da 100644 --- a/bakara/src/bakara/core/application.cpp +++ b/bakara/src/bakara/core/application.cpp @@ -3,8 +3,8 @@ namespace Bk { Application::Application() { - p_window = Window::create_window(); - p_window->set_event_callback(BK_BIND_EVENT_FN(on_event)); + h_window = Window::create_window(); + h_window->set_event_callback(BK_BIND_EVENT_FN(on_event)); } Application::~Application() { } @@ -15,7 +15,7 @@ namespace Bk { if (!(dispatcher.dispatch(BK_BIND_DISPACHER_FN(WindowCloseEvent, on_window_close)) || dispatcher.dispatch(BK_BIND_DISPACHER_FN(WindowResizeEvent, on_window_resize)))) { - for(auto it = layer_stack.rbegin(); it != layer_stack.rend(); it++) + for(auto it = p_layer_stack.rbegin(); it != p_layer_stack.rend(); it++) { (*it)->on_event(e); } @@ -24,7 +24,7 @@ namespace Bk { bool Application::on_window_close(WindowCloseEvent& e) { - p_window->close(); + h_window->close(); return true; } @@ -39,8 +39,7 @@ namespace Bk { { while (p_running) { - p_window->on_update(); - if (!p_window->is_open()) p_window->open(); + h_window->on_update(); } } } diff --git a/bakara/src/bakara/core/application.h b/bakara/src/bakara/core/application.h index ef00ace..ff2e5aa 100644 --- a/bakara/src/bakara/core/application.h +++ b/bakara/src/bakara/core/application.h @@ -1,35 +1,82 @@ #pragma once +/*! \file application.h +This file contains the main app abstraction. +*/ + #include #include #include #include namespace Bk { - - #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 Bk::Application + Serves as the entry for the users program. + This handles layers, the main window, and events. It makes sure to propegate events and updates through the layers. + */ class Application { public: Application(); + /*! \fn Bk::Application::~Application + Virtual destructor enables subclasses to cleanup on termination + */ virtual ~Application(); + + /*! \fn Bk::Application::on_event + Function bound to the window to get all event from it + @param e : Event to be processed + */ void on_event(Event& e); - bool on_window_close(WindowCloseEvent& e); - bool on_window_resize(WindowResizeEvent& e); - void push_overlay(Layer* layer) { layer_stack.push_overlay(layer); } - std::unique_ptr pop_overlay() { return layer_stack.pop_overlay(); } - void push_layer(Layer* layer) { layer_stack.push_layer(layer); } - std::unique_ptr pop_layer() { return layer_stack.pop_layer(); } + /*! \fn Bk::Application::on_window_close + Handler of Bk::WindowCloseEvent and will be bind to a event dispacher + @param e : event to handled + */ + virtual bool on_window_close(WindowCloseEvent& e); + /*! \fn Bk::Application::on_window_resize + Handler of Bk::WindowResizeEvent and will be bind to a event dispacher + @param e : event to handled + */ + virtual bool on_window_resize(WindowResizeEvent& e); + /*! \fn Bk::Application::push_overlay + Push's the layer on top of the layer stack + @param layer : Layer pointer to push + */ + inline void push_overlay(Layer* layer) { p_layer_stack.push_overlay(layer); } + /*! \fn Bk::Application::pop_overlay + Pop's the layer on top of the layer stack + @return a unique ptr to the layer ressource + */ + inline std::unique_ptr pop_overlay() { return p_layer_stack.pop_overlay(); } + /*! \fn Bk::Application::push_overlay + Push's the layer at the bottom of the layer stack + @param layer : Layer pointer to push + */ + inline void push_layer(Layer* layer) { p_layer_stack.push_layer(layer); } + /*! \fn Bk::Application::push_overlay + Pop's the layer at the bottom of the layer stack + @return a unique ptr to the layer ressource + */ + inline std::unique_ptr pop_layer() { return p_layer_stack.pop_layer(); } + + /*! \fn Bk::Application::run + Starts the application and the update loop. + */ void run(); + + protected: + std::unique_ptr h_window; //!< Pointer to the main window + private: - std::unique_ptr p_window; - LayerStack layer_stack; - bool p_running = true; + LayerStack p_layer_stack; //!< Layer stack of the application + bool p_running = true; //!< Flag that indicates if the update loop should stop or not }; - + /*! \fn Bk::create_app + Is used to retrive the user app class instance, made from inheritance. + Must be defined in the user program + @return User defined application + */ std::unique_ptr create_app(); } \ No newline at end of file diff --git a/bakara/src/bakara/core/base.h b/bakara/src/bakara/core/base.h index e24c4f9..525e0f2 100644 --- a/bakara/src/bakara/core/base.h +++ b/bakara/src/bakara/core/base.h @@ -5,7 +5,8 @@ #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); } #ifdef BK_DEBUG #if defined(BK_PLATFORM_WINDOWS)