Merge pull request #570 from SethArchambault/master

SNES-like GAMEPAD Support added for Android, Makefile has optional support for 32bit
This commit is contained in:
Ray 2018-07-07 09:38:19 +02:00 committed by GitHub
commit 50088bf49b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 7 deletions

View File

@ -241,6 +241,24 @@
#define GAMEPAD_XBOX_BUTTON_LEFT 13 #define GAMEPAD_XBOX_BUTTON_LEFT 13
#define GAMEPAD_XBOX_BUTTON_HOME 8 #define GAMEPAD_XBOX_BUTTON_HOME 8
// 8BitDo Gamepad SNES CLASSIC
#define GAMEPAD_SNES_DPAD_UP 19
#define GAMEPAD_SNES_DPAD_DOWN 20
#define GAMEPAD_SNES_DPAD_LEFT 21
#define GAMEPAD_SNES_DPAD_RIGHT 22
#define GAMEPAD_SNES_DPAD_CENTER 23
#define GAMEPAD_SNES_BUTTON_A 96
#define GAMEPAD_SNES_BUTTON_B 97
#define GAMEPAD_SNES_BUTTON_C 98
#define GAMEPAD_SNES_BUTTON_X 99
#define GAMEPAD_SNES_BUTTON_Y 100
#define GAMEPAD_SNES_BUTTON_Z 101
#define GAMEPAD_SNES_BUTTON_L1 102
#define GAMEPAD_SNES_BUTTON_R1 103
#define GAMEPAD_SNES_BUTTON_L2 104
#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
#if defined(PLATFORM_RPI) #if defined(PLATFORM_RPI)
@ -966,7 +984,7 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Font loading/unloading functions // Font loading/unloading functions
RLAPI Font GetFontDefault(void); // Get the default Font RLAPI Font GetFontDefault(void); // Get the default Font
RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM)
RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load font from file with extended parameters RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load font from file with extended parameters
RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use

View File

@ -208,6 +208,9 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(ANDROID_ARCH),ARM64) ifeq ($(ANDROID_ARCH),ARM64)
RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/android/arm64-v8a RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/android/arm64-v8a
endif endif
ifeq ($(ANDROID_ARCH),ARM)
RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/android/armeabi-v7a
endif
endif endif
# Define raylib graphics api depending on selected platform # Define raylib graphics api depending on selected platform
@ -261,6 +264,9 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
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 endif
ifeq ($(ANDROID_ARCH),ARM)
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-clang
endif
endif endif
# Default archiver program to pack libraries # Default archiver program to pack libraries
@ -279,6 +285,9 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(ANDROID_ARCH),ARM64) 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)
AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar
endif
endif endif
# Define compiler flags: # Define compiler flags:
@ -317,8 +326,12 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
endif 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)
#CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 ifeq ($(ANDROID_ARCH),ARM64)
CFLAGS += -target aarch64 -mfix-cortex-a53-835769 CFLAGS += -target aarch64 -mfix-cortex-a53-835769
endif
ifeq ($(ANDROID_ARCH),ARM)
CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
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
@ -439,6 +452,9 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(ANDROID_ARCH),ARM64) ifeq ($(ANDROID_ARCH),ARM64)
$(ANDROID_NDK)/build/tools/make-standalone-toolchain.sh --platform=android-21 --toolchain=aarch64-linux-androideabi-4.9 --use-llvm --install-dir=$(ANDROID_TOOLCHAIN) $(ANDROID_NDK)/build/tools/make-standalone-toolchain.sh --platform=android-21 --toolchain=aarch64-linux-androideabi-4.9 --use-llvm --install-dir=$(ANDROID_TOOLCHAIN)
endif endif
ifeq ($(ANDROID_ARCH),ARM)
$(ANDROID_NDK)/build/tools/make-standalone-toolchain.sh --platform=android-21 --toolchain=arm-linux-androideabi-4.9 --use-llvm --install-dir=$(ANDROID_TOOLCHAIN)
endif
endif endif
# Compile raylib library # Compile raylib library

View File

@ -3098,6 +3098,15 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
//AMotionEvent_getAction() //AMotionEvent_getAction()
//AMotionEvent_getAxisValue() //AMotionEvent_getAxisValue()
//AMotionEvent_getButtonState() //AMotionEvent_getButtonState()
// This is all it takes to capture gamepad dpad button presses
int32_t keycode = AKeyEvent_getKeyCode(event);
if (AKeyEvent_getAction(event) == 0)
{
currentKeyState[keycode] = 1; // Key down
lastKeyPressed = keycode;
}
else currentKeyState[keycode] = 0; // Key up
} }
else if (type == AINPUT_EVENT_TYPE_KEY) else if (type == AINPUT_EVENT_TYPE_KEY)
{ {
@ -3137,7 +3146,14 @@ 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
@ -3147,21 +3163,24 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
// Register touch points count // Register touch points count
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 // Register touch points id
// Register touch points position
// NOTE: Only two points registered
// @Fix: This is where the break happens for dpads
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);
// Register touch points position
// NOTE: Only two points registered
gestureEvent.position[0] = (Vector2){ AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) }; gestureEvent.position[0] = (Vector2){ AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
gestureEvent.position[1] = (Vector2){ AMotionEvent_getX(event, 1), AMotionEvent_getY(event, 1) }; 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[0].y /= (float)GetScreenHeight();
gestureEvent.position[1].x /= (float)GetScreenWidth(); gestureEvent.position[1].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight();
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

View File

@ -241,6 +241,24 @@
#define GAMEPAD_XBOX_BUTTON_LEFT 13 #define GAMEPAD_XBOX_BUTTON_LEFT 13
#define GAMEPAD_XBOX_BUTTON_HOME 8 #define GAMEPAD_XBOX_BUTTON_HOME 8
// 8BitDo Gamepad SNES CLASSIC
#define GAMEPAD_SNES_DPAD_UP 19
#define GAMEPAD_SNES_DPAD_DOWN 20
#define GAMEPAD_SNES_DPAD_LEFT 21
#define GAMEPAD_SNES_DPAD_RIGHT 22
#define GAMEPAD_SNES_DPAD_CENTER 23
#define GAMEPAD_SNES_BUTTON_A 96
#define GAMEPAD_SNES_BUTTON_B 97
#define GAMEPAD_SNES_BUTTON_C 98
#define GAMEPAD_SNES_BUTTON_X 99
#define GAMEPAD_SNES_BUTTON_Y 100
#define GAMEPAD_SNES_BUTTON_Z 101
#define GAMEPAD_SNES_BUTTON_L1 102
#define GAMEPAD_SNES_BUTTON_R1 103
#define GAMEPAD_SNES_BUTTON_L2 104
#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
#if defined(PLATFORM_RPI) #if defined(PLATFORM_RPI)