Procházet zdrojové kódy

Add XInput support

Provide support for XInput mappings.
feature/data-structs
TheoryOfNekomata před 2 roky
rodič
revize
bc62f37f7a
3 změnil soubory, kde provedl 38 přidání a 3 odebrání
  1. +1
    -1
      CMakeLists.txt
  2. +33
    -0
      src/packages/game/input/IZ_joystick.c
  3. +4
    -2
      src/packages/game/input/IZ_joystick.h

+ 1
- 1
CMakeLists.txt Zobrazit soubor

@@ -18,7 +18,7 @@ add_definitions(
-DIZ_APP_NAME="Izanagi"
-DIZ_APP_DESCRIPTION="Run and gun game"
-DIZ_APP_SERVER_DESCRIPTION="Dedicated server"
-DIZ_PLAYERS=2
-DIZ_PLAYERS=1
)

if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")


+ 33
- 0
src/packages/game/input/IZ_joystick.c Zobrazit soubor

@@ -26,6 +26,38 @@ void IZ_JoystickHandleDeviceEvents(IZ_JoystickState* state, SDL_Event e) {

void IZ_JoystickHandleAxisEvents(IZ_JoystickState* state, IZ_Action* action, SDL_Event e) {
if (e.type == SDL_JOYAXISMOTION) {
// XInput handling
u8 control_index;
for (control_index = 4; control_index < IZ_CONTROLS; control_index += 1) {
if (e.jaxis.axis == IZ_JOY_AXIS_DIRECTION_LEFT_SHOULDER && state->config.control_mapping[control_index] == 10) {
const u16 bitflag = (0x1 << control_index);

if (e.jaxis.value > state->config.axis_threshold) {
*action |= bitflag;
return;
}

if (e.jaxis.value <= state->config.axis_threshold) {
*action &= ~bitflag;
return;
}
}

if (e.jaxis.axis == IZ_JOY_AXIS_DIRECTION_RIGHT_SHOULDER && state->config.control_mapping[control_index] == 11) {
const u16 bitflag = (0x1 << control_index);

if (e.jaxis.value > state->config.axis_threshold) {
*action |= bitflag;
return;
}

if (e.jaxis.value <= state->config.axis_threshold) {
*action &= ~bitflag;
return;
}
}
}

if (
e.jaxis.axis == IZ_JOY_AXIS_DIRECTION_HORIZONTAL1
|| e.jaxis.axis == IZ_JOY_AXIS_DIRECTION_HORIZONTAL2
@@ -72,6 +104,7 @@ void IZ_JoystickHandleHatEvents(IZ_Action* action, SDL_Event e) {

void IZ_JoystickHandleButtonEvents(IZ_JoystickState* state, IZ_Action* action, SDL_Event e) {
u8 control_index;

for (control_index = 4; control_index < IZ_CONTROLS; control_index += 1) {
if (e.jbutton.button == state->config.control_mapping[control_index]) {
const u16 bitflag = (0x1 << control_index);


+ 4
- 2
src/packages/game/input/IZ_joystick.h Zobrazit soubor

@@ -15,8 +15,10 @@ static const u16 IZ_DEFAULT_AXIS_THRESHOLD = 8000;
typedef enum {
IZ_JOY_AXIS_DIRECTION_HORIZONTAL1 = 0,
IZ_JOY_AXIS_DIRECTION_VERTICAL1 = 1,
IZ_JOY_AXIS_DIRECTION_HORIZONTAL2 = 3,
IZ_JOY_AXIS_DIRECTION_VERTICAL2 = 4,
IZ_JOY_AXIS_DIRECTION_HORIZONTAL2 = 2,
IZ_JOY_AXIS_DIRECTION_VERTICAL2 = 3,
IZ_JOY_AXIS_DIRECTION_LEFT_SHOULDER = 4,
IZ_JOY_AXIS_DIRECTION_RIGHT_SHOULDER = 5,
} IZ_JoyAxisDirection;

typedef struct {


Načítá se…
Zrušit
Uložit