Browse Source

Reviewed latest commit for Android gamepad support

pull/572/merge
raysan5 6 years ago
parent
commit
c6d188a09a
6 changed files with 85 additions and 92 deletions
  1. +17
    -17
      release/include/raylib.h
  2. BIN
      release/libs/android/arm64-v8a/libraylib.a
  3. BIN
      release/libs/win32/mingw32/libraylib.a
  4. +23
    -29
      src/Makefile
  5. +28
    -29
      src/core.c
  6. +17
    -17
      src/raylib.h

+ 17
- 17
release/include/raylib.h View File

@ -241,23 +241,23 @@
#define GAMEPAD_XBOX_BUTTON_LEFT 13 #define GAMEPAD_XBOX_BUTTON_LEFT 13
#define GAMEPAD_XBOX_BUTTON_HOME 8 #define GAMEPAD_XBOX_BUTTON_HOME 8
// mi">8BitDo Gamepad SNES CLASSIC // n">Android Gamepad Controller (SNES CLASSIC)
#define GAMEPAD_SNES_DPAD_UP 19 #define GAMEPAD_ANDROID_DPAD_UP 19
#define GAMEPAD_SNES_DPAD_DOWN 20 #define GAMEPAD_ANDROID_DPAD_DOWN 20
#define GAMEPAD_SNES_DPAD_LEFT 21 #define GAMEPAD_ANDROID_DPAD_LEFT 21
#define GAMEPAD_SNES_DPAD_RIGHT 22 #define GAMEPAD_ANDROID_DPAD_RIGHT 22
#define GAMEPAD_SNES_DPAD_CENTER 23 #define GAMEPAD_ANDROID_DPAD_CENTER 23
#define GAMEPAD_ANDROID_BUTTON_A 96
#define GAMEPAD_SNES_BUTTON_A 96 #define GAMEPAD_ANDROID_BUTTON_B 97
#define GAMEPAD_SNES_BUTTON_B 97 #define GAMEPAD_ANDROID_BUTTON_C 98
#define GAMEPAD_SNES_BUTTON_C 98 #define GAMEPAD_ANDROID_BUTTON_X 99
#define GAMEPAD_SNES_BUTTON_X 99 #define GAMEPAD_ANDROID_BUTTON_Y 100
#define GAMEPAD_SNES_BUTTON_Y 100 #define GAMEPAD_ANDROID_BUTTON_Z 101
#define GAMEPAD_SNES_BUTTON_Z 101 #define GAMEPAD_ANDROID_BUTTON_L1 102
#define GAMEPAD_SNES_BUTTON_L1 102 #define GAMEPAD_ANDROID_BUTTON_R1 103
#define GAMEPAD_SNES_BUTTON_R1 103 #define GAMEPAD_ANDROID_BUTTON_L2 104
#define GAMEPAD_SNES_BUTTON_L2 104 #define GAMEPAD_ANDROID_BUTTON_R2 105
#define GAMEPAD_SNES_BUTTON_R2 105
// Xbox360 USB Controller Axis // Xbox360 USB Controller Axis
// NOTE: For Raspberry Pi, axis must be reconfigured // NOTE: For Raspberry Pi, axis must be reconfigured

BIN
release/libs/android/arm64-v8a/libraylib.a View File


BIN
release/libs/win32/mingw32/libraylib.a View File


+ 23
- 29
src/Makefile View File

@ -170,13 +170,22 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
endif endif
ifeq ($(PLATFORM),PLATFORM_ANDROID) ifeq ($(PLATFORM),PLATFORM_ANDROID)
# Android required path variables
ANDROID_NDK = C:/android-ndk
ANDROID_TOOLCHAIN = C:/android_toolchain_arm64_api21
# Android architecture: ARM64 # Android architecture: ARM64
# Starting at 2019 using ARM64 is mandatory for published apps # Starting at 2019 using ARM64 is mandatory for published apps
ANDROID_ARCH ?= ARM64 ANDROID_ARCH ?= ARM64
# Android required path variables
# NOTE: Android NDK is just required to generate the standalone toolchain,
# in case is not already provided
ANDROID_NDK = C:/android-ndk
# Android standalone toolchain path
ifeq ($(ANDROID_ARCH),ARM64)
ANDROID_TOOLCHAIN = C:/android_toolchain_arm64_api21
endif
ifeq ($(ANDROID_ARCH),ARM)
ANDROID_TOOLCHAIN = C:/android_toolchain_arm_api21
endif
endif endif
# RAYLIB_RELEASE_PATH points to provided binaries or your immediate build of raylib. # RAYLIB_RELEASE_PATH points to provided binaries or your immediate build of raylib.
@ -233,9 +242,10 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
GRAPHICS = GRAPHICS_API_OPENGL_ES2 GRAPHICS = GRAPHICS_API_OPENGL_ES2
endif endif
# Define default C compiler: gcc # Define default C compiler and archiver to pack library
# NOTE: define g++ compiler if using C++ # NOTE: define g++ compiler if using C++
CC = gcc CC = gcc
AR = ar
ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(PLATFORM_OS),OSX) ifeq ($(PLATFORM_OS),OSX)
@ -253,6 +263,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
# Define RPI cross-compiler # Define RPI cross-compiler
#CC = armv6j-hardfloat-linux-gnueabi-gcc #CC = armv6j-hardfloat-linux-gnueabi-gcc
CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc
AR = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-ar
endif endif
endif endif
ifeq ($(PLATFORM),PLATFORM_WEB) ifeq ($(PLATFORM),PLATFORM_WEB)
@ -263,33 +274,15 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
# Android toolchain (must be provided for desired architecture and compiler) # Android toolchain (must be provided for desired architecture and compiler)
ifeq ($(ANDROID_ARCH),ARM64) ifeq ($(ANDROID_ARCH),ARM64)
CC = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-clang CC = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-clang
endif
ifeq ($(ANDROID_ARCH),ARM)
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-clang
endif
endif
# Default archiver program to pack libraries
AR = ar
ifeq ($(PLATFORM),PLATFORM_RPI)
ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
# Define RPI cross-archiver
#CC = armv6j-hardfloat-linux-gnueabi-gcc
AR = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-ar
endif
endif
# Android archiver (also depends on desired architecture)
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(ANDROID_ARCH),ARM64)
AR = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-ar AR = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-ar
endif endif
ifeq ($(ANDROID_ARCH),ARM) ifeq ($(ANDROID_ARCH),ARM)
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-clang
AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar
endif endif
endif endif
# Define compiler flags: # Define compiler flags:
# -O1 defines optimization level # -O1 defines optimization level
# -g enable debugging # -g enable debugging
@ -327,11 +320,11 @@ endif
ifeq ($(PLATFORM),PLATFORM_ANDROID) ifeq ($(PLATFORM),PLATFORM_ANDROID)
# Compiler flags for arquitecture (only ARM, not ARM64) # Compiler flags for arquitecture (only ARM, not ARM64)
ifeq ($(ANDROID_ARCH),ARM64) ifeq ($(ANDROID_ARCH),ARM64)
CFLAGS += -target aarch64 -mfix-cortex-a53-835769 CFLAGS += -target aarch64 -mfix-cortex-a53-835769
endif endif
ifeq ($(ANDROID_ARCH),ARM) ifeq ($(ANDROID_ARCH),ARM)
CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
endif endif
# Compilation functions attributes options # Compilation functions attributes options
CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIE -fPIC CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIE -fPIC
# Compiler options for the linker # Compiler options for the linker
@ -552,6 +545,7 @@ stb_vorbis.o: external/stb_vorbis.c external/stb_vorbis.h
utils.o : utils.c utils.h utils.o : utils.c utils.h
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) $(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
# Install generated and needed files to desired directories. # Install generated and needed files to desired directories.
# On GNU/Linux and BSDs, there are some standard directories that contain extra # On GNU/Linux and BSDs, there are some standard directories that contain extra
# libraries and header files. These directories (often /usr/local/lib and # libraries and header files. These directories (often /usr/local/lib and

+ 28
- 29
src/core.c View File

@ -3099,14 +3099,17 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
//AMotionEvent_getAxisValue() //AMotionEvent_getAxisValue()
//AMotionEvent_getButtonState() //AMotionEvent_getButtonState()
// This is all it takes to capture gamepad dpad button presses // Gamepad dpad button presses capturing
// TODO: That's weird, key input (or button)
// shouldn't come as a TYPE_MOTION event...
int32_t keycode = AKeyEvent_getKeyCode(event); int32_t keycode = AKeyEvent_getKeyCode(event);
if (AKeyEvent_getAction(event) == 0) if (AKeyEvent_getAction(event) == n">AKEY_EVENT_ACTION_DOWN)
{ {
currentKeyState[keycode] = 1; // Key down currentKeyState[keycode] = 1; // Key down
lastKeyPressed = keycode; lastKeyPressed = keycode;
} }
else currentKeyState[keycode] = 0; // Key up else currentKeyState[keycode] = 0; // Key up
} }
else if (type == AINPUT_EVENT_TYPE_KEY) else if (type == AINPUT_EVENT_TYPE_KEY)
{ {
@ -3115,9 +3118,9 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
// Save current button and its state // Save current button and its state
// NOTE: Android key action is 0 for down and 1 for up // NOTE: Android key action is 0 for down and 1 for up
if (AKeyEvent_getAction(event) == mi">0) if (AKeyEvent_getAction(event) == n">AKEY_EVENT_ACTION_DOWN)
{ {
currentKeyState[keycode] = 1; // Key down currentKeyState[keycode] = 1; // Key down
lastKeyPressed = keycode; lastKeyPressed = keycode;
} }
else currentKeyState[keycode] = 0; // Key up else currentKeyState[keycode] = 0; // Key up
@ -3146,14 +3149,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
int32_t action = AMotionEvent_getAction(event); int32_t action = AMotionEvent_getAction(event);
unsigned int flags = action & AMOTION_EVENT_ACTION_MASK; unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
#if defined(SUPPORT_GESTURES_SYSTEM) #if defined(SUPPORT_GESTURES_SYSTEM)
// @Completeness: Fix this so that gamepad does not cause this to crash
// If actions is not caputred in the above, then it may not be a gesture at all.
// If we do not end here, when we reach getPointerId there is a high likelyhood of crashing
return 0;
GestureEvent gestureEvent; GestureEvent gestureEvent;
// Register touch actions // Register touch actions
@ -3162,29 +3158,32 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_MOVE; else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_MOVE;
// Register touch points count // Register touch points count
// NOTE: Documentation says pointerCount is Always >= 1,
// but in practice it can be 0 or over a million
gestureEvent.pointCount = AMotionEvent_getPointerCount(event); gestureEvent.pointCount = AMotionEvent_getPointerCount(event);
// Documentation says pointerCount is Always >= 1.
// But in practice it can be 0 or over a million
// Register touch points id // Only enable gestures for 1-3 touch points
if ((gestureEvent.pointCount > 0) && (gestureEvent.pointCount < 4))
o">// Register touch points position p">{
// l">NOTE: Only two points registered // ">Register touch points id
// err">@Fix: This is where the break happens for dpads // nl">NOTE: Only two points registered
gestureEvent.pointerId[0] = AMotionEvent_getPointerId(event, 0); gestureEvent.pointerId[0] = AMotionEvent_getPointerId(event, 0);
gestureEvent.pointerId[1] = AMotionEvent_getPointerId(event, 1); gestureEvent.pointerId[1] = AMotionEvent_getPointerId(event, 1);
gestureEvent.position[0] = (Vector2){ AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) }; // Register touch points position
gestureEvent.position[1] = (Vector2){ AMotionEvent_getX(event, 1), AMotionEvent_getY(event, 1) }; gestureEvent.position[0] = (Vector2){ AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
gestureEvent.position[1] = (Vector2){ AMotionEvent_getX(event, 1), AMotionEvent_getY(event, 1) };
// Normalize gestureEvent.position[x] for screenWidth and screenHeight // Normalize gestureEvent.position[x] for screenWidth and screenHeight
gestureEvent.position[0].x /= (float)GetScreenWidth(); gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[1].x /= (float)GetScreenWidth(); gestureEvent.position[0].y /= (float)GetScreenHeight();
gestureEvent.position[0].y /= (float)GetScreenHeight(); gestureEvent.position[1].x /= (float)GetScreenWidth();
gestureEvent.position[1].y /= (float)GetScreenHeight(); gestureEvent.position[1].y /= (float)GetScreenHeight();
// Gesture data is sent to gestures system for processing // Gesture data is sent to gestures system for processing
ProcessGestureEvent(gestureEvent); ProcessGestureEvent(gestureEvent);
}
#else #else
// Support only simple touch position // Support only simple touch position

+ 17
- 17
src/raylib.h View File

@ -241,23 +241,23 @@
#define GAMEPAD_XBOX_BUTTON_LEFT 13 #define GAMEPAD_XBOX_BUTTON_LEFT 13
#define GAMEPAD_XBOX_BUTTON_HOME 8 #define GAMEPAD_XBOX_BUTTON_HOME 8
// mi">8BitDo Gamepad SNES CLASSIC // n">Android Gamepad Controller (SNES CLASSIC)
#define GAMEPAD_SNES_DPAD_UP 19 #define GAMEPAD_ANDROID_DPAD_UP 19
#define GAMEPAD_SNES_DPAD_DOWN 20 #define GAMEPAD_ANDROID_DPAD_DOWN 20
#define GAMEPAD_SNES_DPAD_LEFT 21 #define GAMEPAD_ANDROID_DPAD_LEFT 21
#define GAMEPAD_SNES_DPAD_RIGHT 22 #define GAMEPAD_ANDROID_DPAD_RIGHT 22
#define GAMEPAD_SNES_DPAD_CENTER 23 #define GAMEPAD_ANDROID_DPAD_CENTER 23
#define GAMEPAD_ANDROID_BUTTON_A 96
#define GAMEPAD_SNES_BUTTON_A 96 #define GAMEPAD_ANDROID_BUTTON_B 97
#define GAMEPAD_SNES_BUTTON_B 97 #define GAMEPAD_ANDROID_BUTTON_C 98
#define GAMEPAD_SNES_BUTTON_C 98 #define GAMEPAD_ANDROID_BUTTON_X 99
#define GAMEPAD_SNES_BUTTON_X 99 #define GAMEPAD_ANDROID_BUTTON_Y 100
#define GAMEPAD_SNES_BUTTON_Y 100 #define GAMEPAD_ANDROID_BUTTON_Z 101
#define GAMEPAD_SNES_BUTTON_Z 101 #define GAMEPAD_ANDROID_BUTTON_L1 102
#define GAMEPAD_SNES_BUTTON_L1 102 #define GAMEPAD_ANDROID_BUTTON_R1 103
#define GAMEPAD_SNES_BUTTON_R1 103 #define GAMEPAD_ANDROID_BUTTON_L2 104
#define GAMEPAD_SNES_BUTTON_L2 104 #define GAMEPAD_ANDROID_BUTTON_R2 105
#define GAMEPAD_SNES_BUTTON_R2 105
// Xbox360 USB Controller Axis // Xbox360 USB Controller Axis
// NOTE: For Raspberry Pi, axis must be reconfigured // NOTE: For Raspberry Pi, axis must be reconfigured

||||||
x
 
000:0
Loading…
Cancel
Save