Skip to content

Commit

Permalink
Analog pads support
Browse files Browse the repository at this point in the history
  • Loading branch information
kivutar committed Jul 5, 2022
1 parent a7455f9 commit e071d1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Binary file modified deps/osx_arm64/lib/libglfw3.a
Binary file not shown.
21 changes: 19 additions & 2 deletions input.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <stdio.h>

#include "input.h"
#include "config.h"
Expand Down Expand Up @@ -201,10 +202,15 @@ struct keymap joy_binds[] = {
};

#define MAX_PLAYERS 5
static unsigned state[MAX_PLAYERS][RETRO_DEVICE_ID_JOYPAD_R3+1] = { 0 };
static int16_t state[MAX_PLAYERS][RETRO_DEVICE_ID_JOYPAD_R3+1] = { 0 };
static int16_t analog_state[MAX_PLAYERS][2][2] = { 0 };
static retro_keyboard_event_t key_event = NULL;
extern GLFWwindow *window;

int16_t floatToAnalog(float v) {
return v * 32767.0;
}

void input_poll(void) {
int i;

Expand Down Expand Up @@ -247,6 +253,11 @@ void input_poll(void) {
}
}

analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = floatToAnalog(axes[GLFW_GAMEPAD_AXIS_LEFT_X]);
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = floatToAnalog(axes[GLFW_GAMEPAD_AXIS_LEFT_Y]);
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = floatToAnalog(axes[GLFW_GAMEPAD_AXIS_RIGHT_X]);
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = floatToAnalog(axes[GLFW_GAMEPAD_AXIS_RIGHT_Y]);

state[port][RETRO_DEVICE_ID_JOYPAD_L2] = axes[GLFW_GAMEPAD_AXIS_LEFT_TRIGGER] > 0.5;
state[port][RETRO_DEVICE_ID_JOYPAD_R2] = axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.5;
}
Expand All @@ -261,9 +272,15 @@ static double oldx = 0;
static double oldy = 0;

int16_t input_state(unsigned port, unsigned device, unsigned index, unsigned id) {
if (port < MAX_PLAYERS && device == RETRO_DEVICE_JOYPAD)
if (port >= MAX_PLAYERS)
return 0;

if (device == RETRO_DEVICE_JOYPAD)
return state[port][id];

if (device == RETRO_DEVICE_ANALOG)
return analog_state[port][index][id];

if (device == RETRO_DEVICE_MOUSE && window != NULL) {
double x = 0;
double y = 0;
Expand Down

0 comments on commit e071d1f

Please sign in to comment.