Added documentation to the application class and moved Fn bind macro

dev
anulax1225 ago%!(EXTRA string=1 year)
parent 82c0be37cd
commit 77ab328e48
  1. 11
      bakara/src/bakara/core/application.cpp
  2. 75
      bakara/src/bakara/core/application.h
  3. 3
      bakara/src/bakara/core/base.h

@ -3,8 +3,8 @@
namespace Bk { namespace Bk {
Application::Application() Application::Application()
{ {
p_window = Window::create_window(); h_window = Window::create_window();
p_window->set_event_callback(BK_BIND_EVENT_FN(on_event)); h_window->set_event_callback(BK_BIND_EVENT_FN(on_event));
} }
Application::~Application() { } Application::~Application() { }
@ -15,7 +15,7 @@ namespace Bk {
if (!(dispatcher.dispatch<WindowCloseEvent>(BK_BIND_DISPACHER_FN(WindowCloseEvent, on_window_close)) || if (!(dispatcher.dispatch<WindowCloseEvent>(BK_BIND_DISPACHER_FN(WindowCloseEvent, on_window_close)) ||
dispatcher.dispatch<WindowResizeEvent>(BK_BIND_DISPACHER_FN(WindowResizeEvent, on_window_resize)))) dispatcher.dispatch<WindowResizeEvent>(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); (*it)->on_event(e);
} }
@ -24,7 +24,7 @@ namespace Bk {
bool Application::on_window_close(WindowCloseEvent& e) bool Application::on_window_close(WindowCloseEvent& e)
{ {
p_window->close(); h_window->close();
return true; return true;
} }
@ -39,8 +39,7 @@ namespace Bk {
{ {
while (p_running) while (p_running)
{ {
p_window->on_update(); h_window->on_update();
if (!p_window->is_open()) p_window->open();
} }
} }
} }

@ -1,35 +1,82 @@
#pragma once #pragma once
/*! \file application.h
This file contains the main app abstraction.
*/
#include <bkpch.h> #include <bkpch.h>
#include <bakara/io/window.h> #include <bakara/io/window.h>
#include <bakara/events/events.h> #include <bakara/events/events.h>
#include <bakara/core/layer_stack.h> #include <bakara/core/layer_stack.h>
namespace Bk { namespace Bk {
/*! \class Bk::Application
#define BK_BIND_EVENT_FN(fn) [this](Event& e) { fn(e); } Serves as the entry for the users program.
#define BK_BIND_DISPACHER_FN(event, fn) [this](event& e) -> bool{ return fn(e); } This handles layers, the main window, and events. It makes sure to propegate events and updates through the layers.
*/
class Application class Application
{ {
public: public:
Application(); Application();
/*! \fn Bk::Application::~Application
Virtual destructor enables subclasses to cleanup on termination
*/
virtual ~Application(); 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); 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); } /*! \fn Bk::Application::on_window_close
std::unique_ptr<Layer> pop_overlay() { return layer_stack.pop_overlay(); } Handler of Bk::WindowCloseEvent and will be bind to a event dispacher
void push_layer(Layer* layer) { layer_stack.push_layer(layer); } @param e : event to handled
std::unique_ptr<Layer> pop_layer() { return layer_stack.pop_layer(); } */
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<Layer> 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<Layer> pop_layer() { return p_layer_stack.pop_layer(); }
/*! \fn Bk::Application::run
Starts the application and the update loop.
*/
void run(); void run();
protected:
std::unique_ptr<Window> h_window; //!< Pointer to the main window
private: private:
std::unique_ptr<Window> p_window; LayerStack p_layer_stack; //!< Layer stack of the application
LayerStack layer_stack; bool p_running = true; //!< Flag that indicates if the update loop should stop or not
bool p_running = true;
}; };
/*! \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<Application> create_app(); std::unique_ptr<Application> create_app();
} }

@ -5,7 +5,8 @@
#define BK_STRINGIFY(x) #x #define BK_STRINGIFY(x) #x
#define BIT_SHIFT(x) (1 << 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 #ifdef BK_DEBUG
#if defined(BK_PLATFORM_WINDOWS) #if defined(BK_PLATFORM_WINDOWS)

Loading…
Cancel
Save