From 8a4b3c119d0ea1691937f74236e9698e9151cc3e Mon Sep 17 00:00:00 2001 From: tobid7 Date: Sun, 5 Apr 2026 04:20:32 +0200 Subject: [PATCH] Add NX Hid Driver Template - Add WIP HidNX Driver (clangd not working with devkitpro for switch on windows) - Add default-release as default search path for compile_commands.json - remove mingw preset (casue its exactly the default target) - Move Mouse pos cycle into HidDriver::Update - Test around with HidGlfw on Nintendo switch --- .clangd | 1 + CMakePresets.json | 1 - backends/CMakeLists.txt | 61 ++++++++++----------------- backends/include/pd_system/hid_nx.hpp | 17 ++++++++ backends/source/hid_glfw.cpp | 1 - backends/source/hid_nx.cpp | 31 ++++++++++++++ cmake/presets/mingw.json | 35 --------------- source/drivers/hid.cpp | 1 + tests/gfx/source/os/horizon-nx.cpp | 2 +- 9 files changed, 73 insertions(+), 77 deletions(-) create mode 100644 backends/include/pd_system/hid_nx.hpp create mode 100644 backends/source/hid_nx.cpp delete mode 100644 cmake/presets/mingw.json diff --git a/.clangd b/.clangd index d0d682e..a15458d 100644 --- a/.clangd +++ b/.clangd @@ -1,4 +1,5 @@ CompileFlags: + CompilationDatabase: build/default-release Add: [] Completion: diff --git a/CMakePresets.json b/CMakePresets.json index 1f84cc2..1fd97a0 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,7 +9,6 @@ "cmake/presets/default.json", "cmake/presets/3ds.json", "cmake/presets/switch.json", - "cmake/presets/mingw.json", "cmake/presets/msvc.json" ] } \ No newline at end of file diff --git a/backends/CMakeLists.txt b/backends/CMakeLists.txt index dccb689..533477d 100644 --- a/backends/CMakeLists.txt +++ b/backends/CMakeLists.txt @@ -8,6 +8,7 @@ option(PD_ENABLE_DIRECTX9 "Enable DirectX9 Support" ON) option(PD_ENABLE_CITRO3D "Enable Citro3D Support (3DS)" OFF) option(PD_ENABLE_VULKAN "Not implemented yet" OFF) option(PD_ENABLE_HID_GLFW "Enable GLFW Input Driver" ON) +option(PD_ENABLE_HID_NX "Enable NX Input Driver" OFF) if(NOT WIN32) # cause we are not on windows... set(PD_ENABLE_DIRECTX9 OFF) @@ -17,13 +18,16 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS") set(PD_ENABLE_OPENGL2 OFF) set(PD_ENABLE_OPENGL3 OFF) set(PD_ENABLE_VULKAN OFF) - set(PD_ENABLE_HID_GLFW OFF) set(PD_ENABLE_CITRO3D ON) + set(PD_ENABLE_HID_GLFW OFF) + set(PD_ENABLE_HID_NX OFF) elseif(${CMAKE_SYSTEM_NAME} STREQUAL "NintendoSwitch") set(PD_ENABLE_OPENGL2 OFF) set(PD_ENABLE_OPENGL3 ON) set(PD_ENABLE_VULKAN OFF) set(PD_ENABLE_CITRO3D OFF) + set(PD_ENABLE_HID_NX ON) # Best case for Nintendo Switch + set(PD_ENABLE_HID_GLFW ON) # Technically supported but not recommended endif() add_library(pd-system STATIC @@ -33,12 +37,15 @@ add_library(pd-system STATIC ${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_directx9.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_citro3d.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/hid_glfw.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/source/hid_nx.cpp ) target_include_directories(pd-system PUBLIC $ $ + # Why is this not a default include (same problem as with the __SWITCH__ define) + $<$:${DEVKITPRO}/portlibs/switch/include> ) target_compile_options(palladium @@ -56,48 +63,24 @@ target_compile_definitions(pd-system $<$:PD_ENABLE_DIRECTX9> $<$:PD_ENABLE_CITRO3D> $<$:PD_ENABLE_HID_GLFW> + $<$:PD_ENABLE_HID_NX> ) # Palladium target_link_libraries(pd-system PUBLIC palladium::palladium) -# glad (if we have any OpenGL version included) -if(PD_ENABLE_OPENGL2 OR PD_ENABLE_OPENGL3) - target_link_libraries(pd-system - PUBLIC glad - ) -endif() -# DirectX9 -if(PD_ENABLE_DIRECTX9) - target_link_libraries(pd-system - PUBLIC - d3d9 - d3dcompiler - ) -endif() +# Depandant Lib includes (i love this cmake feature) +target_link_libraries(pd-system PUBLIC + $<$:d3d9 d3dcompiler> # DirectX9 + $<$:pica::pica citro3d ctru> # 3ds + $<$:spirv-helper> # OpenGL3 + # Include Glad if we have any OpenGL Usage + $<$,$>:glad> + $<$:nx> # Hid NX requirement + # Hid GLFW requirement + $<$: + $<$:glfw3> + $<$>:glfw>> -if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS") - target_link_libraries(pd-system - PUBLIC - pica::pica - citro3d - ctru - ) -else() - if(${CMAKE_SYSTEM_NAME} STREQUAL "NintendoSwitch") - target_include_directories(pd-system - PUBLIC $ENV{DEVKITPRO}/portlibs/switch/include - ) - if(PD_ENABLE_HID_GLFW) - target_link_libraries(pd-system PUBLIC glfw3) # use dkp glfw - endif() - else() - if(PD_ENABLE_HID_GLFW) - target_link_libraries(pd-system PUBLIC glfw) # use vendor glfw - endif() - endif() - target_link_libraries(pd-system - PUBLIC spirv-helper - ) -endif() +) diff --git a/backends/include/pd_system/hid_nx.hpp b/backends/include/pd_system/hid_nx.hpp new file mode 100644 index 0000000..dfc1baf --- /dev/null +++ b/backends/include/pd_system/hid_nx.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace PD { +class HidNX : public HidDriver { + public: + HidNX(); + ~HidNX(); + + void Update() override; + + private: + struct Impl; + Impl* impl; +}; +} // namespace PD \ No newline at end of file diff --git a/backends/source/hid_glfw.cpp b/backends/source/hid_glfw.cpp index 286ae21..b72f001 100644 --- a/backends/source/hid_glfw.cpp +++ b/backends/source/hid_glfw.cpp @@ -78,7 +78,6 @@ void HidGlfw::Update() { // } double x, y; glfwGetCursorPos(impl->Win, &x, &y); - pMouse[1] = pMouse[0]; // Cycle pMouse pos pMouse[0] = fvec2(x, y); } } // namespace PD diff --git a/backends/source/hid_nx.cpp b/backends/source/hid_nx.cpp new file mode 100644 index 0000000..03dc2f7 --- /dev/null +++ b/backends/source/hid_nx.cpp @@ -0,0 +1,31 @@ + +#include + +#ifdef PD_ENABLE_HID_NX +#include + +namespace PD { +struct HidNX::Impl { + PadState Pad; +}; + +HidNX::HidNX() : HidDriver("HidNX") { impl = new Impl; } + +HidNX::~HidNX() {} + +void HidNX::Update() { + HidDriver::Update(); // clear stats +} +} // namespace PD +#else +namespace PD { + +HidNX::HidNX() : HidDriver("HidNX") {} + +HidNX::~HidNX() {} + +void HidNX::Update() { + HidDriver::Update(); // clear stats +} +} // namespace PD +#endif \ No newline at end of file diff --git a/cmake/presets/mingw.json b/cmake/presets/mingw.json deleted file mode 100644 index 90eed34..0000000 --- a/cmake/presets/mingw.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "version": 10, - "configurePresets": [ - { - "name": "mingw-release", - "displayName": "MinGW", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/mingw-release", - "cacheVariables": { - "SPV_EXCLUDE_GLSLANG": "ON", - "CMAKE_BUILD_TYPE": "Release" - } - }, - { - "name": "mingw-debug", - "displayName": "MinGW", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/mingw-debug", - "cacheVariables": { - "SPV_EXCLUDE_GLSLANG": "ON", - "CMAKE_BUILD_TYPE": "Debug" - } - } - ], - "buildPresets": [ - { - "name": "mingw-release", - "configurePreset": "mingw-release" - }, - { - "name": "mingw-debug", - "configurePreset": "mingw-debug" - } - ] -} \ No newline at end of file diff --git a/source/drivers/hid.cpp b/source/drivers/hid.cpp index 9573de9..c1cf3c9 100644 --- a/source/drivers/hid.cpp +++ b/source/drivers/hid.cpp @@ -43,5 +43,6 @@ PD_API void HidDriver::Update() { it.second = 0; // ? why was this Event_Null } } + pMouse[1] = pMouse[0]; // cycle here } } // namespace PD \ No newline at end of file diff --git a/tests/gfx/source/os/horizon-nx.cpp b/tests/gfx/source/os/horizon-nx.cpp index cc1803d..8948387 100644 --- a/tests/gfx/source/os/horizon-nx.cpp +++ b/tests/gfx/source/os/horizon-nx.cpp @@ -29,7 +29,7 @@ void HorizonNX::Init() { gladLoadGL(); glfwSwapInterval(1); PD::Gfx::UseDriver(); - PD::Hid::UseDriver(); + PD::Hid::UseDriver(impl->win); } void HorizonNX::Deinit() {