mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-26 04:36:01 +00:00
Merge branch 'master' into play
This commit is contained in:
commit
64239f5f47
5
AUTHORS
Normal file
5
AUTHORS
Normal file
@ -0,0 +1,5 @@
|
||||
Hans-Kristian Arntzen - <maister@archlinux.us>
|
||||
- Main code, maintainer
|
||||
|
||||
Devin J. Pohly - <djpohly@djpohly.com>
|
||||
- Joypad axis support
|
61
config.h
61
config.h
@ -118,42 +118,49 @@ static const bool audio_sync = true;
|
||||
// Keybinds, Joypad
|
||||
////////////////////
|
||||
|
||||
// Axis threshold (between 0.0 and 1.0)
|
||||
// How far an axis must be tilted to result in a button press
|
||||
#define AXIS_THRESHOLD 0.8
|
||||
|
||||
// To figure out which joypad buttons to use, check jstest or similar.
|
||||
// Axes are configured using the axis number for the positive (up, right)
|
||||
// direction and the number's two's-complement (~) for negative directions.
|
||||
// To use the axis, set the button to -1.
|
||||
|
||||
// Player 1
|
||||
static const struct snes_keybind snes_keybinds_1[] = {
|
||||
// SNES button | keyboard key | joypad button |
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, 'X', 1 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, 'Z', 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, 'S', 3 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, 'A', 2 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, 'Q', 4 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, 'W', 5 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, GLFW_KEY_LEFT, 11 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, GLFW_KEY_RIGHT, 12 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, GLFW_KEY_UP, 13 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, GLFW_KEY_DOWN, 14 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, GLFW_KEY_ENTER, 6 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, GLFW_KEY_RSHIFT, 7 },
|
||||
{ SNES_FAST_FORWARD_KEY, GLFW_KEY_SPACE, 9 },
|
||||
// SNES button | keyboard key | js btn | js axis |
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, 'X', 1, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, 'Z', 0, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, 'S', 3, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, 'A', 2, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, 'Q', 4, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, 'W', 5, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, GLFW_KEY_LEFT, 11, ~4 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, GLFW_KEY_RIGHT, 12, 4 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, GLFW_KEY_UP, 13, 5 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, GLFW_KEY_DOWN, 14, ~5 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, GLFW_KEY_ENTER, 6, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, GLFW_KEY_RSHIFT, 7, 0 },
|
||||
{ SNES_FAST_FORWARD_KEY, GLFW_KEY_SPACE, 9, 0 },
|
||||
{ -1 }
|
||||
};
|
||||
|
||||
// Player 2
|
||||
static const struct snes_keybind snes_keybinds_2[] = {
|
||||
// SNES button | keyboard key | joypad button |
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, 'B', 1 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, 'V', 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, 'G', 3 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, 'F', 2 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, 'R', 4 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, 'T', 5 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, 'J', 11 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, 'L', 12 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, 'I', 13 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, 'K', 14 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, 'P', 6 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, 'O', 7 },
|
||||
// SNES button | keyboard key | js btn | js axis |
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, 'B', 1, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, 'V', 0, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, 'G', 3, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, 'F', 2, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, 'R', 4, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, 'T', 5, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, 'J', 11, ~4 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, 'L', 12, 4 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, 'I', 13, 5 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, 'K', 14, ~5 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, 'P', 6, 0 },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, 'O', 7, 0 },
|
||||
{ -1 }
|
||||
};
|
||||
|
||||
|
1
driver.h
1
driver.h
@ -32,6 +32,7 @@ struct snes_keybind
|
||||
int id;
|
||||
int key;
|
||||
int joykey;
|
||||
int joyaxis;
|
||||
};
|
||||
|
||||
typedef struct video_info
|
||||
|
61
gl.c
61
gl.c
@ -75,9 +75,11 @@ static void glfw_input_poll(void *data)
|
||||
}
|
||||
|
||||
#define BUTTONS_MAX 128
|
||||
#define AXES_MAX 128
|
||||
|
||||
static int joypad_id[2];
|
||||
static int joypad_buttons[2];
|
||||
static int joypad_axes[2];
|
||||
static bool joypad_inited = false;
|
||||
static int joypad_count = 0;
|
||||
|
||||
@ -93,6 +95,9 @@ static int init_joypads(int max_pads)
|
||||
joypad_buttons[count] = glfwGetJoystickParam(i, GLFW_BUTTONS);
|
||||
if (joypad_buttons[count] > BUTTONS_MAX)
|
||||
joypad_buttons[count] = BUTTONS_MAX;
|
||||
joypad_axes[count] = glfwGetJoystickParam(i, GLFW_AXES);
|
||||
if (joypad_axes[count] > AXES_MAX)
|
||||
joypad_axes[count] = AXES_MAX;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@ -100,6 +105,19 @@ static int init_joypads(int max_pads)
|
||||
return count;
|
||||
}
|
||||
|
||||
static bool glfw_is_pressed(int port_num, const struct snes_keybind *key, unsigned char *buttons, float *axes)
|
||||
{
|
||||
if (glfwGetKey(key->key))
|
||||
return true;
|
||||
if (port_num >= joypad_count)
|
||||
return false;
|
||||
if (key->joykey >= 0)
|
||||
return (key->joykey < joypad_buttons[port_num] && buttons[key->joykey] == GLFW_PRESS);
|
||||
if (key->joyaxis >= 0)
|
||||
return (key->joyaxis < joypad_axes[port_num] && axes[key->joyaxis] >= AXIS_THRESHOLD);
|
||||
return (~key->joyaxis < joypad_axes[port_num] && axes[~key->joyaxis] <= -AXIS_THRESHOLD);
|
||||
}
|
||||
|
||||
static int16_t glfw_input_state(void *data, const struct snes_keybind **binds, bool port, unsigned device, unsigned index, unsigned id)
|
||||
{
|
||||
if ( device != SNES_DEVICE_JOYPAD )
|
||||
@ -110,9 +128,13 @@ static int16_t glfw_input_state(void *data, const struct snes_keybind **binds, b
|
||||
|
||||
int port_num = port ? 1 : 0;
|
||||
unsigned char buttons[BUTTONS_MAX];
|
||||
float axes[AXES_MAX];
|
||||
|
||||
if ( joypad_count > port_num )
|
||||
{
|
||||
glfwGetJoystickButtons(joypad_id[port_num], buttons, joypad_buttons[port_num]);
|
||||
glfwGetJoystickPos(joypad_id[port_num], axes, joypad_axes[port_num]);
|
||||
}
|
||||
|
||||
|
||||
const struct snes_keybind *snes_keybinds;
|
||||
@ -121,35 +143,15 @@ static int16_t glfw_input_state(void *data, const struct snes_keybind **binds, b
|
||||
else
|
||||
snes_keybinds = binds[1];
|
||||
|
||||
// Finds fast forwarding state.
|
||||
for ( int i = 0; snes_keybinds[i].id != -1; i++ )
|
||||
{
|
||||
if ( snes_keybinds[i].id == SNES_FAST_FORWARD_KEY )
|
||||
{
|
||||
// Checks if button is pressed, and sets fast-forwarding state
|
||||
bool pressed = false;
|
||||
if ( glfwGetKey(snes_keybinds[i].key) )
|
||||
pressed = true;
|
||||
else if ( (joypad_count > port_num) && (snes_keybinds[i].joykey < joypad_buttons[port_num]) && (buttons[snes_keybinds[i].joykey] == GLFW_PRESS) )
|
||||
pressed = true;
|
||||
set_fast_forward_button(pressed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Checks if button is pressed
|
||||
for ( int i = 0; snes_keybinds[i].id != -1; i++ )
|
||||
{
|
||||
if ( snes_keybinds[i].id == (int)id )
|
||||
{
|
||||
if ( glfwGetKey(snes_keybinds[i].key) )
|
||||
return 1;
|
||||
if ( snes_keybinds[i].id == SNES_FAST_FORWARD_KEY )
|
||||
set_fast_forward_button(glfw_is_pressed(port_num, &snes_keybinds[i], buttons, axes));
|
||||
else if ( !pressed && snes_keybinds[i].id == (int)id )
|
||||
pressed = glfw_is_pressed(port_num, &snes_keybinds[i], buttons, axes);
|
||||
|
||||
if ( (joypad_count > port_num) && (snes_keybinds[i].joykey < joypad_buttons[port_num]) && (buttons[snes_keybinds[i].joykey] == GLFW_PRESS) )
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return pressed;
|
||||
}
|
||||
|
||||
static void glfw_free_input(void *data)
|
||||
@ -213,7 +215,7 @@ static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, i
|
||||
|
||||
static inline void show_fps(void)
|
||||
{
|
||||
// Shows FPS in taskbar.
|
||||
// Shows FPS in taskbar.
|
||||
static int frames = 0;
|
||||
static struct timeval tv;
|
||||
struct timeval new_tv;
|
||||
@ -224,10 +226,7 @@ static inline void show_fps(void)
|
||||
if ((frames % 180) == 0 && frames > 0)
|
||||
{
|
||||
gettimeofday(&new_tv, NULL);
|
||||
struct timeval tmp_tv = {
|
||||
.tv_sec = tv.tv_sec,
|
||||
.tv_usec = tv.tv_usec
|
||||
};
|
||||
struct timeval tmp_tv = tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
char tmpstr[256] = {0};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user