diff --git a/examples/test_imgui.cpp b/examples/test_imgui.cpp index 1b8c631..516031e 100644 --- a/examples/test_imgui.cpp +++ b/examples/test_imgui.cpp @@ -8,7 +8,7 @@ class TestLayer : public Bk::Layer public: TestLayer() : Layer("Test") {} - void imgui_render() override + void ImguiRender() override { static bool show = true; ImGui::ShowDemoWindow(&show); @@ -21,12 +21,12 @@ class Sandbox : public Bk::Application public: Sandbox() { - push_layer(new TestLayer()); + PushLayer(new TestLayer()); } }; -std::unique_ptr Bk::create_app() { +std::unique_ptr Bk::CreateApp() { return std::unique_ptr(new Sandbox()); } \ No newline at end of file diff --git a/examples/test_layer.cpp b/examples/test_layer.cpp index 58c6429..a3fd3f0 100644 --- a/examples/test_layer.cpp +++ b/examples/test_layer.cpp @@ -19,12 +19,12 @@ class TestLayer : public Bk::Layer BK_INFO("Layer {} detached", name); } - void on_event(Bk::Event& e) override + void OnEvent(Bk::Event& e) override { BK_INFO("Layer {} event", name); } - void on_update() override + void OnUpdate() override { BK_INFO("Layer {} updated", name); } @@ -35,10 +35,10 @@ class Sandbox : public Bk::Application public: Sandbox() { - push_layer(new TestLayer()); + PushLayer(new TestLayer()); } }; -std::unique_ptr Bk::create_app() { +std::unique_ptr Bk::CreateApp() { return std::unique_ptr(new Sandbox()); } \ No newline at end of file diff --git a/manual/index.md b/manual/index.md index b85d52a..ad05e6d 100644 --- a/manual/index.md +++ b/manual/index.md @@ -1,32 +1,2 @@ \mainpage Bakara Manual -## Build -### Windows -On windows, write commands : -```batch - git clone https://github.com/anulax/bakara - git submodule init - git submodule update - .\vendor\premake5 vs2022 - dotnet build - dotnet run -``` -Or use visual studio 2022 to build your project. - -### Linux -On linux (if you don't have premake5, install it with your distro's packet manager). You have two env variable to change build proccess : - -| Name | Value | -| ----------- | ----------- | -| autoexec | 0/1 | -| clearbin | 0/1 | - -Then write commands : - -```bash - git clone https://github.com/anulax/bakara - git submodule init - git submodule update - (export clearbin=1 autoexec=1) - ./build.sh config=release -``` diff --git a/src/bakara/core/application.cpp b/src/bakara/core/application.cpp index 420704d..920f7b1 100644 --- a/src/bakara/core/application.cpp +++ b/src/bakara/core/application.cpp @@ -7,64 +7,66 @@ namespace Bk { { BK_CORE_MSG_ASSERT(p_instance == nullptr, "Application already exists, can not create two application.") Application::p_instance = this; - h_window = std::unique_ptr(Window::create_window()); + h_window = std::unique_ptr(Window::CreateWindow()); imgui_layer = new ImguiLayer(); - push_overlay(imgui_layer); - h_window->set_event_callback(BK_BIND_EVENT_FN(on_event)); + PushOverlay(imgui_layer); + h_window->SetEventCallback(BK_BIND_EVENT_FN(OnEvent)); p_running = true; } Application::~Application() { } - void Application::on_event(Event& e) + void Application::OnEvent(Event& e) { EventDispatcher dispatcher(e); - dispatcher.dispatch(BK_BIND_DISPACHER_FN(MouseButtonPressEvent, Mouse::button_callback)); - dispatcher.dispatch(BK_BIND_DISPACHER_FN(MouseButtonReleaseEvent, Mouse::button_callback)); - dispatcher.dispatch(BK_BIND_DISPACHER_FN(MouseScrollEvent, Mouse::wheel_callback)); - dispatcher.dispatch(BK_BIND_DISPACHER_FN(MouseMoveEvent, Mouse::cursor_callback)); - if (!(dispatcher.dispatch(BK_BIND_DISPACHER_FN(WindowCloseEvent, on_window_close)) - || dispatcher.dispatch(BK_BIND_DISPACHER_FN(WindowResizeEvent, on_window_resize)))) + dispatcher.dispatch(BK_BIND_DISPACHER_FN(MouseButtonPressEvent, Mouse::ButtonCallback)); + dispatcher.dispatch(BK_BIND_DISPACHER_FN(MouseButtonReleaseEvent, Mouse::ButtonCallback)); + dispatcher.dispatch(BK_BIND_DISPACHER_FN(MouseScrollEvent, Mouse::WheelCallback)); + dispatcher.dispatch(BK_BIND_DISPACHER_FN(MouseMoveEvent, Mouse::CursorCallback)); + dispatcher.dispatch(BK_BIND_DISPACHER_FN(KeyPressEvent, Keyboard::KeyCallback)); + dispatcher.dispatch(BK_BIND_DISPACHER_FN(KeyReleaseEvent, Keyboard::KeyCallback)); + if (!(dispatcher.dispatch(BK_BIND_DISPACHER_FN(WindowCloseEvent, OnWindowClose)) + || dispatcher.dispatch(BK_BIND_DISPACHER_FN(WindowResizeEvent, OnWindowResize)))) { - for(auto it = p_layer_stack.rbegin(); it != p_layer_stack.rend(); it++) + for(auto it = p_layer_stack.ReverseBegin(); it != p_layer_stack.ReverseEnd(); it++) { - (*it)->on_event(e); + (*it)->OnEvent(e); } } } - void Application::close() + void Application::Close() { - h_window->close(); + h_window->Close(); p_running = false; } - bool Application::on_window_close(WindowCloseEvent& e) + bool Application::OnWindowClose(WindowCloseEvent& e) { - close(); + Close(); return true; } - bool Application::on_window_resize(WindowResizeEvent& e) + bool Application::OnWindowResize(WindowResizeEvent& e) { return true; } - void Application::run() + void Application::Run() { while (p_running) { for (Layer* layer : p_layer_stack) - layer->on_update(); + layer->OnUpdate(); - imgui_layer->begin(); + imgui_layer->Begin(); for (Layer* layer : p_layer_stack) - layer->imgui_render(); - imgui_layer->end(); + layer->ImguiRender(); + imgui_layer->End(); - h_window->on_update(); + h_window->OnUpdate(); } } } diff --git a/src/bakara/core/application.h b/src/bakara/core/application.h index fa3186f..6f16a50 100644 --- a/src/bakara/core/application.h +++ b/src/bakara/core/application.h @@ -8,6 +8,7 @@ This file contains the main app abstraction. #include "bakara/core/window.h" #include "bakara/events/events.h" #include "bakara/io/mouse.h" +#include "bakara/io/keyboard.h" #include "bakara/core/layer_stack.h" #include "bakara/imgui/imgui_layer.h" @@ -28,69 +29,69 @@ namespace Bk { */ virtual ~Application(); - /*! \fn Bk::Application::on_event + /*! \fn Bk::Application::OnEvent Function bound to the window to get all event from it @param e : Event to be processed */ - void on_event(Event& e); + void OnEvent(Event& e); - /*! \fn Bk::Application::on_window_close + /*! \fn Bk::Application::OnWindowClose 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 + virtual bool OnWindowClose(WindowCloseEvent& e); + /*! \fn Bk::Application::OnWindowResize Handler of Bk::WindowResizeEvent and will be bind to a event dispacher @param e : event to handled */ - virtual bool on_window_resize(WindowResizeEvent& e); + virtual bool OnWindowResize(WindowResizeEvent& e); - /*! \fn Bk::Application::push_overlay + /*! \fn Bk::Application::PushOverlay 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 + inline void PushOverlay(Layer* layer) { p_layer_stack.PushOverlay(layer); } + /*! \fn Bk::Application::PopOverlay Pop's the layer on top of the layer stack */ - inline void pop_overlay(Layer* layer) { p_layer_stack.pop_overlay(layer); } - /*! \fn Bk::Application::push_overlay + inline void PopOverlay(Layer* layer) { p_layer_stack.PopOverlay(layer); } + /*! \fn Bk::Application::PushOverlay 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 + inline void PushLayer(Layer* layer) { p_layer_stack.PushLayer(layer); } + /*! \fn Bk::Application::PushOverlay Pop's the layer at the bottom of the layer stack */ - inline void pop_layer(Layer* layer) { p_layer_stack.pop_layer(layer); } + inline void PopLayer(Layer* layer) { p_layer_stack.PopLayer(layer); } /*! \fn Bk::Application::run Starts the application and the update loop. */ - void run(); + void Run(); - Window& get_window() { return *h_window; } + Window& GetWindow() { return *h_window; } - static Application& get() { return *p_instance; } + static Application& Get() { return *p_instance; } protected: std::unique_ptr h_window; //!< Pointer to the main window ImguiLayer* imgui_layer; - /*! \fn Bk::Application::close + /*! \fn Bk::Application::Close Stops the application and the update loop without creating an event. */ - void close(); + 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 static Application* p_instance; }; - /*! \fn std::unique_ptr Bk::create_app() + /*! \fn std::unique_ptr Bk::CreateApp() 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(); + std::unique_ptr CreateApp(); } \ No newline at end of file diff --git a/src/bakara/core/entry.cpp b/src/bakara/core/entry.cpp index f3b7410..a2230b9 100644 --- a/src/bakara/core/entry.cpp +++ b/src/bakara/core/entry.cpp @@ -5,17 +5,17 @@ This file contains the entry point of the program. */ -/*! \fn std::unique_ptr Bk::create_app() +/*! \fn std::unique_ptr Bk::CreateApp() External function implemented client side. */ -extern std::unique_ptr Bk::create_app(); +extern std::unique_ptr Bk::CreateApp(); /*! \fn int main(int argc, char** argv) Entry of the program. */ int main(int argc, char** argv) { - Bk::Log::init("Bakara"); - std::unique_ptr app = Bk::create_app(); - app->run(); + Bk::Log::Init("Bakara"); + std::unique_ptr app = Bk::CreateApp(); + app->Run(); return 0; } \ No newline at end of file diff --git a/src/bakara/core/layer.h b/src/bakara/core/layer.h index 4a55674..eea541f 100644 --- a/src/bakara/core/layer.h +++ b/src/bakara/core/layer.h @@ -9,12 +9,12 @@ namespace Bk { Layer(const std::string& name = "Layer"); ~Layer() {} - virtual void on_attach() {} - virtual void on_detach() {} - virtual void on_event(Event& e) {} - virtual void on_update() {} - virtual void imgui_render() {} - const std::string to_string() const { return name; } + virtual void OnAttach() {} + virtual void OnDetach() {} + virtual void OnEvent(Event& e) {} + virtual void OnUpdate() {} + virtual void ImguiRender() {} + const std::string ToString() const { return name; } protected: std::string name; }; diff --git a/src/bakara/core/layer_stack.cpp b/src/bakara/core/layer_stack.cpp index 513e7f8..e893cd5 100644 --- a/src/bakara/core/layer_stack.cpp +++ b/src/bakara/core/layer_stack.cpp @@ -3,35 +3,35 @@ namespace Bk { LayerStack::~LayerStack() { clear(); } - void LayerStack::push_overlay(Layer* layer) + void LayerStack::PushOverlay(Layer* layer) { - layer->on_attach(); + layer->OnAttach(); p_layers.emplace_back(layer); } - void LayerStack::pop_overlay(Layer* layer) + void LayerStack::PopOverlay(Layer* layer) { auto it = std::find(p_layers.begin() + p_layer_index, p_layers.end(), layer); if (it != p_layers.end()) { - layer->on_detach(); + layer->OnDetach(); p_layers.erase(it); } } - void LayerStack::push_layer(Layer* layer) + void LayerStack::PushLayer(Layer* layer) { - layer->on_attach(); + layer->OnAttach(); p_layers.emplace(p_layers.begin() + p_layer_index, layer); p_layer_index++; } - void LayerStack::pop_layer(Layer* layer) + void LayerStack::PopLayer(Layer* layer) { 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(); + layer->OnDetach(); p_layers.erase(it); p_layer_index--; } @@ -41,7 +41,7 @@ namespace Bk { { std::for_each(p_layers.begin(), p_layers.end(), [](Layer* layer) { - layer->on_detach(); + layer->OnDetach(); delete layer; }); p_layers.clear(); diff --git a/src/bakara/core/layer_stack.h b/src/bakara/core/layer_stack.h index 95f1434..e819852 100644 --- a/src/bakara/core/layer_stack.h +++ b/src/bakara/core/layer_stack.h @@ -10,17 +10,19 @@ namespace Bk { LayerStack() = default; ~LayerStack(); - void push_overlay(Layer* layer); - void pop_overlay(Layer* layer); - void push_layer(Layer* layer); - void pop_layer(Layer* layer); + void PushOverlay(Layer* layer); + void PopOverlay(Layer* layer); + void PushLayer(Layer* layer); + void PopLayer(Layer* layer); void clear(); std::vector::iterator begin() { return p_layers.begin(); } std::vector::iterator end() { return p_layers.end(); } + std::vector::iterator Begin() { return p_layers.begin(); } + std::vector::iterator End() { return p_layers.end(); } - std::vector::reverse_iterator rbegin() { return p_layers.rbegin(); } - std::vector::reverse_iterator rend() { return p_layers.rend(); } + std::vector::reverse_iterator ReverseBegin() { return p_layers.rbegin(); } + std::vector::reverse_iterator ReverseEnd() { return p_layers.rend(); } private: std::vector p_layers; diff --git a/src/bakara/core/window.h b/src/bakara/core/window.h index 29054d2..204c7e6 100644 --- a/src/bakara/core/window.h +++ b/src/bakara/core/window.h @@ -20,7 +20,7 @@ namespace Bk { uint height; //!< Height of the window /*! \fn Bk::WindowProps::WindowProps - Default window is initialized with a width of 1000 and a height 800 + Default window is Initialized with a width of 1000 and a height 800 @param title : Title of the window @param width : Width of the window @param height : Height of the window @@ -47,57 +47,57 @@ namespace Bk { */ virtual ~Window() {} - /*! \fn Bk::Window::get_width + /*! \fn Bk::Window::GetWidth @return The width of the window */ - virtual uint get_width() const = 0; - /*! \fn Bk::Window::get_height + virtual uint GetWidth() const = 0; + /*! \fn Bk::Window::GetHeight @return The height of the window */ - virtual uint get_height() const = 0; + virtual uint GetHeight() const = 0; - /*! \fn Bk::Window::on_update + /*! \fn Bk::Window::OnUpdate Updates the frame of the window */ - virtual void on_update() = 0; - /*! \fn Bk::Window::set_event_callback + virtual void OnUpdate() = 0; + /*! \fn Bk::Window::SetEventCallback Sets the function pointer for events of the window @param callback : function called when a new event occures */ - virtual void set_event_callback(const EventCallback callback) = 0; + virtual void SetEventCallback(const EventCallback callback) = 0; - /*! \fn Bk::Window::set_vsync + /*! \fn Bk::Window::SetVsync Sets the window buffer swap interval. Is enabled by default. If set to false the frame rate should be more constant, but more slow. */ - virtual void set_vsync(bool enable) = 0; - /*! \fn Bk::Window::is_vsync + virtual void SetVsync(bool enable) = 0; + /*! \fn Bk::Window::IsVsync Indicates if window is vsync @return Vsync flag */ - virtual bool is_vsync() const = 0; + virtual bool IsVsync() const = 0; - /*! \fn Bk::Window::close + /*! \fn Bk::Window::Close Closes the window */ - virtual void close() = 0; - /*! \fn Bk::Window::open - Opens and initializes the window + virtual void Close() = 0; + /*! \fn Bk::Window::Open + Opens and Initializes the window */ - virtual void open() = 0; - /*! \fn Bk::Window::is_open - Indicates if the window is opened + virtual void Open() = 0; + /*! \fn Bk::Window::IsOpen + Indicates if the window is Opened @return Open flag */ - virtual bool is_open() = 0; + virtual bool IsOpen() = 0; - virtual void* get_native_window() = 0; + virtual void* GetNativeWindow() = 0; - /*! \fn Bk::Window::create_window() + /*! \fn Bk::Window::CreateWindow() Static function implemented in the api window class to get a window specifique api. If no parameter is specified, creates the window with the default settings. @param props : Window information */ - static Window* create_window(const WindowProps& props = WindowProps()); + static Window* CreateWindow(const WindowProps& props = WindowProps()); }; } \ No newline at end of file diff --git a/src/bakara/events/event.h b/src/bakara/events/event.h index b57c972..6bb0fa5 100644 --- a/src/bakara/events/event.h +++ b/src/bakara/events/event.h @@ -43,9 +43,9 @@ namespace Bk { #define EVENT_CLASS_CATEGORY(category) virtual int get_category_flags() const override { return category; } #ifdef BK_DEBUG - #define EVENT_STRINGIFY(str, ...) std::string to_string() const override { return Tools::string_format(str, __VA_ARGS__); } + #define EVENT_STRINGIFY(str, ...) std::string ToString() const override { return Tools::string_format(str, __VA_ARGS__); } - #define GET_EVENT_STRING(event) event.to_string() + #define GET_EVENT_STRING(event) event.ToString() #else #define EVENT_STRINGIFY(str, ...) @@ -63,7 +63,7 @@ namespace Bk { virtual const char* get_name() const = 0; virtual int get_category_flags() const = 0; #ifdef BK_DEBUG - virtual std::string to_string() const { return get_name(); } + virtual std::string ToString() const { return get_name(); } #endif bool is_in_category(EventCategory category) { return get_category_flags() & category; } }; diff --git a/src/bakara/events/window_event.h b/src/bakara/events/window_event.h index ee6d702..94012d1 100644 --- a/src/bakara/events/window_event.h +++ b/src/bakara/events/window_event.h @@ -9,8 +9,8 @@ namespace Bk { WindowResizeEvent(uint width, uint height) : p_width(width), p_height(height) {}; - uint get_width() const { return p_width; } - uint get_height() const { return p_height; } + uint GetWidth() const { return p_width; } + uint GetHeight() const { return p_height; } EVENT_STRINGIFY("WindowResizeEvent : %d %d", p_width, p_height) diff --git a/src/bakara/imgui/imgui_layer.cpp b/src/bakara/imgui/imgui_layer.cpp index f5137ec..6a5184b 100644 --- a/src/bakara/imgui/imgui_layer.cpp +++ b/src/bakara/imgui/imgui_layer.cpp @@ -14,7 +14,7 @@ #include namespace Bk { - void ImguiLayer::on_attach() + void ImguiLayer::OnAttach() { IMGUI_CHECKVERSION(); ImGui::CreateContext(); @@ -40,32 +40,32 @@ namespace Bk { ImGui::StyleColorsDark(); //ImGui::StyleColorsClassic(); - Application& app = Application::get(); - GLFWwindow* window = static_cast(app.get_window().get_native_window()); + Application& app = Application::Get(); + GLFWwindow* window = static_cast(app.GetWindow().GetNativeWindow()); // Setup Platform/Renderer bindings ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init("#version 420"); } - void ImguiLayer::on_detach() + void ImguiLayer::OnDetach() { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); } - void ImguiLayer::begin() + void ImguiLayer::Begin() { ImGuiIO& io = ImGui::GetIO(); - Application& app = Application::get(); - io.DisplaySize = ImVec2((float)app.get_window().get_width(), (float)app.get_window().get_height()); + Application& app = Application::Get(); + io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight()); ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); } - void ImguiLayer::end() + void ImguiLayer::End() { // Rendering ImGui::Render(); diff --git a/src/bakara/imgui/imgui_layer.h b/src/bakara/imgui/imgui_layer.h index 4c7f096..c28be56 100644 --- a/src/bakara/imgui/imgui_layer.h +++ b/src/bakara/imgui/imgui_layer.h @@ -10,9 +10,9 @@ namespace Bk { ImguiLayer() : Layer("Imgui") {} - void on_attach() override; - void on_detach() override; - void begin(); - void end(); + void OnAttach() override; + void OnDetach() override; + void Begin(); + void End(); }; } \ No newline at end of file diff --git a/src/bakara/io/keyboard.cpp b/src/bakara/io/keyboard.cpp index e69de29..1a6cc6e 100644 --- a/src/bakara/io/keyboard.cpp +++ b/src/bakara/io/keyboard.cpp @@ -0,0 +1,39 @@ +#include "keyboard.h" + +namespace Bk +{ + std::vector Keyboard::keys; + std::vector Keyboard::keysChanged; + + bool Keyboard::KeyCallback(KeyEvent& e) + { + //If the button is pressed or down then key is true + if (e.get_name() == "KeyPress" || e.get_name() == "KeyRelease") keys[e.get_key()] = !keys[e.get_key()]; + else keys[e.get_key()] = false; + //If the button is not down then keyChanged is true + keysChanged[e.get_key()] = e.get_name() == "KeyPress" || e.get_name() == "KeyRelease"; + return false; + } + + bool Keyboard::KeyDown(KeyCode key) + { + return keys[key]; + } + + bool Keyboard::KeyWentUp(KeyCode key) + { + return !keys[key] && keyChanged(key); + } + + bool Keyboard::KeyWentDown(KeyCode key) + { + return keys[key] && keyChanged(key); + } + + bool Keyboard::keyChanged(KeyCode key) + { + bool ret = keysChanged[key]; + keysChanged[key] = false; + return ret; + } +} \ No newline at end of file diff --git a/src/bakara/io/keyboard.h b/src/bakara/io/keyboard.h index e69de29..747e7b5 100644 --- a/src/bakara/io/keyboard.h +++ b/src/bakara/io/keyboard.h @@ -0,0 +1,25 @@ +#pragma once + +#include "bakara.pch" +#include "key_codes.h" +#include "bakara/events/key_event.h" + +namespace Bk +{ + class Keyboard { + public: + + static bool KeyCallback(KeyEvent& e); + //Assesors + static bool KeyDown(KeyCode key); + static bool KeyWentUp(KeyCode key); + static bool KeyWentDown(KeyCode key); + + private: + //Keys state + static std::vector keys; + static std::vector keysChanged; + //Assesor + static bool keyChanged(KeyCode key); + }; +} \ No newline at end of file diff --git a/src/bakara/io/mouse.cpp b/src/bakara/io/mouse.cpp index 2ec70ce..e03c8bb 100644 --- a/src/bakara/io/mouse.cpp +++ b/src/bakara/io/mouse.cpp @@ -18,7 +18,7 @@ namespace Bk std::vector Mouse::buttons = { 0 }; std::vector Mouse::buttonsChanged = { 0 }; - bool Mouse::cursor_callback(MouseMoveEvent& e) { + bool Mouse::CursorCallback(MouseMoveEvent& e) { x = e.get_x(); y = e.get_y(); @@ -34,7 +34,7 @@ namespace Bk return false; } - bool Mouse::button_callback(MouseButtonEvent& e) { + bool Mouse::ButtonCallback(MouseButtonEvent& e) { if (e.get_name() != "MouseButtonRelease") { if(!buttons[e.get_btn()]) { buttons[e.get_btn()] = true; @@ -47,49 +47,49 @@ namespace Bk return false; } - bool Mouse::wheel_callback(MouseScrollEvent& e) { + bool Mouse::WheelCallback(MouseScrollEvent& e) { scrollDX = e.get_dx(); scrollDY = e.get_dy(); return false; } - Vec2 Mouse::get_position() { + Vec2 Mouse::GetPosition() { return Vec2(x, y); } - double Mouse::get_dx() { + double Mouse::GetDX() { double _dX = dX; dX = 0; return _dX; } - double Mouse::get_dy() { + double Mouse::GetDY() { double _dY = dY; dY = 0; return _dY; } - double Mouse::get_scroll_dx() { + double Mouse::GetScrollDX() { double _scrollDX = scrollDX; scrollDX = 0; return _scrollDX; } - double Mouse::get_scroll_dy() { + double Mouse::GetScrollDY() { double _scrollDY = scrollDY; scrollDY = 0; return _scrollDY; } - bool Mouse::button(MouseCode button) { + bool Mouse::Button(MouseCode button) { return buttons[button]; } - bool Mouse::button_up(MouseCode button) { + bool Mouse::ButtonUp(MouseCode button) { return !buttons[button] && buttonChanged(button); } - bool Mouse::button_down(MouseCode button) { + bool Mouse::ButtonDown(MouseCode button) { return buttons[button] && buttonChanged(button); } diff --git a/src/bakara/io/mouse.h b/src/bakara/io/mouse.h index f8bb200..f86100e 100644 --- a/src/bakara/io/mouse.h +++ b/src/bakara/io/mouse.h @@ -8,23 +8,23 @@ namespace Bk class Mouse { public: //GLFW callback function - static bool cursor_callback(MouseMoveEvent& e); - static bool button_callback(MouseButtonEvent& e); - static bool wheel_callback(MouseScrollEvent& e); + static bool CursorCallback(MouseMoveEvent& e); + static bool ButtonCallback(MouseButtonEvent& e); + static bool WheelCallback(MouseScrollEvent& e); //Mouse position assesors - static Vec2 get_position(); + static Vec2 GetPosition(); //Mouse scroll assesors - static double get_dx(); - static double get_dy(); - static double get_scroll_dx(); - static double get_scroll_dy(); + static double GetDX(); + static double GetDY(); + static double GetScrollDX(); + static double GetScrollDY(); //Mouse buttons assesors - static bool button(MouseCode button); - static bool button_up(MouseCode button); - static bool button_down(MouseCode button); + static bool Button(MouseCode button); + static bool ButtonUp(MouseCode button); + static bool ButtonDown(MouseCode button); private: static double x; diff --git a/src/bakara/renderer/graphics_context.h b/src/bakara/renderer/graphics_context.h index c003724..5f9e538 100644 --- a/src/bakara/renderer/graphics_context.h +++ b/src/bakara/renderer/graphics_context.h @@ -5,7 +5,7 @@ namespace Bk class GraphicsContext { public: - virtual void init() = 0; - virtual void swap_buffers() = 0; + virtual void Init() = 0; + virtual void SwapBuffers() = 0; }; } \ No newline at end of file diff --git a/src/platforms/glfw/glfw_window.cpp b/src/platforms/glfw/glfw_window.cpp index b0e8bf3..f32661c 100644 --- a/src/platforms/glfw/glfw_window.cpp +++ b/src/platforms/glfw/glfw_window.cpp @@ -5,13 +5,13 @@ #include namespace Bk { - Window* Window::create_window(const WindowProps& props) + Window* Window::CreateWindow(const WindowProps& props) { return new Platform::WinGLFW(props); } namespace Platform { - static uint p_glfw_initialized = 0; + static uint p_glfw_Initialized = 0; static void glfw_error_callback(int error, const char* description) { @@ -23,35 +23,35 @@ namespace Bk { p_data.title = props.title; p_data.width = props.width; p_data.height = props.height; - init(); + Init(); } WinGLFW::~WinGLFW() { delete context; - close(); + Close(); } - void WinGLFW::init() + void WinGLFW::Init() { - h_is_open = true; + h_IsOpen = true; BK_CORE_INFO("Creating window : {0} ({1}, {2})", p_data.title, p_data.width, p_data.height); - if (!p_glfw_initialized++) + if (!p_glfw_Initialized++) { int success = glfwInit(); - BK_CORE_MSG_ASSERT(success, "Couldn't initialize glfw!") + BK_CORE_MSG_ASSERT(success, "Couldn't Initialize glfw!") glfwSetErrorCallback(glfw_error_callback); } p_window = glfwCreateWindow((int)p_data.width, (int)p_data.height, p_data.title.c_str(), nullptr, nullptr); context = new OpenglContext(p_window); - context->init(); + context->Init(); glfwSetWindowUserPointer(p_window, &p_data); - set_vsync(true); + SetVsync(true); - init_event_callbacks(); + InitEventCallbacks(); } - void WinGLFW::init_event_callbacks() + void WinGLFW::InitEventCallbacks() { glfwSetFramebufferSizeCallback(p_window, [](GLFWwindow* window, int width, int height) { @@ -125,24 +125,24 @@ namespace Bk { }); } - void WinGLFW::on_update() + void WinGLFW::OnUpdate() { glfwPollEvents(); - context->swap_buffers(); - if (h_is_open) + context->SwapBuffers(); + if (h_IsOpen) { - if (p_shutdown && h_is_open) { shutdown(); } + if (p_Shutdown && h_IsOpen) { Shutdown(); } } } - void WinGLFW::set_event_callback(const EventCallback callback) + void WinGLFW::SetEventCallback(const EventCallback callback) { p_data.callback = callback; } - void WinGLFW::set_vsync(bool enable) + void WinGLFW::SetVsync(bool enable) { - if (h_is_open) + if (h_IsOpen) { if (enable) { glfwSwapInterval(1); } else { glfwSwapInterval(0); } @@ -150,28 +150,28 @@ namespace Bk { } } - bool WinGLFW::is_vsync() const + bool WinGLFW::IsVsync() const { return p_data.vsync; } - void WinGLFW::shutdown() + void WinGLFW::Shutdown() { - h_is_open = false; - p_shutdown = false; + h_IsOpen = false; + p_Shutdown = false; glfwDestroyWindow(p_window); } - void WinGLFW::close() + void WinGLFW::Close() { - p_shutdown = true; + p_Shutdown = true; } - void WinGLFW::open() + void WinGLFW::Open() { - if (!h_is_open) + if (!h_IsOpen) { - init(); + Init(); } } diff --git a/src/platforms/glfw/glfw_window.h b/src/platforms/glfw/glfw_window.h index 90bf705..68774f8 100644 --- a/src/platforms/glfw/glfw_window.h +++ b/src/platforms/glfw/glfw_window.h @@ -13,27 +13,27 @@ namespace Bk::Platform { WinGLFW(const WindowProps& props); virtual ~WinGLFW(); - inline uint get_width() const override { return p_data.width; } - inline uint get_height() const override { return p_data.height; } + inline uint GetWidth() const override { return p_data.width; } + inline uint GetHeight() const override { return p_data.height; } - void on_update() override; - void set_event_callback(const EventCallback callback) override; + void OnUpdate() override; + void SetEventCallback(const EventCallback callback) override; - void set_vsync(bool enable) override; - bool is_vsync() const override; + void SetVsync(bool enable) override; + bool IsVsync() const override; - void close() override; - void open() override; + void Close() override; + void Open() override; - void* get_native_window() override { return p_window; } - /*! \fn Bk::Window::is_open - Indicates if the window is opened + void* GetNativeWindow() override { return p_window; } + /*! \fn Bk::Window::IsOpen + Indicates if the window is Opened @return Open flag */ - bool is_open() override { return h_is_open; } + bool IsOpen() override { return h_IsOpen; } private: - bool h_is_open; //!< indicaste if the window is opened or not - bool p_shutdown; + bool h_IsOpen; //!< indicaste if the window is Opened or not + bool p_Shutdown; GLFWwindow* p_window; OpenglContext* context; @@ -47,8 +47,8 @@ namespace Bk::Platform { }; WindowData p_data; - void init_event_callbacks(); - void init(); - void shutdown(); + void InitEventCallbacks(); + void Init(); + void Shutdown(); }; } \ No newline at end of file diff --git a/src/platforms/opengl/opengl_context.cpp b/src/platforms/opengl/opengl_context.cpp index 36170e3..b472d98 100644 --- a/src/platforms/opengl/opengl_context.cpp +++ b/src/platforms/opengl/opengl_context.cpp @@ -7,7 +7,7 @@ namespace Bk::Platform OpenglContext::OpenglContext(GLFWwindow* window_handle) : window_handle(window_handle) {} - void OpenglContext::init() + void OpenglContext::Init() { glfwMakeContextCurrent(window_handle); int success = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); @@ -19,7 +19,7 @@ namespace Bk::Platform BK_CORE_INFO("Opengl Version : {0}.{1}", majVers, minVers); } - void OpenglContext::swap_buffers() + void OpenglContext::SwapBuffers() { glfwSwapBuffers(window_handle); } diff --git a/src/platforms/opengl/opengl_context.h b/src/platforms/opengl/opengl_context.h index 94714a3..383e37f 100644 --- a/src/platforms/opengl/opengl_context.h +++ b/src/platforms/opengl/opengl_context.h @@ -11,8 +11,8 @@ namespace Bk::Platform { public: OpenglContext(GLFWwindow* window_handle); - void init() override; - void swap_buffers() override; + void Init() override; + void SwapBuffers() override; private: GLFWwindow* window_handle; };