mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 07:20:36 +00:00
Split up input_driver code to separate file - input_driver.c
This commit is contained in:
parent
7f484edc98
commit
07a7386c9d
@ -98,6 +98,7 @@ OBJ += frontend/frontend.o \
|
||||
libretro-sdk/file/file_path.o \
|
||||
hash.o \
|
||||
audio/audio_driver.o \
|
||||
input_driver.o \
|
||||
gfx/video_driver.o \
|
||||
driver.o \
|
||||
settings.o \
|
||||
|
134
driver.c
134
driver.c
@ -40,118 +40,6 @@
|
||||
|
||||
driver_t driver;
|
||||
|
||||
static const input_driver_t *input_drivers[] = {
|
||||
#ifdef __CELLOS_LV2__
|
||||
&input_ps3,
|
||||
#endif
|
||||
#if defined(SN_TARGET_PSP2) || defined(PSP)
|
||||
&input_psp,
|
||||
#endif
|
||||
#if defined(HAVE_SDL) || defined(HAVE_SDL2)
|
||||
&input_sdl,
|
||||
#endif
|
||||
#ifdef HAVE_DINPUT
|
||||
&input_dinput,
|
||||
#endif
|
||||
#ifdef HAVE_X11
|
||||
&input_x,
|
||||
#endif
|
||||
#ifdef XENON
|
||||
&input_xenon360,
|
||||
#endif
|
||||
#if defined(HAVE_XINPUT2) || defined(HAVE_XINPUT_XBOX1)
|
||||
&input_xinput,
|
||||
#endif
|
||||
#ifdef GEKKO
|
||||
&input_gx,
|
||||
#endif
|
||||
#ifdef ANDROID
|
||||
&input_android,
|
||||
#endif
|
||||
#ifdef HAVE_UDEV
|
||||
&input_udev,
|
||||
#endif
|
||||
#if defined(__linux__) && !defined(ANDROID)
|
||||
&input_linuxraw,
|
||||
#endif
|
||||
#if defined(IOS) || defined(OSX)
|
||||
/* Don't use __APPLE__ as it breaks basic SDL builds */
|
||||
&input_apple,
|
||||
#endif
|
||||
#ifdef __QNX__
|
||||
&input_qnx,
|
||||
#endif
|
||||
#ifdef EMSCRIPTEN
|
||||
&input_rwebinput,
|
||||
#endif
|
||||
&input_null,
|
||||
NULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* input_driver_find_handle:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: handle to input driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
static const void *input_driver_find_handle(int index)
|
||||
{
|
||||
const void *drv = input_drivers[index];
|
||||
if (!drv)
|
||||
return NULL;
|
||||
return drv;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_driver_find_ident:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: Human-readable identifier of input driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
static const char *input_driver_find_ident(int index)
|
||||
{
|
||||
const input_driver_t *drv = input_drivers[index];
|
||||
if (!drv)
|
||||
return NULL;
|
||||
return drv->ident;
|
||||
}
|
||||
|
||||
/**
|
||||
* config_get_input_driver_options:
|
||||
*
|
||||
* Get an enumerated list of all input driver names, separated by '|'.
|
||||
*
|
||||
* Returns: string listing of all input driver names, separated by '|'.
|
||||
**/
|
||||
const char* config_get_input_driver_options(void)
|
||||
{
|
||||
union string_list_elem_attr attr;
|
||||
unsigned i;
|
||||
char *options = NULL;
|
||||
int options_len = 0;
|
||||
struct string_list *options_l = string_list_new();
|
||||
|
||||
attr.i = 0;
|
||||
|
||||
for (i = 0; input_driver_find_handle(i); i++)
|
||||
{
|
||||
const char *opt = input_driver_find_ident(i);
|
||||
options_len += strlen(opt) + 1;
|
||||
string_list_append(options_l, opt, attr);
|
||||
}
|
||||
|
||||
options = (char*)calloc(options_len, sizeof(char));
|
||||
|
||||
string_list_join_concat(options, options_len, options_l, "|");
|
||||
|
||||
string_list_free(options_l);
|
||||
options_l = NULL;
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
static const input_osk_driver_t *osk_drivers[] = {
|
||||
#ifdef __CELLOS_LV2__
|
||||
&input_ps3_osk,
|
||||
@ -976,28 +864,6 @@ static void find_menu_driver(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void find_input_driver(void)
|
||||
{
|
||||
int i = find_driver_index("input_driver", g_settings.input.driver);
|
||||
if (i >= 0)
|
||||
driver.input = input_driver_find_handle(i);
|
||||
else
|
||||
{
|
||||
unsigned d;
|
||||
RARCH_ERR("Couldn't find any input driver named \"%s\"\n",
|
||||
g_settings.input.driver);
|
||||
RARCH_LOG_OUTPUT("Available input drivers are:\n");
|
||||
for (d = 0; input_driver_find_handle(d); d++)
|
||||
RARCH_LOG_OUTPUT("\t%s\n", input_driver_find_ident(d));
|
||||
RARCH_WARN("Going to default to first input driver...\n");
|
||||
|
||||
driver.input = input_driver_find_handle(0);
|
||||
|
||||
if (!driver.input)
|
||||
rarch_fail(1, "find_input_driver()");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* init_drivers_pre:
|
||||
*
|
||||
|
10
driver.h
10
driver.h
@ -25,7 +25,6 @@
|
||||
#include <compat/posix_string.h>
|
||||
#include "gfx/scaler/scaler.h"
|
||||
#include "gfx/image/image.h"
|
||||
#include "input/input_context.h"
|
||||
|
||||
#include "frontend/frontend_context.h"
|
||||
#include <retro_miscellaneous.h>
|
||||
@ -600,15 +599,6 @@ bool driver_update_system_av_info(const struct retro_system_av_info *info);
|
||||
|
||||
extern driver_t driver;
|
||||
|
||||
/**
|
||||
* config_get_input_driver_options:
|
||||
*
|
||||
* Get an enumerated list of all input driver names, separated by '|'.
|
||||
*
|
||||
* Returns: string listing of all input driver names, separated by '|'.
|
||||
**/
|
||||
const char* config_get_input_driver_options(void);
|
||||
|
||||
/**
|
||||
* config_get_camera_driver_options:
|
||||
*
|
||||
|
@ -23,76 +23,14 @@
|
||||
#include <boolean.h>
|
||||
#include "../libretro.h"
|
||||
|
||||
#include "../input/input_context.h"
|
||||
#include "../gfx/shader/shader_parse.h"
|
||||
#include "../input_driver.h"
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
#include "../input/overlay.h"
|
||||
#endif
|
||||
#include "../gfx/shader/shader_parse.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct retro_keybind
|
||||
{
|
||||
bool valid;
|
||||
unsigned id;
|
||||
const char *desc;
|
||||
enum retro_key key;
|
||||
|
||||
uint64_t joykey;
|
||||
/* Default key binding value - for resetting bind to default */
|
||||
uint64_t def_joykey;
|
||||
|
||||
uint32_t joyaxis;
|
||||
uint32_t def_joyaxis;
|
||||
|
||||
/* Used by input_{push,pop}_analog_dpad(). */
|
||||
uint32_t orig_joyaxis;
|
||||
|
||||
char joykey_label[256];
|
||||
char joyaxis_label[256];
|
||||
};
|
||||
|
||||
typedef struct input_driver
|
||||
{
|
||||
void *(*init)(void);
|
||||
void (*poll)(void *data);
|
||||
int16_t (*input_state)(void *data,
|
||||
const struct retro_keybind **retro_keybinds,
|
||||
unsigned port, unsigned device, unsigned index, unsigned id);
|
||||
bool (*key_pressed)(void *data, int key);
|
||||
void (*free)(void *data);
|
||||
bool (*set_sensor_state)(void *data, unsigned port,
|
||||
enum retro_sensor_action action, unsigned rate);
|
||||
float (*get_sensor_input)(void *data, unsigned port, unsigned id);
|
||||
uint64_t (*get_capabilities)(void *data);
|
||||
const char *ident;
|
||||
|
||||
void (*grab_mouse)(void *data, bool state);
|
||||
bool (*set_rumble)(void *data, unsigned port,
|
||||
enum retro_rumble_effect effect, uint16_t state);
|
||||
const rarch_joypad_driver_t *(*get_joypad_driver)(void *data);
|
||||
} input_driver_t;
|
||||
|
||||
extern input_driver_t input_android;
|
||||
extern input_driver_t input_sdl;
|
||||
extern input_driver_t input_dinput;
|
||||
extern input_driver_t input_x;
|
||||
extern input_driver_t input_wayland;
|
||||
extern input_driver_t input_ps3;
|
||||
extern input_driver_t input_psp;
|
||||
extern input_driver_t input_xenon360;
|
||||
extern input_driver_t input_gx;
|
||||
extern input_driver_t input_xinput;
|
||||
extern input_driver_t input_linuxraw;
|
||||
extern input_driver_t input_udev;
|
||||
extern input_driver_t input_apple;
|
||||
extern input_driver_t input_qnx;
|
||||
extern input_driver_t input_rwebinput;
|
||||
extern input_driver_t input_null;
|
||||
|
||||
struct rarch_viewport;
|
||||
|
||||
typedef struct video_info
|
||||
|
@ -497,6 +497,7 @@ AUDIO
|
||||
DRIVERS
|
||||
============================================================ */
|
||||
#include "../gfx/video_driver.c"
|
||||
#include "../input_driver.c"
|
||||
#include "../audio/audio_driver.c"
|
||||
#include "../driver.c"
|
||||
|
||||
|
155
input_driver.c
Normal file
155
input_driver.c
Normal file
@ -0,0 +1,155 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <string/string_list.h>
|
||||
#include "input_driver.h"
|
||||
#include "driver.h"
|
||||
#include "general.h"
|
||||
|
||||
static const input_driver_t *input_drivers[] = {
|
||||
#ifdef __CELLOS_LV2__
|
||||
&input_ps3,
|
||||
#endif
|
||||
#if defined(SN_TARGET_PSP2) || defined(PSP)
|
||||
&input_psp,
|
||||
#endif
|
||||
#if defined(HAVE_SDL) || defined(HAVE_SDL2)
|
||||
&input_sdl,
|
||||
#endif
|
||||
#ifdef HAVE_DINPUT
|
||||
&input_dinput,
|
||||
#endif
|
||||
#ifdef HAVE_X11
|
||||
&input_x,
|
||||
#endif
|
||||
#ifdef XENON
|
||||
&input_xenon360,
|
||||
#endif
|
||||
#if defined(HAVE_XINPUT2) || defined(HAVE_XINPUT_XBOX1)
|
||||
&input_xinput,
|
||||
#endif
|
||||
#ifdef GEKKO
|
||||
&input_gx,
|
||||
#endif
|
||||
#ifdef ANDROID
|
||||
&input_android,
|
||||
#endif
|
||||
#ifdef HAVE_UDEV
|
||||
&input_udev,
|
||||
#endif
|
||||
#if defined(__linux__) && !defined(ANDROID)
|
||||
&input_linuxraw,
|
||||
#endif
|
||||
#if defined(IOS) || defined(OSX)
|
||||
/* Don't use __APPLE__ as it breaks basic SDL builds */
|
||||
&input_apple,
|
||||
#endif
|
||||
#ifdef __QNX__
|
||||
&input_qnx,
|
||||
#endif
|
||||
#ifdef EMSCRIPTEN
|
||||
&input_rwebinput,
|
||||
#endif
|
||||
&input_null,
|
||||
NULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* input_driver_find_handle:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: handle to input driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
const void *input_driver_find_handle(int index)
|
||||
{
|
||||
const void *drv = input_drivers[index];
|
||||
if (!drv)
|
||||
return NULL;
|
||||
return drv;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_driver_find_ident:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: Human-readable identifier of input driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
const char *input_driver_find_ident(int index)
|
||||
{
|
||||
const input_driver_t *drv = input_drivers[index];
|
||||
if (!drv)
|
||||
return NULL;
|
||||
return drv->ident;
|
||||
}
|
||||
|
||||
/**
|
||||
* config_get_input_driver_options:
|
||||
*
|
||||
* Get an enumerated list of all input driver names, separated by '|'.
|
||||
*
|
||||
* Returns: string listing of all input driver names, separated by '|'.
|
||||
**/
|
||||
const char* config_get_input_driver_options(void)
|
||||
{
|
||||
union string_list_elem_attr attr;
|
||||
unsigned i;
|
||||
char *options = NULL;
|
||||
int options_len = 0;
|
||||
struct string_list *options_l = string_list_new();
|
||||
|
||||
attr.i = 0;
|
||||
|
||||
for (i = 0; input_driver_find_handle(i); i++)
|
||||
{
|
||||
const char *opt = input_driver_find_ident(i);
|
||||
options_len += strlen(opt) + 1;
|
||||
string_list_append(options_l, opt, attr);
|
||||
}
|
||||
|
||||
options = (char*)calloc(options_len, sizeof(char));
|
||||
|
||||
string_list_join_concat(options, options_len, options_l, "|");
|
||||
|
||||
string_list_free(options_l);
|
||||
options_l = NULL;
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
void find_input_driver(void)
|
||||
{
|
||||
int i = find_driver_index("input_driver", g_settings.input.driver);
|
||||
if (i >= 0)
|
||||
driver.input = input_driver_find_handle(i);
|
||||
else
|
||||
{
|
||||
unsigned d;
|
||||
RARCH_ERR("Couldn't find any input driver named \"%s\"\n",
|
||||
g_settings.input.driver);
|
||||
RARCH_LOG_OUTPUT("Available input drivers are:\n");
|
||||
for (d = 0; input_driver_find_handle(d); d++)
|
||||
RARCH_LOG_OUTPUT("\t%s\n", input_driver_find_ident(d));
|
||||
RARCH_WARN("Going to default to first input driver...\n");
|
||||
|
||||
driver.input = input_driver_find_handle(0);
|
||||
|
||||
if (!driver.input)
|
||||
rarch_fail(1, "find_input_driver()");
|
||||
}
|
||||
}
|
128
input_driver.h
Normal file
128
input_driver.h
Normal file
@ -0,0 +1,128 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __INPUT_DRIVER__H
|
||||
#define __INPUT_DRIVER__H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <boolean.h>
|
||||
#include "libretro.h"
|
||||
|
||||
#include "input/input_context.h"
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
#include "input/overlay.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct retro_keybind
|
||||
{
|
||||
bool valid;
|
||||
unsigned id;
|
||||
const char *desc;
|
||||
enum retro_key key;
|
||||
|
||||
uint64_t joykey;
|
||||
/* Default key binding value - for resetting bind to default */
|
||||
uint64_t def_joykey;
|
||||
|
||||
uint32_t joyaxis;
|
||||
uint32_t def_joyaxis;
|
||||
|
||||
/* Used by input_{push,pop}_analog_dpad(). */
|
||||
uint32_t orig_joyaxis;
|
||||
|
||||
char joykey_label[256];
|
||||
char joyaxis_label[256];
|
||||
};
|
||||
|
||||
typedef struct input_driver
|
||||
{
|
||||
void *(*init)(void);
|
||||
void (*poll)(void *data);
|
||||
int16_t (*input_state)(void *data,
|
||||
const struct retro_keybind **retro_keybinds,
|
||||
unsigned port, unsigned device, unsigned index, unsigned id);
|
||||
bool (*key_pressed)(void *data, int key);
|
||||
void (*free)(void *data);
|
||||
bool (*set_sensor_state)(void *data, unsigned port,
|
||||
enum retro_sensor_action action, unsigned rate);
|
||||
float (*get_sensor_input)(void *data, unsigned port, unsigned id);
|
||||
uint64_t (*get_capabilities)(void *data);
|
||||
const char *ident;
|
||||
|
||||
void (*grab_mouse)(void *data, bool state);
|
||||
bool (*set_rumble)(void *data, unsigned port,
|
||||
enum retro_rumble_effect effect, uint16_t state);
|
||||
const rarch_joypad_driver_t *(*get_joypad_driver)(void *data);
|
||||
} input_driver_t;
|
||||
|
||||
extern input_driver_t input_android;
|
||||
extern input_driver_t input_sdl;
|
||||
extern input_driver_t input_dinput;
|
||||
extern input_driver_t input_x;
|
||||
extern input_driver_t input_wayland;
|
||||
extern input_driver_t input_ps3;
|
||||
extern input_driver_t input_psp;
|
||||
extern input_driver_t input_xenon360;
|
||||
extern input_driver_t input_gx;
|
||||
extern input_driver_t input_xinput;
|
||||
extern input_driver_t input_linuxraw;
|
||||
extern input_driver_t input_udev;
|
||||
extern input_driver_t input_apple;
|
||||
extern input_driver_t input_qnx;
|
||||
extern input_driver_t input_rwebinput;
|
||||
extern input_driver_t input_null;
|
||||
|
||||
/**
|
||||
* input_driver_find_handle:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: handle to input driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
const void *input_driver_find_handle(int index);
|
||||
|
||||
/**
|
||||
* input_driver_find_ident:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: Human-readable identifier of input driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
const char *input_driver_find_ident(int index);
|
||||
|
||||
/**
|
||||
* config_get_input_driver_options:
|
||||
*
|
||||
* Get an enumerated list of all input driver names, separated by '|'.
|
||||
*
|
||||
* Returns: string listing of all input driver names, separated by '|'.
|
||||
**/
|
||||
const char* config_get_input_driver_options(void);
|
||||
|
||||
void find_input_driver(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user