Compare commits

...

10 Commits

Author SHA1 Message Date
adbffacd40 update some libs and fix opengl info 2025-09-21 22:54:11 +03:00
27c2e00faa add try catch 2025-06-09 14:58:51 +03:00
0215e46e4f add get result 2025-06-09 14:54:51 +03:00
b5ec861332 fix public 2025-06-09 14:04:00 +03:00
373111a3eb add define event overide 2025-06-09 14:02:34 +03:00
5b9867506c add overide event 2025-06-09 13:59:54 +03:00
677ead1195 add returned event field 2025-06-09 13:54:56 +03:00
1d0bb54fae fix type id 2025-05-31 14:25:23 +03:00
2668ad9944 add event to emnit 2025-05-31 14:08:32 +03:00
bf25408033 add new event id 2025-05-31 13:44:35 +03:00
17 changed files with 131 additions and 184 deletions

View File

@@ -47,14 +47,25 @@ namespace example
if (!ImGui::Begin(VE_NAME("Test signal"), nullptr, m_win_flags)) ImGui::End();
if (ImGui::Button("Test signal", ImVec2(128, 130)))
EMIT(test_event::TEST_EVEN, std::string("test event message"), 1, "test event log msg");
{
VE::event e { test_event::TEST_EVEN_1, std::string("test event 1 message"), "asdf-asdf-asdf" };
EMIT(e);
auto r = e.get_result<std::string>();
hack::log()(r);
e = { test_event::TEST_EVEN_2, std::string("test event 2 message") };
EMIT(e);
r = e.get_result<std::string>();
hack::log()(r);
}
VE_POP_FONT();
ImGui::End();
}
void ui_layer::on_event(VE::event e)
void ui_layer::on_event(VE::event& e)
{
// для событий от перефирии
// if (e.m_type.type() == typeid(VE::event_type))
@@ -67,8 +78,11 @@ namespace example
if (e.m_type.type() == typeid(test_event))
{
auto t = std::any_cast<test_event>(e.m_type);
if (t == test_event::TEST_EVEN)
if (t == test_event::TEST_EVEN_1)
{
hack::log()(std::any_cast<std::string>(e.m_data));
e.m_result = std::string("test_event_1");
}
}
}

View File

@@ -7,6 +7,7 @@ namespace example
class ui_layer : public VE::layer, public VE::flags, public VE::connector
{
VE_OVERIDE();
VE_EVENT_OVERIDE();
ImVec2 m_size = ImVec2{ 400.f, 400.f };
ImVec2 m_pos = ImVec2{ 400.f, 400.f };

View File

@@ -26,7 +26,10 @@ namespace example
VE_PUSH_FONT(REGULAR, 20);
if (ImGui::Button("Test signal_double", ImVec2(128, 130)))
EMIT(test_event::TEST_EVEN, std::string("test event message ui_layer_double"));
{
VE::event e { test_event::TEST_EVEN_2, std::string("test event message ui_layer_double") };
EMIT(e);
}
if (ImGui::Button("Test on_detach", ImVec2(128, 130))) on_detach();
if (ImGui::Button("Test on_attach", ImVec2(128, 130))) on_attach();
@@ -39,7 +42,7 @@ namespace example
ImGui::End();
}
void ui_layer_double::on_event(VE::event e)
void ui_layer_double::on_event(VE::event& e)
{
// для событий от перефирии
// if (e.m_type.type() == typeid(VE::event_type))
@@ -52,8 +55,11 @@ namespace example
if (e.m_type.type() == typeid(test_event))
{
auto t = std::any_cast<test_event>(e.m_type);
if (t == test_event::TEST_EVEN)
if (t == test_event::TEST_EVEN_2)
{
hack::log()(std::any_cast<std::string>(e.m_data));
e.m_result = std::string("test_event_2");
}
}
}

View File

@@ -7,6 +7,7 @@ namespace example
class ui_layer_double : public VE::layer, public VE::flags, public VE::connector
{
VE_OVERIDE();
VE_EVENT_OVERIDE();
ImVec2 m_size = ImVec2{ 400.f, 400.f };
ImVec2 m_pos = ImVec2{ 400.f, 400.f };

View File

@@ -4,6 +4,7 @@ namespace example
{
enum class test_event
{
TEST_EVEN
TEST_EVEN_1,
TEST_EVEN_2
};
}

View File

@@ -30,48 +30,14 @@ namespace VE
}
public:
template <typename TYPE, typename DATA>
static void EMIT(TYPE t, DATA d, int id = -1, std::string msg = "")
{
event e{ t, d, id};
if (msg != "") e.m_event_log_message = msg;
event_manager::instance().emit(e);
}
static void EMIT(event e)
static void EMIT(event& e)
{
event_manager::instance().emit(e);
}
void log()
{
hack::log()("key = ", m_key);
}
virtual void on_event(event& e) {};
private:
std::string m_key;
};
// template <typename T>
// void CONNECT(T* obj)
// {
// event_manager::instance().connect(obj, &T::on_event);
// }
//
// template <typename T>
// void DISCONNECT(T* obj)
// {
// event_manager::instance().disconnect(obj, &T::on_event);
// }
// template <typename TYPE, typename DATA>
// void EMIT(TYPE t, DATA d, int id = -1)
// {
// event_manager::instance().emit(event{ t, d, id});
// }
//
// inline void EMIT(event e)
// {
// event_manager::instance().emit(e);
// }
}

View File

@@ -3,18 +3,38 @@
#include <any>
#include <string>
#include <hack/security/uuid.hpp>
#include <hack/exception/exception.hpp>
#include <hack/logger/logger.hpp>
namespace VE
{
struct event
{
event(std::any type, std::any data, std::size_t id) : m_type{ type }, m_data{ data }, m_id { id } {}
event(std::any type, std::any data, std::string id = hack::security::generate_uuid()) : m_type{ type }, m_data{ data }, m_id { id } {}
~event() = default;
std::any m_type;
std::any m_data;
std::size_t m_id;
std::any m_result;
std::string m_id;
std::string m_event_log_message;
std::string m_event_id = hack::security::generate_uuid();
template<typename T>
T get_result()
{
T r;
try { r = std::any_cast<T>(m_result); }
catch(std::exception& e)
{
hack::exception ex;
ex.service(e.what());
ex.description("dont convert type any_cast");
hack::error()(ex);
throw ex;
}
return r;
}
};
}

View File

@@ -11,7 +11,7 @@ namespace VE
struct event_manager : public hack::patterns::singleton<event_manager>
{
template<typename T>
std::string connect(T* obj, void (T::*method)(event))
std::string connect(T* obj, void (T::*method)(event&))
{
std::string key = hack::security::generate_uuid();
m_funcs[key] = std::bind(method, obj, std::placeholders::_1);
@@ -25,7 +25,7 @@ namespace VE
m_funcs.erase(it);
}
void emit(event e)
void emit(event& e)
{
if (m_funcs.size() == 0)
{
@@ -60,86 +60,3 @@ namespace VE
std::map<std::string, event_fn<event>> m_funcs;
};
}
// #pragma once
//
// #include <functional>
// #include <hack/patterns/singleton.hpp>
// #include <hack/logger/logger.hpp>
// #include <hack/security/uuid.hpp>
// #include <hack/exception/exception.hpp>
//
// #include "event.hpp"
//
// namespace VE
// {
// struct event_manager : public hack::patterns::singleton<event_manager>
// {
// void emit(event e)
// {
// if (m_funcs.size() == 0)
// {
// hack::warn()("funs is empty");
// return;
// }
// else if (!e.m_msg.empty())
// {
// hack::warn()("EMIT MSG:", e.m_msg, m_funcs.size());
// }
//
// std::size_t i = 0;
// try
// {
// for(;i < m_funcs.size();++i) m_funcs[i].m_func(e);
// }
// catch(std::exception& ext)
// {
// hack::error()("call function is error:", ext.what());
// hack::exception ex;
// ex.system_error(ext);
// ex.set_data(e);
// throw ex;
// }
// catch(...)
// {
// hack::error()("call function is error:", "oopps...");
// hack::exception ex;
// ex.set_data(e);
// throw ex;
// }
// }
//
// template<typename T>
// void connect(T* obj, void (T::*method)(event))
// {
// m_funcs.push_back({
// std::bind(method, obj, std::placeholders::_1),
// static_cast<void*>(obj)
// });
// hack::warn()("connect (size)", m_funcs.size());
// }
//
// template<typename T>
// void disconnect(T* obj, void (T::*method)(event))
// {
// m_funcs.erase(
// std::remove_if(m_funcs.begin(), m_funcs.end(),
// [obj](const auto& handler) {
// return handler.m_obj == obj;
// }),
// m_funcs.end()
// );
// hack::warn()("disconnect (size)", m_funcs.size());
// }
//
// struct EventHandler
// {
// std::function<void(event)> m_func;
// void* m_obj;
// };
//
// std::vector<EventHandler> m_funcs;
//
// };
// }

View File

@@ -1,5 +1,7 @@
#include "context.hpp"
#include "vertex_engine/utils/define.hpp" // IWYU pragma: keep
namespace VE
{
context::context(GLFWwindow* w) : m_win { w }
@@ -7,12 +9,12 @@ namespace VE
glfwMakeContextCurrent(m_win);
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
hack::log(": ")("Glad loader status", status == 1 ? "Load" : "UNLOAD");
hack::log(": ")("OpenGL Info");
hack::log(": ")(" Vendor", glGetString(GL_VENDOR));
hack::log(": ")(" Renderer", glGetString(GL_RENDERER));
hack::log(": ")(" Version", glGetString(GL_VERSION));
hack::log(": ")(" GLSL Version", glGetString(GL_SHADING_LANGUAGE_VERSION));
hack::log()("Glad loader status:", status == 1 ? "Load" : "UNLOAD");
hack::log()("OpenGL Info:");
hack::log()(" Vendor:", VE_GLGETSTRING(GL_VENDOR));
hack::log()(" Renderer:", VE_GLGETSTRING(GL_RENDERER));
hack::log()(" Version:", VE_GLGETSTRING(GL_VERSION));
hack::log()(" GLSL Version:", VE_GLGETSTRING(GL_SHADING_LANGUAGE_VERSION));
glfwSwapInterval(1);

View File

@@ -16,7 +16,7 @@ namespace VE
glfw::~glfw()
{
hack::warn(": ")("Destroy glfw window", m_win_data.m_name);
hack::warn()("Destroy glfw window:", m_win_data.m_name);
glfwDestroyWindow(m_win);
glfwTerminate();
}
@@ -67,9 +67,9 @@ namespace VE
glfwGetWindowSize(m_win, &m_win_data.m_width, &m_win_data.m_height);
hack::log(": ")("Created glfw window", m_win_data.m_name);
hack::log(" = ")(" width", m_win_data.m_width);
hack::log(" = ")(" height", m_win_data.m_height);
hack::log()("Created glfw window:", m_win_data.m_name);
hack::log()(" width =", m_win_data.m_width);
hack::log()(" height =", m_win_data.m_height);
}
void glfw::set_graphic_context()
@@ -124,17 +124,20 @@ namespace VE
{
case GLFW_PRESS:
{
connector::EMIT(event_type::KEY_PRESSED, key);
event e { event_type::KEY_PRESSED, key };
connector::EMIT(e);
break;
}
case GLFW_RELEASE:
{
connector::EMIT(event_type::KEY_RELEASED, key);
event e { event_type::KEY_RELEASED, key };
connector::EMIT(e);
break;
}
case GLFW_REPEAT:
{
connector::EMIT(event_type::KEY_REPEATE, key);
event e { event_type::KEY_REPEATE, key };
connector::EMIT(e);
break;
}
}
@@ -155,16 +158,23 @@ namespace VE
std::chrono::duration<double, std::milli> duration = local - time;
if (duration.count() > 10 && duration.count() < 200)
connector::EMIT(event_type::MOUSE_BUTTON_DOUBLE_PRESSED, button);
{
event e { event_type::MOUSE_BUTTON_DOUBLE_PRESSED, button };
connector::EMIT(e);
}
else
connector::EMIT(event_type::MOUSE_BUTTON_PRESSED, button);
{
event e { event_type::MOUSE_BUTTON_PRESSED, button };
connector::EMIT(e);
}
time = local;
break;
}
case GLFW_RELEASE:
{
connector::EMIT(event_type::MOUSE_BUTTON_RELEASED, button);
event e { event_type::MOUSE_BUTTON_RELEASED, button };
connector::EMIT(e);
break;
}
}
@@ -175,7 +185,8 @@ namespace VE
try
{
auto data = std::pair<float, float>{ static_cast<float>(xOffset), static_cast<float>(yOffset) };
connector::EMIT(event_type::MOUSE_SCROLL, data);
event e { event_type::MOUSE_SCROLL, data };
connector::EMIT(e);
}
catch(std::exception& e)
{
@@ -188,7 +199,8 @@ namespace VE
try
{
auto data = std::pair<float, float>{ static_cast<float>(xPos), static_cast<float>(yPos) };
connector::EMIT(event_type::MOUSE_CURSOR_POSITION, data);
event e { event_type::MOUSE_CURSOR_POSITION, data };
connector::EMIT(e);
}
catch(std::exception& e)
{
@@ -210,7 +222,8 @@ namespace VE
try
{
auto data = std::pair<float, float>{ static_cast<float>(width), static_cast<float>(height) };
connector::EMIT(event_type::WINDOW_RESIZE, data);
event e { event_type::WINDOW_RESIZE, data };
connector::EMIT(e);
}
catch(std::exception& e)
{
@@ -222,7 +235,8 @@ namespace VE
{
try
{
connector::EMIT(event_type::WINDOW_CLOSE, nullptr);
event e { event_type::WINDOW_CLOSE, nullptr };
connector::EMIT(e);
}
catch(std::exception& e)
{
@@ -234,7 +248,8 @@ namespace VE
{
try
{
connector::EMIT(event_type::WINDOW_FOCUS, focused);
event e { event_type::WINDOW_FOCUS, focused };
connector::EMIT(e);
}
catch(std::exception& e)
{

View File

@@ -19,7 +19,6 @@ namespace VE
virtual void on_detach() {};
virtual void render() {};
virtual void update() {};
virtual void on_event(event e) {};
protected:
event_fn<event> execute;

View File

@@ -112,10 +112,10 @@ namespace VE
if (compale == GL_FALSE)
{
glGetShaderInfoLog(shader, 1024, NULL, info);
hack::error("")("shader compale error: ", type_to_name(type), info);
hack::error()("shader compale error:", type_to_name(type), info);
return true;
}
hack::log("")("shader compale is good: ", type_to_name(type));
hack::log()("shader compale is good:", type_to_name(type));
return false;
}
}

View File

@@ -3,13 +3,16 @@
#define BIT(x)\
(1 << x)
#define VE_EVENT_OVERIDE()\
public:\
void on_event(VE::event& e) override
#define VE_OVERIDE()\
public:\
void on_attach() override;\
void on_detach() override;\
void render() override;\
void update() override;\
void on_event(VE::event e) override
void update() override
#define VE_PUSH_FONT(def_font, def_size)\
ImGui::PushFont(VE::style::fonts::get_font(VE::style::fonts::font_type::def_font, def_size))
@@ -18,3 +21,4 @@
#define VE_NAME(n) VE::func::name(n).data()
#define VE_COLOR(c, t) VE::func::color(c, t)
#define VE_GLGETSTRING(n) reinterpret_cast<const char*>(glGetString(n))

View File

@@ -5,7 +5,7 @@
namespace VE
{
template<typename Event>
using event_fn = std::function<void(Event)>;
using event_fn = std::function<void(Event&)>;
template<typename Layer>
using layers_stack = std::vector<Layer*>;

18
subprojects/glfw.wrap Executable file → Normal file
View File

@@ -1,13 +1,13 @@
[wrap-file]
directory = glfw-3.3.7
source_url = https://github.com/glfw/glfw/archive/refs/tags/3.3.7.tar.gz
source_filename = glfw-3.3.7.tar.gz
source_hash = fd21a5f65bcc0fc3c76e0f8865776e852de09ef6fbc3620e09ce96d2b2807e04
patch_filename = glfw_3.3.7-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/glfw_3.3.7-1/get_patch
patch_hash = cfc19fedadd1492f1bcf4a7e7604c81398571a696f94f3d18992060caf6b7057
wrapdb_version = 3.3.7-1
directory = glfw-3.4
source_url = https://github.com/glfw/glfw/archive/refs/tags/3.4.tar.gz
source_filename = glfw-3.4.tar.gz
source_hash = c038d34200234d071fae9345bc455e4a8f2f544ab60150765d7704e08f3dac01
patch_filename = glfw_3.4-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/glfw_3.4-1/get_patch
patch_hash = 58a6a6cdb28195d7f7e6f5de85dff7044d378e49b46bf1d4a9b04c97ed93e6b0
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/glfw_3.4-1/glfw-3.4.tar.gz
wrapdb_version = 3.4-1
[provide]
glfw3 = glfw_dep

17
subprojects/glm.wrap Executable file → Normal file
View File

@@ -1,12 +1,13 @@
[wrap-file]
directory = glm-0.9.9.8
source_url = https://github.com/g-truc/glm/archive/0.9.9.8.tar.gz
source_filename = 0.9.9.8.tar.gz
source_hash = 7d508ab72cb5d43227a3711420f06ff99b0a0cb63ee2f93631b162bfe1fe9592
patch_url = https://wrapdb.mesonbuild.com/v2/glm_0.9.9.8-2/get_patch
patch_filename = glm-0.9.9.8-2-wrap.zip
patch_hash = d930a1fcd3a28d84be4e92cc4c71ff59e170a1ebbd3dbfce631eba19e478d83d
directory = glm-1.0.1
source_url = https://github.com/g-truc/glm/archive/refs/tags/1.0.1.tar.gz
source_filename = glm-1.0.1.tar.gz
source_hash = 9f3174561fd26904b23f0db5e560971cbf9b3cbda0b280f04d5c379d03bf234c
patch_filename = glm_1.0.1-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/glm_1.0.1-1/get_patch
patch_hash = 25679275e26bc4c36bb617d1b4a52197039402af828d2a4bf67b3c0260a5df6a
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/glm_1.0.1-1/glm-1.0.1.tar.gz
wrapdb_version = 1.0.1-1
[provide]
glm = glm_dep

View File

@@ -3,11 +3,11 @@ directory = imgui-1.91.6
source_url = https://github.com/ocornut/imgui/archive/refs/tags/v1.91.6.tar.gz
source_filename = imgui-1.91.6.tar.gz
source_hash = c5fbc5dcab1d46064001c3b84d7a88812985cde7e0e9ced03f5677bec1ba502a
patch_filename = imgui_1.91.6-2_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/imgui_1.91.6-2/get_patch
patch_hash = 515e31b18e3928aafce2c62c94fa6d8426f5132e9c3f2d9951b7e96b6381f33a
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/imgui_1.91.6-2/imgui-1.91.6.tar.gz
wrapdb_version = 1.91.6-2
patch_filename = imgui_1.91.6-3_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/imgui_1.91.6-3/get_patch
patch_hash = 2f7977114ba07d06559aaf8890a92a4ebd25186592d4447954605aaf2244634d
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/imgui_1.91.6-3/imgui-1.91.6.tar.gz
wrapdb_version = 1.91.6-3
[provide]
imgui = imgui_dep