From 351fb84877ecabb809045827ebaa3a2b27558f7b Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Tue, 19 Nov 2024 20:51:38 +0100 Subject: [PATCH 01/94] implement basic functions for controller support --- game/game/playercontrol.cpp | 144 ++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 62deb7f3a..d78926731 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1,6 +1,10 @@ #include "playercontrol.h" #include +#include +#include +#include +#include #include "world/objects/npc.h" #include "world/objects/item.h" @@ -10,6 +14,61 @@ #include "ui/inventorymenu.h" #include "gothic.h" +static volatile bool run_flag = true; + +// Signal handler for clean exit +#ifdef LGP_UNIX +#include +void handler(int s) { + LGP_UNUSED(s); + run_flag = false; +} +#else +#include +BOOL WINAPI handler(DWORD s) { + LGP_UNUSED(s); + run_flag = false; + return TRUE; +} +#endif + +PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) + : dlg(dlg), inv(inv) { + Gothic::inst().onSettingsChanged.bind(this, &PlayerControl::setupSettings); + setupSettings(); + +#ifdef LGP_UNIX + signal(SIGINT, handler); +#else + SetConsoleCtrlHandler(handler, TRUE); +#endif + + hook = gamepad::hook::make(); + hook->set_plug_and_play(true, gamepad::ms(1000)); + hook->set_sleep_time(gamepad::ms(5)); + + // Setup libgamepad event handlers + hook->set_button_event_handler([this](std::shared_ptr dev) { + handleButtonInput(dev); + }); + + hook->set_axis_event_handler([this](std::shared_ptr dev) { + handleAxisInput(dev); + }); + + hook->set_connect_event_handler([](std::shared_ptr dev) { + std::cout << dev->get_name() << " connected.\n"; + }); + + hook->set_disconnect_event_handler([](std::shared_ptr dev) { + std::cout << dev->get_name() << " disconnected.\n"; + }); + + if (!hook->start()) { + std::cerr << "Failed to start libgamepad hook.\n"; + } +} + PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) :dlg(dlg),inv(inv) { Gothic::inst().onSettingsChanged.bind(this,&PlayerControl::setupSettings); @@ -18,6 +77,8 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) PlayerControl::~PlayerControl() { Gothic::inst().onSettingsChanged.ubind(this,&PlayerControl::setupSettings); + hook->stop(); + hook.reset(); } void PlayerControl::setupSettings() { @@ -1092,3 +1153,86 @@ void PlayerControl::processAutoRotate(Npc& pl, float& rot, uint64_t dt) { } } } + +void PlayerControl::handleButtonInput(std::shared_ptr dev) { + if (dev->is_button_pressed(gamepad::button::DPAD_UP)) { + onKeyPressed(Action::WeaponMele, Tempest::KeyEvent::K_Space, KeyCodec::Mapping::Primary); + } + if (dev->is_button_pressed(gamepad::button::DPAD_RIGHT)) { + onKeyPressed(Action::WeaponBow, Tempest::KeyEvent::K_Space, KeyCodec::Mapping::Primary); + } + if (dev->is_button_pressed(gamepad::button::DPAD_DOWN)) { + static int currentMagicSlot = Action::WeaponMage3; + onKeyPressed(static_cast(currentMagicSlot), Tempest::KeyEvent::K_Space, KeyCodec::Mapping::Primary); + currentMagicSlot++; + if (currentMagicSlot > Action::WeaponMage10) { + currentMagicSlot = Action::WeaponMage3; + } + } + if (dev->is_button_pressed(gamepad::button::Y)) { + ctrl[Action::Jump] = true; + } else { + ctrl[Action::Jump] = false; + } + + if (dev->is_button_pressed(gamepad::button::LEFT_SHOULDER)) { + movement.strafeRightLeft.reverse[0] = true; + } else { + movement.strafeRightLeft.reverse[0] = false; + } + + if (dev->is_button_pressed(gamepad::button::RIGHT_SHOULDER)) { + movement.strafeRightLeft.main[0] = true; + } else { + movement.strafeRightLeft.main[0] = false; + } +} + +void PlayerControl::handleAxisInput(std::shared_ptr dev) { + const int DEADZONE = 16384; + + auto leftX = dev->get_axis_value(gamepad::axis::LEFT_STICK_X); + auto leftY = dev->get_axis_value(gamepad::axis::LEFT_STICK_Y); + + if (std::abs(leftX) > DEADZONE) { + if (leftX > 0) { + movement.strafeRightLeft.main[0] = true; + } else { + movement.strafeRightLeft.reverse[0] = true; + } + } else { + movement.strafeRightLeft.reset(); + } + + if (std::abs(leftY) > DEADZONE) { + if (leftY > 0) { + movement.forwardBackward.reverse[0] = true; + } else { + movement.forwardBackward.main[0] = true; + } + } else { + movement.forwardBackward.reset(); + } + + auto rightX = dev->get_axis_value(gamepad::axis::RIGHT_STICK_X); + auto rightY = dev->get_axis_value(gamepad::axis::RIGHT_STICK_Y); + + if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { + float angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.f / M_PI; + if (angle < 0) angle += 360.f; + + int selectedOption = 0; + if (angle >= 0 && angle < 90) { + selectedOption = 0; // Right + } else if (angle >= 90 && angle < 180) { + selectedOption = 1; // Down + } else if (angle >= 180 && angle < 270) { + selectedOption = 2; // Left + } else { + selectedOption = 3; // Up + } + + std::cout << "Joystick angle: " << angle << "°\n"; + std::cout << "Selected Option: " << selectedOption << "\n"; + } +} \ No newline at end of file From dee805c5775158cba4c3fbc55b8fa980cf638a86 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:27:42 +0100 Subject: [PATCH 02/94] ... --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b0f6e94a..65f12627f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,6 +156,9 @@ endif() include_directories(lib/bullet3/src) target_link_libraries(${PROJECT_NAME} BulletDynamics BulletCollision LinearMath) +include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad) +target_link_libraries(Gothic2Notr PRIVATE ${CMAKE_SOURCE_DIR}/lib/libgamepad) + # script for launching in binary directory if(WIN32) add_custom_command( From 0508a1761b735b3120900078ea3f121e8d022ca4 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:28:54 +0100 Subject: [PATCH 03/94] ... --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65f12627f..179678718 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,9 +156,11 @@ endif() include_directories(lib/bullet3/src) target_link_libraries(${PROJECT_NAME} BulletDynamics BulletCollision LinearMath) +add_subdirectory(lib/libgamepad) include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad) target_link_libraries(Gothic2Notr PRIVATE ${CMAKE_SOURCE_DIR}/lib/libgamepad) + # script for launching in binary directory if(WIN32) add_custom_command( From 6d857e75216b5419da930b2e0d6565813409cae4 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:31:52 +0100 Subject: [PATCH 04/94] ... --- CMakeLists.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 179678718..5cfa65e3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,15 @@ if(NOT MSVC) endif() endif() +# Include libgamepad +include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad) + +# Link libgamepad (if it is a compiled library) +target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/lib/libgamepad) + +# Add the libgamepad subdirectory if it contains its own CMakeLists.txt +add_subdirectory(lib/libgamepad) + if(WIN32) if(MSVC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup" ) @@ -156,11 +165,6 @@ endif() include_directories(lib/bullet3/src) target_link_libraries(${PROJECT_NAME} BulletDynamics BulletCollision LinearMath) -add_subdirectory(lib/libgamepad) -include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad) -target_link_libraries(Gothic2Notr PRIVATE ${CMAKE_SOURCE_DIR}/lib/libgamepad) - - # script for launching in binary directory if(WIN32) add_custom_command( From 5a4c9a500497a588da26e0ae4de329c90c45d65c Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:32:22 +0100 Subject: [PATCH 05/94] ... --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cfa65e3c..67e90667b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,9 +37,6 @@ endif() # Include libgamepad include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad) -# Link libgamepad (if it is a compiled library) -target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/lib/libgamepad) - # Add the libgamepad subdirectory if it contains its own CMakeLists.txt add_subdirectory(lib/libgamepad) From 1190885c76bd9c4c33d39e2675bac4f4f8660bf0 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:45:59 +0100 Subject: [PATCH 06/94] ... --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67e90667b..5a585a4fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,8 +34,8 @@ if(NOT MSVC) endif() endif() -# Include libgamepad -include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad) +# Add the libgamepad include directory +include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad/include) # Add the libgamepad subdirectory if it contains its own CMakeLists.txt add_subdirectory(lib/libgamepad) From ed6322aa61e7203142b46b5dfa8a5b5b0e8950f0 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:06:01 +0100 Subject: [PATCH 07/94] ... --- game/game/playercontrol.cpp | 2 +- game/game/playercontrol.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index d78926731..7f946c12e 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -43,7 +43,7 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) SetConsoleCtrlHandler(handler, TRUE); #endif - hook = gamepad::hook::make(); + std::shared_ptr hook = gamepad::hook::make(); hook->set_plug_and_play(true, gamepad::ms(1000)); hook->set_sleep_time(gamepad::ms(5)); diff --git a/game/game/playercontrol.h b/game/game/playercontrol.h index b04d6c1c5..4a5da07b6 100644 --- a/game/game/playercontrol.h +++ b/game/game/playercontrol.h @@ -20,6 +20,9 @@ class PlayerControl final { PlayerControl(DialogMenu& dlg, InventoryMenu& inv); ~PlayerControl(); + void handleButtonInput(std::shared_ptr dev); + void handleAxisInput(std::shared_ptr dev); + void onKeyPressed (KeyCodec::Action a, Tempest::Event::KeyType key, KeyCodec::Mapping mapping = KeyCodec::Mapping::Primary); void onKeyReleased(KeyCodec::Action a, KeyCodec::Mapping mapping = KeyCodec::Mapping::Primary); bool isPressed(KeyCodec::Action a) const; From ad707e96f6b005665d7896750587628452c04984 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:12:57 +0100 Subject: [PATCH 08/94] Added for std::shared_ptr --- game/game/playercontrol.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/game/game/playercontrol.h b/game/game/playercontrol.h index 4a5da07b6..4feb3d9ae 100644 --- a/game/game/playercontrol.h +++ b/game/game/playercontrol.h @@ -5,6 +5,7 @@ #include "constants.h" #include +#include class DialogMenu; class InventoryMenu; @@ -64,7 +65,7 @@ class PlayerControl final { Weapon10, Last, - }; + }; enum FocusAction : uint8_t { ActForward=0, @@ -74,7 +75,7 @@ class PlayerControl final { ActGeneric=4, ActMove =5, ActKill =6, - }; + }; using Action=KeyCodec::Action; @@ -210,4 +211,4 @@ class PlayerControl final { /// @param actionMapping - the pressed/released action /// @param pressed - true if the key was pressed, false if it was released auto handleMovementAction(KeyCodec::ActionMapping actionMapping, bool pressed) -> void; - }; +}; From 099a18108e119cb7c31a7e2eed6f2c4bad82086b Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:50:44 +0100 Subject: [PATCH 09/94] Update playercontrol.cpp removed sdl2 reference --- game/game/playercontrol.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 7f946c12e..f0108a34e 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -43,11 +43,12 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) SetConsoleCtrlHandler(handler, TRUE); #endif - std::shared_ptr hook = gamepad::hook::make(); + // Initialisierung von hook + hook = gamepad::hook::make(); hook->set_plug_and_play(true, gamepad::ms(1000)); hook->set_sleep_time(gamepad::ms(5)); - // Setup libgamepad event handlers + // Event-Handler für libgamepad registrieren hook->set_button_event_handler([this](std::shared_ptr dev) { handleButtonInput(dev); }); @@ -64,8 +65,11 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) std::cout << dev->get_name() << " disconnected.\n"; }); + // Hook starten if (!hook->start()) { std::cerr << "Failed to start libgamepad hook.\n"; + } else { + std::cout << "libgamepad hook started successfully.\n"; } } @@ -1156,12 +1160,15 @@ void PlayerControl::processAutoRotate(Npc& pl, float& rot, uint64_t dt) { void PlayerControl::handleButtonInput(std::shared_ptr dev) { if (dev->is_button_pressed(gamepad::button::DPAD_UP)) { + std::cout << "DPAD pressed" << std::endl; onKeyPressed(Action::WeaponMele, Tempest::KeyEvent::K_Space, KeyCodec::Mapping::Primary); } if (dev->is_button_pressed(gamepad::button::DPAD_RIGHT)) { + std::cout << "DPAD pressed" << std::endl; onKeyPressed(Action::WeaponBow, Tempest::KeyEvent::K_Space, KeyCodec::Mapping::Primary); } if (dev->is_button_pressed(gamepad::button::DPAD_DOWN)) { + std::cout << "DPAD pressed" << std::endl; static int currentMagicSlot = Action::WeaponMage3; onKeyPressed(static_cast(currentMagicSlot), Tempest::KeyEvent::K_Space, KeyCodec::Mapping::Primary); currentMagicSlot++; @@ -1170,18 +1177,21 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } } if (dev->is_button_pressed(gamepad::button::Y)) { + std::cout << "Y pressed" << std::endl; ctrl[Action::Jump] = true; } else { ctrl[Action::Jump] = false; } if (dev->is_button_pressed(gamepad::button::LEFT_SHOULDER)) { + std::cout << "Lshoulder pressed" << std::endl; movement.strafeRightLeft.reverse[0] = true; } else { movement.strafeRightLeft.reverse[0] = false; } if (dev->is_button_pressed(gamepad::button::RIGHT_SHOULDER)) { + std::cout << "Rshoulder pressed" << std::endl; movement.strafeRightLeft.main[0] = true; } else { movement.strafeRightLeft.main[0] = false; @@ -1196,6 +1206,7 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { if (std::abs(leftX) > DEADZONE) { if (leftX > 0) { + std::cout << "Left Stick" << std::endl; movement.strafeRightLeft.main[0] = true; } else { movement.strafeRightLeft.reverse[0] = true; @@ -1206,6 +1217,7 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { if (std::abs(leftY) > DEADZONE) { if (leftY > 0) { + std::cout << "Left Stick" << std::endl; movement.forwardBackward.reverse[0] = true; } else { movement.forwardBackward.main[0] = true; @@ -1235,4 +1247,4 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { std::cout << "Joystick angle: " << angle << "°\n"; std::cout << "Selected Option: " << selectedOption << "\n"; } -} \ No newline at end of file +} From 0dc709e3074f8c9504f2dcf0e572b1702fcfe791 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:53:42 +0100 Subject: [PATCH 10/94] Update playercontrol.h --- game/game/playercontrol.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/game/game/playercontrol.h b/game/game/playercontrol.h index 4feb3d9ae..678573291 100644 --- a/game/game/playercontrol.h +++ b/game/game/playercontrol.h @@ -3,6 +3,7 @@ #include "world/focus.h" #include "utils/keycodec.h" #include "constants.h" +#include #include #include @@ -51,6 +52,8 @@ class PlayerControl final { bool tickCameraMove(uint64_t dt); private: + std::shared_ptr hook; // Hook für Gamepad-Ereignisse + enum WeaponAction : uint8_t { WeaponClose, WeaponMele, From 1fff9f1ded9fc0370524073ad2bb5dc1052d6d81 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 16:53:07 +0100 Subject: [PATCH 11/94] Update playercontrol.cpp corrected gamepad calls --- game/game/playercontrol.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index f0108a34e..33e3702b8 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1183,14 +1183,14 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { ctrl[Action::Jump] = false; } - if (dev->is_button_pressed(gamepad::button::LEFT_SHOULDER)) { + if (dev->is_button_pressed(gamepad::button::LB)) { std::cout << "Lshoulder pressed" << std::endl; movement.strafeRightLeft.reverse[0] = true; } else { movement.strafeRightLeft.reverse[0] = false; } - if (dev->is_button_pressed(gamepad::button::RIGHT_SHOULDER)) { + if (dev->is_button_pressed(gamepad::button::RB)) { std::cout << "Rshoulder pressed" << std::endl; movement.strafeRightLeft.main[0] = true; } else { @@ -1201,8 +1201,8 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { void PlayerControl::handleAxisInput(std::shared_ptr dev) { const int DEADZONE = 16384; - auto leftX = dev->get_axis_value(gamepad::axis::LEFT_STICK_X); - auto leftY = dev->get_axis_value(gamepad::axis::LEFT_STICK_Y); + auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); + auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); if (std::abs(leftX) > DEADZONE) { if (leftX > 0) { @@ -1226,8 +1226,9 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { movement.forwardBackward.reset(); } - auto rightX = dev->get_axis_value(gamepad::axis::RIGHT_STICK_X); - auto rightY = dev->get_axis_value(gamepad::axis::RIGHT_STICK_Y); + // Rechts Stick + auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); + auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { float angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.f / M_PI; From a71b031a10e8de591875f639926575019f342acb Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 16:54:13 +0100 Subject: [PATCH 12/94] Update playercontrol.cpp obsolete cleanup --- game/game/playercontrol.cpp | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 33e3702b8..0b7be91a1 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -73,26 +73,6 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) } } -PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) - :dlg(dlg),inv(inv) { - Gothic::inst().onSettingsChanged.bind(this,&PlayerControl::setupSettings); - setupSettings(); - } - -PlayerControl::~PlayerControl() { - Gothic::inst().onSettingsChanged.ubind(this,&PlayerControl::setupSettings); - hook->stop(); - hook.reset(); - } - -void PlayerControl::setupSettings() { - if(Gothic::inst().version().game==2) { - g2Ctrl = Gothic::inst().settingsGetI("GAME","USEGOTHIC1CONTROLS")==0; - } else { - g2Ctrl = false; - } - } - void PlayerControl::setTarget(Npc *other) { auto w = Gothic::inst().world(); auto pl = w ? w->player() : nullptr; From ccce7d469e9500192e52b8f30bfcf66b4ec1b7d9 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 16:56:47 +0100 Subject: [PATCH 13/94] Update playercontrol.cpp previous conversion error --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 0b7be91a1..2d0eb996d 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1211,7 +1211,7 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { - float angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.f / M_PI; + float angle = std::atan2f(static_cast(rightY), static_cast(rightX)) * 180.f / M_PI; if (angle < 0) angle += 360.f; int selectedOption = 0; From d931ff970e9034aa70f0dd8c699363f4fa1441a1 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 16:58:12 +0100 Subject: [PATCH 14/94] Update playercontrol.cpp --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 2d0eb996d..6c4243993 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1211,7 +1211,7 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { - float angle = std::atan2f(static_cast(rightY), static_cast(rightX)) * 180.f / M_PI; + float angle = static_cast(std::atan2(static_cast(rightY), static_cast(rightX))) * 180.f / M_PI; if (angle < 0) angle += 360.f; int selectedOption = 0; From bf17d2b38e109e4a4dca2389dac57b01e7efd55d Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:00:20 +0100 Subject: [PATCH 15/94] Update playercontrol.cpp --- game/game/playercontrol.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 6c4243993..1882e6049 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1181,8 +1181,9 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { void PlayerControl::handleAxisInput(std::shared_ptr dev) { const int DEADZONE = 16384; - auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); - auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); + // Left Stick X/Y + auto leftX = dev->get_axis_value(gamepad::axis::LEFT_STICK_X); + auto leftY = dev->get_axis_value(gamepad::axis::LEFT_STICK_Y); if (std::abs(leftX) > DEADZONE) { if (leftX > 0) { @@ -1206,12 +1207,13 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { movement.forwardBackward.reset(); } - // Rechts Stick - auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); - auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); + // Right Stick X/Y + auto rightX = dev->get_axis_value(gamepad::axis::RIGHT_STICK_X); + auto rightY = dev->get_axis_value(gamepad::axis::RIGHT_STICK_Y); if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { - float angle = static_cast(std::atan2(static_cast(rightY), static_cast(rightX))) * 180.f / M_PI; + // Berechnung des Winkels mit atan2f für float-Arithmetik + float angle = std::atan2f(rightY, rightX) * 180.f / M_PI; if (angle < 0) angle += 360.f; int selectedOption = 0; From ca27937ec19144bbfc1291b2edfe8b1111495994 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:02:47 +0100 Subject: [PATCH 16/94] Update playercontrol.cpp --- game/game/playercontrol.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 1882e6049..f0384530f 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1181,9 +1181,13 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { void PlayerControl::handleAxisInput(std::shared_ptr dev) { const int DEADZONE = 16384; - // Left Stick X/Y - auto leftX = dev->get_axis_value(gamepad::axis::LEFT_STICK_X); - auto leftY = dev->get_axis_value(gamepad::axis::LEFT_STICK_Y); + input_event event; + if (dev->update_axis(gamepad::axis::LEFT_STICK_X, event)) { + auto leftX = event.virtual_value; + } + if (dev->update_axis(gamepad::axis::LEFT_STICK_Y, event)) { + auto leftY = event.virtual_value; + } if (std::abs(leftX) > DEADZONE) { if (leftX > 0) { @@ -1207,13 +1211,16 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { movement.forwardBackward.reset(); } - // Right Stick X/Y - auto rightX = dev->get_axis_value(gamepad::axis::RIGHT_STICK_X); - auto rightY = dev->get_axis_value(gamepad::axis::RIGHT_STICK_Y); + // Rechts Stick + if (dev->update_axis(gamepad::axis::RIGHT_STICK_X, event)) { + auto rightX = event.virtual_value; + } + if (dev->update_axis(gamepad::axis::RIGHT_STICK_Y, event)) { + auto rightY = event.virtual_value; + } if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { - // Berechnung des Winkels mit atan2f für float-Arithmetik - float angle = std::atan2f(rightY, rightX) * 180.f / M_PI; + float angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.f / M_PI; if (angle < 0) angle += 360.f; int selectedOption = 0; From 6787923125b1ac158a6129f409323c5aa8851a35 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:04:00 +0100 Subject: [PATCH 17/94] Update playercontrol.cpp --- game/game/playercontrol.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index f0384530f..adbdeedf6 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1181,13 +1181,9 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { void PlayerControl::handleAxisInput(std::shared_ptr dev) { const int DEADZONE = 16384; - input_event event; - if (dev->update_axis(gamepad::axis::LEFT_STICK_X, event)) { - auto leftX = event.virtual_value; - } - if (dev->update_axis(gamepad::axis::LEFT_STICK_Y, event)) { - auto leftY = event.virtual_value; - } + // Hier wird angenommen, dass 'get_axis' die Achsenwerte zurückgibt + auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); // Anpassen, falls nötig + auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); // Anpassen, falls nötig if (std::abs(leftX) > DEADZONE) { if (leftX > 0) { @@ -1212,12 +1208,8 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { } // Rechts Stick - if (dev->update_axis(gamepad::axis::RIGHT_STICK_X, event)) { - auto rightX = event.virtual_value; - } - if (dev->update_axis(gamepad::axis::RIGHT_STICK_Y, event)) { - auto rightY = event.virtual_value; - } + auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); // Anpassen, falls nötig + auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); // Anpassen, falls nötig if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { float angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.f / M_PI; @@ -1238,3 +1230,4 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { std::cout << "Selected Option: " << selectedOption << "\n"; } } + From 9d535bfb9059c1bac51b03af559b64b84646fa00 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:06:35 +0100 Subject: [PATCH 18/94] Update playercontrol.cpp --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index adbdeedf6..aa320d186 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1212,7 +1212,7 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); // Anpassen, falls nötig if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { - float angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.f / M_PI; + double angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.0 / M_PI; if (angle < 0) angle += 360.f; int selectedOption = 0; From 8fdd8f05adf13e01ae8850f39ecfbbe7be1663fc Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:16:57 +0100 Subject: [PATCH 19/94] Update playercontrol.cpp --- game/game/playercontrol.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index aa320d186..ce4e5dc02 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -44,24 +44,24 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) #endif // Initialisierung von hook - hook = gamepad::hook::make(); - hook->set_plug_and_play(true, gamepad::ms(1000)); - hook->set_sleep_time(gamepad::ms(5)); + auto hook = hook::make(); + h->set_plug_and_play(true, gamepad::ms(1000)); + std::atomic run_flag = true; // Event-Handler für libgamepad registrieren - hook->set_button_event_handler([this](std::shared_ptr dev) { + h->set_button_event_handler([this](std::shared_ptr dev) { handleButtonInput(dev); }); - hook->set_axis_event_handler([this](std::shared_ptr dev) { + h->set_axis_event_handler([this](std::shared_ptr dev) { handleAxisInput(dev); }); - hook->set_connect_event_handler([](std::shared_ptr dev) { + h->set_connect_event_handler([](std::shared_ptr dev) { std::cout << dev->get_name() << " connected.\n"; }); - hook->set_disconnect_event_handler([](std::shared_ptr dev) { + h->set_disconnect_event_handler([](std::shared_ptr dev) { std::cout << dev->get_name() << " disconnected.\n"; }); From 26f65cbf3d1ddc03d5dcd4c3ad3bf7d9b48344a1 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:24:11 +0100 Subject: [PATCH 20/94] Update playercontrol.cpp --- game/game/playercontrol.cpp | 73 +++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index ce4e5dc02..39dfecd82 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -37,40 +37,57 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) Gothic::inst().onSettingsChanged.bind(this, &PlayerControl::setupSettings); setupSettings(); -#ifdef LGP_UNIX - signal(SIGINT, handler); -#else - SetConsoleCtrlHandler(handler, TRUE); -#endif + #ifdef LGP_UNIX + signal(SIGINT, handler); + #else + SetConsoleCtrlHandler(handler, TRUE); + #endif - // Initialisierung von hook - auto hook = hook::make(); + auto h = gamepad::hook::make(); h->set_plug_and_play(true, gamepad::ms(1000)); - std::atomic run_flag = true; - - // Event-Handler für libgamepad registrieren - h->set_button_event_handler([this](std::shared_ptr dev) { - handleButtonInput(dev); - }); - - h->set_axis_event_handler([this](std::shared_ptr dev) { - handleAxisInput(dev); - }); + h->set_sleep_time(gamepad::ms(5)); // just std::chrono::milliseconds + + auto button_handler = [](std::shared_ptr dev) { + ginfo("Received button event: Native id: %i, Virtual id: 0x%X (%i) val: %f", + dev->last_button_event()->native_id, dev->last_button_event()->vc, + dev->last_button_event()->vc, dev->last_button_event()->virtual_value); + }; + + auto axis_handler = [](std::shared_ptr dev) { + ginfo("Received axis event: Native id: %i, Virtual id: 0x%X (%i) val: %f", dev->last_axis_event()->native_id, + dev->last_axis_event()->vc, dev->last_axis_event()->vc, dev->last_axis_event()->virtual_value); + }; + + auto connect_handler = [h](std::shared_ptr dev) { + ginfo("%s connected", dev->get_name().c_str()); + if (!dev->has_binding()) { + #ifdef LGP_ENABLE_JSON + ginfo("Found device, running config wizard"); + json11::Json cfg; + h->make_xbox_config(dev, cfg); + ginfo("Result config: %s", cfg.dump().c_str()); + #else + ginfo("Json isn't enabled for libgamepad, so the config wizard can't be used"); + #endif + } + }; - h->set_connect_event_handler([](std::shared_ptr dev) { - std::cout << dev->get_name() << " connected.\n"; - }); + auto disconnect_handler = [](std::shared_ptr dev) { + ginfo("%s disconnected", dev->get_name().c_str()); + }; - h->set_disconnect_event_handler([](std::shared_ptr dev) { - std::cout << dev->get_name() << " disconnected.\n"; - }); + h->set_axis_event_handler(axis_handler); + h->set_button_event_handler(button_handler); + h->set_connect_event_handler(connect_handler); + h->set_disconnect_event_handler(disconnect_handler); - // Hook starten - if (!hook->start()) { - std::cerr << "Failed to start libgamepad hook.\n"; - } else { - std::cout << "libgamepad hook started successfully.\n"; + if (!h->start()) { + gerr("Couldn't start hook"); + return 1; } + + while (run_flag) + std::this_thread::sleep_for(gamepad::ms(50)) } void PlayerControl::setTarget(Npc *other) { From ec1535725c3469627bddc8e586311f3e526fd95d Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:25:38 +0100 Subject: [PATCH 21/94] Update playercontrol.cpp --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 39dfecd82..efc78677c 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -87,7 +87,7 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) } while (run_flag) - std::this_thread::sleep_for(gamepad::ms(50)) + std::this_thread::sleep_for(gamepad::ms(50)); } void PlayerControl::setTarget(Npc *other) { From b8727a5254a5d16181e0726a4312fbeb220fc332 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:29:31 +0100 Subject: [PATCH 22/94] Update playercontrol.cpp --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index efc78677c..950ff52cc 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -82,8 +82,8 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) h->set_disconnect_event_handler(disconnect_handler); if (!h->start()) { - gerr("Couldn't start hook"); - return 1; + gerr("Couldn't start gamepad hook"); + throw std::runtime_error("Failed to initialize gamepad hook"); } while (run_flag) From 93710d5ec1461dcbd8ed7a0f73fdaeb0df4e0d1e Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:37:27 +0100 Subject: [PATCH 23/94] Update playercontrol.cpp --- game/game/playercontrol.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 950ff52cc..362440379 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1248,3 +1248,7 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { } } +void PlayerControl::setupSettings() { + // Gamepad-spezifische Einstellungen hier initialisieren. +} + From 3c4b2ba6cd79ccc23da31168cdba485d9cc866c0 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:41:47 +0100 Subject: [PATCH 24/94] path --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 362440379..68d3fb7e0 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1,7 +1,7 @@ #include "playercontrol.h" #include -#include +#include ../../lib/libgamepad/ #include #include #include From 471c5a901abad0df754cc15d822144da6ad3c559 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:49:48 +0100 Subject: [PATCH 25/94] 1234 --- CMakeLists.txt | 2 ++ game/game/playercontrol.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a585a4fc..b510a3010 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,8 @@ include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad/include) # Add the libgamepad subdirectory if it contains its own CMakeLists.txt add_subdirectory(lib/libgamepad) +target_link_libraries(Gothic2Notr PRIVATE gamepad) + if(WIN32) if(MSVC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup" ) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 68d3fb7e0..362440379 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1,7 +1,7 @@ #include "playercontrol.h" #include -#include ../../lib/libgamepad/ +#include #include #include #include From 4987467df6ee4b3db3be910a15c497d5a6a6d52a Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:50:58 +0100 Subject: [PATCH 26/94] 1234 --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b510a3010..5a585a4fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,8 +40,6 @@ include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad/include) # Add the libgamepad subdirectory if it contains its own CMakeLists.txt add_subdirectory(lib/libgamepad) -target_link_libraries(Gothic2Notr PRIVATE gamepad) - if(WIN32) if(MSVC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup" ) From 93244b960eadf8b7a1acf400e312e16ee69e87a2 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:57:18 +0100 Subject: [PATCH 27/94] test --- game/game/playercontrol.cpp | 2 +- game/game/playercontrol.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 362440379..c54230920 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1,7 +1,7 @@ #include "playercontrol.h" #include -#include +#include "libgamepad.hpp" #include #include #include diff --git a/game/game/playercontrol.h b/game/game/playercontrol.h index 678573291..caf3df892 100644 --- a/game/game/playercontrol.h +++ b/game/game/playercontrol.h @@ -3,7 +3,7 @@ #include "world/focus.h" #include "utils/keycodec.h" #include "constants.h" -#include +#include "libgamepad.hpp" #include #include From 35d32d3db213b68bd04bf18098372e22dc494222 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:09:14 +0100 Subject: [PATCH 28/94] test --- game/game/playercontrol.cpp | 109 ++++++++++++++++-------------------- game/game/playercontrol.h | 2 +- 2 files changed, 50 insertions(+), 61 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index c54230920..f4233b5c7 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1,7 +1,7 @@ #include "playercontrol.h" #include -#include "libgamepad.hpp" +#include #include #include #include @@ -54,8 +54,54 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) }; auto axis_handler = [](std::shared_ptr dev) { - ginfo("Received axis event: Native id: %i, Virtual id: 0x%X (%i) val: %f", dev->last_axis_event()->native_id, - dev->last_axis_event()->vc, dev->last_axis_event()->vc, dev->last_axis_event()->virtual_value); + const int DEADZONE = 16384; + + auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); + auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); + + if (std::abs(leftX) > DEADZONE) { + if (leftX > 0) { + std::cout << "Left Stick" << std::endl; + movement.strafeRightLeft.main[0] = true; + } else { + movement.strafeRightLeft.reverse[0] = true; + } + } else { + movement.strafeRightLeft.reset(); + } + + if (std::abs(leftY) > DEADZONE) { + if (leftY > 0) { + std::cout << "Left Stick" << std::endl; + movement.forwardBackward.reverse[0] = true; + } else { + movement.forwardBackward.main[0] = true; + } + } else { + movement.forwardBackward.reset(); + } + + auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); + auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); + + if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { + double angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.0 / M_PI; + if (angle < 0) angle += 360.f; + + int selectedOption = 0; + if (angle >= 0 && angle < 90) { + selectedOption = 0; // Right + } else if (angle >= 90 && angle < 180) { + selectedOption = 1; // Down + } else if (angle >= 180 && angle < 270) { + selectedOption = 2; // Left + } else { + selectedOption = 3; // Up + } + + std::cout << "Joystick angle: " << angle << "°\n"; + std::cout << "Selected Option: " << selectedOption << "\n"; + } }; auto connect_handler = [h](std::shared_ptr dev) { @@ -1195,60 +1241,3 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } } -void PlayerControl::handleAxisInput(std::shared_ptr dev) { - const int DEADZONE = 16384; - - // Hier wird angenommen, dass 'get_axis' die Achsenwerte zurückgibt - auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); // Anpassen, falls nötig - auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); // Anpassen, falls nötig - - if (std::abs(leftX) > DEADZONE) { - if (leftX > 0) { - std::cout << "Left Stick" << std::endl; - movement.strafeRightLeft.main[0] = true; - } else { - movement.strafeRightLeft.reverse[0] = true; - } - } else { - movement.strafeRightLeft.reset(); - } - - if (std::abs(leftY) > DEADZONE) { - if (leftY > 0) { - std::cout << "Left Stick" << std::endl; - movement.forwardBackward.reverse[0] = true; - } else { - movement.forwardBackward.main[0] = true; - } - } else { - movement.forwardBackward.reset(); - } - - // Rechts Stick - auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); // Anpassen, falls nötig - auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); // Anpassen, falls nötig - - if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { - double angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.0 / M_PI; - if (angle < 0) angle += 360.f; - - int selectedOption = 0; - if (angle >= 0 && angle < 90) { - selectedOption = 0; // Right - } else if (angle >= 90 && angle < 180) { - selectedOption = 1; // Down - } else if (angle >= 180 && angle < 270) { - selectedOption = 2; // Left - } else { - selectedOption = 3; // Up - } - - std::cout << "Joystick angle: " << angle << "°\n"; - std::cout << "Selected Option: " << selectedOption << "\n"; - } -} - -void PlayerControl::setupSettings() { - // Gamepad-spezifische Einstellungen hier initialisieren. -} - diff --git a/game/game/playercontrol.h b/game/game/playercontrol.h index caf3df892..678573291 100644 --- a/game/game/playercontrol.h +++ b/game/game/playercontrol.h @@ -3,7 +3,7 @@ #include "world/focus.h" #include "utils/keycodec.h" #include "constants.h" -#include "libgamepad.hpp" +#include #include #include From 943702d87f3add754207d45cf6c9dedd965b5d5a Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:10:07 +0100 Subject: [PATCH 29/94] oh no --- game/game/playercontrol.cpp | 107 ++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 48 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index f4233b5c7..362440379 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -54,54 +54,8 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) }; auto axis_handler = [](std::shared_ptr dev) { - const int DEADZONE = 16384; - - auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); - auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); - - if (std::abs(leftX) > DEADZONE) { - if (leftX > 0) { - std::cout << "Left Stick" << std::endl; - movement.strafeRightLeft.main[0] = true; - } else { - movement.strafeRightLeft.reverse[0] = true; - } - } else { - movement.strafeRightLeft.reset(); - } - - if (std::abs(leftY) > DEADZONE) { - if (leftY > 0) { - std::cout << "Left Stick" << std::endl; - movement.forwardBackward.reverse[0] = true; - } else { - movement.forwardBackward.main[0] = true; - } - } else { - movement.forwardBackward.reset(); - } - - auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); - auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); - - if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { - double angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.0 / M_PI; - if (angle < 0) angle += 360.f; - - int selectedOption = 0; - if (angle >= 0 && angle < 90) { - selectedOption = 0; // Right - } else if (angle >= 90 && angle < 180) { - selectedOption = 1; // Down - } else if (angle >= 180 && angle < 270) { - selectedOption = 2; // Left - } else { - selectedOption = 3; // Up - } - - std::cout << "Joystick angle: " << angle << "°\n"; - std::cout << "Selected Option: " << selectedOption << "\n"; - } + ginfo("Received axis event: Native id: %i, Virtual id: 0x%X (%i) val: %f", dev->last_axis_event()->native_id, + dev->last_axis_event()->vc, dev->last_axis_event()->vc, dev->last_axis_event()->virtual_value); }; auto connect_handler = [h](std::shared_ptr dev) { @@ -1241,3 +1195,60 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } } +void PlayerControl::handleAxisInput(std::shared_ptr dev) { + const int DEADZONE = 16384; + + // Hier wird angenommen, dass 'get_axis' die Achsenwerte zurückgibt + auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); // Anpassen, falls nötig + auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); // Anpassen, falls nötig + + if (std::abs(leftX) > DEADZONE) { + if (leftX > 0) { + std::cout << "Left Stick" << std::endl; + movement.strafeRightLeft.main[0] = true; + } else { + movement.strafeRightLeft.reverse[0] = true; + } + } else { + movement.strafeRightLeft.reset(); + } + + if (std::abs(leftY) > DEADZONE) { + if (leftY > 0) { + std::cout << "Left Stick" << std::endl; + movement.forwardBackward.reverse[0] = true; + } else { + movement.forwardBackward.main[0] = true; + } + } else { + movement.forwardBackward.reset(); + } + + // Rechts Stick + auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); // Anpassen, falls nötig + auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); // Anpassen, falls nötig + + if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { + double angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.0 / M_PI; + if (angle < 0) angle += 360.f; + + int selectedOption = 0; + if (angle >= 0 && angle < 90) { + selectedOption = 0; // Right + } else if (angle >= 90 && angle < 180) { + selectedOption = 1; // Down + } else if (angle >= 180 && angle < 270) { + selectedOption = 2; // Left + } else { + selectedOption = 3; // Up + } + + std::cout << "Joystick angle: " << angle << "°\n"; + std::cout << "Selected Option: " << selectedOption << "\n"; + } +} + +void PlayerControl::setupSettings() { + // Gamepad-spezifische Einstellungen hier initialisieren. +} + From 6563194ed1fc7221e34ce1e62e1e0ba9bdddb360 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:14:40 +0100 Subject: [PATCH 30/94] maybe now? --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a585a4fc..5ab8d1685 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,8 @@ include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad/include) # Add the libgamepad subdirectory if it contains its own CMakeLists.txt add_subdirectory(lib/libgamepad) +target_link_libraries(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/libgamepad/libgamepad.a) + if(WIN32) if(MSVC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup" ) From 7df4357481c46029817ba245deda9573747144d9 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:15:36 +0100 Subject: [PATCH 31/94] now? --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ab8d1685..ec47d8e2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad/include) # Add the libgamepad subdirectory if it contains its own CMakeLists.txt add_subdirectory(lib/libgamepad) -target_link_libraries(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/libgamepad/libgamepad.a) +target_link_libraries(${PROJECT_NAME} PRIVATE gamepad) if(WIN32) if(MSVC) From 66e119c7ca77cc63d8444d8f0fb79e19a57dc41d Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:16:54 +0100 Subject: [PATCH 32/94] ? --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec47d8e2e..5ab8d1685 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ include_directories(${CMAKE_SOURCE_DIR}/lib/libgamepad/include) # Add the libgamepad subdirectory if it contains its own CMakeLists.txt add_subdirectory(lib/libgamepad) -target_link_libraries(${PROJECT_NAME} PRIVATE gamepad) +target_link_libraries(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/libgamepad/libgamepad.a) if(WIN32) if(MSVC) From ceea9e5ac71f0bb2fce21cccf38948db7381a129 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:22:18 +0100 Subject: [PATCH 33/94] asfa --- game/game/playercontrol.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 362440379..f8028f38c 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -32,6 +32,11 @@ BOOL WINAPI handler(DWORD s) { } #endif + +PlayerControl::~PlayerControl() { + Gothic::inst().onSettingsChanged.ubind(this,&PlayerControl::setupSettings); + } + PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) : dlg(dlg), inv(inv) { Gothic::inst().onSettingsChanged.bind(this, &PlayerControl::setupSettings); From 2ba64643923f70c07d90a3e8f14a7ed1f6da979a Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:25:24 +0100 Subject: [PATCH 34/94] falesly deleted --- game/game/playercontrol.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index f8028f38c..7842f2428 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1254,6 +1254,9 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { } void PlayerControl::setupSettings() { - // Gamepad-spezifische Einstellungen hier initialisieren. + if(Gothic::inst().version().game==2) { + g2Ctrl = Gothic::inst().settingsGetI("GAME","USEGOTHIC1CONTROLS")==0; + } else { + g2Ctrl = false; } From 7b364b6955505be1c8690fed306372d471dddc8c Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:26:15 +0100 Subject: [PATCH 35/94] ... --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 7842f2428..dc88bd373 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1259,4 +1259,4 @@ void PlayerControl::setupSettings() { } else { g2Ctrl = false; } - +} From 999cb27da93abc686c645fba67a89ca9a940c8b3 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:32:16 +0100 Subject: [PATCH 36/94] now it should get called --- game/game/playercontrol.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index dc88bd373..6a706825b 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1254,6 +1254,10 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { } void PlayerControl::setupSettings() { + + handleButtonInput(std::shared_ptr dev) + handleAxisInput(std::shared_ptr dev) + if(Gothic::inst().version().game==2) { g2Ctrl = Gothic::inst().settingsGetI("GAME","USEGOTHIC1CONTROLS")==0; } else { From cca847e7f28841ea073d97c43535a800ae7810b3 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:33:27 +0100 Subject: [PATCH 37/94] 11 --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 6a706825b..3b3a36603 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1255,8 +1255,8 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { void PlayerControl::setupSettings() { - handleButtonInput(std::shared_ptr dev) - handleAxisInput(std::shared_ptr dev) + handleButtonInput(dev) + handleAxisInput(dev) if(Gothic::inst().version().game==2) { g2Ctrl = Gothic::inst().settingsGetI("GAME","USEGOTHIC1CONTROLS")==0; From 8edfc3b8f6400655f04b61e9810fd582896503d7 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:34:25 +0100 Subject: [PATCH 38/94] ... --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 3b3a36603..2d8aca719 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1255,8 +1255,8 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { void PlayerControl::setupSettings() { - handleButtonInput(dev) - handleAxisInput(dev) + handleButtonInput(dev); + handleAxisInput(dev); if(Gothic::inst().version().game==2) { g2Ctrl = Gothic::inst().settingsGetI("GAME","USEGOTHIC1CONTROLS")==0; From be4660688d1a0b470f042d97793e4810da96bcd3 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:34:51 +0100 Subject: [PATCH 39/94] ... --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 2d8aca719..33f426e76 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1255,8 +1255,8 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { void PlayerControl::setupSettings() { - handleButtonInput(dev); - handleAxisInput(dev); + handleButtonInput(); + handleAxisInput(); if(Gothic::inst().version().game==2) { g2Ctrl = Gothic::inst().settingsGetI("GAME","USEGOTHIC1CONTROLS")==0; From 5367e3472c0d3de930abea926b7e428ae4fd78cd Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 19:25:06 +0100 Subject: [PATCH 40/94] erase debug --- game/game/playercontrol.cpp | 99 ++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 33f426e76..b8dd9e1c0 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -47,52 +47,6 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) #else SetConsoleCtrlHandler(handler, TRUE); #endif - - auto h = gamepad::hook::make(); - h->set_plug_and_play(true, gamepad::ms(1000)); - h->set_sleep_time(gamepad::ms(5)); // just std::chrono::milliseconds - - auto button_handler = [](std::shared_ptr dev) { - ginfo("Received button event: Native id: %i, Virtual id: 0x%X (%i) val: %f", - dev->last_button_event()->native_id, dev->last_button_event()->vc, - dev->last_button_event()->vc, dev->last_button_event()->virtual_value); - }; - - auto axis_handler = [](std::shared_ptr dev) { - ginfo("Received axis event: Native id: %i, Virtual id: 0x%X (%i) val: %f", dev->last_axis_event()->native_id, - dev->last_axis_event()->vc, dev->last_axis_event()->vc, dev->last_axis_event()->virtual_value); - }; - - auto connect_handler = [h](std::shared_ptr dev) { - ginfo("%s connected", dev->get_name().c_str()); - if (!dev->has_binding()) { - #ifdef LGP_ENABLE_JSON - ginfo("Found device, running config wizard"); - json11::Json cfg; - h->make_xbox_config(dev, cfg); - ginfo("Result config: %s", cfg.dump().c_str()); - #else - ginfo("Json isn't enabled for libgamepad, so the config wizard can't be used"); - #endif - } - }; - - auto disconnect_handler = [](std::shared_ptr dev) { - ginfo("%s disconnected", dev->get_name().c_str()); - }; - - h->set_axis_event_handler(axis_handler); - h->set_button_event_handler(button_handler); - h->set_connect_event_handler(connect_handler); - h->set_disconnect_event_handler(disconnect_handler); - - if (!h->start()) { - gerr("Couldn't start gamepad hook"); - throw std::runtime_error("Failed to initialize gamepad hook"); - } - - while (run_flag) - std::this_thread::sleep_for(gamepad::ms(50)); } void PlayerControl::setTarget(Npc *other) { @@ -1254,13 +1208,54 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { } void PlayerControl::setupSettings() { + // Ensure the gamepad hook is initialized + auto h = gamepad::hook::make(); - handleButtonInput(); - handleAxisInput(); + // Set plug-and-play and polling sleep time + h->set_plug_and_play(true, gamepad::ms(1000)); + h->set_sleep_time(gamepad::ms(5)); + + // Reassign handlers to ensure they are correctly hooked + h->set_button_event_handler([this](std::shared_ptr dev) { + this->handleButtonInput(dev); + }); + + h->set_axis_event_handler([this](std::shared_ptr dev) { + this->handleAxisInput(dev); + }); + + h->set_connect_event_handler([h](std::shared_ptr dev) { + ginfo("%s connected", dev->get_name().c_str()); + if (!dev->has_binding()) { + #ifdef LGP_ENABLE_JSON + ginfo("Found device, running config wizard"); + json11::Json cfg; + h->make_xbox_config(dev, cfg); + ginfo("Result config: %s", cfg.dump().c_str()); + #else + ginfo("Json isn't enabled for libgamepad, so the config wizard can't be used"); + #endif + } + }); + + h->set_disconnect_event_handler([](std::shared_ptr dev) { + ginfo("%s disconnected", dev->get_name().c_str()); + }); - if(Gothic::inst().version().game==2) { - g2Ctrl = Gothic::inst().settingsGetI("GAME","USEGOTHIC1CONTROLS")==0; + // Start the gamepad hook if not already started + if (!h->start()) { + gerr("Couldn't start gamepad hook"); + throw std::runtime_error("Failed to initialize gamepad hook"); + } + + // Log gamepad setup success + ginfo("Gamepad hook initialized and handlers set"); + + // Set Gothic 2 control mode if applicable + if (Gothic::inst().version().game == 2) { + g2Ctrl = Gothic::inst().settingsGetI("GAME", "USEGOTHIC1CONTROLS") == 0; } else { - g2Ctrl = false; -} + g2Ctrl = false; + } } + From c35bf11defd62a73d419c86d37b0b496727567cb Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 19:59:15 +0100 Subject: [PATCH 41/94] controller configuration --- game/game/playercontrol.cpp | 139 ++++++++++++++++++++++++++++++++++-- 1 file changed, 133 insertions(+), 6 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index b8dd9e1c0..ad6e658af 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -47,8 +47,56 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) #else SetConsoleCtrlHandler(handler, TRUE); #endif + + // Gamepad hook setup + auto h = gamepad::hook::make(); + h->set_plug_and_play(true, gamepad::ms(1000)); + h->set_sleep_time(gamepad::ms(5)); + + // Reassign handlers + h->set_button_event_handler([this](std::shared_ptr dev) { + this->handleButtonInput(dev); + }); + + h->set_axis_event_handler([this](std::shared_ptr dev) { + this->handleAxisInput(dev); + }); + + h->set_connect_event_handler([h, this](std::shared_ptr dev) { + ginfo("%s connected", dev->get_name().c_str()); + if (!dev->has_binding()) { + std::cout << "No binding found. Starting configuration wizard..." << std::endl; + configureController(dev); // Call configuration wizard here + } else { + std::cout << "Existing binding found for device: " << dev->get_name() << std::endl; + } + }); + + h->set_disconnect_event_handler([](std::shared_ptr dev) { + ginfo("%s disconnected", dev->get_name().c_str()); + }); + + // Start the hook + if (!h->start()) { + gerr("Couldn't start gamepad hook"); + throw std::runtime_error("Failed to initialize gamepad hook"); + } + + // Load configuration if exists or prompt configuration + std::ifstream inFile("controller_config.json"); + if (inFile.is_open()) { + std::string configStr((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); + h->load_binding_from_json(configStr); + std::cout << "Loaded configuration from file." << std::endl; + } else { + std::cout << "No configuration file found. Starting configuration wizard..." << std::endl; + if (auto dev = h->get_devices().front()) { // Assuming at least one device is connected + configureController(dev); + } + } } + void PlayerControl::setTarget(Npc *other) { auto w = Gothic::inst().world(); auto pl = w ? w->player() : nullptr; @@ -1157,9 +1205,8 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { void PlayerControl::handleAxisInput(std::shared_ptr dev) { const int DEADZONE = 16384; - // Hier wird angenommen, dass 'get_axis' die Achsenwerte zurückgibt - auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); // Anpassen, falls nötig - auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); // Anpassen, falls nötig + auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); + auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); if (std::abs(leftX) > DEADZONE) { if (leftX > 0) { @@ -1183,9 +1230,8 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { movement.forwardBackward.reset(); } - // Rechts Stick - auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); // Anpassen, falls nötig - auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); // Anpassen, falls nötig + auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); + auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { double angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.0 / M_PI; @@ -1259,3 +1305,84 @@ void PlayerControl::setupSettings() { } } +void configureController(std::shared_ptr dev) { + if (!dev) { + std::cerr << "No device provided for configuration." << std::endl; + return; + } + + json11::Json::object controllerConfig; + std::cout << "Starting configuration wizard for device: " << dev->get_name() << std::endl; + + // Button actions + const std::map buttonActions = { + {"Jump", "button_jump"}, + {"Melee Attack", "button_melee"}, + {"Bow Attack", "button_bow"}, + {"Magic Use", "button_magic"}, + {"Interact", "button_interact"}, + {"Inventory", "button_inventory"} + }; + + // Axis actions + const std::map axisActions = { + {"Move Horizontal", "axis_move_x"}, + {"Move Vertical", "axis_move_y"}, + {"Camera Horizontal", "axis_camera_x"}, + {"Camera Vertical", "axis_camera_y"} + }; + + // Map buttons + for (const auto& [actionName, configKey] : buttonActions) { + std::cout << "Press the button for action: " << actionName << std::endl; + + gamepad::button_event* evt = nullptr; + do { + evt = dev->last_button_event(); + } while (!evt || evt->virtual_value <= 0); + + int buttonId = evt->native_id; + std::cout << "Assigned button " << buttonId << " to " << actionName << std::endl; + + controllerConfig[configKey] = buttonId; + + // Debounce + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } + + // Map axes + for (const auto& [actionName, configKey] : axisActions) { + std::cout << "Move the axis for action: " << actionName << std::endl; + + gamepad::axis_event* evt = nullptr; + do { + evt = dev->last_axis_event(); + } while (!evt || std::abs(evt->virtual_value) < 0.5); + + int axisId = evt->native_id; + std::cout << "Assigned axis " << axisId << " to " << actionName << std::endl; + + controllerConfig[configKey] = axisId; + + // Debounce + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } + + // Save configuration to JSON + json11::Json config = controllerConfig; + std::string configStr = config.dump(); + + // Optionally save to file + std::ofstream outFile("controller_config.json"); + if (outFile.is_open()) { + outFile << configStr; + outFile.close(); + std::cout << "Configuration saved to controller_config.json" << std::endl; + } else { + std::cerr << "Failed to save configuration to file." << std::endl; + } + + // Load the configuration back into the device + dev->load_binding_from_json(configStr); + std::cout << "Configuration applied to the device." << std::endl; +} From 97ac6794c3fae2ce4fa21dc22f868fec79f049da Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:00:56 +0100 Subject: [PATCH 42/94] debug --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index ad6e658af..16434b3bc 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1305,7 +1305,7 @@ void PlayerControl::setupSettings() { } } -void configureController(std::shared_ptr dev) { +void PlayerControl::configureController(std::shared_ptr dev) { if (!dev) { std::cerr << "No device provided for configuration." << std::endl; return; From d1fa2d7e98bd640d2ec0fe87c11261ddb879eed3 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:04:50 +0100 Subject: [PATCH 43/94] debug --- game/game/playercontrol.h | 1 + 1 file changed, 1 insertion(+) diff --git a/game/game/playercontrol.h b/game/game/playercontrol.h index 678573291..7559e7374 100644 --- a/game/game/playercontrol.h +++ b/game/game/playercontrol.h @@ -27,6 +27,7 @@ class PlayerControl final { void onKeyPressed (KeyCodec::Action a, Tempest::Event::KeyType key, KeyCodec::Mapping mapping = KeyCodec::Mapping::Primary); void onKeyReleased(KeyCodec::Action a, KeyCodec::Mapping mapping = KeyCodec::Mapping::Primary); + void configureController(std::shared_ptr dev); bool isPressed(KeyCodec::Action a) const; void onRotateMouse(float dAngle); void onRotateMouseDy(float dAngle); From 0d4b9482b9d62829a8a7b8bfb439ec9b8de4d3cd Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:07:19 +0100 Subject: [PATCH 44/94] debug --- game/game/playercontrol.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 16434b3bc..5e5a99237 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "world/objects/npc.h" #include "world/objects/item.h" @@ -86,8 +87,9 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) std::ifstream inFile("controller_config.json"); if (inFile.is_open()) { std::string configStr((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); - h->load_binding_from_json(configStr); - std::cout << "Loaded configuration from file." << std::endl; + //h->load_binding_from_json(configStr); + //std::cout << "Loaded configuration from file." << std::endl; + std::cout << "Loading configuration manually is not yet implemented" << std::endl; } else { std::cout << "No configuration file found. Starting configuration wizard..." << std::endl; if (auto dev = h->get_devices().front()) { // Assuming at least one device is connected From 75f771e5fe560398e0ffeeed73c1a123cfb1ad77 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:07:54 +0100 Subject: [PATCH 45/94] debug --- game/game/playercontrol.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 5e5a99237..f8fdcbbe2 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -87,9 +87,8 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) std::ifstream inFile("controller_config.json"); if (inFile.is_open()) { std::string configStr((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); - //h->load_binding_from_json(configStr); - //std::cout << "Loaded configuration from file." << std::endl; - std::cout << "Loading configuration manually is not yet implemented" << std::endl; + h->load_binding_from_json(configStr); + std::cout << "Loaded configuration from file." << std::endl; } else { std::cout << "No configuration file found. Starting configuration wizard..." << std::endl; if (auto dev = h->get_devices().front()) { // Assuming at least one device is connected From bf7225691f5e40dcae7d97eb6b9c142c9b63b84d Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:11:50 +0100 Subject: [PATCH 46/94] debug --- game/game/playercontrol.cpp | 44 +++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index f8fdcbbe2..d00a6da66 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -87,8 +87,9 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) std::ifstream inFile("controller_config.json"); if (inFile.is_open()) { std::string configStr((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); - h->load_binding_from_json(configStr); - std::cout << "Loaded configuration from file." << std::endl; + //h->load_binding_from_json(configStr); + //std::cout << "Loaded configuration from file." << std::endl; + std::cout << "Loading configuration manually is not yet implemented" << std::endl; } else { std::cout << "No configuration file found. Starting configuration wizard..." << std::endl; if (auto dev = h->get_devices().front()) { // Assuming at least one device is connected @@ -1337,14 +1338,17 @@ void PlayerControl::configureController(std::shared_ptr dev) { for (const auto& [actionName, configKey] : buttonActions) { std::cout << "Press the button for action: " << actionName << std::endl; - gamepad::button_event* evt = nullptr; + int buttonId = -1; do { - evt = dev->last_button_event(); - } while (!evt || evt->virtual_value <= 0); + for (int i = gamepad::button::A; i < gamepad::button::MAX; ++i) { + if (dev->is_button_pressed(static_cast(i))) { + buttonId = i; + break; + } + } + } while (buttonId == -1); - int buttonId = evt->native_id; std::cout << "Assigned button " << buttonId << " to " << actionName << std::endl; - controllerConfig[configKey] = buttonId; // Debounce @@ -1355,14 +1359,17 @@ void PlayerControl::configureController(std::shared_ptr dev) { for (const auto& [actionName, configKey] : axisActions) { std::cout << "Move the axis for action: " << actionName << std::endl; - gamepad::axis_event* evt = nullptr; + int axisId = -1; do { - evt = dev->last_axis_event(); - } while (!evt || std::abs(evt->virtual_value) < 0.5); + for (int i = gamepad::axis::LEFT_X; i < gamepad::axis::MAX; ++i) { + if (std::abs(dev->get_axis_value(static_cast(i))) > 0.5) { + axisId = i; + break; + } + } + } while (axisId == -1); - int axisId = evt->native_id; std::cout << "Assigned axis " << axisId << " to " << actionName << std::endl; - controllerConfig[configKey] = axisId; // Debounce @@ -1383,7 +1390,16 @@ void PlayerControl::configureController(std::shared_ptr dev) { std::cerr << "Failed to save configuration to file." << std::endl; } - // Load the configuration back into the device - dev->load_binding_from_json(configStr); + // After saving the configuration, you can manually apply it if needed std::cout << "Configuration applied to the device." << std::endl; + + // If you want to apply the saved configuration, you'd need to load it manually + // Example of loading the config and applying to the device + // std::ifstream inFile("controller_config.json"); + // if (inFile.is_open()) { + // std::string configStr((std::istreambuf_iterator(inFile)), + // std::istreambuf_iterator()); + // json11::Json config = json11::Json::parse(configStr); + // // Apply the config to the device (map actions manually) + // } } From 13845f0fdb1f1fb2a80e73adf76b346ef00d6fba Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:22:28 +0100 Subject: [PATCH 47/94] wrong axis name --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index d00a6da66..2a3f80ee3 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1361,7 +1361,7 @@ void PlayerControl::configureController(std::shared_ptr dev) { int axisId = -1; do { - for (int i = gamepad::axis::LEFT_X; i < gamepad::axis::MAX; ++i) { + for (int i = gamepad::axis::LEFT_STICK_X; i < gamepad::axis::MAX; ++i) { if (std::abs(dev->get_axis_value(static_cast(i))) > 0.5) { axisId = i; break; From 563c9517e1a7b0d26d0075ee93b1a89434971b41 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:27:34 +0100 Subject: [PATCH 48/94] debug --- game/game/playercontrol.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 2a3f80ee3..b36c9d209 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1340,7 +1340,8 @@ void PlayerControl::configureController(std::shared_ptr dev) { int buttonId = -1; do { - for (int i = gamepad::button::A; i < gamepad::button::MAX; ++i) { + // Iterate through the button values explicitly + for (int i = gamepad::button::A; i <= gamepad::button::GUIDE; ++i) { if (dev->is_button_pressed(static_cast(i))) { buttonId = i; break; @@ -1361,8 +1362,10 @@ void PlayerControl::configureController(std::shared_ptr dev) { int axisId = -1; do { - for (int i = gamepad::axis::LEFT_STICK_X; i < gamepad::axis::MAX; ++i) { - if (std::abs(dev->get_axis_value(static_cast(i))) > 0.5) { + // Iterate through the axis values explicitly + for (int i = gamepad::axis::LEFT_STICK_X; i < gamepad::axis::LAST; ++i) { + float axisValue = dev->get_axis_value(static_cast(i)); + if (std::abs(axisValue) > 0.5f) { axisId = i; break; } @@ -1392,14 +1395,5 @@ void PlayerControl::configureController(std::shared_ptr dev) { // After saving the configuration, you can manually apply it if needed std::cout << "Configuration applied to the device." << std::endl; - - // If you want to apply the saved configuration, you'd need to load it manually - // Example of loading the config and applying to the device - // std::ifstream inFile("controller_config.json"); - // if (inFile.is_open()) { - // std::string configStr((std::istreambuf_iterator(inFile)), - // std::istreambuf_iterator()); - // json11::Json config = json11::Json::parse(configStr); - // // Apply the config to the device (map actions manually) - // } } + From 2113108e70f73df9bcdbcb2caf3d603655b8dd61 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:30:40 +0100 Subject: [PATCH 49/94] debug --- game/game/playercontrol.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index b36c9d209..ae1d88cc5 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1340,9 +1340,9 @@ void PlayerControl::configureController(std::shared_ptr dev) { int buttonId = -1; do { - // Iterate through the button values explicitly - for (int i = gamepad::button::A; i <= gamepad::button::GUIDE; ++i) { - if (dev->is_button_pressed(static_cast(i))) { + // Iterate through button values from A to LAST - 1 + for (int i = gamepad::button::A; i < gamepad::button::LAST; ++i) { + if (dev->is_button_pressed(static_cast(i))) { buttonId = i; break; } @@ -1362,9 +1362,9 @@ void PlayerControl::configureController(std::shared_ptr dev) { int axisId = -1; do { - // Iterate through the axis values explicitly + // Iterate through axis values from LEFT_STICK_X to LAST - 1 for (int i = gamepad::axis::LEFT_STICK_X; i < gamepad::axis::LAST; ++i) { - float axisValue = dev->get_axis_value(static_cast(i)); + float axisValue = dev->get_axis_value(static_cast(i)); if (std::abs(axisValue) > 0.5f) { axisId = i; break; From 4414301f8713c3a722f636081daaffa4d1862cb6 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:32:36 +0100 Subject: [PATCH 50/94] debug --- game/game/playercontrol.cpp | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index ae1d88cc5..ed1abba06 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1334,6 +1334,10 @@ void PlayerControl::configureController(std::shared_ptr dev) { {"Camera Vertical", "axis_camera_y"} }; + // Constants for deadzone and angle threshold + const double DEADZONE = 0.5; // Adjust deadzone sensitivity as needed + const double M_PI = 3.14159265358979323846; + // Map buttons for (const auto& [actionName, configKey] : buttonActions) { std::cout << "Press the button for action: " << actionName << std::endl; @@ -1341,7 +1345,7 @@ void PlayerControl::configureController(std::shared_ptr dev) { int buttonId = -1; do { // Iterate through button values from A to LAST - 1 - for (int i = gamepad::button::A; i < gamepad::button::LAST; ++i) { + for (int i = gamepad::button::A; i < gamepad::button::LAST; ++i) { if (dev->is_button_pressed(static_cast(i))) { buttonId = i; break; @@ -1364,15 +1368,35 @@ void PlayerControl::configureController(std::shared_ptr dev) { do { // Iterate through axis values from LEFT_STICK_X to LAST - 1 for (int i = gamepad::axis::LEFT_STICK_X; i < gamepad::axis::LAST; ++i) { - float axisValue = dev->get_axis_value(static_cast(i)); - if (std::abs(axisValue) > 0.5f) { - axisId = i; + // Get axis values for the selected axis (e.g., X and Y axes) + double axisValueX = dev->get_axis_value(static_cast(i)); // X value + double axisValueY = dev->get_axis_value(static_cast(i + 1)); // Y value (next axis) + + // Apply deadzone and angle calculation + if (std::abs(axisValueX) > DEADZONE || std::abs(axisValueY) > DEADZONE) { + // Calculate the angle using atan2 + double angle = std::atan2(axisValueY, axisValueX) * 180.0 / M_PI; + if (angle < 0) angle += 360.0; + + int selectedOption = 0; + // Determine direction based on the angle + if (angle >= 0 && angle < 90) { + selectedOption = 0; // Right + } else if (angle >= 90 && angle < 180) { + selectedOption = 1; // Down + } else if (angle >= 180 && angle < 270) { + selectedOption = 2; // Left + } else { + selectedOption = 3; // Up + } + + axisId = i; // Assign axis id based on selected option + std::cout << "Assigned axis " << axisId << " to " << actionName << " with direction: " << selectedOption << std::endl; break; } } } while (axisId == -1); - std::cout << "Assigned axis " << axisId << " to " << actionName << std::endl; controllerConfig[configKey] = axisId; // Debounce @@ -1396,4 +1420,3 @@ void PlayerControl::configureController(std::shared_ptr dev) { // After saving the configuration, you can manually apply it if needed std::cout << "Configuration applied to the device." << std::endl; } - From 66065abc8bd73a7fa7484cf6b51ddfb9d832b289 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:35:36 +0100 Subject: [PATCH 51/94] debug --- game/game/playercontrol.cpp | 54 +++++++++++++++---------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index ed1abba06..bde4817e9 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1334,10 +1334,6 @@ void PlayerControl::configureController(std::shared_ptr dev) { {"Camera Vertical", "axis_camera_y"} }; - // Constants for deadzone and angle threshold - const double DEADZONE = 0.5; // Adjust deadzone sensitivity as needed - const double M_PI = 3.14159265358979323846; - // Map buttons for (const auto& [actionName, configKey] : buttonActions) { std::cout << "Press the button for action: " << actionName << std::endl; @@ -1345,7 +1341,7 @@ void PlayerControl::configureController(std::shared_ptr dev) { int buttonId = -1; do { // Iterate through button values from A to LAST - 1 - for (int i = gamepad::button::A; i < gamepad::button::LAST; ++i) { + for (int i = gamepad::button::A; i < gamepad::button::LAST; ++i) { if (dev->is_button_pressed(static_cast(i))) { buttonId = i; break; @@ -1366,37 +1362,29 @@ void PlayerControl::configureController(std::shared_ptr dev) { int axisId = -1; do { - // Iterate through axis values from LEFT_STICK_X to LAST - 1 - for (int i = gamepad::axis::LEFT_STICK_X; i < gamepad::axis::LAST; ++i) { - // Get axis values for the selected axis (e.g., X and Y axes) - double axisValueX = dev->get_axis_value(static_cast(i)); // X value - double axisValueY = dev->get_axis_value(static_cast(i + 1)); // Y value (next axis) - - // Apply deadzone and angle calculation - if (std::abs(axisValueX) > DEADZONE || std::abs(axisValueY) > DEADZONE) { - // Calculate the angle using atan2 - double angle = std::atan2(axisValueY, axisValueX) * 180.0 / M_PI; - if (angle < 0) angle += 360.0; - - int selectedOption = 0; - // Determine direction based on the angle - if (angle >= 0 && angle < 90) { - selectedOption = 0; // Right - } else if (angle >= 90 && angle < 180) { - selectedOption = 1; // Down - } else if (angle >= 180 && angle < 270) { - selectedOption = 2; // Left - } else { - selectedOption = 3; // Up - } - - axisId = i; // Assign axis id based on selected option - std::cout << "Assigned axis " << axisId << " to " << actionName << " with direction: " << selectedOption << std::endl; - break; - } + // Wait for a valid axis event + gamepad::axis_event* evt = dev->last_axis_event(); + if (!evt) continue; + + // Log the axis event details + ginfo("Received axis event: Native id: %i, Virtual id: 0x%X (%i) val: %f", + evt->native_id, evt->vc, evt->vc, evt->virtual_value); + + // Use the angle or value of the axis to determine the direction + int selectedOption = 0; + float angle = std::atan2(evt->virtual_value, evt->virtual_value) * 180.0 / M_PI; // Example logic to calculate angle + if (angle >= 90 && angle < 180) { + selectedOption = 1; // Down + } else if (angle >= 180 && angle < 270) { + selectedOption = 2; // Left + } else { + selectedOption = 3; // Up } + + axisId = evt->native_id; // Use the native id for the axis } while (axisId == -1); + std::cout << "Assigned axis " << axisId << " to " << actionName << std::endl; controllerConfig[configKey] = axisId; // Debounce From 7c6ea9f77c9edca2bfd3c360a26b35ff03e1fe62 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:37:41 +0100 Subject: [PATCH 52/94] debug --- game/game/playercontrol.cpp | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index bde4817e9..43c3a29f0 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1341,7 +1341,7 @@ void PlayerControl::configureController(std::shared_ptr dev) { int buttonId = -1; do { // Iterate through button values from A to LAST - 1 - for (int i = gamepad::button::A; i < gamepad::button::LAST; ++i) { + for (int i = gamepad::button::A; i < gamepad::button::LAST; ++i) { if (dev->is_button_pressed(static_cast(i))) { buttonId = i; break; @@ -1356,32 +1356,32 @@ void PlayerControl::configureController(std::shared_ptr dev) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } + // Lambda for axis event processing + auto axis_handler = [](std::shared_ptr dev) { + auto event = dev->last_axis_event(); + if (event) { + ginfo("Received axis event: Native id: %i, Virtual id: 0x%X (%i) val: %f", event->native_id, + event->vc, event->vc, event->virtual_value); + } + }; + // Map axes for (const auto& [actionName, configKey] : axisActions) { std::cout << "Move the axis for action: " << actionName << std::endl; int axisId = -1; do { - // Wait for a valid axis event - gamepad::axis_event* evt = dev->last_axis_event(); - if (!evt) continue; - - // Log the axis event details - ginfo("Received axis event: Native id: %i, Virtual id: 0x%X (%i) val: %f", - evt->native_id, evt->vc, evt->vc, evt->virtual_value); - - // Use the angle or value of the axis to determine the direction - int selectedOption = 0; - float angle = std::atan2(evt->virtual_value, evt->virtual_value) * 180.0 / M_PI; // Example logic to calculate angle - if (angle >= 90 && angle < 180) { - selectedOption = 1; // Down - } else if (angle >= 180 && angle < 270) { - selectedOption = 2; // Left - } else { - selectedOption = 3; // Up + // Iterate through axis values from LEFT_STICK_X to LAST - 1 + for (int i = gamepad::axis::LEFT_STICK_X; i < gamepad::axis::LAST; ++i) { + // Process axis events with the lambda function + axis_handler(dev); + + auto event = dev->last_axis_event(); + if (event && std::abs(event->virtual_value) > 0.5f) { + axisId = i; + break; + } } - - axisId = evt->native_id; // Use the native id for the axis } while (axisId == -1); std::cout << "Assigned axis " << axisId << " to " << actionName << std::endl; From 8ead7ef1fdc2a69d75dd95802f10c1156d675e22 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:43:19 +0100 Subject: [PATCH 53/94] less console bloat --- game/game/playercontrol.cpp | 63 +++++-------------------------------- 1 file changed, 7 insertions(+), 56 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 43c3a29f0..c730041d9 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1255,58 +1255,6 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { } } -void PlayerControl::setupSettings() { - // Ensure the gamepad hook is initialized - auto h = gamepad::hook::make(); - - // Set plug-and-play and polling sleep time - h->set_plug_and_play(true, gamepad::ms(1000)); - h->set_sleep_time(gamepad::ms(5)); - - // Reassign handlers to ensure they are correctly hooked - h->set_button_event_handler([this](std::shared_ptr dev) { - this->handleButtonInput(dev); - }); - - h->set_axis_event_handler([this](std::shared_ptr dev) { - this->handleAxisInput(dev); - }); - - h->set_connect_event_handler([h](std::shared_ptr dev) { - ginfo("%s connected", dev->get_name().c_str()); - if (!dev->has_binding()) { - #ifdef LGP_ENABLE_JSON - ginfo("Found device, running config wizard"); - json11::Json cfg; - h->make_xbox_config(dev, cfg); - ginfo("Result config: %s", cfg.dump().c_str()); - #else - ginfo("Json isn't enabled for libgamepad, so the config wizard can't be used"); - #endif - } - }); - - h->set_disconnect_event_handler([](std::shared_ptr dev) { - ginfo("%s disconnected", dev->get_name().c_str()); - }); - - // Start the gamepad hook if not already started - if (!h->start()) { - gerr("Couldn't start gamepad hook"); - throw std::runtime_error("Failed to initialize gamepad hook"); - } - - // Log gamepad setup success - ginfo("Gamepad hook initialized and handlers set"); - - // Set Gothic 2 control mode if applicable - if (Gothic::inst().version().game == 2) { - g2Ctrl = Gothic::inst().settingsGetI("GAME", "USEGOTHIC1CONTROLS") == 0; - } else { - g2Ctrl = false; - } -} - void PlayerControl::configureController(std::shared_ptr dev) { if (!dev) { std::cerr << "No device provided for configuration." << std::endl; @@ -1356,12 +1304,13 @@ void PlayerControl::configureController(std::shared_ptr dev) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } - // Lambda for axis event processing - auto axis_handler = [](std::shared_ptr dev) { + // Lambda for axis event processing (only log once per axis) + auto axis_handler = [](std::shared_ptr dev, bool& logged) { auto event = dev->last_axis_event(); - if (event) { + if (event && !logged) { ginfo("Received axis event: Native id: %i, Virtual id: 0x%X (%i) val: %f", event->native_id, event->vc, event->vc, event->virtual_value); + logged = true; // Set the flag to true after logging once } }; @@ -1370,11 +1319,13 @@ void PlayerControl::configureController(std::shared_ptr dev) { std::cout << "Move the axis for action: " << actionName << std::endl; int axisId = -1; + bool logged = false; // Track if we have logged the axis event + do { // Iterate through axis values from LEFT_STICK_X to LAST - 1 for (int i = gamepad::axis::LEFT_STICK_X; i < gamepad::axis::LAST; ++i) { // Process axis events with the lambda function - axis_handler(dev); + axis_handler(dev, logged); auto event = dev->last_axis_event(); if (event && std::abs(event->virtual_value) > 0.5f) { From 2305b615ed868362bb5f82636c0759b70eedc710 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:44:34 +0100 Subject: [PATCH 54/94] deleted wrong code --- game/game/playercontrol.cpp | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index c730041d9..d50316514 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1255,6 +1255,58 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { } } +void PlayerControl::setupSettings() { + // Ensure the gamepad hook is initialized + auto h = gamepad::hook::make(); + + // Set plug-and-play and polling sleep time + h->set_plug_and_play(true, gamepad::ms(1000)); + h->set_sleep_time(gamepad::ms(5)); + + // Reassign handlers to ensure they are correctly hooked + h->set_button_event_handler([this](std::shared_ptr dev) { + this->handleButtonInput(dev); + }); + + h->set_axis_event_handler([this](std::shared_ptr dev) { + this->handleAxisInput(dev); + }); + + h->set_connect_event_handler([h](std::shared_ptr dev) { + ginfo("%s connected", dev->get_name().c_str()); + if (!dev->has_binding()) { + #ifdef LGP_ENABLE_JSON + ginfo("Found device, running config wizard"); + json11::Json cfg; + h->make_xbox_config(dev, cfg); + ginfo("Result config: %s", cfg.dump().c_str()); + #else + ginfo("Json isn't enabled for libgamepad, so the config wizard can't be used"); + #endif + } + }); + + h->set_disconnect_event_handler([](std::shared_ptr dev) { + ginfo("%s disconnected", dev->get_name().c_str()); + }); + + // Start the gamepad hook if not already started + if (!h->start()) { + gerr("Couldn't start gamepad hook"); + throw std::runtime_error("Failed to initialize gamepad hook"); + } + + // Log gamepad setup success + ginfo("Gamepad hook initialized and handlers set"); + + // Set Gothic 2 control mode if applicable + if (Gothic::inst().version().game == 2) { + g2Ctrl = Gothic::inst().settingsGetI("GAME", "USEGOTHIC1CONTROLS") == 0; + } else { + g2Ctrl = false; + } +} + void PlayerControl::configureController(std::shared_ptr dev) { if (!dev) { std::cerr << "No device provided for configuration." << std::endl; From 9f0bd064481eebddea5820d21a1752dca2e44264 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:56:10 +0100 Subject: [PATCH 55/94] revert --- game/game/playercontrol.cpp | 154 ------------------------------------ game/game/playercontrol.h | 1 - 2 files changed, 155 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index d50316514..ad35165f8 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include "world/objects/npc.h" #include "world/objects/item.h" @@ -48,57 +47,8 @@ PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv) #else SetConsoleCtrlHandler(handler, TRUE); #endif - - // Gamepad hook setup - auto h = gamepad::hook::make(); - h->set_plug_and_play(true, gamepad::ms(1000)); - h->set_sleep_time(gamepad::ms(5)); - - // Reassign handlers - h->set_button_event_handler([this](std::shared_ptr dev) { - this->handleButtonInput(dev); - }); - - h->set_axis_event_handler([this](std::shared_ptr dev) { - this->handleAxisInput(dev); - }); - - h->set_connect_event_handler([h, this](std::shared_ptr dev) { - ginfo("%s connected", dev->get_name().c_str()); - if (!dev->has_binding()) { - std::cout << "No binding found. Starting configuration wizard..." << std::endl; - configureController(dev); // Call configuration wizard here - } else { - std::cout << "Existing binding found for device: " << dev->get_name() << std::endl; - } - }); - - h->set_disconnect_event_handler([](std::shared_ptr dev) { - ginfo("%s disconnected", dev->get_name().c_str()); - }); - - // Start the hook - if (!h->start()) { - gerr("Couldn't start gamepad hook"); - throw std::runtime_error("Failed to initialize gamepad hook"); - } - - // Load configuration if exists or prompt configuration - std::ifstream inFile("controller_config.json"); - if (inFile.is_open()) { - std::string configStr((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); - //h->load_binding_from_json(configStr); - //std::cout << "Loaded configuration from file." << std::endl; - std::cout << "Loading configuration manually is not yet implemented" << std::endl; - } else { - std::cout << "No configuration file found. Starting configuration wizard..." << std::endl; - if (auto dev = h->get_devices().front()) { // Assuming at least one device is connected - configureController(dev); - } - } } - void PlayerControl::setTarget(Npc *other) { auto w = Gothic::inst().world(); auto pl = w ? w->player() : nullptr; @@ -1307,107 +1257,3 @@ void PlayerControl::setupSettings() { } } -void PlayerControl::configureController(std::shared_ptr dev) { - if (!dev) { - std::cerr << "No device provided for configuration." << std::endl; - return; - } - - json11::Json::object controllerConfig; - std::cout << "Starting configuration wizard for device: " << dev->get_name() << std::endl; - - // Button actions - const std::map buttonActions = { - {"Jump", "button_jump"}, - {"Melee Attack", "button_melee"}, - {"Bow Attack", "button_bow"}, - {"Magic Use", "button_magic"}, - {"Interact", "button_interact"}, - {"Inventory", "button_inventory"} - }; - - // Axis actions - const std::map axisActions = { - {"Move Horizontal", "axis_move_x"}, - {"Move Vertical", "axis_move_y"}, - {"Camera Horizontal", "axis_camera_x"}, - {"Camera Vertical", "axis_camera_y"} - }; - - // Map buttons - for (const auto& [actionName, configKey] : buttonActions) { - std::cout << "Press the button for action: " << actionName << std::endl; - - int buttonId = -1; - do { - // Iterate through button values from A to LAST - 1 - for (int i = gamepad::button::A; i < gamepad::button::LAST; ++i) { - if (dev->is_button_pressed(static_cast(i))) { - buttonId = i; - break; - } - } - } while (buttonId == -1); - - std::cout << "Assigned button " << buttonId << " to " << actionName << std::endl; - controllerConfig[configKey] = buttonId; - - // Debounce - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - } - - // Lambda for axis event processing (only log once per axis) - auto axis_handler = [](std::shared_ptr dev, bool& logged) { - auto event = dev->last_axis_event(); - if (event && !logged) { - ginfo("Received axis event: Native id: %i, Virtual id: 0x%X (%i) val: %f", event->native_id, - event->vc, event->vc, event->virtual_value); - logged = true; // Set the flag to true after logging once - } - }; - - // Map axes - for (const auto& [actionName, configKey] : axisActions) { - std::cout << "Move the axis for action: " << actionName << std::endl; - - int axisId = -1; - bool logged = false; // Track if we have logged the axis event - - do { - // Iterate through axis values from LEFT_STICK_X to LAST - 1 - for (int i = gamepad::axis::LEFT_STICK_X; i < gamepad::axis::LAST; ++i) { - // Process axis events with the lambda function - axis_handler(dev, logged); - - auto event = dev->last_axis_event(); - if (event && std::abs(event->virtual_value) > 0.5f) { - axisId = i; - break; - } - } - } while (axisId == -1); - - std::cout << "Assigned axis " << axisId << " to " << actionName << std::endl; - controllerConfig[configKey] = axisId; - - // Debounce - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - } - - // Save configuration to JSON - json11::Json config = controllerConfig; - std::string configStr = config.dump(); - - // Optionally save to file - std::ofstream outFile("controller_config.json"); - if (outFile.is_open()) { - outFile << configStr; - outFile.close(); - std::cout << "Configuration saved to controller_config.json" << std::endl; - } else { - std::cerr << "Failed to save configuration to file." << std::endl; - } - - // After saving the configuration, you can manually apply it if needed - std::cout << "Configuration applied to the device." << std::endl; -} diff --git a/game/game/playercontrol.h b/game/game/playercontrol.h index 7559e7374..678573291 100644 --- a/game/game/playercontrol.h +++ b/game/game/playercontrol.h @@ -27,7 +27,6 @@ class PlayerControl final { void onKeyPressed (KeyCodec::Action a, Tempest::Event::KeyType key, KeyCodec::Mapping mapping = KeyCodec::Mapping::Primary); void onKeyReleased(KeyCodec::Action a, KeyCodec::Mapping mapping = KeyCodec::Mapping::Primary); - void configureController(std::shared_ptr dev); bool isPressed(KeyCodec::Action a) const; void onRotateMouse(float dAngle); void onRotateMouseDy(float dAngle); From b01ead03f49fcb36d08e02a665dd1efa10b2a7bf Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:35:58 +0100 Subject: [PATCH 56/94] more controls --- game/game/playercontrol.cpp | 39 ++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index ad35165f8..b5803b482 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1132,13 +1132,6 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { currentMagicSlot = Action::WeaponMage3; } } - if (dev->is_button_pressed(gamepad::button::Y)) { - std::cout << "Y pressed" << std::endl; - ctrl[Action::Jump] = true; - } else { - ctrl[Action::Jump] = false; - } - if (dev->is_button_pressed(gamepad::button::LB)) { std::cout << "Lshoulder pressed" << std::endl; movement.strafeRightLeft.reverse[0] = true; @@ -1152,6 +1145,31 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } else { movement.strafeRightLeft.main[0] = false; } + + if (dev->is_button_pressed(gamepad::button::Y)) { + std::cout << "Y pressed" << std::endl; + ctrl[Action::Jump] = true; + } else { + ctrl[Action::Jump] = false; + } + if (dev->is_button_pressed(gamepad::button::B)) { + std::cout << "B pressed" << std::endl; + ctrl[Action::Weapon] = true; + } else { + ctrl[Action::Weapon] = false; + } + if (dev->is_button_pressed(gamepad::button::A)) { + std::cout << "A pressed" << std::endl; + ctrl[Action::interact] = true; + } else { + ctrl[Action::interact] = false; + } + if (dev->is_button_pressed(gamepad::button::X)) { + std::cout << "X pressed" << std::endl; + ctrl[Action::Weapon] = true; + } else { + ctrl[Action::Weapon] = false; + } } void PlayerControl::handleAxisInput(std::shared_ptr dev) { @@ -1167,16 +1185,17 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { } else { movement.strafeRightLeft.reverse[0] = true; } - } else { + } else if { movement.strafeRightLeft.reset(); } if (std::abs(leftY) > DEADZONE) { if (leftY > 0) { std::cout << "Left Stick" << std::endl; - movement.forwardBackward.reverse[0] = true; + Action::Back = true; } else { movement.forwardBackward.main[0] = true; + Action::Forward = true; } } else { movement.forwardBackward.reset(); @@ -1192,10 +1211,12 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { int selectedOption = 0; if (angle >= 0 && angle < 90) { selectedOption = 0; // Right + KeyCodec::RotateR } else if (angle >= 90 && angle < 180) { selectedOption = 1; // Down } else if (angle >= 180 && angle < 270) { selectedOption = 2; // Left + KeyCodec::RotateL } else { selectedOption = 3; // Up } From 0294584d489dd88c1bfc8af8ae9ce1fd0ed92ff5 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:42:35 +0100 Subject: [PATCH 57/94] more control --- game/game/playercontrol.cpp | 40 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index b5803b482..ab1acef3b 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1160,13 +1160,13 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } if (dev->is_button_pressed(gamepad::button::A)) { std::cout << "A pressed" << std::endl; - ctrl[Action::interact] = true; + ctrl[Action::K_ENTER] = true; } else { - ctrl[Action::interact] = false; + ctrl[Action::K_ENTER] = false; } if (dev->is_button_pressed(gamepad::button::X)) { std::cout << "X pressed" << std::endl; - ctrl[Action::Weapon] = true; + ctrl[Action::] = true; } else { ctrl[Action::Weapon] = false; } @@ -1180,26 +1180,32 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { if (std::abs(leftX) > DEADZONE) { if (leftX > 0) { - std::cout << "Left Stick" << std::endl; - movement.strafeRightLeft.main[0] = true; + std::cout << "Left Stick Right" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); } else { - movement.strafeRightLeft.reverse[0] = true; + std::cout << "Left Stick Left" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); } - } else if { - movement.strafeRightLeft.reset(); + } else { + // Reset left/right movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); } - if (std::abs(leftY) > DEADZONE) { - if (leftY > 0) { - std::cout << "Left Stick" << std::endl; - Action::Back = true; - } else { - movement.forwardBackward.main[0] = true; - Action::Forward = true; - } +if (std::abs(leftY) > DEADZONE) { + if (leftY > 0) { + std::cout << "Left Stick Backward" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); } else { - movement.forwardBackward.reset(); + std::cout << "Left Stick Forward" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); } +} else { + // Reset forward/backward movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); +} + auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); From df80f89ab8878f21a2ce379bf9f04b4a808586b0 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:43:00 +0100 Subject: [PATCH 58/94] debug --- game/game/playercontrol.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index ab1acef3b..ee671704f 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1192,19 +1192,19 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); } -if (std::abs(leftY) > DEADZONE) { - if (leftY > 0) { - std::cout << "Left Stick Backward" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); + if (std::abs(leftY) > DEADZONE) { + if (leftY > 0) { + std::cout << "Left Stick Backward" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); + } else { + std::cout << "Left Stick Forward" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); + } } else { - std::cout << "Left Stick Forward" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); + // Reset forward/backward movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); } -} else { - // Reset forward/backward movement if within the deadzone - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); -} auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); From cd0fc26e7a247bee13706b0dfe4ac7ff25a116d1 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:43:36 +0100 Subject: [PATCH 59/94] debug --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index ee671704f..770654578 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1217,12 +1217,12 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { int selectedOption = 0; if (angle >= 0 && angle < 90) { selectedOption = 0; // Right - KeyCodec::RotateR + //KeyCodec::RotateR } else if (angle >= 90 && angle < 180) { selectedOption = 1; // Down } else if (angle >= 180 && angle < 270) { selectedOption = 2; // Left - KeyCodec::RotateL + //KeyCodec::RotateL } else { selectedOption = 3; // Up } From 409791ba1fa9648cd05412d9b9e30a0478d088ea Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:44:36 +0100 Subject: [PATCH 60/94] debug --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 770654578..056f2b732 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1166,7 +1166,7 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } if (dev->is_button_pressed(gamepad::button::X)) { std::cout << "X pressed" << std::endl; - ctrl[Action::] = true; + ctrl[Action::Weapon] = true; } else { ctrl[Action::Weapon] = false; } From d590eaf66677a95346dff214702dcc8a0ef83c9b Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:48:51 +0100 Subject: [PATCH 61/94] debug --- game/game/playercontrol.cpp | 55 ++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 056f2b732..8368e6123 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1176,35 +1176,40 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { const int DEADZONE = 16384; auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); - auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); +auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); - if (std::abs(leftX) > DEADZONE) { - if (leftX > 0) { - std::cout << "Left Stick Right" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); - } else { - std::cout << "Left Stick Left" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); - } +std::cout << "Left Stick X: " << leftX << " Y: " << leftY << std::endl; // Debugging both axis values + +if (std::abs(leftX) > DEADZONE) { + if (leftX > 0) { + std::cout << "Left Stick Right detected, sending right movement action" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); } else { - // Reset left/right movement if within the deadzone - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); - } + std::cout << "Left Stick Left detected, sending left movement action" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); + } +} else { + std::cout << "Left Stick X in deadzone, resetting left/right movement" << std::endl; + // Reset left/right movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); +} - if (std::abs(leftY) > DEADZONE) { - if (leftY > 0) { - std::cout << "Left Stick Backward" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); - } else { - std::cout << "Left Stick Forward" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); - } +if (std::abs(leftY) > DEADZONE) { + if (leftY > 0) { + std::cout << "Left Stick Down (Back) detected, sending backward movement action" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); } else { - // Reset forward/backward movement if within the deadzone - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); - } + std::cout << "Left Stick Up (Forward) detected, sending forward movement action" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); + } +} else { + std::cout << "Left Stick Y in deadzone, resetting forward/backward movement" << std::endl; + // Reset forward/backward movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); +} + auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); From 77a5b13f3a580417e3c9a2ef33d54a64deec2dd1 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:50:38 +0100 Subject: [PATCH 62/94] debug --- game/game/playercontrol.cpp | 57 +++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 8368e6123..3cd92eab6 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1173,43 +1173,38 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } void PlayerControl::handleAxisInput(std::shared_ptr dev) { - const int DEADZONE = 16384; + const int DEADZONE = 3; auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); -auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); + auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); -std::cout << "Left Stick X: " << leftX << " Y: " << leftY << std::endl; // Debugging both axis values - -if (std::abs(leftX) > DEADZONE) { - if (leftX > 0) { - std::cout << "Left Stick Right detected, sending right movement action" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); + if (std::abs(leftX) > DEADZONE) { + if (leftX > 0) { + std::cout << "Left Stick Right" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); + } else { + std::cout << "Left Stick Left" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); + } } else { - std::cout << "Left Stick Left detected, sending left movement action" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); - } -} else { - std::cout << "Left Stick X in deadzone, resetting left/right movement" << std::endl; - // Reset left/right movement if within the deadzone - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); -} + // Reset left/right movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); + } -if (std::abs(leftY) > DEADZONE) { - if (leftY > 0) { - std::cout << "Left Stick Down (Back) detected, sending backward movement action" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); + if (std::abs(leftY) > DEADZONE) { + if (leftY > 0) { + std::cout << "Left Stick Backward" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); + } else { + std::cout << "Left Stick Forward" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); + } } else { - std::cout << "Left Stick Up (Forward) detected, sending forward movement action" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); - } -} else { - std::cout << "Left Stick Y in deadzone, resetting forward/backward movement" << std::endl; - // Reset forward/backward movement if within the deadzone - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); -} - + // Reset forward/backward movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); + } auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); From 994a13c3cce582b5c20eeac60b34b9c870f6d136 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:51:47 +0100 Subject: [PATCH 63/94] debug --- game/game/playercontrol.cpp | 55 ++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 3cd92eab6..6b2635345 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1176,35 +1176,40 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { const int DEADZONE = 3; auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); - auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); +auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); - if (std::abs(leftX) > DEADZONE) { - if (leftX > 0) { - std::cout << "Left Stick Right" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); - } else { - std::cout << "Left Stick Left" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); - } +std::cout << "Left Stick X: " << leftX << " Y: " << leftY << std::endl; // Debugging both axis values + +if (std::abs(leftX) > DEADZONE) { + if (leftX > 0) { + std::cout << "Left Stick Right detected, sending right movement action" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); } else { - // Reset left/right movement if within the deadzone - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); - } + std::cout << "Left Stick Left detected, sending left movement action" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); + } +} else { + std::cout << "Left Stick X in deadzone, resetting left/right movement" << std::endl; + // Reset left/right movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); +} - if (std::abs(leftY) > DEADZONE) { - if (leftY > 0) { - std::cout << "Left Stick Backward" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); - } else { - std::cout << "Left Stick Forward" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); - } +if (std::abs(leftY) > DEADZONE) { + if (leftY > 0) { + std::cout << "Left Stick Down (Back) detected, sending backward movement action" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); } else { - // Reset forward/backward movement if within the deadzone - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); - } + std::cout << "Left Stick Up (Forward) detected, sending forward movement action" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); + } +} else { + std::cout << "Left Stick Y in deadzone, resetting forward/backward movement" << std::endl; + // Reset forward/backward movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); +} + auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); From f70c2d6ceebd2bd939924298ae8d6bf06aacda30 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:53:43 +0100 Subject: [PATCH 64/94] deadzone --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 6b2635345..b3795f8f5 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1173,7 +1173,7 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } void PlayerControl::handleAxisInput(std::shared_ptr dev) { - const int DEADZONE = 3; + const int DEADZONE = 0.05f; auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); From 90fef6d2fe2f7bac1d6f5ca4c8d4e6aaf3954401 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:55:08 +0100 Subject: [PATCH 65/94] debug --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index b3795f8f5..bd708bbf6 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1173,7 +1173,7 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } void PlayerControl::handleAxisInput(std::shared_ptr dev) { - const int DEADZONE = 0.05f; + const int DEADZONE = 0; auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); From c46bbc98c164441baf2256283fde004f4f4c8d80 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:56:42 +0100 Subject: [PATCH 66/94] debug --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index bd708bbf6..f7a87aa1f 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1173,7 +1173,7 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } void PlayerControl::handleAxisInput(std::shared_ptr dev) { - const int DEADZONE = 0; + const int DEADZONE = 5; auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); From 6eadefe88cc175be874622be02fc22904f39b6b6 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:01:14 +0100 Subject: [PATCH 67/94] debug --- game/game/playercontrol.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index f7a87aa1f..a1a62f60c 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1173,15 +1173,21 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } void PlayerControl::handleAxisInput(std::shared_ptr dev) { - const int DEADZONE = 5; + const int DEADZONE = 0; - auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); + // Get axis values from the gamepad +auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); -std::cout << "Left Stick X: " << leftX << " Y: " << leftY << std::endl; // Debugging both axis values +// Normalize the values to range from -1 to 1 +float normalizedLeftX = (leftX - 0.5f) * 2.0f; // [0.5, 1.0] becomes [0, 1], [0.5, 0.0] becomes [0, -1] +float normalizedLeftY = (leftY - 0.5f) * 2.0f; // Same for Y axis -if (std::abs(leftX) > DEADZONE) { - if (leftX > 0) { +std::cout << "Normalized Left Stick X: " << normalizedLeftX << " Y: " << normalizedLeftY << std::endl; + +// Left stick X movement (left/right) +if (std::abs(normalizedLeftX) > DEADZONE) { + if (normalizedLeftX > 0) { std::cout << "Left Stick Right detected, sending right movement action" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); } else { @@ -1190,13 +1196,13 @@ if (std::abs(leftX) > DEADZONE) { } } else { std::cout << "Left Stick X in deadzone, resetting left/right movement" << std::endl; - // Reset left/right movement if within the deadzone handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); } -if (std::abs(leftY) > DEADZONE) { - if (leftY > 0) { +// Left stick Y movement (forward/backward) +if (std::abs(normalizedLeftY) > DEADZONE) { + if (normalizedLeftY > 0) { std::cout << "Left Stick Down (Back) detected, sending backward movement action" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); } else { @@ -1205,13 +1211,13 @@ if (std::abs(leftY) > DEADZONE) { } } else { std::cout << "Left Stick Y in deadzone, resetting forward/backward movement" << std::endl; - // Reset forward/backward movement if within the deadzone handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); } + auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); From 4c004bd9547aac998dc7007213b6374c7dae1eac Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:15:05 +0100 Subject: [PATCH 68/94] debug --- game/game/playercontrol.cpp | 70 ++++++++++++++----------------------- 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index a1a62f60c..a59c33459 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1173,51 +1173,35 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } void PlayerControl::handleAxisInput(std::shared_ptr dev) { - const int DEADZONE = 0; - // Get axis values from the gamepad -auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); -auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); - -// Normalize the values to range from -1 to 1 -float normalizedLeftX = (leftX - 0.5f) * 2.0f; // [0.5, 1.0] becomes [0, 1], [0.5, 0.0] becomes [0, -1] -float normalizedLeftY = (leftY - 0.5f) * 2.0f; // Same for Y axis - -std::cout << "Normalized Left Stick X: " << normalizedLeftX << " Y: " << normalizedLeftY << std::endl; - -// Left stick X movement (left/right) -if (std::abs(normalizedLeftX) > DEADZONE) { - if (normalizedLeftX > 0) { - std::cout << "Left Stick Right detected, sending right movement action" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); - } else { - std::cout << "Left Stick Left detected, sending left movement action" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); + auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); + auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); + + if (std::abs(leftX) > 0.5) { + std::cout << "Left Stick Right" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); + } else if (std::abs(leftX) < 0.5){ + std::cout << "Left Stick Left" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); + + } else if (std::abs(leftX) == 0.5){ + // Reset left/right movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); + } + + if (std::abs(leftY) > 0.5) { + std::cout << "Left Stick Backward" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); + } else if (std::abs(leftY) < 0.5){ + std::cout << "Left Stick Forward" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); + + } else if (std::abs(leftY) == 0.5){ + // Reset left/right movement if within the deadzone + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); } -} else { - std::cout << "Left Stick X in deadzone, resetting left/right movement" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); -} - -// Left stick Y movement (forward/backward) -if (std::abs(normalizedLeftY) > DEADZONE) { - if (normalizedLeftY > 0) { - std::cout << "Left Stick Down (Back) detected, sending backward movement action" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); - } else { - std::cout << "Left Stick Up (Forward) detected, sending forward movement action" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); - } -} else { - std::cout << "Left Stick Y in deadzone, resetting forward/backward movement" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); -} - - - - auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); From fe7527db6f2506b2172b3815492a773fc7b803c2 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:16:05 +0100 Subject: [PATCH 69/94] debug --- game/game/playercontrol.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index a59c33459..2c58eb6a3 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1185,7 +1185,6 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); } else if (std::abs(leftX) == 0.5){ - // Reset left/right movement if within the deadzone handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); } @@ -1198,14 +1197,13 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); } else if (std::abs(leftY) == 0.5){ - // Reset left/right movement if within the deadzone handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); } auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); - if (std::abs(rightX) > DEADZONE || std::abs(rightY) > DEADZONE) { + if (std::abs(rightX) > 0.5 || std::abs(rightY) > 0.5) { double angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.0 / M_PI; if (angle < 0) angle += 360.f; From 3221eca7713dc1e959b9eca0def3e64b9089118b Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:30:03 +0100 Subject: [PATCH 70/94] look around --- game/game/playercontrol.cpp | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 2c58eb6a3..4dc77063e 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1176,7 +1176,6 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); - if (std::abs(leftX) > 0.5) { std::cout << "Left Stick Right" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); @@ -1200,28 +1199,25 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); } + auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); + if (std::abs(rightX) > 0.5) { + std::cout << "Right Stick Right" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::RotateR, KeyCodec::Mapping::Primary}, true); + } else if (std::abs(rightX) < 0.5){ + std::cout << "Right Stick Left" << std::endl; + handleMovementAction(KeyCodec::ActionMapping{Action::RotateL, KeyCodec::Mapping::Primary}, true); + + } else if (std::abs(rightX) == 0.5){ + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); + } - if (std::abs(rightX) > 0.5 || std::abs(rightY) > 0.5) { - double angle = std::atan2(static_cast(rightY), static_cast(rightX)) * 180.0 / M_PI; - if (angle < 0) angle += 360.f; - - int selectedOption = 0; - if (angle >= 0 && angle < 90) { - selectedOption = 0; // Right - //KeyCodec::RotateR - } else if (angle >= 90 && angle < 180) { - selectedOption = 1; // Down - } else if (angle >= 180 && angle < 270) { - selectedOption = 2; // Left - //KeyCodec::RotateL - } else { - selectedOption = 3; // Up - } - - std::cout << "Joystick angle: " << angle << "°\n"; - std::cout << "Selected Option: " << selectedOption << "\n"; + if (std::abs(rightY) != 0.5) { + float dAngle = (leftX - 0.5f) * 200.0f; + dAngle = std::max(-100.f, std::min(dAngle, 100.f)); + rotMouseY += dAngle * 0.2f; } } From 0ad105cff682a2780571e7a46f45527eb8b68440 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:32:46 +0100 Subject: [PATCH 71/94] debug --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 4dc77063e..8bbd29cb9 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1210,8 +1210,8 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { handleMovementAction(KeyCodec::ActionMapping{Action::RotateL, KeyCodec::Mapping::Primary}, true); } else if (std::abs(rightX) == 0.5){ - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::RotateR, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::RotateL, KeyCodec::Mapping::Primary}, false); } if (std::abs(rightY) != 0.5) { From f702c206a37ba27bf422aca5d62cb08f19e30c9c Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:39:41 +0100 Subject: [PATCH 72/94] Weapon on Y --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 8bbd29cb9..73ebc6cea 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1148,9 +1148,9 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { if (dev->is_button_pressed(gamepad::button::Y)) { std::cout << "Y pressed" << std::endl; - ctrl[Action::Jump] = true; + ctrl[Action::Weapon] = true; } else { - ctrl[Action::Jump] = false; + ctrl[Action::Weapon = false; } if (dev->is_button_pressed(gamepad::button::B)) { std::cout << "B pressed" << std::endl; From 90e4dc085e9c90f3f4a184c71539b7d03e4299cf Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:45:18 +0100 Subject: [PATCH 73/94] weapon on b --- game/game/playercontrol.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 73ebc6cea..5983fdfcd 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1148,15 +1148,14 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { if (dev->is_button_pressed(gamepad::button::Y)) { std::cout << "Y pressed" << std::endl; - ctrl[Action::Weapon] = true; + ctrl[Action::Jump] = true; } else { - ctrl[Action::Weapon = false; + ctrl[Action::Jump] = false; } if (dev->is_button_pressed(gamepad::button::B)) { - std::cout << "B pressed" << std::endl; - ctrl[Action::Weapon] = true; - } else { - ctrl[Action::Weapon] = false; + std::cout << "B pressed" << std::endl; + // Trigger Action::Weapon + handleMovementAction(KeyCodec::ActionMapping{Action::Weapon, KeyCodec::Mapping::Primary}, true); } if (dev->is_button_pressed(gamepad::button::A)) { std::cout << "A pressed" << std::endl; From 8e677c5c48d9c61e5fd2b96526afae3e65ca7686 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:49:24 +0100 Subject: [PATCH 74/94] debug --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 5983fdfcd..6e50afeb8 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1155,7 +1155,7 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { if (dev->is_button_pressed(gamepad::button::B)) { std::cout << "B pressed" << std::endl; // Trigger Action::Weapon - handleMovementAction(KeyCodec::ActionMapping{Action::Weapon, KeyCodec::Mapping::Primary}, true); + onKeyPressed(KeyCodec::Action::Weapon, Tempest::KeyEvent::KeyType::K_Return, KeyCodec::Mapping()); } if (dev->is_button_pressed(gamepad::button::A)) { std::cout << "A pressed" << std::endl; From 4fdd2af17613ae9228dcc23b034f5272c2ec37e0 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:54:40 +0100 Subject: [PATCH 75/94] ActionGeneric on A --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 6e50afeb8..1eb79aa5c 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1159,9 +1159,9 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } if (dev->is_button_pressed(gamepad::button::A)) { std::cout << "A pressed" << std::endl; - ctrl[Action::K_ENTER] = true; + ctrl[Action::ActionGeneric] = true; } else { - ctrl[Action::K_ENTER] = false; + ctrl[Action::ActionGeneric] = false; } if (dev->is_button_pressed(gamepad::button::X)) { std::cout << "X pressed" << std::endl; From 3afcb382a9026df4f86514e79d44b0c7f868b1fd Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:58:47 +0100 Subject: [PATCH 76/94] A ActionGeneric --- game/game/playercontrol.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 1eb79aa5c..b1667b6ec 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1159,9 +1159,7 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } if (dev->is_button_pressed(gamepad::button::A)) { std::cout << "A pressed" << std::endl; - ctrl[Action::ActionGeneric] = true; - } else { - ctrl[Action::ActionGeneric] = false; + onKeyPressed(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::L_Shift, KeyCodec::Mapping()); } if (dev->is_button_pressed(gamepad::button::X)) { std::cout << "X pressed" << std::endl; From 294dc723e5bb486a25437d661f29d12cbe78b75b Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:01:41 +0100 Subject: [PATCH 77/94] K_LShift --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index b1667b6ec..2298db203 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1159,7 +1159,7 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } if (dev->is_button_pressed(gamepad::button::A)) { std::cout << "A pressed" << std::endl; - onKeyPressed(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::L_Shift, KeyCodec::Mapping()); + onKeyPressed(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::K_LShift, KeyCodec::Mapping()); } if (dev->is_button_pressed(gamepad::button::X)) { std::cout << "X pressed" << std::endl; From 650349a9fbeb066f8761daebdc28ce45faa7265e Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:21:37 +0100 Subject: [PATCH 78/94] coninuous a press --- game/game/playercontrol.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 2298db203..2ffae2b6c 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1159,7 +1159,12 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } if (dev->is_button_pressed(gamepad::button::A)) { std::cout << "A pressed" << std::endl; + // Perform continuous action for A button onKeyPressed(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::K_LShift, KeyCodec::Mapping()); + } else { + // Stop action when A button is released + std::cout << "A released" << std::endl; + onKeyReleased(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::K_LShift, KeyCodec::Mapping()); } if (dev->is_button_pressed(gamepad::button::X)) { std::cout << "X pressed" << std::endl; @@ -1167,6 +1172,14 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } else { ctrl[Action::Weapon] = false; } + if (dev->is_button_pressed(gamepad::button::R_THUMB)) { + std::cout << "X pressed" << std::endl; + onKeyPressed(KeyCodec::Action::FirstPerson, Tempest::KeyEvent::KeyType::K_F, KeyCodec::Mapping()); + } + if (dev->is_button_pressed(gamepad::button::L_THUMB)) { + std::cout << "X pressed" << std::endl; + onKeyPressed(KeyCodec::Action::Sneak, Tempest::KeyEvent::KeyType::K_X, KeyCodec::Mapping()); + } } void PlayerControl::handleAxisInput(std::shared_ptr dev) { From ac749438443e77e85808585e11c7a9f3837a4a5d Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:22:51 +0100 Subject: [PATCH 79/94] debug --- game/game/playercontrol.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 2ffae2b6c..c37574ee4 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1152,11 +1152,13 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { } else { ctrl[Action::Jump] = false; } + if (dev->is_button_pressed(gamepad::button::B)) { - std::cout << "B pressed" << std::endl; - // Trigger Action::Weapon - onKeyPressed(KeyCodec::Action::Weapon, Tempest::KeyEvent::KeyType::K_Return, KeyCodec::Mapping()); + std::cout << "B pressed" << std::endl; + // Trigger Action::Weapon + onKeyPressed(KeyCodec::Action::Weapon, Tempest::KeyEvent::KeyType::K_Return, KeyCodec::Mapping()); } + if (dev->is_button_pressed(gamepad::button::A)) { std::cout << "A pressed" << std::endl; // Perform continuous action for A button @@ -1166,18 +1168,20 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { std::cout << "A released" << std::endl; onKeyReleased(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::K_LShift, KeyCodec::Mapping()); } + if (dev->is_button_pressed(gamepad::button::X)) { std::cout << "X pressed" << std::endl; ctrl[Action::Weapon] = true; } else { ctrl[Action::Weapon] = false; } + if (dev->is_button_pressed(gamepad::button::R_THUMB)) { - std::cout << "X pressed" << std::endl; + std::cout << "R_THUMB pressed" << std::endl; onKeyPressed(KeyCodec::Action::FirstPerson, Tempest::KeyEvent::KeyType::K_F, KeyCodec::Mapping()); } if (dev->is_button_pressed(gamepad::button::L_THUMB)) { - std::cout << "X pressed" << std::endl; + std::cout << "L_THUMB pressed" << std::endl; onKeyPressed(KeyCodec::Action::Sneak, Tempest::KeyEvent::KeyType::K_X, KeyCodec::Mapping()); } } From 09641f59310927f5a64d3c8e5ae99f8b7479bd96 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:24:36 +0100 Subject: [PATCH 80/94] debug --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index c37574ee4..405d3ba07 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1164,9 +1164,9 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { // Perform continuous action for A button onKeyPressed(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::K_LShift, KeyCodec::Mapping()); } else { - // Stop action when A button is released std::cout << "A released" << std::endl; - onKeyReleased(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::K_LShift, KeyCodec::Mapping()); + // Correcting the call to only pass two parameters (KeyCodec::Action and KeyCodec::Mapping) + onKeyReleased(KeyCodec::Action::ActionGeneric, KeyCodec::Mapping()); } if (dev->is_button_pressed(gamepad::button::X)) { From 49b9c4e4a0827c43de1a51df007f70c26188762f Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:28:57 +0100 Subject: [PATCH 81/94] action forward --- game/game/playercontrol.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 405d3ba07..8b7a64bbb 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1198,8 +1198,8 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); } else if (std::abs(leftX) == 0.5){ - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); } if (std::abs(leftY) > 0.5) { @@ -1207,7 +1207,7 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); } else if (std::abs(leftY) < 0.5){ std::cout << "Left Stick Forward" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, true); + onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_W, KeyCodec::Mapping()); } else if (std::abs(leftY) == 0.5){ handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); From 8d829190f3068fff1e0209efd48b1fdfd2b1a418 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:35:10 +0100 Subject: [PATCH 82/94] debug --- game/game/playercontrol.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 8b7a64bbb..c3c4febc2 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1190,40 +1190,40 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); - if (std::abs(leftX) > 0.5) { + if (std::abs(leftX) > 0.51) { std::cout << "Left Stick Right" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); - } else if (std::abs(leftX) < 0.5){ + onKeyPressed(KeyCodec::Action::Right, Tempest::KeyEvent::KeyType::K_D, KeyCodec::Mapping()); + } else if (std::abs(leftX) < 0.49){ std::cout << "Left Stick Left" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); + onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_A, KeyCodec::Mapping()); - } else if (std::abs(leftX) == 0.5){ + } else if (std::abs(leftX) >= 0.49 && std::abs(leftX) <= 0.51){ handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); } - if (std::abs(leftY) > 0.5) { + if (std::abs(leftY) > 0.51) { std::cout << "Left Stick Backward" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); - } else if (std::abs(leftY) < 0.5){ + onKeyPressed(KeyCodec::Action::Back, Tempest::KeyEvent::KeyType::K_S, KeyCodec::Mapping()); + } else if (std::abs(leftY) < 0.49){ std::cout << "Left Stick Forward" << std::endl; onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_W, KeyCodec::Mapping()); - } else if (std::abs(leftY) == 0.5){ + } else if (std::abs(leftY) >= 0.49 && std::abs(leftY) <= 0.51){ handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); } auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); - if (std::abs(rightX) > 0.5) { + if (std::abs(rightX) > 0.49) { std::cout << "Right Stick Right" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::RotateR, KeyCodec::Mapping::Primary}, true); - } else if (std::abs(rightX) < 0.5){ + } else if (std::abs(rightX) < 0.51){ std::cout << "Right Stick Left" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::RotateL, KeyCodec::Mapping::Primary}, true); - } else if (std::abs(rightX) == 0.5){ + } else if (std::abs(rightX) >= 0.49 && std::abs(rightX) <= 0.51){ handleMovementAction(KeyCodec::ActionMapping{Action::RotateR, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::RotateL, KeyCodec::Mapping::Primary}, false); } From 238c1ec132e5bc058ce05f85f9a7da59864de897 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:35:28 +0100 Subject: [PATCH 83/94] debug --- game/game/playercontrol.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index c3c4febc2..a3f98999f 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1163,12 +1163,7 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { std::cout << "A pressed" << std::endl; // Perform continuous action for A button onKeyPressed(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::K_LShift, KeyCodec::Mapping()); - } else { - std::cout << "A released" << std::endl; - // Correcting the call to only pass two parameters (KeyCodec::Action and KeyCodec::Mapping) - onKeyReleased(KeyCodec::Action::ActionGeneric, KeyCodec::Mapping()); - } - + } if (dev->is_button_pressed(gamepad::button::X)) { std::cout << "X pressed" << std::endl; ctrl[Action::Weapon] = true; From e9578d4a6f40db744e137abecb0945ed6b1f0fbc Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:37:54 +0100 Subject: [PATCH 84/94] debug --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index a3f98999f..c57e6f0e3 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1211,10 +1211,10 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); - if (std::abs(rightX) > 0.49) { + if (std::abs(rightX) > 0.51) { std::cout << "Right Stick Right" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::RotateR, KeyCodec::Mapping::Primary}, true); - } else if (std::abs(rightX) < 0.51){ + } else if (std::abs(rightX) < 0.49){ std::cout << "Right Stick Left" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::RotateL, KeyCodec::Mapping::Primary}, true); From 183785101e24be785228555818388dee6502f493 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:42:55 +0100 Subject: [PATCH 85/94] debug --- game/game/playercontrol.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index c57e6f0e3..832675c1f 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1163,7 +1163,12 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { std::cout << "A pressed" << std::endl; // Perform continuous action for A button onKeyPressed(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::K_LShift, KeyCodec::Mapping()); - } + } else { + std::cout << "A released" << std::endl; + // Correcting the call to only pass two parameters (KeyCodec::Action and KeyCodec::Mapping) + onKeyReleased(KeyCodec::Action::ActionGeneric, KeyCodec::Mapping()); + } + if (dev->is_button_pressed(gamepad::button::X)) { std::cout << "X pressed" << std::endl; ctrl[Action::Weapon] = true; @@ -1192,10 +1197,10 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { std::cout << "Left Stick Left" << std::endl; onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_A, KeyCodec::Mapping()); - } else if (std::abs(leftX) >= 0.49 && std::abs(leftX) <= 0.51){ - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); - } + } //else if (std::abs(leftX) >= 0.49 && std::abs(leftX) <= 0.51){ + // handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); + // handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); + //} if (std::abs(leftY) > 0.51) { std::cout << "Left Stick Backward" << std::endl; @@ -1204,10 +1209,10 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { std::cout << "Left Stick Forward" << std::endl; onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_W, KeyCodec::Mapping()); - } else if (std::abs(leftY) >= 0.49 && std::abs(leftY) <= 0.51){ - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); - } + } //else if (std::abs(leftY) >= 0.49 && std::abs(leftY) <= 0.51){ + //handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); + //handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); + //} auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); From be6083a21d6037e2258d4dbc4d1b8de8696dca53 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:44:55 +0100 Subject: [PATCH 86/94] debug --- game/game/playercontrol.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 832675c1f..207459523 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1190,10 +1190,10 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); - if (std::abs(leftX) > 0.51) { + if (std::abs(leftX) > 0.5) { std::cout << "Left Stick Right" << std::endl; onKeyPressed(KeyCodec::Action::Right, Tempest::KeyEvent::KeyType::K_D, KeyCodec::Mapping()); - } else if (std::abs(leftX) < 0.49){ + } else if (std::abs(leftX) < 0.5){ std::cout << "Left Stick Left" << std::endl; onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_A, KeyCodec::Mapping()); @@ -1202,10 +1202,10 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { // handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); //} - if (std::abs(leftY) > 0.51) { + if (std::abs(leftY) > 0.5) { std::cout << "Left Stick Backward" << std::endl; onKeyPressed(KeyCodec::Action::Back, Tempest::KeyEvent::KeyType::K_S, KeyCodec::Mapping()); - } else if (std::abs(leftY) < 0.49){ + } else if (std::abs(leftY) < 0.5){ std::cout << "Left Stick Forward" << std::endl; onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_W, KeyCodec::Mapping()); @@ -1216,14 +1216,14 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); - if (std::abs(rightX) > 0.51) { + if (std::abs(rightX) > 0.5) { std::cout << "Right Stick Right" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::RotateR, KeyCodec::Mapping::Primary}, true); - } else if (std::abs(rightX) < 0.49){ + } else if (std::abs(rightX) < 0.5){ std::cout << "Right Stick Left" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::RotateL, KeyCodec::Mapping::Primary}, true); - } else if (std::abs(rightX) >= 0.49 && std::abs(rightX) <= 0.51){ + } else if (std::abs(rightX) == 0.5){ handleMovementAction(KeyCodec::ActionMapping{Action::RotateR, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::RotateL, KeyCodec::Mapping::Primary}, false); } From ec694a56d17f0e166cbff315936fb8e19687e1a0 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:49:15 +0100 Subject: [PATCH 87/94] debug --- game/game/playercontrol.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 207459523..084ae119f 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1190,40 +1190,40 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto leftX = dev->get_axis(gamepad::axis::LEFT_STICK_X); auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); - if (std::abs(leftX) > 0.5) { + if (std::abs(leftX) > 0.51) { std::cout << "Left Stick Right" << std::endl; - onKeyPressed(KeyCodec::Action::Right, Tempest::KeyEvent::KeyType::K_D, KeyCodec::Mapping()); - } else if (std::abs(leftX) < 0.5){ + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); + } else if (std::abs(leftX) < 0.49){ std::cout << "Left Stick Left" << std::endl; - onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_A, KeyCodec::Mapping()); + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); - } //else if (std::abs(leftX) >= 0.49 && std::abs(leftX) <= 0.51){ - // handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); - // handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); - //} + } else if (std::abs(leftX) >= 0.49 && std::abs(leftX) <= 0.51){ + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); + } - if (std::abs(leftY) > 0.5) { + if (std::abs(leftY) > 0.51) { std::cout << "Left Stick Backward" << std::endl; onKeyPressed(KeyCodec::Action::Back, Tempest::KeyEvent::KeyType::K_S, KeyCodec::Mapping()); - } else if (std::abs(leftY) < 0.5){ + } else if (std::abs(leftY) < 0.49){ std::cout << "Left Stick Forward" << std::endl; onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_W, KeyCodec::Mapping()); - } //else if (std::abs(leftY) >= 0.49 && std::abs(leftY) <= 0.51){ - //handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); - //handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); - //} + } else if (std::abs(leftY) >= 0.49 && std::abs(leftY) <= 0.51){ + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); + } auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); auto rightY = dev->get_axis(gamepad::axis::RIGHT_STICK_Y); - if (std::abs(rightX) > 0.5) { + if (std::abs(rightX) > 0.51) { std::cout << "Right Stick Right" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::RotateR, KeyCodec::Mapping::Primary}, true); - } else if (std::abs(rightX) < 0.5){ + } else if (std::abs(rightX) < 0.49){ std::cout << "Right Stick Left" << std::endl; handleMovementAction(KeyCodec::ActionMapping{Action::RotateL, KeyCodec::Mapping::Primary}, true); - } else if (std::abs(rightX) == 0.5){ + } else if (std::abs(rightX) >= 0.49 && std::abs(rightX) <= 0.51){ handleMovementAction(KeyCodec::ActionMapping{Action::RotateR, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::RotateL, KeyCodec::Mapping::Primary}, false); } From dbdccfd784a6f228d73efb6c4a7a532429425e1d Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:57:24 +0100 Subject: [PATCH 88/94] debug --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 084ae119f..45dca619c 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1204,7 +1204,7 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { if (std::abs(leftY) > 0.51) { std::cout << "Left Stick Backward" << std::endl; - onKeyPressed(KeyCodec::Action::Back, Tempest::KeyEvent::KeyType::K_S, KeyCodec::Mapping()); + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); } else if (std::abs(leftY) < 0.49){ std::cout << "Left Stick Forward" << std::endl; onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_W, KeyCodec::Mapping()); From 5d5e20fccd37a6565be3e8b0df20bbe5f3832d3a Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:09:08 +0100 Subject: [PATCH 89/94] debug --- game/game/playercontrol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 45dca619c..dabed29e8 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1204,10 +1204,10 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { if (std::abs(leftY) > 0.51) { std::cout << "Left Stick Backward" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, true); + onKeyPressed(KeyCodec::Action::Back, Tempest::KeyEvent::KeyType::K_S, KeyCodec::Mapping()); } else if (std::abs(leftY) < 0.49){ std::cout << "Left Stick Forward" << std::endl; - onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_W, KeyCodec::Mapping()); + ctrl[Action::Forward]; } else if (std::abs(leftY) >= 0.49 && std::abs(leftY) <= 0.51){ handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); From 3f95a6cc32b71e2d21acf0ac7ea83bff7c1de8e4 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:10:33 +0100 Subject: [PATCH 90/94] debug --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index dabed29e8..3c1185b1b 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1207,7 +1207,7 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { onKeyPressed(KeyCodec::Action::Back, Tempest::KeyEvent::KeyType::K_S, KeyCodec::Mapping()); } else if (std::abs(leftY) < 0.49){ std::cout << "Left Stick Forward" << std::endl; - ctrl[Action::Forward]; + actrl[ActForward] = true; } else if (std::abs(leftY) >= 0.49 && std::abs(leftY) <= 0.51){ handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); From bb63daa39e794300ed962e9a346a774b028bd37a Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:16:47 +0100 Subject: [PATCH 91/94] debug --- game/game/playercontrol.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 3c1185b1b..8a69199c1 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1162,11 +1162,11 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { if (dev->is_button_pressed(gamepad::button::A)) { std::cout << "A pressed" << std::endl; // Perform continuous action for A button - onKeyPressed(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::K_LShift, KeyCodec::Mapping()); + actrl[ActGeneric] = true; } else { std::cout << "A released" << std::endl; // Correcting the call to only pass two parameters (KeyCodec::Action and KeyCodec::Mapping) - onKeyReleased(KeyCodec::Action::ActionGeneric, KeyCodec::Mapping()); + actrl[ActGeneric] = false; } if (dev->is_button_pressed(gamepad::button::X)) { @@ -1192,26 +1192,26 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); if (std::abs(leftX) > 0.51) { std::cout << "Left Stick Right" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, true); + actrl[ActRight] = true; } else if (std::abs(leftX) < 0.49){ std::cout << "Left Stick Left" << std::endl; - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, true); + actrl[ActLeft] = true; } else if (std::abs(leftX) >= 0.49 && std::abs(leftX) <= 0.51){ - handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); + actrl[ActLeft] = false; + actrl[ActRight] = false; } if (std::abs(leftY) > 0.51) { std::cout << "Left Stick Backward" << std::endl; - onKeyPressed(KeyCodec::Action::Back, Tempest::KeyEvent::KeyType::K_S, KeyCodec::Mapping()); + actrl[ActBack] = true; } else if (std::abs(leftY) < 0.49){ std::cout << "Left Stick Forward" << std::endl; actrl[ActForward] = true; } else if (std::abs(leftY) >= 0.49 && std::abs(leftY) <= 0.51){ - handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); - handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); + actrl[ActForward] = false; + actrl[ActBack] = false; } auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); From d0dc79ab65f7dd84f626ed4ced22c8918cc2172e Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:25:43 +0100 Subject: [PATCH 92/94] debug --- game/game/playercontrol.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 8a69199c1..0e52ce59b 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1162,11 +1162,11 @@ void PlayerControl::handleButtonInput(std::shared_ptr dev) { if (dev->is_button_pressed(gamepad::button::A)) { std::cout << "A pressed" << std::endl; // Perform continuous action for A button - actrl[ActGeneric] = true; + onKeyPressed(KeyCodec::Action::ActionGeneric, Tempest::KeyEvent::KeyType::K_LShift, KeyCodec::Mapping()); } else { std::cout << "A released" << std::endl; // Correcting the call to only pass two parameters (KeyCodec::Action and KeyCodec::Mapping) - actrl[ActGeneric] = false; + onKeyReleased(KeyCodec::Action::ActionGeneric, KeyCodec::Mapping()); } if (dev->is_button_pressed(gamepad::button::X)) { @@ -1192,26 +1192,30 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { auto leftY = dev->get_axis(gamepad::axis::LEFT_STICK_Y); if (std::abs(leftX) > 0.51) { std::cout << "Left Stick Right" << std::endl; - actrl[ActRight] = true; + onKeyPressed(KeyCodec::Action::Right, Tempest::KeyEvent::KeyType::K_D, KeyCodec::Mapping()); } else if (std::abs(leftX) < 0.49){ std::cout << "Left Stick Left" << std::endl; - actrl[ActLeft] = true; + onKeyPressed(KeyCodec::Action::Left, Tempest::KeyEvent::KeyType::K_A, KeyCodec::Mapping()); } else if (std::abs(leftX) >= 0.49 && std::abs(leftX) <= 0.51){ + handleMovementAction(KeyCodec::ActionMapping{Action::Right, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Left, KeyCodec::Mapping::Primary}, false); actrl[ActLeft] = false; actrl[ActRight] = false; } if (std::abs(leftY) > 0.51) { std::cout << "Left Stick Backward" << std::endl; - actrl[ActBack] = true; + onKeyPressed(KeyCodec::Action::Back, Tempest::KeyEvent::KeyType::K_S, KeyCodec::Mapping()); } else if (std::abs(leftY) < 0.49){ std::cout << "Left Stick Forward" << std::endl; - actrl[ActForward] = true; + onKeyPressed(KeyCodec::Action::Forward, Tempest::KeyEvent::KeyType::K_W, KeyCodec::Mapping()); } else if (std::abs(leftY) >= 0.49 && std::abs(leftY) <= 0.51){ + handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); + handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); + actrl[ActBackward] = false; actrl[ActForward] = false; - actrl[ActBack] = false; } auto rightX = dev->get_axis(gamepad::axis::RIGHT_STICK_X); From 8f6f883c28e8302202f8c49b341016051f13fec3 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:26:18 +0100 Subject: [PATCH 93/94] debug --- game/game/playercontrol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/game/playercontrol.cpp b/game/game/playercontrol.cpp index 0e52ce59b..c26c9c90a 100644 --- a/game/game/playercontrol.cpp +++ b/game/game/playercontrol.cpp @@ -1214,7 +1214,7 @@ void PlayerControl::handleAxisInput(std::shared_ptr dev) { } else if (std::abs(leftY) >= 0.49 && std::abs(leftY) <= 0.51){ handleMovementAction(KeyCodec::ActionMapping{Action::Back, KeyCodec::Mapping::Primary}, false); handleMovementAction(KeyCodec::ActionMapping{Action::Forward, KeyCodec::Mapping::Primary}, false); - actrl[ActBackward] = false; + actrl[ActBack] = false; actrl[ActForward] = false; } From 6413ae91d050b3cb147ad96f19a1411a9c76df54 Mon Sep 17 00:00:00 2001 From: Schlumpf7 <77499857+Schlumpf7@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:34:58 +0000 Subject: [PATCH 94/94] added submodul --- .gitmodules | 3 +++ lib/libgamepad | 1 + 2 files changed, 4 insertions(+) create mode 160000 lib/libgamepad diff --git a/.gitmodules b/.gitmodules index 732812ee1..22f541fe5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "lib/dmusic"] path = lib/dmusic url = https://github.com/GothicKit/dmusic.git +[submodule "lib/libgamepad"] + path = lib/libgamepad + url = https://github.com/univrsal/libgamepad.git diff --git a/lib/libgamepad b/lib/libgamepad new file mode 160000 index 000000000..db34bbd17 --- /dev/null +++ b/lib/libgamepad @@ -0,0 +1 @@ +Subproject commit db34bbd1747ccb8e4e394253b3e848161ee6e571