From cbdabd3fc2e98be848114229fd8f0b843b25b06c Mon Sep 17 00:00:00 2001 From: Orange Date: Tue, 10 Mar 2026 17:57:11 +0300 Subject: [PATCH] removed useless header --- include/omath/lua/lua.hpp | 9 +++ source/lua/internal.hpp | 17 ---- source/lua/lua.cpp | 2 +- source/lua/lua_color.cpp | 50 ++++++------ source/lua/lua_engines.cpp | 157 ++++++++++++++++++------------------- source/lua/lua_vec2.cpp | 3 +- source/lua/lua_vec3.cpp | 3 +- source/lua/lua_vec4.cpp | 3 +- 8 files changed, 116 insertions(+), 128 deletions(-) delete mode 100644 source/lua/internal.hpp diff --git a/include/omath/lua/lua.hpp b/include/omath/lua/lua.hpp index 4cc0d12..b2112bb 100644 --- a/include/omath/lua/lua.hpp +++ b/include/omath/lua/lua.hpp @@ -10,4 +10,13 @@ namespace omath::lua { void register_lib(lua_State* lua_state); } +namespace omath::lua::detail +{ + void register_vec2(sol::table& omath_table); + void register_vec3(sol::table& omath_table); + void register_vec4(sol::table& omath_table); + void register_color(sol::table& omath_table); + void register_shared_types(sol::table& omath_table); + void register_engines(sol::table& omath_table); +} #endif \ No newline at end of file diff --git a/source/lua/internal.hpp b/source/lua/internal.hpp deleted file mode 100644 index 485faff..0000000 --- a/source/lua/internal.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// -// Created by orange on 07.03.2026. -// -#pragma once -#ifdef OMATH_ENABLE_LUA -#include - -namespace omath::lua::detail -{ - void register_vec2(sol::table& omath_table); - void register_vec3(sol::table& omath_table); - void register_vec4(sol::table& omath_table); - void register_color(sol::table& omath_table); - void register_shared_types(sol::table& omath_table); - void register_engines(sol::table& omath_table); -} -#endif diff --git a/source/lua/lua.cpp b/source/lua/lua.cpp index 200aee1..b1258ce 100644 --- a/source/lua/lua.cpp +++ b/source/lua/lua.cpp @@ -3,7 +3,7 @@ // #ifdef OMATH_ENABLE_LUA #include "lua.hpp" -#include "internal.hpp" +#include #include "omath/lua/lua.hpp" namespace omath::lua diff --git a/source/lua/lua_color.cpp b/source/lua/lua_color.cpp index c56c430..d07c179 100644 --- a/source/lua/lua_color.cpp +++ b/source/lua/lua_color.cpp @@ -2,7 +2,8 @@ // Created by orange on 07.03.2026. // #ifdef OMATH_ENABLE_LUA -#include "internal.hpp" +#include "omath/lua/lua.hpp" +#include #include namespace omath::lua::detail @@ -11,38 +12,35 @@ namespace omath::lua::detail { omath_table.new_usertype( "Color", - sol::factories( - [](float r, float g, float b, float a) { return omath::Color(r, g, b, a); }, - []() { return omath::Color(); }), + sol::factories([](float r, float g, float b, float a) { return omath::Color(r, g, b, a); }, + []() { return omath::Color(); }), - "from_rgba", [](uint8_t r, uint8_t g, uint8_t b, uint8_t a) { - return omath::Color::from_rgba(r, g, b, a); - }, - "from_hsv", sol::overload( - [](float h, float s, float v) { return omath::Color::from_hsv(h, s, v); }, - [](const omath::Hsv& hsv) { return omath::Color::from_hsv(hsv); }), - "red", []() { return omath::Color::red(); }, - "green", []() { return omath::Color::green(); }, - "blue", []() { return omath::Color::blue(); }, + "from_rgba", [](uint8_t r, uint8_t g, uint8_t b, uint8_t a) + { return omath::Color::from_rgba(r, g, b, a); }, "from_hsv", + sol::overload([](float h, float s, float v) { return omath::Color::from_hsv(h, s, v); }, + [](const omath::Hsv& hsv) { return omath::Color::from_hsv(hsv); }), + "red", []() { return omath::Color::red(); }, "green", []() { return omath::Color::green(); }, "blue", + []() { return omath::Color::blue(); }, - "r", sol::property([](const omath::Color& c) { return c.value().x; }), - "g", sol::property([](const omath::Color& c) { return c.value().y; }), - "b", sol::property([](const omath::Color& c) { return c.value().z; }), - "a", sol::property([](const omath::Color& c) { return c.value().w; }), + "r", sol::property([](const omath::Color& c) { return c.value().x; }), "g", + sol::property([](const omath::Color& c) { return c.value().y; }), "b", + sol::property([](const omath::Color& c) { return c.value().z; }), "a", + sol::property([](const omath::Color& c) { return c.value().w; }), - "to_hsv", &omath::Color::to_hsv, - "set_hue", &omath::Color::set_hue, - "set_saturation", &omath::Color::set_saturation, - "set_value", &omath::Color::set_value, - "blend", &omath::Color::blend, + "to_hsv", &omath::Color::to_hsv, "set_hue", &omath::Color::set_hue, "set_saturation", + &omath::Color::set_saturation, "set_value", &omath::Color::set_value, "blend", &omath::Color::blend, sol::meta_function::to_string, &omath::Color::to_string); omath_table.new_usertype( - "Hsv", sol::constructors(), - "hue", sol::property([](const omath::Hsv& h) { return h.hue; }, [](omath::Hsv& h, float val) { h.hue = val; }), - "saturation", sol::property([](const omath::Hsv& h) { return h.saturation; }, [](omath::Hsv& h, float val) { h.saturation = val; }), - "value", sol::property([](const omath::Hsv& h) { return h.value; }, [](omath::Hsv& h, float val) { h.value = val; })); + "Hsv", sol::constructors(), "hue", + sol::property([](const omath::Hsv& h) { return h.hue; }, [](omath::Hsv& h, float val) { h.hue = val; }), + "saturation", + sol::property([](const omath::Hsv& h) { return h.saturation; }, + [](omath::Hsv& h, float val) { h.saturation = val; }), + "value", + sol::property([](const omath::Hsv& h) { return h.value; }, + [](omath::Hsv& h, float val) { h.value = val; })); } } // namespace omath::lua::detail #endif diff --git a/source/lua/lua_engines.cpp b/source/lua/lua_engines.cpp index eafd8c5..2a24c26 100644 --- a/source/lua/lua_engines.cpp +++ b/source/lua/lua_engines.cpp @@ -2,7 +2,8 @@ // Created by orange on 07.03.2026. // #ifdef OMATH_ENABLE_LUA -#include "internal.hpp" +#include "omath/lua/lua.hpp" +#include #include #include #include @@ -11,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -28,14 +28,14 @@ namespace // ---- Canonical shared C++ type aliases ---------------------------------- // Each unique template instantiation must be registered exactly once. - using PitchAngle90 = omath::Angle; - using PitchAngle89 = omath::Angle; + using PitchAngle90 = omath::Angle; + using PitchAngle89 = omath::Angle; using SharedYawRoll = omath::Angle; - using SharedFoV = omath::Angle; - using ViewAngles90 = omath::ViewAngles; - using ViewAngles89 = omath::ViewAngles; + using SharedFoV = omath::Angle; + using ViewAngles90 = omath::ViewAngles; + using ViewAngles89 = omath::ViewAngles; - static std::string projection_error_to_string(omath::projection::Error e) + std::string projection_error_to_string(omath::projection::Error e) { switch (e) { @@ -51,27 +51,16 @@ namespace void register_angle(sol::table& table, const char* name) { table.new_usertype( - name, sol::no_constructor, - "from_degrees", &AngleType::from_degrees, - "from_radians", &AngleType::from_radians, - "as_degrees", &AngleType::as_degrees, - "as_radians", &AngleType::as_radians, - "sin", &AngleType::sin, - "cos", &AngleType::cos, - "tan", &AngleType::tan, - "cot", &AngleType::cot, - sol::meta_function::addition, + name, sol::no_constructor, "from_degrees", &AngleType::from_degrees, "from_radians", + &AngleType::from_radians, "as_degrees", &AngleType::as_degrees, "as_radians", &AngleType::as_radians, + "sin", &AngleType::sin, "cos", &AngleType::cos, "tan", &AngleType::tan, "cot", &AngleType::cot, + sol::meta_function::addition, [](const AngleType& a, const AngleType& b) + { return AngleType::from_degrees(a.as_degrees() + b.as_degrees()); }, sol::meta_function::subtraction, [](const AngleType& a, const AngleType& b) - { return AngleType::from_degrees(a.as_degrees() + b.as_degrees()); }, - sol::meta_function::subtraction, - [](const AngleType& a, const AngleType& b) - { return AngleType::from_degrees(a.as_degrees() - b.as_degrees()); }, - sol::meta_function::unary_minus, + { return AngleType::from_degrees(a.as_degrees() - b.as_degrees()); }, sol::meta_function::unary_minus, [](const AngleType& a) { return AngleType::from_degrees(-a.as_degrees()); }, - sol::meta_function::equal_to, - [](const AngleType& a, const AngleType& b) { return a == b; }, - sol::meta_function::to_string, - [](const AngleType& a) { return std::format("{}deg", a.as_degrees()); }); + sol::meta_function::equal_to, [](const AngleType& a, const AngleType& b) { return a == b; }, + sol::meta_function::to_string, [](const AngleType& a) { return std::format("{}deg", a.as_degrees()); }); } // Set aliases in an engine subtable pointing to the already-registered shared types @@ -83,10 +72,10 @@ namespace else engine_table["PitchAngle"] = types["PitchAngle89"]; - engine_table["YawAngle"] = types["YawRoll"]; - engine_table["RollAngle"] = types["YawRoll"]; + engine_table["YawAngle"] = types["YawRoll"]; + engine_table["RollAngle"] = types["YawRoll"]; engine_table["FieldOfView"] = types["FieldOfView"]; - engine_table["ViewPort"] = types["ViewPort"]; + engine_table["ViewPort"] = types["ViewPort"]; if constexpr (std::is_same_v) engine_table["ViewAngles"] = types["ViewAngles90"]; @@ -100,40 +89,33 @@ namespace { using PitchAngle = typename EngineTraits::PitchAngle; using ViewAngles = typename EngineTraits::ViewAngles; - using Camera = typename EngineTraits::Camera; + using Camera = typename EngineTraits::Camera; auto engine_table = omath_table[subtable_name].get_or_create(); - auto types = omath_table["_types"].get(); + auto types = omath_table["_types"].get(); set_engine_aliases(engine_table, types); engine_table.new_usertype( "Camera", sol::constructors&, const ViewAngles&, - const omath::projection::ViewPort&, - const omath::projection::FieldOfView&, float, float)>(), - "look_at", &Camera::look_at, - "get_forward", &Camera::get_forward, - "get_right", &Camera::get_right, - "get_up", &Camera::get_up, - "get_origin", &Camera::get_origin, - "get_view_angles", &Camera::get_view_angles, - "get_near_plane", &Camera::get_near_plane, - "get_far_plane", &Camera::get_far_plane, - "get_field_of_view", &Camera::get_field_of_view, - "set_origin", &Camera::set_origin, - "set_view_angles", &Camera::set_view_angles, - "set_view_port", &Camera::set_view_port, - "set_field_of_view", &Camera::set_field_of_view, - "set_near_plane", &Camera::set_near_plane, - "set_far_plane", &Camera::set_far_plane, + const omath::projection::ViewPort&, const omath::projection::FieldOfView&, + float, float)>(), + "look_at", &Camera::look_at, "get_forward", &Camera::get_forward, "get_right", &Camera::get_right, + "get_up", &Camera::get_up, "get_origin", &Camera::get_origin, "get_view_angles", + &Camera::get_view_angles, "get_near_plane", &Camera::get_near_plane, "get_far_plane", + &Camera::get_far_plane, "get_field_of_view", &Camera::get_field_of_view, "set_origin", + &Camera::set_origin, "set_view_angles", &Camera::set_view_angles, "set_view_port", + &Camera::set_view_port, "set_field_of_view", &Camera::set_field_of_view, "set_near_plane", + &Camera::set_near_plane, "set_far_plane", &Camera::set_far_plane, "world_to_screen", [](const Camera& cam, const omath::Vector3& pos) -> std::tuple>, sol::optional> { auto result = cam.world_to_screen(pos); - if (result) return {*result, sol::nullopt}; + if (result) + return {*result, sol::nullopt}; return {sol::nullopt, projection_error_to_string(result.error())}; }, @@ -142,7 +124,8 @@ namespace -> std::tuple>, sol::optional> { auto result = cam.screen_to_world(pos); - if (result) return {*result, sol::nullopt}; + if (result) + return {*result, sol::nullopt}; return {sol::nullopt, projection_error_to_string(result.error())}; }); } @@ -153,43 +136,43 @@ namespace { using PitchAngle = omath::opengl_engine::PitchAngle; using ViewAngles = omath::opengl_engine::ViewAngles; - using Camera = omath::opengl_engine::Camera; + using Camera = omath::opengl_engine::Camera; }; struct FrostbiteEngineTraits { using PitchAngle = omath::frostbite_engine::PitchAngle; using ViewAngles = omath::frostbite_engine::ViewAngles; - using Camera = omath::frostbite_engine::Camera; + using Camera = omath::frostbite_engine::Camera; }; struct IWEngineTraits { using PitchAngle = omath::iw_engine::PitchAngle; using ViewAngles = omath::iw_engine::ViewAngles; - using Camera = omath::iw_engine::Camera; + using Camera = omath::iw_engine::Camera; }; struct SourceEngineTraits { using PitchAngle = omath::source_engine::PitchAngle; using ViewAngles = omath::source_engine::ViewAngles; - using Camera = omath::source_engine::Camera; + using Camera = omath::source_engine::Camera; }; struct UnityEngineTraits { using PitchAngle = omath::unity_engine::PitchAngle; using ViewAngles = omath::unity_engine::ViewAngles; - using Camera = omath::unity_engine::Camera; + using Camera = omath::unity_engine::Camera; }; struct UnrealEngineTraits { using PitchAngle = omath::unreal_engine::PitchAngle; using ViewAngles = omath::unreal_engine::ViewAngles; - using Camera = omath::unreal_engine::Camera; + using Camera = omath::unreal_engine::Camera; }; struct CryEngineTraits { using PitchAngle = omath::cry_engine::PitchAngle; using ViewAngles = omath::cry_engine::ViewAngles; - using Camera = omath::cry_engine::Camera; + using Camera = omath::cry_engine::Camera; }; } // namespace @@ -199,44 +182,56 @@ namespace omath::lua::detail { auto t = omath_table["_types"].get_or_create(); - register_angle(t, "PitchAngle90"); - register_angle(t, "PitchAngle89"); + register_angle(t, "PitchAngle90"); + register_angle(t, "PitchAngle89"); register_angle(t, "YawRoll"); - register_angle(t, "FieldOfView"); + register_angle(t, "FieldOfView"); t.new_usertype( - "ViewPort", - sol::factories([](float w, float h) { return omath::projection::ViewPort{w, h}; }), - "width", sol::property([](const omath::projection::ViewPort& vp) { return vp.m_width; }, [](omath::projection::ViewPort& vp, float val) { vp.m_width = val; }), - "height", sol::property([](const omath::projection::ViewPort& vp) { return vp.m_height; }, [](omath::projection::ViewPort& vp, float val) { vp.m_height = val; }), + "ViewPort", sol::factories([](float w, float h) { return omath::projection::ViewPort{w, h}; }), "width", + sol::property([](const omath::projection::ViewPort& vp) { return vp.m_width; }, + [](omath::projection::ViewPort& vp, float val) { vp.m_width = val; }), + "height", + sol::property([](const omath::projection::ViewPort& vp) { return vp.m_height; }, + [](omath::projection::ViewPort& vp, float val) { vp.m_height = val; }), "aspect_ratio", &omath::projection::ViewPort::aspect_ratio); t.new_usertype( "ViewAngles90", - sol::factories([](PitchAngle90 p, SharedYawRoll y, SharedYawRoll r) - { return ViewAngles90{p, y, r}; }), - "pitch", sol::property([](const ViewAngles90& va) { return va.pitch; }, [](ViewAngles90& va, const PitchAngle90& val) { va.pitch = val; }), - "yaw", sol::property([](const ViewAngles90& va) { return va.yaw; }, [](ViewAngles90& va, const SharedYawRoll& val) { va.yaw = val; }), - "roll", sol::property([](const ViewAngles90& va) { return va.roll; }, [](ViewAngles90& va, const SharedYawRoll& val) { va.roll = val; })); + sol::factories([](PitchAngle90 p, SharedYawRoll y, SharedYawRoll r) { return ViewAngles90{p, y, r}; }), + "pitch", + sol::property([](const ViewAngles90& va) { return va.pitch; }, + [](ViewAngles90& va, const PitchAngle90& val) { va.pitch = val; }), + "yaw", + sol::property([](const ViewAngles90& va) { return va.yaw; }, + [](ViewAngles90& va, const SharedYawRoll& val) { va.yaw = val; }), + "roll", + sol::property([](const ViewAngles90& va) { return va.roll; }, + [](ViewAngles90& va, const SharedYawRoll& val) { va.roll = val; })); t.new_usertype( "ViewAngles89", - sol::factories([](PitchAngle89 p, SharedYawRoll y, SharedYawRoll r) - { return ViewAngles89{p, y, r}; }), - "pitch", sol::property([](const ViewAngles89& va) { return va.pitch; }, [](ViewAngles89& va, const PitchAngle89& val) { va.pitch = val; }), - "yaw", sol::property([](const ViewAngles89& va) { return va.yaw; }, [](ViewAngles89& va, const SharedYawRoll& val) { va.yaw = val; }), - "roll", sol::property([](const ViewAngles89& va) { return va.roll; }, [](ViewAngles89& va, const SharedYawRoll& val) { va.roll = val; })); + sol::factories([](PitchAngle89 p, SharedYawRoll y, SharedYawRoll r) { return ViewAngles89{p, y, r}; }), + "pitch", + sol::property([](const ViewAngles89& va) { return va.pitch; }, + [](ViewAngles89& va, const PitchAngle89& val) { va.pitch = val; }), + "yaw", + sol::property([](const ViewAngles89& va) { return va.yaw; }, + [](ViewAngles89& va, const SharedYawRoll& val) { va.yaw = val; }), + "roll", + sol::property([](const ViewAngles89& va) { return va.roll; }, + [](ViewAngles89& va, const SharedYawRoll& val) { va.roll = val; })); } void register_engines(sol::table& omath_table) { - register_engine(omath_table, "opengl"); + register_engine(omath_table, "opengl"); register_engine(omath_table, "frostbite"); - register_engine(omath_table, "iw"); - register_engine(omath_table, "source"); - register_engine(omath_table, "unity"); - register_engine(omath_table, "unreal"); - register_engine(omath_table, "cry"); + register_engine(omath_table, "iw"); + register_engine(omath_table, "source"); + register_engine(omath_table, "unity"); + register_engine(omath_table, "unreal"); + register_engine(omath_table, "cry"); } } // namespace omath::lua::detail #endif diff --git a/source/lua/lua_vec2.cpp b/source/lua/lua_vec2.cpp index bbb9266..ce5614f 100644 --- a/source/lua/lua_vec2.cpp +++ b/source/lua/lua_vec2.cpp @@ -2,7 +2,8 @@ // Created by orange on 07.03.2026. // #ifdef OMATH_ENABLE_LUA -#include "internal.hpp" +#include "omath/lua/lua.hpp" +#include #include namespace omath::lua::detail diff --git a/source/lua/lua_vec3.cpp b/source/lua/lua_vec3.cpp index 11cd2f4..5ddc97e 100644 --- a/source/lua/lua_vec3.cpp +++ b/source/lua/lua_vec3.cpp @@ -2,7 +2,8 @@ // Created by orange on 07.03.2026. // #ifdef OMATH_ENABLE_LUA -#include "internal.hpp" +#include "omath/lua/lua.hpp" +#include #include namespace omath::lua::detail diff --git a/source/lua/lua_vec4.cpp b/source/lua/lua_vec4.cpp index c86e68e..af9637f 100644 --- a/source/lua/lua_vec4.cpp +++ b/source/lua/lua_vec4.cpp @@ -2,7 +2,8 @@ // Created by orange on 07.03.2026. // #ifdef OMATH_ENABLE_LUA -#include "internal.hpp" +#include "omath/lua/lua.hpp" +#include #include namespace omath::lua::detail