From 8ccf468c2a8799454649a2fc5591008f436f02e9 Mon Sep 17 00:00:00 2001 From: mrq Date: Sat, 23 Aug 2025 11:36:36 -0500 Subject: [PATCH] fixes from the slop --- Makefile | 6 +- engine/inc/uf/ext/vulkan/vk.h | 7 -- engine/inc/uf/spec/context/linux.h | 3 + engine/inc/uf/spec/window/linux.h | 14 ++- engine/src/ext/lua/usertypes/quaternion.cpp | 99 --------------------- engine/src/ext/lua/usertypes/vector.cpp | 96 ++++++++++++++++++++ engine/src/ext/openal/openal.cpp | 2 + engine/src/ext/opengl/opengl.cpp | 4 +- engine/src/spec/context/linux.cpp | 6 +- engine/src/spec/window/linux.cpp | 16 ++++ 10 files changed, 140 insertions(+), 113 deletions(-) delete mode 100644 engine/src/ext/lua/usertypes/quaternion.cpp diff --git a/Makefile b/Makefile index 5324f42b..a87ef797 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,11 @@ ifneq (,$(findstring opengl,$(REQ_DEPS))) # OpenGL through GLEW else FLAGS += -DUF_USE_GLEW - DEPS += -lglew32 -lopengl32 -lglu32 + ifneq (,$(findstring linux,$(ARCH))) + DEPS += -lGLU -lglut -lGLEW + else + DEPS += -lglew32 -lopengl32 -lglu32 + endif endif endif diff --git a/engine/inc/uf/ext/vulkan/vk.h b/engine/inc/uf/ext/vulkan/vk.h index 52d4a6a1..5ef31176 100644 --- a/engine/inc/uf/ext/vulkan/vk.h +++ b/engine/inc/uf/ext/vulkan/vk.h @@ -4,13 +4,6 @@ #include #include -#if UF_ENV_LINUX - #ifdef Success - #undef Success - #undef None - #endif -#endif - #include #include #include diff --git a/engine/inc/uf/spec/context/linux.h b/engine/inc/uf/spec/context/linux.h index c0069522..8af7005b 100644 --- a/engine/inc/uf/spec/context/linux.h +++ b/engine/inc/uf/spec/context/linux.h @@ -8,6 +8,9 @@ namespace spec { typedef spec::unknown::Context Context; } #else + +#include + namespace spec { namespace x11 { class UF_API_VAR Context : public spec::uni::Context { diff --git a/engine/inc/uf/spec/window/linux.h b/engine/inc/uf/spec/window/linux.h index 3d64c45b..597b03ef 100644 --- a/engine/inc/uf/spec/window/linux.h +++ b/engine/inc/uf/spec/window/linux.h @@ -11,9 +11,17 @@ #if UF_USE_VULKAN #include - #include + // #include #elif UF_USE_OPENGL - #include + // #include +#endif + +// these macros interfere with other things +#ifdef Success + #undef Success +#endif +#ifdef None + #undef None #endif namespace spec { @@ -47,6 +55,7 @@ namespace spec { void UF_API_CALL create(const vector_t& size, const title_t& title = L"Window"); void UF_API_CALL terminate(); + Display* UF_API_CALL getDisplay() const; handle_t UF_API_CALL getHandle() const; vector_t UF_API_CALL getPosition() const; vector_t UF_API_CALL getSize() const; @@ -91,4 +100,5 @@ namespace spec { namespace uf { using Window = spec::x11::Window; } + #endif \ No newline at end of file diff --git a/engine/src/ext/lua/usertypes/quaternion.cpp b/engine/src/ext/lua/usertypes/quaternion.cpp deleted file mode 100644 index 74f710e5..00000000 --- a/engine/src/ext/lua/usertypes/quaternion.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include -#if UF_USE_LUA -#include - -namespace { - typedef pod::Quaternion<> Quaternion; -} - -namespace binds { - float index( const ::Quaternion& self, size_t index ) { - return self[index]; - } - ::Quaternion lookAt( const pod::Vector3f& at, const pod::Vector3f& up ) { - return uf::quaternion::lookAt( at, up ); - } - ::Quaternion normalize( const ::Quaternion& self ) { - return uf::quaternion::normalize( self ); - } - ::Quaternion multiply( const ::Quaternion& left, const ::Quaternion& right ) { - return uf::quaternion::multiply( left, right ); - } - ::Quaternion axisAngle( sol::object arg, float angle ){ - if ( arg.is() ) { - return uf::quaternion::axisAngle( arg.as(), angle ); - } else if ( arg.is() ) { - sol::table table = arg.as(); - return uf::quaternion::axisAngle( pod::Vector3f{ table[0], table[1], table[2] }, angle ); - } - return ::Quaternion{}; - } - pod::Vector3f rotate( const ::Quaternion& left, const pod::Vector3f& right ) { - return uf::quaternion::rotate( left, right ); - } - ::Quaternion eulerAngles( const ::Quaternion& quaternion ) { - return uf::quaternion::eulerAngles( quaternion ); - } - ::Quaternion conjugate( const ::Quaternion& quaternion ) { - return uf::quaternion::conjugate( quaternion ); - } - ::Quaternion inverse( const ::Quaternion& quaternion ) { - return uf::quaternion::inverse( quaternion ); - } - float pitch( const ::Quaternion& quaternion ) { - return uf::quaternion::pitch( quaternion ); - } - float yaw( const ::Quaternion& quaternion ) { - return uf::quaternion::yaw( quaternion ); - } - float roll( const ::Quaternion& quaternion ) { - return uf::quaternion::roll( quaternion ); - } - ::Quaternion slerp( const ::Quaternion& left, const ::Quaternion& right, float a ) { - return uf::quaternion::slerp( left, right, a ); - } - pod::Matrix4f matrix( const ::Quaternion& q ) { - return uf::quaternion::matrix( q ); - } - uf::stl::string __tostring( const ::Quaternion& self ) { - return uf::string::toString( self ); - } -} - -#include -UF_LUA_REGISTER_USERTYPE_AND_COMPONENT(::Quaternion, - sol::call_constructor, sol::initializers( - []( ::Quaternion& self ) { - return self = {0,0,0,1}; - }, - []( ::Quaternion& self, const ::Quaternion& copy ) { - return self = copy; - }, - []( ::Quaternion& self, float x, float y, float z, float w ) { - return self = uf::vector::create(x, y, z, w); - } - ), - - UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::x), - UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::y), - UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::z), - UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::w), - - UF_LUA_REGISTER_USERTYPE_DEFINE( v, UF_LUA_C_FUN(::binds::index) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( lookAt, UF_LUA_C_FUN(::binds::lookAt) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( normalize, UF_LUA_C_FUN(::binds::normalize) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( multiply, UF_LUA_C_FUN(::binds::multiply) ), - sol::meta_function::multiplication, UF_LUA_C_FUN(::binds::multiply), - UF_LUA_REGISTER_USERTYPE_DEFINE(axisAngle, UF_LUA_C_FUN(::binds::axisAngle) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( rotate, UF_LUA_C_FUN( ::binds::rotate ) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( eulerAngles, UF_LUA_C_FUN( ::binds::eulerAngles ) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( conjugate, UF_LUA_C_FUN( ::binds::conjugate ) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( inverse, UF_LUA_C_FUN( ::binds::inverse ) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( pitch, UF_LUA_C_FUN( ::binds::pitch ) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( yaw, UF_LUA_C_FUN( ::binds::yaw ) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( roll, UF_LUA_C_FUN( ::binds::roll ) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( slerp, UF_LUA_C_FUN( ::binds::slerp ) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( matrix, UF_LUA_C_FUN( ::binds::matrix ) ), - UF_LUA_REGISTER_USERTYPE_DEFINE( __tostring, UF_LUA_C_FUN( ::binds::__tostring ) ) -) -#endif \ No newline at end of file diff --git a/engine/src/ext/lua/usertypes/vector.cpp b/engine/src/ext/lua/usertypes/vector.cpp index e5b67a5d..25ec1e68 100644 --- a/engine/src/ext/lua/usertypes/vector.cpp +++ b/engine/src/ext/lua/usertypes/vector.cpp @@ -1,6 +1,12 @@ #include #if UF_USE_LUA #include +#include + +namespace { + // I don't remember specifically why beyond having the name drop the <> despite it getting culled anyways in last_ns or whatever + typedef pod::Quaternion<> Quaternion; +} namespace binds { namespace v3f { @@ -165,4 +171,94 @@ UF_LUA_REGISTER_USERTYPE_AND_COMPONENT(pod::Vector4f, UF_LUA_REGISTER_USERTYPE_DEFINE( dot, UF_LUA_C_FUN(::binds::v4f::dot) ), UF_LUA_REGISTER_USERTYPE_DEFINE( __tostring, UF_LUA_C_FUN(::binds::v4f::toString) ) ) + +// need to handle quaternions here because it may get initialized after the above on systems where static initialization order is undefined (Linux) +namespace binds { + float index( const ::Quaternion& self, size_t index ) { + return self[index]; + } + ::Quaternion lookAt( const pod::Vector3f& at, const pod::Vector3f& up ) { + return uf::quaternion::lookAt( at, up ); + } + ::Quaternion normalize( const ::Quaternion& self ) { + return uf::quaternion::normalize( self ); + } + ::Quaternion multiply( const ::Quaternion& left, const ::Quaternion& right ) { + return uf::quaternion::multiply( left, right ); + } + ::Quaternion axisAngle( sol::object arg, float angle ){ + if ( arg.is() ) { + return uf::quaternion::axisAngle( arg.as(), angle ); + } else if ( arg.is() ) { + sol::table table = arg.as(); + return uf::quaternion::axisAngle( pod::Vector3f{ table[0], table[1], table[2] }, angle ); + } + return ::Quaternion{}; + } + pod::Vector3f rotate( const ::Quaternion& left, const pod::Vector3f& right ) { + return uf::quaternion::rotate( left, right ); + } + ::Quaternion eulerAngles( const ::Quaternion& quaternion ) { + return uf::quaternion::eulerAngles( quaternion ); + } + ::Quaternion conjugate( const ::Quaternion& quaternion ) { + return uf::quaternion::conjugate( quaternion ); + } + ::Quaternion inverse( const ::Quaternion& quaternion ) { + return uf::quaternion::inverse( quaternion ); + } + float pitch( const ::Quaternion& quaternion ) { + return uf::quaternion::pitch( quaternion ); + } + float yaw( const ::Quaternion& quaternion ) { + return uf::quaternion::yaw( quaternion ); + } + float roll( const ::Quaternion& quaternion ) { + return uf::quaternion::roll( quaternion ); + } + ::Quaternion slerp( const ::Quaternion& left, const ::Quaternion& right, float a ) { + return uf::quaternion::slerp( left, right, a ); + } + pod::Matrix4f matrix( const ::Quaternion& q ) { + return uf::quaternion::matrix( q ); + } + uf::stl::string __tostring( const ::Quaternion& self ) { + return uf::string::toString( self ); + } +} +UF_LUA_REGISTER_USERTYPE_AND_COMPONENT(::Quaternion, + sol::call_constructor, sol::initializers( + []( ::Quaternion& self ) { + return self = {0,0,0,1}; + }, + []( ::Quaternion& self, const ::Quaternion& copy ) { + return self = copy; + }, + []( ::Quaternion& self, float x, float y, float z, float w ) { + return self = uf::vector::create(x, y, z, w); + } + ), + + UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::x), + UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::y), + UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::z), + UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::w), + + UF_LUA_REGISTER_USERTYPE_DEFINE( v, UF_LUA_C_FUN(::binds::index) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( lookAt, UF_LUA_C_FUN(::binds::lookAt) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( normalize, UF_LUA_C_FUN(::binds::normalize) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( multiply, UF_LUA_C_FUN(::binds::multiply) ), + sol::meta_function::multiplication, UF_LUA_C_FUN(::binds::multiply), + UF_LUA_REGISTER_USERTYPE_DEFINE( axisAngle, UF_LUA_C_FUN(::binds::axisAngle) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( rotate, UF_LUA_C_FUN( ::binds::rotate ) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( eulerAngles, UF_LUA_C_FUN( ::binds::eulerAngles ) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( conjugate, UF_LUA_C_FUN( ::binds::conjugate ) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( inverse, UF_LUA_C_FUN( ::binds::inverse ) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( pitch, UF_LUA_C_FUN( ::binds::pitch ) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( yaw, UF_LUA_C_FUN( ::binds::yaw ) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( roll, UF_LUA_C_FUN( ::binds::roll ) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( slerp, UF_LUA_C_FUN( ::binds::slerp ) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( matrix, UF_LUA_C_FUN( ::binds::matrix ) ), + UF_LUA_REGISTER_USERTYPE_DEFINE( __tostring, UF_LUA_C_FUN( ::binds::__tostring ) ) +) #endif \ No newline at end of file diff --git a/engine/src/ext/openal/openal.cpp b/engine/src/ext/openal/openal.cpp index e05186c1..44db20e3 100644 --- a/engine/src/ext/openal/openal.cpp +++ b/engine/src/ext/openal/openal.cpp @@ -209,6 +209,8 @@ void ext::al::close( uf::audio::Metadata& metadata ) { } void ext::al::listener( const pod::Transform<>& transform ) { + if ( uf::audio::muted ) return; + float o[6] = { transform.forward.x, transform.forward.y, transform.forward.z, transform.up.x, transform.up.y, transform.up.z }; AL_CHECK_RESULT(alListener3f( AL_POSITION, transform.position.x, transform.position.y, transform.position.z )); AL_CHECK_RESULT(alListener3f( AL_VELOCITY, 0, 0, 0 )); diff --git a/engine/src/ext/opengl/opengl.cpp b/engine/src/ext/opengl/opengl.cpp index 094814fb..cfbe4d87 100644 --- a/engine/src/ext/opengl/opengl.cpp +++ b/engine/src/ext/opengl/opengl.cpp @@ -77,7 +77,7 @@ GLhandle(VkColorSpaceKHR) ext::opengl::settings::formats::colorSpace; ext::opengl::enums::Format::type_t ext::opengl::settings::formats::color = ext::opengl::enums::Format::R8G8B8A8_UNORM; ext::opengl::enums::Format::type_t ext::opengl::settings::formats::depth = ext::opengl::enums::Format::D32_SFLOAT; -ext::opengl::Device* ext::opengl::device = NULL; +ext::opengl::Device ext::opengl::device; std::mutex ext::opengl::mutex; std::mutex ext::opengl::immediateModeMutex; @@ -505,8 +505,6 @@ void ext::opengl::destroy() { // swapchain.destroy(); device.destroy(); ext::opengl::mutex.unlock(); - - delete device; } void ext::opengl::synchronize( uint8_t flag ) { if ( flag & 0b01 ) { diff --git a/engine/src/spec/context/linux.cpp b/engine/src/spec/context/linux.cpp index 84eaee7a..35564d8f 100644 --- a/engine/src/spec/context/linux.cpp +++ b/engine/src/spec/context/linux.cpp @@ -8,6 +8,9 @@ #include #include +#define None 0L +#define Success 0 + spec::x11::Context::Context( uni::Context* shared, const Context::Settings& settings ) : uni::Context(NULL, true, settings), m_display(nullptr), @@ -26,7 +29,8 @@ spec::x11::Context::Context( uni::Context* shared, const Context::Settings& sett XSetWindowAttributes swa; swa.event_mask = StructureNotifyMask; m_window = XCreateSimpleWindow(m_display, RootWindow(m_display, scr), 0, 0, 1, 1, 0, 0, 0); - XMapWindow(m_display, m_window); + + //XMapWindow(m_display, m_window); this->create(shared); } diff --git a/engine/src/spec/window/linux.cpp b/engine/src/spec/window/linux.cpp index 9f191127..e15b24f4 100644 --- a/engine/src/spec/window/linux.cpp +++ b/engine/src/spec/window/linux.cpp @@ -14,6 +14,13 @@ #define UF_HOOK_USE_USERDATA 1 #define UF_HOOK_USE_JSON 0 +#if UF_USE_VULKAN + #include + #include +#elif UF_USE_OPENGL + #include +#endif + #include #include #include @@ -23,6 +30,9 @@ #include #include +#define None 0L +#define Success 0 + namespace { Display *globalDisplay = nullptr; int windowCount = 0; @@ -239,6 +249,9 @@ void spec::x11::Window::terminate() { #endif } +Display* spec::x11::Window::getDisplay() const { + return m_display; +} spec::x11::Window::handle_t spec::x11::Window::getHandle() const { return m_handle; } @@ -1053,6 +1066,9 @@ void spec::x11::Window::processEvents() { pod::payloads::windowMouseMoved move{ {{"window:Mouse.Moved", "client"}, {getSize()}}, {current, current - last, 0}}; + + if ( current == last ) break; + this->pushEvent(move.type, move); last = current;