From 56ded3259ded9c5fc8d5c7dff1a50044326f5ab5 Mon Sep 17 00:00:00 2001 From: Reece Mackie <20544390+Rover656@users.noreply.github.com> Date: Sat, 27 Apr 2019 21:36:57 +0100 Subject: [PATCH] More work, UWP now supports it and deleted old gamepads --- projects/VS2017.UWP/raylib.App.UWP/App.cpp | 6 +- projects/VS2017.UWP/raylib.App.UWP/BaseApp.h | 41 +++++----- .../examples/core_basic_window_cpp.vcxproj | 7 +- src/core.c | 38 +++++++++ src/raylib.h | 78 ------------------- 5 files changed, 66 insertions(+), 104 deletions(-) diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.cpp b/projects/VS2017.UWP/raylib.App.UWP/App.cpp index ae137ed2..fb07636c 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.cpp +++ b/projects/VS2017.UWP/raylib.App.UWP/App.cpp @@ -36,8 +36,8 @@ void App::Update() ClearBackground(RAYWHITE); - posX += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_X) * 5; - posY += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_XBOX_AXIS_LEFT_Y) * -5; + posX += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_AXIS_LEFT_X) * 5; + posY += GetGamepadAxisMovement(GAMEPAD_PLAYER1, GAMEPAD_AXIS_LEFT_Y) * -5; DrawRectangle(posX, posY, 400, 100, RED); @@ -63,7 +63,7 @@ void App::Update() if (IsKeyDown(KEY_LEFT_ALT)) DrawRectangle(250, 250, 20, 20, BLACK); - if (IsKeyDown(KEY_BACKSPACE)) + if (IsKeyDown(KEY_BACKSPACE) || IsGamepadButtonDown(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) DrawRectangle(280, 250, 20, 20, BLACK); if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) DrawRectangle(280, 250, 20, 20, BLACK); diff --git a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h index e27909e2..65483754 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h +++ b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h @@ -371,27 +371,30 @@ protected: GamepadReading reading = gamepad->GetCurrentReading(); // NOTE: Maybe it would be wiser to redefine the gamepad button mappings in "raylib.h" for the UWP platform instead of remapping them manually - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_A, ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_B, ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_X, ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_Y, ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LB, ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RB, ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_SELECT, ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View)); // Changed for XB1 Controller - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_START, ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu)); // Changed for XB1 Controller - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_UP, ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_RIGHT, ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_DOWN, ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadDown)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_LEFT, ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadLeft)); - RegisterGamepadButton(i, GAMEPAD_XBOX_BUTTON_HOME, false); // Home button not supported by UWP + RegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_DOWN, ((reading.Buttons & GamepadButtons::A) == GamepadButtons::A)); + RegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, ((reading.Buttons & GamepadButtons::B) == GamepadButtons::B)); + RegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_LEFT, ((reading.Buttons & GamepadButtons::X) == GamepadButtons::X)); + RegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_FACE_UP, ((reading.Buttons & GamepadButtons::Y) == GamepadButtons::Y)); + + RegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_TRIGGER_1, ((reading.Buttons & GamepadButtons::LeftShoulder) == GamepadButtons::LeftShoulder)); + RegisterGamepadButton(i, GAMEPAD_BUTTON_RIGHT_TRIGGER_1, ((reading.Buttons & GamepadButtons::RightShoulder) == GamepadButtons::RightShoulder)); + + RegisterGamepadButton(i, GAMEPAD_BUTTON_MIDDLE_LEFT, ((reading.Buttons & GamepadButtons::View) == GamepadButtons::View)); // Changed for XB1 Controller + RegisterGamepadButton(i, GAMEPAD_BUTTON_MIDDLE_RIGHT, ((reading.Buttons & GamepadButtons::Menu) == GamepadButtons::Menu)); // Changed for XB1 Controller + + RegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_UP, ((reading.Buttons & GamepadButtons::DPadUp) == GamepadButtons::DPadUp)); + RegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_RIGHT, ((reading.Buttons & GamepadButtons::DPadRight) == GamepadButtons::DPadRight)); + RegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_DOWN, ((reading.Buttons & GamepadButtons::DPadDown) == GamepadButtons::DPadDown)); + RegisterGamepadButton(i, GAMEPAD_BUTTON_LEFT_FACE_LEFT, ((reading.Buttons & GamepadButtons::DPadLeft) == GamepadButtons::DPadLeft)); + RegisterGamepadButton(i, GAMEPAD_BUTTON_MIDDLE, false); // Home button not supported by UWP // Get current axis state - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_X, (float)reading.LeftThumbstickX); - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LEFT_Y, (float)reading.LeftThumbstickY); - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_X, (float)reading.RightThumbstickX); - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RIGHT_Y, (float)reading.RightThumbstickY); - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_LT, (float)reading.LeftTrigger); - RegisterGamepadAxis(i, GAMEPAD_XBOX_AXIS_RT, (float)reading.RightTrigger); + RegisterGamepadAxis(i, GAMEPAD_AXIS_LEFT_X, (float)reading.LeftThumbstickX); + RegisterGamepadAxis(i, GAMEPAD_AXIS_LEFT_Y, (float)reading.LeftThumbstickY); + RegisterGamepadAxis(i, GAMEPAD_AXIS_RIGHT_X, (float)reading.RightThumbstickX); + RegisterGamepadAxis(i, GAMEPAD_AXIS_RIGHT_Y, (float)reading.RightThumbstickY); + RegisterGamepadAxis(i, GAMEPAD_AXIS_LEFT_TRIGGER, (float)reading.LeftTrigger); + RegisterGamepadAxis(i, GAMEPAD_AXIS_RIGHT_TRIGGER, (float)reading.RightTrigger); } } } diff --git a/projects/VS2017/examples/core_basic_window_cpp.vcxproj b/projects/VS2017/examples/core_basic_window_cpp.vcxproj index bc8221a5..cfe08524 100644 --- a/projects/VS2017/examples/core_basic_window_cpp.vcxproj +++ b/projects/VS2017/examples/core_basic_window_cpp.vcxproj @@ -166,15 +166,14 @@ kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - {e89d61ac-55de-4482-afd4-df7242ebc859} - true + + + diff --git a/src/core.c b/src/core.c index 7977d0ad..2aa22fa6 100644 --- a/src/core.c +++ b/src/core.c @@ -3095,20 +3095,50 @@ static GamepadButton GetGamepadButton(int button) case GLFW_GAMEPAD_BUTTON_B: b = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break; case GLFW_GAMEPAD_BUTTON_A: b = GAMEPAD_BUTTON_RIGHT_FACE_DOWN; break; case GLFW_GAMEPAD_BUTTON_X: b = GAMEPAD_BUTTON_RIGHT_FACE_LEFT; break; + case GLFW_GAMEPAD_BUTTON_LEFT_BUMPER: b = GAMEPAD_BUTTON_LEFT_TRIGGER_1; break; case GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER: b = GAMEPAD_BUTTON_RIGHT_TRIGGER_1; break; + case GLFW_GAMEPAD_BUTTON_BACK: b = GAMEPAD_BUTTON_MIDDLE_LEFT; break; case GLFW_GAMEPAD_BUTTON_GUIDE: b = GAMEPAD_BUTTON_MIDDLE; break; case GLFW_GAMEPAD_BUTTON_START: b = GAMEPAD_BUTTON_MIDDLE_RIGHT; break; + case GLFW_GAMEPAD_BUTTON_DPAD_UP: b = GAMEPAD_BUTTON_LEFT_FACE_UP; break; case GLFW_GAMEPAD_BUTTON_DPAD_RIGHT: b = GAMEPAD_BUTTON_LEFT_FACE_RIGHT; break; case GLFW_GAMEPAD_BUTTON_DPAD_DOWN: b = GAMEPAD_BUTTON_LEFT_FACE_DOWN; break; case GLFW_GAMEPAD_BUTTON_DPAD_LEFT: b = GAMEPAD_BUTTON_LEFT_FACE_LEFT; break; + case GLFW_GAMEPAD_BUTTON_LEFT_THUMB: b = GAMEPAD_BUTTON_LEFT_THUMB; break; case GLFW_GAMEPAD_BUTTON_RIGHT_THUMB: b = GAMEPAD_BUTTON_RIGHT_THUMB; break; } #endif +#if defined(PLATFORM_UWP) + /*switch(button) + { + case 4: b = GAMEPAD_BUTTON_RIGHT_FACE_DOWN; break; + case 8: b = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break; + case 16: b = GAMEPAD_BUTTON_RIGHT_FACE_LEFT; break; + case 32: b = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break; + + case 128: b = GAMEPAD_BUTTON_LEFT_FACE_DOWN; break; + case 256: b = GAMEPAD_BUTTON_LEFT_FACE_LEFT; break; + case 512: b = GAMEPAD_BUTTON_LEFT_FACE_RIGHT; break; + case 64: b = GAMEPAD_BUTTON_LEFT_FACE_UP; break; + + case 1024: b = GAMEPAD_BUTTON_LEFT_TRIGGER_1; break; + case 2048: b = GAMEPAD_BUTTON_RIGHT_TRIGGER_1; break; + + case 4096: b = GAMEPAD_BUTTON_LEFT_THUMB; break; + case 8192: b = GAMEPAD_BUTTON_RIGHT_THUMB; break; + + case 2: b = GAMEPAD_BUTTON_MIDDLE_LEFT; + case 1: b = GAMEPAD_BUTTON_MIDDLE_RIGHT; + }*/ + //Above might not be most efficient, so not doing it for now + b = button; +#endif + #if defined(PLATFORM_WEB) //TODO: TEST //https://www.w3.org/TR/gamepad/#gamepad-interface @@ -3151,6 +3181,10 @@ static GamepadAxis GetGamepadAxis(int axis) } #endif +#if defined(PLATFORM_UWP) + a = axis; //UWP will provide the correct axis +#endif + #if defined(PLATFORM_WEB) //TODO: TEST switch(axis) @@ -3347,6 +3381,10 @@ static void PollInputEvents(void) { if (msg->Int0 < MAX_GAMEPADS && msg->Int1 < MAX_GAMEPAD_AXIS) gamepadAxisState[msg->Int0][msg->Int1] = msg->Float0; + + //Register buttons for 2nd triggers + currentGamepadState[msg->Int0][GAMEPAD_BUTTON_LEFT_TRIGGER_2] = (char)(gamepadAxisState[msg->Int0][GAMEPAD_AXIS_LEFT_TRIGGER] > 0.1); + currentGamepadState[msg->Int0][GAMEPAD_BUTTON_RIGHT_TRIGGER_2] = (char)(gamepadAxisState[msg->Int0][GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.1); break; } diff --git a/src/raylib.h b/src/raylib.h index 9759000f..1b4a5434 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -670,84 +670,6 @@ typedef enum GAMEPAD_AXIS_RIGHT_TRIGGER // [1..-1] (pressure-level) } GamepadAxis; -// PS3 USB Controller Buttons -// TODO: Provide a generic way to list gamepad controls schemes, -// defining specific controls schemes is not a good option -typedef enum { - GAMEPAD_PS3_BUTTON_TRIANGLE = 0, - GAMEPAD_PS3_BUTTON_CIRCLE = 1, - GAMEPAD_PS3_BUTTON_CROSS = 2, - GAMEPAD_PS3_BUTTON_SQUARE = 3, - GAMEPAD_PS3_BUTTON_L1 = 6, - GAMEPAD_PS3_BUTTON_R1 = 7, - GAMEPAD_PS3_BUTTON_L2 = 4, - GAMEPAD_PS3_BUTTON_R2 = 5, - GAMEPAD_PS3_BUTTON_START = 8, - GAMEPAD_PS3_BUTTON_SELECT = 9, - GAMEPAD_PS3_BUTTON_PS = 12, - GAMEPAD_PS3_BUTTON_UP = 24, - GAMEPAD_PS3_BUTTON_RIGHT = 25, - GAMEPAD_PS3_BUTTON_DOWN = 26, - GAMEPAD_PS3_BUTTON_LEFT = 27 -} GamepadPS3Button; - -// PS3 USB Controller Axis -typedef enum { - GAMEPAD_PS3_AXIS_LEFT_X = 0, - GAMEPAD_PS3_AXIS_LEFT_Y = 1, - GAMEPAD_PS3_AXIS_RIGHT_X = 2, - GAMEPAD_PS3_AXIS_RIGHT_Y = 5, - GAMEPAD_PS3_AXIS_L2 = 3, // [1..-1] (pressure-level) - GAMEPAD_PS3_AXIS_R2 = 4 // [1..-1] (pressure-level) -} GamepadPS3Axis; - -// Xbox360 USB Controller Buttons -typedef enum { - GAMEPAD_XBOX_BUTTON_A = 0, - GAMEPAD_XBOX_BUTTON_B = 1, - GAMEPAD_XBOX_BUTTON_X = 2, - GAMEPAD_XBOX_BUTTON_Y = 3, - GAMEPAD_XBOX_BUTTON_LB = 4, - GAMEPAD_XBOX_BUTTON_RB = 5, - GAMEPAD_XBOX_BUTTON_SELECT = 6, - GAMEPAD_XBOX_BUTTON_START = 7, - GAMEPAD_XBOX_BUTTON_HOME = 8, - GAMEPAD_XBOX_BUTTON_UP = 10, - GAMEPAD_XBOX_BUTTON_RIGHT = 11, - GAMEPAD_XBOX_BUTTON_DOWN = 12, - GAMEPAD_XBOX_BUTTON_LEFT = 13 -} GamepadXbox360Button; - -// Xbox360 USB Controller Axis, -// NOTE: For Raspberry Pi, axis must be reconfigured -typedef enum { - GAMEPAD_XBOX_AXIS_LEFT_X = 0, // [-1..1] (left->right) - GAMEPAD_XBOX_AXIS_LEFT_Y = 1, // [1..-1] (up->down) - GAMEPAD_XBOX_AXIS_RIGHT_X = 2, // [-1..1] (left->right) - GAMEPAD_XBOX_AXIS_RIGHT_Y = 3, // [1..-1] (up->down) - GAMEPAD_XBOX_AXIS_LT = 4, // [-1..1] (pressure-level) - GAMEPAD_XBOX_AXIS_RT = 5 // [-1..1] (pressure-level) -} GamepadXbox360Axis; - -// Android Gamepad Controller (SNES CLASSIC) -typedef enum { - GAMEPAD_ANDROID_DPAD_UP = 19, - GAMEPAD_ANDROID_DPAD_DOWN = 20, - GAMEPAD_ANDROID_DPAD_LEFT = 21, - GAMEPAD_ANDROID_DPAD_RIGHT = 22, - GAMEPAD_ANDROID_DPAD_CENTER = 23, - GAMEPAD_ANDROID_BUTTON_A = 96, - GAMEPAD_ANDROID_BUTTON_B = 97, - GAMEPAD_ANDROID_BUTTON_C = 98, - GAMEPAD_ANDROID_BUTTON_X = 99, - GAMEPAD_ANDROID_BUTTON_Y = 100, - GAMEPAD_ANDROID_BUTTON_Z = 101, - GAMEPAD_ANDROID_BUTTON_L1 = 102, - GAMEPAD_ANDROID_BUTTON_R1 = 103, - GAMEPAD_ANDROID_BUTTON_L2 = 104, - GAMEPAD_ANDROID_BUTTON_R2 = 105 -} GamepadAndroid; - // Shader location point type typedef enum { LOC_VERTEX_POSITION = 0,