mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
Gamepad: WIP towards customising axis behaviour and sensitivity
This commit is contained in:
parent
d056f8c2ff
commit
cfa3676e44
3 changed files with 86 additions and 83 deletions
133
src/Core.h
133
src/Core.h
|
@ -6,74 +6,74 @@ Copyright 2014-2023 ClassiCube | Licensed under BSD-3
|
|||
*/
|
||||
|
||||
#if _MSC_VER
|
||||
typedef signed __int8 cc_int8;
|
||||
typedef signed __int16 cc_int16;
|
||||
typedef signed __int32 cc_int32;
|
||||
typedef signed __int64 cc_int64;
|
||||
|
||||
typedef unsigned __int8 cc_uint8;
|
||||
typedef unsigned __int16 cc_uint16;
|
||||
typedef unsigned __int32 cc_uint32;
|
||||
typedef unsigned __int64 cc_uint64;
|
||||
#ifdef _WIN64
|
||||
typedef unsigned __int64 cc_uintptr;
|
||||
#else
|
||||
typedef unsigned __int32 cc_uintptr;
|
||||
#endif
|
||||
|
||||
#define CC_INLINE inline
|
||||
#define CC_NOINLINE __declspec(noinline)
|
||||
#ifndef CC_API
|
||||
#define CC_API __declspec(dllexport, noinline)
|
||||
#define CC_VAR __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
#define CC_HAS_TYPES
|
||||
#define CC_HAS_MISC
|
||||
typedef signed __int8 cc_int8;
|
||||
typedef signed __int16 cc_int16;
|
||||
typedef signed __int32 cc_int32;
|
||||
typedef signed __int64 cc_int64;
|
||||
|
||||
typedef unsigned __int8 cc_uint8;
|
||||
typedef unsigned __int16 cc_uint16;
|
||||
typedef unsigned __int32 cc_uint32;
|
||||
typedef unsigned __int64 cc_uint64;
|
||||
#ifdef _WIN64
|
||||
typedef unsigned __int64 cc_uintptr;
|
||||
#else
|
||||
typedef unsigned __int32 cc_uintptr;
|
||||
#endif
|
||||
|
||||
#define CC_INLINE inline
|
||||
#define CC_NOINLINE __declspec(noinline)
|
||||
#ifndef CC_API
|
||||
#define CC_API __declspec(dllexport, noinline)
|
||||
#define CC_VAR __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
#define CC_HAS_TYPES
|
||||
#define CC_HAS_MISC
|
||||
#elif __GNUC__
|
||||
/* really old GCC/clang might not have these defined */
|
||||
#ifdef __INT8_TYPE__
|
||||
/* avoid including <stdint.h> because it breaks defining UNICODE in Platform.c with MinGW */
|
||||
typedef __INT8_TYPE__ cc_int8;
|
||||
typedef __INT16_TYPE__ cc_int16;
|
||||
typedef __INT32_TYPE__ cc_int32;
|
||||
typedef __INT64_TYPE__ cc_int64;
|
||||
|
||||
#ifdef __UINT8_TYPE__
|
||||
typedef __UINT8_TYPE__ cc_uint8;
|
||||
typedef __UINT16_TYPE__ cc_uint16;
|
||||
typedef __UINT32_TYPE__ cc_uint32;
|
||||
typedef __UINT64_TYPE__ cc_uint64;
|
||||
typedef __UINTPTR_TYPE__ cc_uintptr;
|
||||
#else
|
||||
/* clang doesn't define the __UINT8_TYPE__ */
|
||||
typedef unsigned __INT8_TYPE__ cc_uint8;
|
||||
typedef unsigned __INT16_TYPE__ cc_uint16;
|
||||
typedef unsigned __INT32_TYPE__ cc_uint32;
|
||||
typedef unsigned __INT64_TYPE__ cc_uint64;
|
||||
typedef unsigned __INTPTR_TYPE__ cc_uintptr;
|
||||
#endif
|
||||
#define CC_HAS_TYPES
|
||||
#endif
|
||||
|
||||
#define CC_INLINE inline
|
||||
#define CC_NOINLINE __attribute__((noinline))
|
||||
#ifndef CC_API
|
||||
#ifdef _WIN32
|
||||
#define CC_API __attribute__((dllexport, noinline))
|
||||
#define CC_VAR __attribute__((dllexport))
|
||||
#else
|
||||
#define CC_API __attribute__((visibility("default"), noinline))
|
||||
#define CC_VAR __attribute__((visibility("default")))
|
||||
#endif
|
||||
#endif
|
||||
#define CC_HAS_MISC
|
||||
#ifdef __BIG_ENDIAN__
|
||||
#define CC_BIG_ENDIAN
|
||||
#endif
|
||||
/* really old GCC/clang might not have these defined */
|
||||
#ifdef __INT8_TYPE__
|
||||
/* avoid including <stdint.h> because it breaks defining UNICODE in Platform.c with MinGW */
|
||||
typedef __INT8_TYPE__ cc_int8;
|
||||
typedef __INT16_TYPE__ cc_int16;
|
||||
typedef __INT32_TYPE__ cc_int32;
|
||||
typedef __INT64_TYPE__ cc_int64;
|
||||
|
||||
#ifdef __UINT8_TYPE__
|
||||
typedef __UINT8_TYPE__ cc_uint8;
|
||||
typedef __UINT16_TYPE__ cc_uint16;
|
||||
typedef __UINT32_TYPE__ cc_uint32;
|
||||
typedef __UINT64_TYPE__ cc_uint64;
|
||||
typedef __UINTPTR_TYPE__ cc_uintptr;
|
||||
#else
|
||||
/* clang doesn't define the __UINT8_TYPE__ */
|
||||
typedef unsigned __INT8_TYPE__ cc_uint8;
|
||||
typedef unsigned __INT16_TYPE__ cc_uint16;
|
||||
typedef unsigned __INT32_TYPE__ cc_uint32;
|
||||
typedef unsigned __INT64_TYPE__ cc_uint64;
|
||||
typedef unsigned __INTPTR_TYPE__ cc_uintptr;
|
||||
#endif
|
||||
#define CC_HAS_TYPES
|
||||
#endif
|
||||
|
||||
#define CC_INLINE inline
|
||||
#define CC_NOINLINE __attribute__((noinline))
|
||||
#ifndef CC_API
|
||||
#ifdef _WIN32
|
||||
#define CC_API __attribute__((dllexport, noinline))
|
||||
#define CC_VAR __attribute__((dllexport))
|
||||
#else
|
||||
#define CC_API __attribute__((visibility("default"), noinline))
|
||||
#define CC_VAR __attribute__((visibility("default")))
|
||||
#endif
|
||||
#endif
|
||||
#define CC_HAS_MISC
|
||||
#ifdef __BIG_ENDIAN__
|
||||
#define CC_BIG_ENDIAN
|
||||
#endif
|
||||
#elif __MWERKS__
|
||||
/* TODO: Is there actual attribute support for CC_API etc somewhere? */
|
||||
#define CC_BIG_ENDIAN
|
||||
/* TODO: Is there actual attribute support for CC_API etc somewhere? */
|
||||
#define CC_BIG_ENDIAN
|
||||
#endif
|
||||
|
||||
/* Unrecognised compiler, so just go with some sensible default typdefs */
|
||||
|
@ -146,6 +146,7 @@ typedef cc_uint8 cc_bool;
|
|||
#define CC_BUILD_WIN
|
||||
#define CC_BUILD_D3D9
|
||||
#define CC_BUILD_WINGUI
|
||||
#define CC_BUILD_HTTPCLIENT
|
||||
#define CC_BUILD_SCHANNEL
|
||||
#define CC_BUILD_WINMM
|
||||
#elif defined __ANDROID__
|
||||
|
|
27
src/Input.c
27
src/Input.c
|
@ -420,6 +420,10 @@ static void KeyBind_Init(void) {
|
|||
#define GAMEPAD_BEG_BTN CCPAD_A
|
||||
static float pad_holdtime[INPUT_COUNT - GAMEPAD_BEG_BTN];
|
||||
|
||||
int Gamepad_AxisBehaviour[2] = { AXIS_BEHAVIOUR_MOVEMENT, AXIS_BEHAVIOUR_CAMERA };
|
||||
int Gamepad_AxisSensitivity[2] = { AXIS_SENSI_NORMAL, AXIS_SENSI_NORMAL };
|
||||
static const float axis_sensiFactor[] = { 0.25f, 0.5f, 1.0f, 2.0f, 4.0f };
|
||||
|
||||
void Gamepad_SetButton(int btn, int pressed) {
|
||||
/* Reset hold tracking time */
|
||||
if (pressed && !Input.Pressed[btn]) pad_holdtime[btn - GAMEPAD_BEG_BTN] = 0;
|
||||
|
@ -427,25 +431,18 @@ void Gamepad_SetButton(int btn, int pressed) {
|
|||
Input_SetNonRepeatable(btn, pressed);
|
||||
}
|
||||
|
||||
static void Gamepad_SetLAxis(float x, float y, double delta) {
|
||||
if (x == 0 && y == 0) return;
|
||||
|
||||
Input.JoystickMovement = true;
|
||||
Input.JoystickAngle = Math_Atan2(x, -y);
|
||||
}
|
||||
|
||||
static void Gamepad_SetRAxis(float x, float y, double delta) {
|
||||
float scale = delta * 60.0;
|
||||
Event_RaiseRawMove(&ControllerEvents.RawMoved, x * scale, y * scale);
|
||||
}
|
||||
|
||||
void Gamepad_SetAxis(int axis, float x, float y, double delta) {
|
||||
if (!Input.RawMode) return;
|
||||
|
||||
if (axis == PAD_AXIS_LEFT) {
|
||||
Gamepad_SetLAxis(x, y, delta);
|
||||
if (Gamepad_AxisBehaviour[axis] == AXIS_BEHAVIOUR_MOVEMENT) {
|
||||
if (x == 0 && y == 0) return;
|
||||
|
||||
Input.JoystickMovement = true;
|
||||
Input.JoystickAngle = Math_Atan2(x, -y);
|
||||
} else {
|
||||
Gamepad_SetRAxis(x, y, delta);
|
||||
int sensi = Gamepad_AxisSensitivity[axis];
|
||||
float scale = delta * 60.0 * axis_sensiFactor[sensi];
|
||||
Event_RaiseRawMove(&ControllerEvents.RawMoved, x * scale, y * scale);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -187,9 +187,14 @@ void KeyBind_Set(KeyBind binding, int key, cc_uint8* binds);
|
|||
|
||||
|
||||
/* Gamepad axes. Default behaviour is: */
|
||||
/* - left axis: player movement */
|
||||
/* - left axis: player movement */
|
||||
/* - right axis: camera movement */
|
||||
enum PAD_AXIS { PAD_AXIS_LEFT, PAD_AXIS_RIGHT };
|
||||
enum PAD_AXIS { PAD_AXIS_LEFT, PAD_AXIS_RIGHT };
|
||||
enum AXIS_SENSITIVITY { AXIS_SENSI_LOWER, AXIS_SENSI_LOW, AXIS_SENSI_NORMAL, AXIS_SENSI_HIGH, AXIS_SENSI_HIGHER };
|
||||
enum AXIS_BEHAVIOUR { AXIS_BEHAVIOUR_MOVEMENT, AXIS_BEHAVIOUR_CAMERA };
|
||||
extern int Gamepad_AxisBehaviour[2];
|
||||
extern int Gamepad_AxisSensitivity[2];
|
||||
|
||||
/* Sets value of the given gamepad button */
|
||||
void Gamepad_SetButton(int btn, int pressed);
|
||||
/* Sets value of the given axis */
|
||||
|
|
Loading…
Reference in a new issue