From 1c3d8189e86f9cc52877e6ac0be1f2e9307b58bc Mon Sep 17 00:00:00 2001 From: chatlanin Date: Wed, 4 Oct 2023 14:04:03 +0300 Subject: [PATCH] fix some tasks and rebase code --- src/sandbox/layers/test_panel/test_panel.cpp | 12 ++-- src/sandbox/layers/test_panel/test_panel.hpp | 10 +-- src/sandbox/sandbox.hpp | 6 +- src/try_engine/application/application.cpp | 28 ++++----- src/try_engine/application/application.hpp | 15 ++--- src/try_engine/event/event_classificator.hpp | 4 +- .../event/system_event/category/key_event.hpp | 14 +++-- .../system_event/category/mouse_event.hpp | 7 +-- .../system_event/category/window_event.hpp | 24 +++---- src/try_engine/event/system_event/event.hpp | 1 - src/try_engine/gui/gui.cpp | 2 + src/try_engine/gui/gui.hpp | 2 +- src/try_engine/gui/style/fonts.hpp | 3 +- src/try_engine/layer/layer.hpp | 5 +- src/try_engine/renderer/renderer.hpp | 2 +- src/try_engine/renderer/texture/texture.cpp | 12 ++-- src/try_engine/renderer/texture/texture.hpp | 10 +-- src/try_engine/try_engine.hpp | 6 +- src/try_engine/utils/define.hpp | 8 +-- src/try_engine/utils/include.hpp | 19 ------ .../utils/{timestap.hpp => time.hpp} | 13 ++++ src/try_engine/utils/using.hpp | 14 +++++ src/try_engine/utils/utils.hpp | 5 ++ .../graphic_context/graphic_context.cpp | 6 +- .../graphic_context/graphic_context.hpp | 9 +-- src/try_engine/window/window.cpp | 63 +++++++++---------- src/try_engine/window/window.hpp | 34 +++++----- 27 files changed, 173 insertions(+), 161 deletions(-) rename src/try_engine/utils/{timestap.hpp => time.hpp} (59%) mode change 100755 => 100644 create mode 100644 src/try_engine/utils/using.hpp create mode 100644 src/try_engine/utils/utils.hpp diff --git a/src/sandbox/layers/test_panel/test_panel.cpp b/src/sandbox/layers/test_panel/test_panel.cpp index 55b1701..9b418a5 100755 --- a/src/sandbox/layers/test_panel/test_panel.cpp +++ b/src/sandbox/layers/test_panel/test_panel.cpp @@ -1,7 +1,5 @@ #include "test_panel.hpp" -#include "try_engine/utils/keycode.hpp" - namespace tr::layers { void test_panel::on_attach() @@ -16,22 +14,22 @@ namespace tr::layers void test_panel::gui_render() { - ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y)); - ImGui::SetNextWindowSize(ImVec2(width, height)); + ImGui::SetNextWindowPos(ImVec2(m_pos_x, m_pos_y)); + ImGui::SetNextWindowSize(ImVec2(m_width, m_height)); BEGIN_IMGUI_WIN("test_win"); if (ImGui::Button("RUN", ImVec2(28, 30))) { - em->execute(std::string("asdf"), "asdf"); + m_event_manager->execute(std::string("test signal key"), "value params run"); } TR_PUSH_FONT(ICON, 18); if (ImGui::Button(try_engine::style::icon::ICON_STOP, ImVec2(28, 30))) { - em->execute(std::string("asdf"), "asdf"); + m_event_manager->execute(std::string("test signal key"), "value paramsl stop"); } - // ImGui::Text(try_engine::style::icon::ICON_PAINT_BRUSH " Paint" ); + ImGui::Text(try_engine::style::icon::ICON_PAINT_BRUSH, " Paint" ); ImGui::Text("\xef\x87\xbc"); TR_POP_FONT(); diff --git a/src/sandbox/layers/test_panel/test_panel.hpp b/src/sandbox/layers/test_panel/test_panel.hpp index 3cf73d1..37a8c36 100755 --- a/src/sandbox/layers/test_panel/test_panel.hpp +++ b/src/sandbox/layers/test_panel/test_panel.hpp @@ -9,13 +9,13 @@ namespace tr::layers BASE_IMPL(test_panel); private: - bool show = true; + bool m_open = true; - float width = 720.f; - float height = 480.f; + float m_width = 720.f; + float m_height = 480.f; - float pos_x = 212.f; - float pos_y = 35.f; + float m_pos_x = 212.f; + float m_pos_y = 35.f; }; } diff --git a/src/sandbox/sandbox.hpp b/src/sandbox/sandbox.hpp index dd0eabc..2b72d65 100755 --- a/src/sandbox/sandbox.hpp +++ b/src/sandbox/sandbox.hpp @@ -1,5 +1,3 @@ -#include "try_engine/try_engine.hpp" - #include "layers/test_panel/test_panel.hpp" namespace try_engine_sandbox @@ -16,12 +14,12 @@ namespace try_engine_sandbox template void push_layer(Args... args) { - (args->set_event_manager(&em), ...); + (args->set_event_manager(&m_event_manager), ...); try_engine::application::push_layer(args...); } private: - event_manager em; + event_manager m_event_manager; }; } diff --git a/src/try_engine/application/application.cpp b/src/try_engine/application/application.cpp index a07c5a8..1efa1db 100755 --- a/src/try_engine/application/application.cpp +++ b/src/try_engine/application/application.cpp @@ -1,6 +1,6 @@ #include "application.hpp" -#include "try_engine/utils/define.hpp" +#include "try_engine/utils/utils.hpp" namespace try_engine { @@ -8,33 +8,33 @@ namespace try_engine { instance = std::unique_ptr(this); - win = std::make_unique(app_name); - win->set_event_callback(BIND_EVENT_FN(application, on_event)); + m_win = std::make_unique(app_name); + m_win->set_event_callback(BIND_EVENT_FN(application, on_event)); - ui = std::make_unique(); + m_gui = std::make_unique(); } void application::run() { - while(!glfwWindowShouldClose(win->glfw_window())) + while(!glfwWindowShouldClose(m_win->glfw_window())) { - win->clear(); + m_win->clear(); - for (auto l : l_stack) + for (auto l : m_layers_stack) l->on_update(time::get_time()); - ui->begin_frame(); - for (auto l : l_stack) + m_gui->begin_frame(); + for (auto l : m_layers_stack) l->gui_render(); - ui->end_frame(); + m_gui->end_frame(); - win->update(); + m_win->update(); } } std::unique_ptr& application::get_window() { - return win; + return m_win; } std::unique_ptr& application::get() @@ -44,11 +44,11 @@ namespace try_engine void application::attach_layers() { - for (auto l : l_stack) l->on_attach(); + for (auto l : m_layers_stack) l->on_attach(); } void application::on_event(system_event::event& e) { - for(const auto l : l_stack) l->on_event(e); + for(const auto l : m_layers_stack) l->on_event(e); } } diff --git a/src/try_engine/application/application.hpp b/src/try_engine/application/application.hpp index 2cb04af..b4e1b38 100755 --- a/src/try_engine/application/application.hpp +++ b/src/try_engine/application/application.hpp @@ -14,6 +14,13 @@ namespace try_engine application(std::string); virtual ~application() = default; + private: + inline static std::unique_ptr instance = nullptr; + std::unique_ptr m_win; + layers_stack m_layers_stack; + std::unique_ptr m_gui; + + public: void run(); void attach_layers(); @@ -22,16 +29,10 @@ namespace try_engine public: template - void push_layer(Args*... args) { (l_stack.push_back(args), ...); } - - private: - inline static std::unique_ptr instance = nullptr; - std::unique_ptr win; - layers_stack l_stack; + void push_layer(Args*... args) { (m_layers_stack.push_back(args), ...); } private: void clear(); - std::unique_ptr ui; void on_event(system_event::event& e); }; diff --git a/src/try_engine/event/event_classificator.hpp b/src/try_engine/event/event_classificator.hpp index 45c549b..4aba35d 100755 --- a/src/try_engine/event/event_classificator.hpp +++ b/src/try_engine/event/event_classificator.hpp @@ -1,9 +1,11 @@ #pragma once -#include "try_engine/utils/include.hpp" +#include "try_engine/utils/utils.hpp" namespace try_engine::system_event::classificator { + // HERE + // переменныейц вынести в кофиг inline std::string WINDOW_RESIZE() { return "WINDOW_RESIZE"; } inline std::string WINDOW_CLOSE() { return "WINDOW_CLOSE"; } inline std::string WINDOW_FOCUS() { return "WINDOW_FOCUS"; } diff --git a/src/try_engine/event/system_event/category/key_event.hpp b/src/try_engine/event/system_event/category/key_event.hpp index 99c0faf..961f884 100755 --- a/src/try_engine/event/system_event/category/key_event.hpp +++ b/src/try_engine/event/system_event/category/key_event.hpp @@ -1,6 +1,6 @@ #pragma once -#include "try_engine/utils/define.hpp" +#include "try_engine/utils/utils.hpp" #include "try_engine/event/system_event/event.hpp" #include "try_engine/event/event_classificator.hpp" @@ -8,14 +8,16 @@ namespace try_engine::system_event { class key_event : public event { + // HERE + // ??? protected: - key_event(int kc) : keycode { kc } {} + key_event(int kc) : m_keycode { kc } {} + + protected: + int m_keycode; public: - inline int get_keycode() const { return keycode; } - - protected: - int keycode; + inline int get_keycode() const { return m_keycode; } }; class key_pressed_event : public key_event diff --git a/src/try_engine/event/system_event/category/mouse_event.hpp b/src/try_engine/event/system_event/category/mouse_event.hpp index 5a48baf..23b36a8 100755 --- a/src/try_engine/event/system_event/category/mouse_event.hpp +++ b/src/try_engine/event/system_event/category/mouse_event.hpp @@ -1,16 +1,11 @@ #pragma once -#include "try_engine/utils/define.hpp" +#include "try_engine/utils/utils.hpp" #include "try_engine/event/system_event/event.hpp" #include "try_engine/event/event_classificator.hpp" namespace try_engine::system_event { - - - // Разобрать и привести в порядок по подобию - // key_event.hpp - // // class MouseMovedEvent : public Event // { // public: diff --git a/src/try_engine/event/system_event/category/window_event.hpp b/src/try_engine/event/system_event/category/window_event.hpp index 8ae1524..7e3433f 100755 --- a/src/try_engine/event/system_event/category/window_event.hpp +++ b/src/try_engine/event/system_event/category/window_event.hpp @@ -1,6 +1,6 @@ #pragma once -#include "try_engine/utils/define.hpp" +#include "try_engine/utils/utils.hpp" #include "try_engine/event/system_event/event.hpp" #include "try_engine/event/event_classificator.hpp" @@ -9,17 +9,17 @@ namespace try_engine::system_event class window_resize_event : public event { public: - window_resize_event(int w, int h) : width { w }, height { h } {} + window_resize_event(int w, int h) : m_width { w }, m_height { h } {} + + private: + int m_width, m_height; public: EVENT_CLASS_TYPE_FN(classificator::WINDOW_RESIZE()) public: - inline unsigned int get_width() const { return width; } - inline unsigned int get_height() const { return height; } - - private: - int width, height; + inline unsigned int get_width() const { return m_width; } + inline unsigned int get_height() const { return m_height; } }; class window_close_event : public event @@ -34,16 +34,16 @@ namespace try_engine::system_event class window_focus_event : public event { public: - window_focus_event(int f) : focused { f } {} + window_focus_event(int f) : m_focused { f } {} + + private: + int m_focused; public: EVENT_CLASS_TYPE_FN(classificator::WINDOW_FOCUS()) public: - inline int get_focused() { return focused; } - - private: - int focused; + inline int get_focused() { return m_focused; } }; } diff --git a/src/try_engine/event/system_event/event.hpp b/src/try_engine/event/system_event/event.hpp index 00a66f5..050cef1 100755 --- a/src/try_engine/event/system_event/event.hpp +++ b/src/try_engine/event/system_event/event.hpp @@ -8,7 +8,6 @@ namespace try_engine::system_event { event() = default; virtual ~event() = default; - virtual std::string get_name() const = 0; }; } diff --git a/src/try_engine/gui/gui.cpp b/src/try_engine/gui/gui.cpp index 805a667..c9f624d 100755 --- a/src/try_engine/gui/gui.cpp +++ b/src/try_engine/gui/gui.cpp @@ -7,6 +7,8 @@ namespace try_engine { gui::gui() { + // HERE + // откуда она ??? IMGUI_CHECKVERSION(); ImGui::CreateContext(); diff --git a/src/try_engine/gui/gui.hpp b/src/try_engine/gui/gui.hpp index 7344ddc..f588c1f 100755 --- a/src/try_engine/gui/gui.hpp +++ b/src/try_engine/gui/gui.hpp @@ -1,6 +1,6 @@ #pragma once -#include "try_engine/utils/include.hpp" +#include "try_engine/utils/utils.hpp" namespace try_engine { diff --git a/src/try_engine/gui/style/fonts.hpp b/src/try_engine/gui/style/fonts.hpp index c8207a3..1a1697a 100755 --- a/src/try_engine/gui/style/fonts.hpp +++ b/src/try_engine/gui/style/fonts.hpp @@ -11,8 +11,7 @@ namespace try_engine::style::fonts { inline std::string font_name = "Montserrat/Montserrat-"; - inline std::vector font_size = { 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, - 16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f }; + inline std::vector font_size = { 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, 16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f }; enum font_type { diff --git a/src/try_engine/layer/layer.hpp b/src/try_engine/layer/layer.hpp index b7b2801..3c4d375 100755 --- a/src/try_engine/layer/layer.hpp +++ b/src/try_engine/layer/layer.hpp @@ -1,6 +1,6 @@ #pragma once -#include "try_engine/utils/include.hpp" +#include "try_engine/utils/utils.hpp" #include "try_engine/event/system_event/event.hpp" namespace try_engine @@ -16,6 +16,9 @@ namespace try_engine layer(const layer&) = delete; layer(layer&) = delete; + // HERE + // реализовать перемещение слоев + public: virtual void on_attach() {}; virtual void on_detach() {}; diff --git a/src/try_engine/renderer/renderer.hpp b/src/try_engine/renderer/renderer.hpp index d2dc5d5..0ac941d 100755 --- a/src/try_engine/renderer/renderer.hpp +++ b/src/try_engine/renderer/renderer.hpp @@ -1,6 +1,6 @@ #pragma once -#include "try_engine/utils/include.hpp" +#include "try_engine/utils/utils.hpp" /* renderer - некий объект отрисовки и разукраски всей сцены. diff --git a/src/try_engine/renderer/texture/texture.cpp b/src/try_engine/renderer/texture/texture.cpp index 1738a56..ad40785 100755 --- a/src/try_engine/renderer/texture/texture.cpp +++ b/src/try_engine/renderer/texture/texture.cpp @@ -4,15 +4,15 @@ namespace try_engine { texture::~texture() { - glDeleteTextures(1, &texture_id); + glDeleteTextures(1, &m_texture_id); } void texture::make() { - if (!texture_id) + if (!m_texture_id) { - glGenTextures(1, &texture_id); - glBindTexture(GL_TEXTURE_2D, texture_id); + glGenTextures(1, &m_texture_id); + glBindTexture(GL_TEXTURE_2D, m_texture_id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); @@ -21,12 +21,12 @@ namespace try_engine void texture::clear() { - glDeleteTextures(1, &texture_id); + glDeleteTextures(1, &m_texture_id); } void texture::draw(ImVec2 pos, ImVec2 size) { // ImGui::Image(reinterpret_cast(static_cast(texture)), ImVec2(pos.x + 100, pos.y + 100)); - ImGui::GetWindowDrawList()->AddImage(reinterpret_cast(static_cast(texture_id)), pos, size); + ImGui::GetWindowDrawList()->AddImage(reinterpret_cast(static_cast(m_texture_id)), pos, size); } } diff --git a/src/try_engine/renderer/texture/texture.hpp b/src/try_engine/renderer/texture/texture.hpp index 74853eb..cdffce3 100755 --- a/src/try_engine/renderer/texture/texture.hpp +++ b/src/try_engine/renderer/texture/texture.hpp @@ -1,6 +1,6 @@ #pragma once -#include "try_engine/utils/include.hpp" +#include "try_engine/utils/utils.hpp" namespace try_engine { @@ -9,7 +9,10 @@ namespace try_engine public: texture() = default; ~texture(); - + + private: + GLuint m_texture_id = 0; + public: template void bind(Image& image) @@ -23,9 +26,6 @@ namespace try_engine void draw(ImVec2 pos, ImVec2 size); void make(); void clear(); - - private: - GLuint texture_id = 0; }; } diff --git a/src/try_engine/try_engine.hpp b/src/try_engine/try_engine.hpp index 3c56310..ac5d033 100755 --- a/src/try_engine/try_engine.hpp +++ b/src/try_engine/try_engine.hpp @@ -1,9 +1,6 @@ #pragma once -#include "try_engine/utils/include.hpp" -#include "try_engine/utils/timestap.hpp" -#include "try_engine/utils/define.hpp" -#include "try_engine/utils/keycode.hpp" +#include "try_engine/utils/utils.hpp" #include "try_engine/gui/style/style.hpp" @@ -17,4 +14,3 @@ #include "try_engine/renderer/renderer.hpp" #include "try_engine/renderer/texture/texture.hpp" - diff --git a/src/try_engine/utils/define.hpp b/src/try_engine/utils/define.hpp index b81f47a..ce4fec1 100755 --- a/src/try_engine/utils/define.hpp +++ b/src/try_engine/utils/define.hpp @@ -26,10 +26,10 @@ if (f.no_bring_to_front) window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus #define SET_EVENT_MANAGER_IMPL()\ - void set_event_manager(event_manager* em_)\ + void set_event_manager(event_manager* in_event_manager)\ {\ - em = em_;\ - em->set_event_callback(this);\ + m_event_manager = in_event_manager;\ + m_event_manager->set_event_callback(this);\ } #define BASE_OVERIDE_IMPL()\ @@ -73,7 +73,7 @@ private:\ FLAGS_STRUCT_DEFINED();\ private:\ - event_manager* em + event_manager* m_event_manager #define BEGIN_IMGUI_WIN(name) if (!ImGui::Begin(name, &f.p_open, window_flags)) ImGui::End() diff --git a/src/try_engine/utils/include.hpp b/src/try_engine/utils/include.hpp index 7a129f9..58d2185 100755 --- a/src/try_engine/utils/include.hpp +++ b/src/try_engine/utils/include.hpp @@ -17,23 +17,4 @@ #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" -#include "timestap.hpp" - -template -using event_callback = std::function; - #include "nlohmann/json.hpp" -using JSON = nlohmann::json; - -namespace try_engine::time -{ - inline timestep get_time() - { - static float frame_time = 0.0f; - float t = (float)glfwGetTime(); - timestep ts = t - frame_time; - frame_time = t; - - return ts; - } -} diff --git a/src/try_engine/utils/timestap.hpp b/src/try_engine/utils/time.hpp old mode 100755 new mode 100644 similarity index 59% rename from src/try_engine/utils/timestap.hpp rename to src/try_engine/utils/time.hpp index 12e5ccb..7058edf --- a/src/try_engine/utils/timestap.hpp +++ b/src/try_engine/utils/time.hpp @@ -1,5 +1,7 @@ #pragma once +#include "using.hpp" + namespace try_engine::time { template @@ -18,5 +20,16 @@ namespace try_engine::time }; } +namespace try_engine::time +{ + inline timestep get_time() + { + static float frame_time = 0.0f; + float t = (float)glfwGetTime(); + timestep ts = t - frame_time; + frame_time = t; + return ts; + } +} diff --git a/src/try_engine/utils/using.hpp b/src/try_engine/utils/using.hpp new file mode 100644 index 0000000..be81501 --- /dev/null +++ b/src/try_engine/utils/using.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "include.hpp" + +namespace try_engine +{ + template + using event_callback = std::function; + + using JSON = nlohmann::json; +} + + + diff --git a/src/try_engine/utils/utils.hpp b/src/try_engine/utils/utils.hpp new file mode 100644 index 0000000..096df16 --- /dev/null +++ b/src/try_engine/utils/utils.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include "keycode.hpp" +#include "define.hpp" +#include "time.hpp" diff --git a/src/try_engine/window/graphic_context/graphic_context.cpp b/src/try_engine/window/graphic_context/graphic_context.cpp index 9b0e04e..310e52c 100755 --- a/src/try_engine/window/graphic_context/graphic_context.cpp +++ b/src/try_engine/window/graphic_context/graphic_context.cpp @@ -2,11 +2,11 @@ namespace try_engine { - graphic_context::graphic_context(GLFWwindow* w) : win { w } {} + graphic_context::graphic_context(GLFWwindow* w) : m_win { w } {} void graphic_context::init() { - glfwMakeContextCurrent(win); + glfwMakeContextCurrent(m_win); int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); hack::log(": ")("Glad loader status", status == 1 ? "true" : "false"); @@ -21,7 +21,7 @@ namespace try_engine void graphic_context::swap_buffers() { - glfwSwapBuffers(win); + glfwSwapBuffers(m_win); } } diff --git a/src/try_engine/window/graphic_context/graphic_context.hpp b/src/try_engine/window/graphic_context/graphic_context.hpp index 69e7366..b846097 100755 --- a/src/try_engine/window/graphic_context/graphic_context.hpp +++ b/src/try_engine/window/graphic_context/graphic_context.hpp @@ -1,6 +1,6 @@ #pragma once -#include "try_engine/utils/include.hpp" +#include "try_engine/utils/utils.hpp" namespace try_engine { @@ -9,10 +9,11 @@ namespace try_engine public: graphic_context(GLFWwindow*); + private: + GLFWwindow* m_win; + + public: void init(); void swap_buffers(); - - private: - GLFWwindow* win; }; } diff --git a/src/try_engine/window/window.cpp b/src/try_engine/window/window.cpp index b0b0ca8..e382706 100755 --- a/src/try_engine/window/window.cpp +++ b/src/try_engine/window/window.cpp @@ -1,6 +1,5 @@ #include "window.hpp" -#include "GLFW/glfw3.h" #include "renderer/renderer.hpp" #include "event/system_event/category/key_event.hpp" #include "event/system_event/category/window_event.hpp" @@ -12,7 +11,7 @@ namespace try_engine if (!glfwInit()) exit(EXIT_FAILURE); - win_data.title = app_name; + m_window_data.m_name = app_name; set_hint(); set_window(); @@ -21,16 +20,16 @@ namespace try_engine set_key_callback(); set_window_callback(); - hack::log(": ")("Creating window", win_data.title); - hack::log(" = ")("w", win_data.width); - hack::log(" = ")("h", win_data.height); + hack::log(": ")("Creating window", m_window_data.m_name); + hack::log(" = ")("w", m_window_data.m_width); + hack::log(" = ")("h", m_window_data.m_height); } window::~window() { - glfwDestroyWindow(win); + glfwDestroyWindow(m_win); glfwTerminate(); - hack::warn(": ")("destroy", "window", win_data.title); + hack::warn(": ")("destroy", "window", m_window_data.m_name); } void window::set_hint() @@ -44,58 +43,58 @@ namespace try_engine void window::set_window() { - win = glfwCreateWindow( + m_win = glfwCreateWindow( glfwGetVideoMode(glfwGetPrimaryMonitor())->width, glfwGetVideoMode(glfwGetPrimaryMonitor())->height, - win_data.title.c_str(), + m_window_data.m_name.c_str(), nullptr, nullptr ); - if(win == NULL) + if(m_win == NULL) { hack::error()("Failed to create GLFW window"); glfwTerminate(); exit(EXIT_FAILURE); } - glfwGetWindowSize(win, &win_data.width, &win_data.height); + glfwGetWindowSize(m_win, &m_window_data.m_width, &m_window_data.m_height); } void window::set_context() { - context = std::make_unique(win); - context->init(); + m_graphic_context = std::make_unique(m_win); + m_graphic_context->init(); } void window::set_pointer() { - glfwSetWindowUserPointer(win, &win_data); + glfwSetWindowUserPointer(m_win, &m_window_data); } void window::set_event_callback(const event_callback& cb) { - win_data.callback = cb; + m_window_data.on_callback = cb; } GLFWwindow* window::glfw_window() const { - return win; + return m_win; } int window::width() const { - return win_data.width; + return m_window_data.m_width; } int window::height() const { - return win_data.height; + return m_window_data.m_height; } void window::update() { glfwPollEvents(); - context->swap_buffers(); + m_graphic_context->swap_buffers(); } void window::clear() const @@ -106,7 +105,7 @@ namespace try_engine void window::set_key_callback() { - glfwSetKeyCallback(win, [](GLFWwindow* w, int key, int scancode, int action, int mods) + glfwSetKeyCallback(m_win, [](GLFWwindow* w, int key, int scancode, int action, int mods) { auto data = static_cast(glfwGetWindowUserPointer(w)); @@ -115,19 +114,19 @@ namespace try_engine case GLFW_PRESS: { system_event::key_pressed_event e { key }; - data->callback(e); + data->on_callback(e); break; } case GLFW_RELEASE: { system_event::key_released_event e { key }; - data->callback(e); + data->on_callback(e); break; } case GLFW_REPEAT: { system_event::key_pressed_event e { key }; - data->callback(e); + data->on_callback(e); break; } } @@ -177,30 +176,30 @@ namespace try_engine void window::set_window_callback() { - glfwSetWindowSizeLimits(win, win_data.width, win_data.height, GLFW_DONT_CARE, GLFW_DONT_CARE); + glfwSetWindowSizeLimits(m_win, m_window_data.m_width, m_window_data.m_height, GLFW_DONT_CARE, GLFW_DONT_CARE); - glfwSetWindowSizeCallback(win, [](GLFWwindow* w, int width, int height) + glfwSetWindowSizeCallback(m_win, [](GLFWwindow* w, int width, int height) { auto data = static_cast(glfwGetWindowUserPointer(w)); - data->width = width; - data->height = height; + data->m_width = width; + data->m_height = height; system_event::window_resize_event e { width, height }; - data->callback(e); + data->on_callback(e); }); - glfwSetWindowCloseCallback(win, [](GLFWwindow* w) + glfwSetWindowCloseCallback(m_win, [](GLFWwindow* w) { auto data = static_cast(glfwGetWindowUserPointer(w)); system_event::window_close_event e; - data->callback(e); + data->on_callback(e); }); - glfwSetWindowFocusCallback(win, [](GLFWwindow* w, int focused) + glfwSetWindowFocusCallback(m_win, [](GLFWwindow* w, int focused) { auto data = static_cast(glfwGetWindowUserPointer(w)); system_event::window_focus_event e { focused }; - data->callback(e); + data->on_callback(e); }); } } diff --git a/src/try_engine/window/window.hpp b/src/try_engine/window/window.hpp index 098971a..c6c0f5d 100755 --- a/src/try_engine/window/window.hpp +++ b/src/try_engine/window/window.hpp @@ -1,6 +1,6 @@ #pragma once -#include "try_engine/utils/include.hpp" +#include "try_engine/utils/utils.hpp" #include "graphic_context/graphic_context.hpp" #include "try_engine/event/system_event/event.hpp" @@ -12,6 +12,24 @@ namespace try_engine window(std::string); ~window(); + // HERE + // реализовать остальные конструкторы + + private: + // ни каких unique_ptr тут неполучится + // т.к. glfwCreateWindow maloc-ом выделяет память + // что не есть хорошо для умных указателей + GLFWwindow* m_win; + std::unique_ptr m_graphic_context; + + struct window_data + { + std::string m_name; + int m_width, m_height; + event_callback on_callback; + } m_window_data; + + public: void update(); GLFWwindow* glfw_window() const; @@ -21,20 +39,6 @@ namespace try_engine void set_event_callback(const event_callback&); void set_window_callback(); - private: - // ни каких unique_ptr тут неполучится - // т.к. glfwCreateWindow maloc-ом выделяет память - // что не есть хорошо для умных указателей - GLFWwindow* win; - std::unique_ptr context; - - struct window_data - { - std::string title; - int width, height; - event_callback callback; - } win_data; - private: void set_hint(); void set_window();