mirror of
https://github.com/libretro/RetroArch
synced 2025-03-20 01:21:03 +00:00
(Console/Android) Init input driver from context driver/graphics
driver from now on - just like PC - input driver initing can be hoisted out of global_drivers_init that way
This commit is contained in:
parent
40591bfdb5
commit
727dc76db8
File diff suppressed because it is too large
Load Diff
3
driver.c
3
driver.c
@ -444,7 +444,6 @@ void global_init_drivers(void)
|
||||
#if defined(HAVE_RGUI) || defined(HAVE_RMENU) || defined(HAVE_RMENU_XUI)
|
||||
driver.video->start(); // Statically starts video driver. Sets driver.video_data.
|
||||
#endif
|
||||
driver.input_data = driver.input->init();
|
||||
|
||||
for(i = 0; i < MAX_PLAYERS; i++)
|
||||
if (driver.input->set_keybinds)
|
||||
@ -464,9 +463,7 @@ void global_init_drivers(void)
|
||||
void global_uninit_drivers(void)
|
||||
{
|
||||
if (driver.video_data)
|
||||
{
|
||||
driver.video_data = NULL;
|
||||
}
|
||||
|
||||
if (driver.input_data)
|
||||
{
|
||||
|
@ -180,9 +180,6 @@ returntype main_entry(signature())
|
||||
}
|
||||
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
|
||||
{
|
||||
#if defined(RARCH_CONSOLE) || defined(ANDROID)
|
||||
driver.input->poll(NULL);
|
||||
#endif
|
||||
if (driver.video_poke->set_aspect_ratio)
|
||||
driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx);
|
||||
|
||||
|
@ -199,8 +199,6 @@ static void android_app_entry(void *data)
|
||||
}
|
||||
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
|
||||
{
|
||||
driver.input->poll(NULL);
|
||||
|
||||
if (driver.video_poke->set_aspect_ratio)
|
||||
driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx);
|
||||
|
||||
|
@ -217,8 +217,9 @@ static bool gfx_ctx_set_video_mode(
|
||||
|
||||
static void gfx_ctx_input_driver(const input_driver_t **input, void **input_data)
|
||||
{
|
||||
*input = NULL;
|
||||
*input_data = NULL;
|
||||
void *androidinput = input_android.init();
|
||||
*input = androidinput ? &input_android : NULL;
|
||||
*input_data = androidinput;
|
||||
}
|
||||
|
||||
static unsigned gfx_ctx_get_resolution_width(unsigned resolution_id)
|
||||
|
@ -292,8 +292,9 @@ static void gfx_ctx_destroy(void)
|
||||
|
||||
static void gfx_ctx_input_driver(const input_driver_t **input, void **input_data)
|
||||
{
|
||||
*input = NULL;
|
||||
*input_data = NULL;
|
||||
void *ps3input = input_ps3.init();
|
||||
*input = ps3input ? &input_ps3 : NULL;
|
||||
*input_data = ps3input;
|
||||
}
|
||||
|
||||
static bool gfx_ctx_bind_api(enum gfx_ctx_api api, unsigned major, unsigned minor)
|
||||
|
2
gfx/gl.c
2
gfx/gl.c
@ -2425,7 +2425,7 @@ static void gl_start(void)
|
||||
video_info.height = g_extern.console.screen.viewports.custom_vp.height;
|
||||
}
|
||||
|
||||
driver.video_data = gl_init(&video_info, NULL, NULL);
|
||||
driver.video_data = gl_init(&video_info, &driver.input, &driver.input_data);
|
||||
|
||||
gl_t *gl = (gl_t*)driver.video_data;
|
||||
gl_get_poke_interface(gl, &driver.video_poke);
|
||||
|
@ -38,11 +38,14 @@
|
||||
|
||||
#define MAX_PADS 4
|
||||
|
||||
static u32 pad_connect[MAX_PADS];
|
||||
static u32 pad_type[MAX_PADS];
|
||||
static u32 pad_detect_pending[MAX_PADS];
|
||||
static uint64_t pad_state[MAX_PADS];
|
||||
static int16_t analog_state[MAX_PADS][2][2];
|
||||
typedef struct gx_input
|
||||
{
|
||||
uint32_t pad_connect[MAX_PADS];
|
||||
uint32_t pad_type[MAX_PADS];
|
||||
uint32_t pad_detect_pending[MAX_PADS];
|
||||
uint64_t pad_state[MAX_PADS];
|
||||
int16_t analog_state[MAX_PADS][2][2];
|
||||
} gx_input_t;
|
||||
|
||||
const struct platform_bind platform_keys[] = {
|
||||
{ GX_GC_A, "GC A button" },
|
||||
@ -107,7 +110,7 @@ static int16_t gx_input_state(void *data, const struct retro_keybind **binds,
|
||||
unsigned port, unsigned device,
|
||||
unsigned index, unsigned id)
|
||||
{
|
||||
(void)data;
|
||||
gx_input_t *gx = (gx_input_t*)data;
|
||||
|
||||
if (port >= MAX_PADS)
|
||||
return 0;
|
||||
@ -115,9 +118,9 @@ static int16_t gx_input_state(void *data, const struct retro_keybind **binds,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return (binds[port][id].joykey & pad_state[port]) ? 1 : 0;
|
||||
return (binds[port][id].joykey & gx->pad_state[port]) ? 1 : 0;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
return analog_state[port][index][id];
|
||||
return gx->analog_state[port][index][id];
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -143,6 +146,7 @@ static void power_callback(void)
|
||||
static void gx_input_set_keybinds(void *data, unsigned device, unsigned port,
|
||||
unsigned id, unsigned keybind_action)
|
||||
{
|
||||
gx_input_t *gx = (gx_input_t*)data;
|
||||
uint64_t *key = &g_settings.input.binds[port][id].joykey;
|
||||
size_t arr_size = sizeof(platform_keys) / sizeof(platform_keys[0]);
|
||||
|
||||
@ -267,16 +271,20 @@ static void gx_input_set_keybinds(void *data, unsigned device, unsigned port,
|
||||
}
|
||||
}
|
||||
|
||||
pad_detect_pending[port] = 1;
|
||||
gx->pad_detect_pending[port] = 1;
|
||||
}
|
||||
|
||||
static void *gx_input_init(void)
|
||||
{
|
||||
gx_input_t *gx = (gx_input_t*)calloc(1, sizeof(*gx));
|
||||
if (!gx)
|
||||
return NULL;
|
||||
|
||||
for (unsigned i = 0; i < MAX_PADS; i++)
|
||||
{
|
||||
pad_connect[i] = 0;
|
||||
pad_type[i] = 0;
|
||||
pad_detect_pending[i] = 1;
|
||||
gx->pad_connect[i] = 0;
|
||||
gx->pad_type[i] = 0;
|
||||
gx->pad_detect_pending[i] = 1;
|
||||
}
|
||||
|
||||
PAD_Init();
|
||||
@ -288,21 +296,21 @@ static void *gx_input_init(void)
|
||||
SYS_SetPowerCallback(power_callback);
|
||||
#endif
|
||||
|
||||
return (void*)-1;
|
||||
return gx;
|
||||
}
|
||||
|
||||
static void gx_input_poll(void *data)
|
||||
{
|
||||
(void)data;
|
||||
gx_input_t *gx = (gx_input_t*)data;
|
||||
|
||||
pad_state[0] = 0;
|
||||
pad_state[1] = 0;
|
||||
pad_state[2] = 0;
|
||||
pad_state[3] = 0;
|
||||
analog_state[0][0][0] = analog_state[0][0][1] = analog_state[0][1][0] = analog_state[0][1][1] = 0;
|
||||
analog_state[1][0][0] = analog_state[1][0][1] = analog_state[1][1][0] = analog_state[1][1][1] = 0;
|
||||
analog_state[2][0][0] = analog_state[2][0][1] = analog_state[2][1][0] = analog_state[2][1][1] = 0;
|
||||
analog_state[3][0][0] = analog_state[3][0][1] = analog_state[3][1][0] = analog_state[3][1][1] = 0;
|
||||
gx->pad_state[0] = 0;
|
||||
gx->pad_state[1] = 0;
|
||||
gx->pad_state[2] = 0;
|
||||
gx->pad_state[3] = 0;
|
||||
gx->analog_state[0][0][0] = gx->analog_state[0][0][1] = gx->analog_state[0][1][0] = gx->analog_state[0][1][1] = 0;
|
||||
gx->analog_state[1][0][0] = gx->analog_state[1][0][1] = gx->analog_state[1][1][0] = gx->analog_state[1][1][1] = 0;
|
||||
gx->analog_state[2][0][0] = gx->analog_state[2][0][1] = gx->analog_state[2][1][0] = gx->analog_state[2][1][1] = 0;
|
||||
gx->analog_state[3][0][0] = gx->analog_state[3][0][1] = gx->analog_state[3][1][0] = gx->analog_state[3][1][1] = 0;
|
||||
|
||||
PAD_ScanPads();
|
||||
|
||||
@ -313,18 +321,18 @@ static void gx_input_poll(void *data)
|
||||
for (unsigned port = 0; port < MAX_PADS; port++)
|
||||
{
|
||||
uint32_t down = 0;
|
||||
uint64_t *state_cur = &pad_state[port];
|
||||
uint64_t *state_cur = &gx->pad_state[port];
|
||||
|
||||
#ifdef HW_RVL
|
||||
if (pad_detect_pending[port])
|
||||
if (gx->pad_detect_pending[port])
|
||||
{
|
||||
u32 *ptype = &pad_type[port];
|
||||
pad_connect[port] = WPAD_Probe(port, ptype);
|
||||
pad_detect_pending[port] = 0;
|
||||
uint32_t *ptype = &gx->pad_type[port];
|
||||
gx->pad_connect[port] = WPAD_Probe(port, ptype);
|
||||
gx->pad_detect_pending[port] = 0;
|
||||
}
|
||||
|
||||
uint32_t connected = pad_connect[port];
|
||||
uint32_t type = pad_type[port];
|
||||
uint32_t connected = gx->pad_connect[port];
|
||||
uint32_t type = gx->pad_type[port];
|
||||
|
||||
if (connected == WPAD_ERR_NONE)
|
||||
{
|
||||
@ -393,10 +401,10 @@ static void gx_input_poll(void *data)
|
||||
int16_t rs_x = (int16_t)(rjs_val_x * 32767.0f);
|
||||
int16_t rs_y = (int16_t)(rjs_val_y * 32767.0f);
|
||||
|
||||
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ls_x;
|
||||
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ls_y;
|
||||
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rs_x;
|
||||
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rs_y;
|
||||
gx->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ls_x;
|
||||
gx->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ls_y;
|
||||
gx->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rs_x;
|
||||
gx->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rs_y;
|
||||
}
|
||||
else if (type == WPAD_EXP_NUNCHUK)
|
||||
{
|
||||
@ -423,8 +431,8 @@ static void gx_input_poll(void *data)
|
||||
int16_t x = (int16_t)(js_val_x * 32767.0f);
|
||||
int16_t y = (int16_t)(js_val_y * 32767.0f);
|
||||
|
||||
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = x;
|
||||
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = y;
|
||||
gx->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = x;
|
||||
gx->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = y;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -451,17 +459,17 @@ static void gx_input_poll(void *data)
|
||||
int16_t rs_x = (int16_t)PAD_SubStickX(port) * 256;
|
||||
int16_t rs_y = (int16_t)PAD_SubStickY(port) * -256;
|
||||
|
||||
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ls_x;
|
||||
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ls_y;
|
||||
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rs_x;
|
||||
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rs_y;
|
||||
gx->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ls_x;
|
||||
gx->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ls_y;
|
||||
gx->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rs_x;
|
||||
gx->analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rs_y;
|
||||
|
||||
if ((*state_cur & (GX_GC_START | GX_GC_Z_TRIGGER | GX_GC_L_TRIGGER | GX_GC_R_TRIGGER)) == (GX_GC_START | GX_GC_Z_TRIGGER | GX_GC_L_TRIGGER | GX_GC_R_TRIGGER))
|
||||
*state_cur |= GX_WIIMOTE_HOME;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t *state_p1 = &pad_state[0];
|
||||
uint64_t *state_p1 = &gx->pad_state[0];
|
||||
uint64_t *lifecycle_state = &g_extern.lifecycle_state;
|
||||
|
||||
*lifecycle_state &= ~(
|
||||
|
@ -454,6 +454,11 @@ static void *gx_init(const video_info_t *video,
|
||||
gx_video_t *gx = (gx_video_t*)calloc(1, sizeof(gx_video_t));
|
||||
if (!gx)
|
||||
return NULL;
|
||||
|
||||
void *gxinput = input_gx.init();
|
||||
*input = gxinput ? &input_gx : NULL;
|
||||
*input_data = gxinput;
|
||||
|
||||
return gx;
|
||||
}
|
||||
|
||||
@ -465,7 +470,7 @@ static void gx_start(void)
|
||||
|
||||
video_info.vsync = g_settings.video.vsync;
|
||||
|
||||
driver.video_data = gx_init(&video_info, NULL, NULL);
|
||||
driver.video_data = gx_init(&video_info, &driver.input, &driver.input_data);
|
||||
|
||||
VIDEO_Init();
|
||||
GX_Init(gx_fifo, sizeof(gx_fifo));
|
||||
|
@ -59,16 +59,19 @@ const struct platform_bind platform_keys[] = {
|
||||
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_R3), "R3 button" },
|
||||
};
|
||||
|
||||
static uint64_t state[MAX_PADS];
|
||||
static unsigned pads_connected;
|
||||
typedef struct ps3_input
|
||||
{
|
||||
uint64_t state[MAX_PADS];
|
||||
unsigned pads_connected;
|
||||
#ifdef HAVE_MOUSE
|
||||
static unsigned mice_connected;
|
||||
unsigned mice_connected;
|
||||
#endif
|
||||
} ps3_input_t;
|
||||
|
||||
static void ps3_input_poll(void *data)
|
||||
{
|
||||
CellPadInfo2 pad_info;
|
||||
(void)data;
|
||||
ps3_input_t *ps3 = (ps3_input_t*)data;
|
||||
|
||||
for (unsigned i = 0; i < MAX_PADS; i++)
|
||||
{
|
||||
@ -77,7 +80,7 @@ static void ps3_input_poll(void *data)
|
||||
|
||||
if (state_tmp.len != 0)
|
||||
{
|
||||
uint64_t *state_cur = &state[i];
|
||||
uint64_t *state_cur = &ps3->state[i];
|
||||
*state_cur = 0;
|
||||
#ifdef __PSL1GHT__
|
||||
*state_cur |= (state_tmp.BTN_LEFT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
|
||||
@ -117,7 +120,7 @@ static void ps3_input_poll(void *data)
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t *state_p1 = &state[0];
|
||||
uint64_t *state_p1 = &ps3->state[0];
|
||||
uint64_t *lifecycle_state = &g_extern.lifecycle_state;
|
||||
|
||||
*lifecycle_state &= ~(
|
||||
@ -134,11 +137,11 @@ static void ps3_input_poll(void *data)
|
||||
*lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE);
|
||||
|
||||
cellPadGetInfo2(&pad_info);
|
||||
pads_connected = pad_info.now_connect;
|
||||
ps3->pads_connected = pad_info.now_connect;
|
||||
#ifdef HAVE_MOUSE
|
||||
CellMouseInfo mouse_info;
|
||||
cellMouseGetInfo(&mouse_info);
|
||||
mice_connected = mouse_info.now_connect;
|
||||
ps3->mice_connected = mouse_info.now_connect;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -146,19 +149,20 @@ static void ps3_input_poll(void *data)
|
||||
|
||||
static int16_t ps3_mouse_device_state(void *data, unsigned player, unsigned id)
|
||||
{
|
||||
ps3_input_t *ps3 = (ps3_input_t*)data;
|
||||
CellMouseData mouse_state;
|
||||
cellMouseGetData(id, &mouse_state);
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return (!mice_connected ? 0 : mouse_state.buttons & CELL_MOUSE_BUTTON_1);
|
||||
return (!ps3->mice_connected ? 0 : mouse_state.buttons & CELL_MOUSE_BUTTON_1);
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return (!mice_connected ? 0 : mouse_state.buttons & CELL_MOUSE_BUTTON_2);
|
||||
return (!ps3->mice_connected ? 0 : mouse_state.buttons & CELL_MOUSE_BUTTON_2);
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
return (!mice_connected ? 0 : mouse_state.x_axis);
|
||||
return (!ps3->mice_connected ? 0 : mouse_state.x_axis);
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
return (!mice_connected ? 0 : mouse_state.y_axis);
|
||||
return (!ps3->mice_connected ? 0 : mouse_state.y_axis);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -170,18 +174,18 @@ static int16_t ps3_input_state(void *data, const struct retro_keybind **binds,
|
||||
unsigned port, unsigned device,
|
||||
unsigned index, unsigned id)
|
||||
{
|
||||
(void)data;
|
||||
ps3_input_t *ps3 = (ps3_input_t*)data;
|
||||
|
||||
unsigned player = port;
|
||||
uint64_t button = binds[player][id].joykey;
|
||||
int16_t retval = 0;
|
||||
|
||||
if (player < pads_connected)
|
||||
if (player < ps3->pads_connected)
|
||||
{
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
retval = (state[player] & button) ? 1 : 0;
|
||||
retval = (ps3->state[player] & button) ? 1 : 0;
|
||||
break;
|
||||
#ifdef HAVE_MOUSE
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
@ -298,16 +302,20 @@ do_deinit:
|
||||
|
||||
static void ps3_input_free_input(void *data)
|
||||
{
|
||||
(void)data;
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
//cellPadEnd();
|
||||
#ifdef HAVE_MOUSE
|
||||
//cellMouseEnd();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ps3_input_set_keybinds(void *data, unsigned device,
|
||||
unsigned port, unsigned id, unsigned keybind_action)
|
||||
{
|
||||
uint64_t *key = &g_settings.input.binds[port][id].joykey;
|
||||
uint64_t joykey = *key;
|
||||
//uint64_t joykey = *key;
|
||||
size_t arr_size = sizeof(platform_keys) / sizeof(platform_keys[0]);
|
||||
|
||||
(void)device;
|
||||
@ -348,12 +356,16 @@ static void ps3_input_set_keybinds(void *data, unsigned device,
|
||||
|
||||
static void* ps3_input_init(void)
|
||||
{
|
||||
ps3_input_t *ps3 = (ps3_input_t*)calloc(1, sizeof(*ps3));
|
||||
if (!ps3)
|
||||
return NULL;
|
||||
|
||||
cellPadInit(MAX_PADS);
|
||||
#ifdef HAVE_MOUSE
|
||||
cellMouseInit(MAX_MICE);
|
||||
#endif
|
||||
|
||||
return (void*)-1;
|
||||
return ps3;
|
||||
}
|
||||
|
||||
static bool ps3_input_key_pressed(void *data, int key)
|
||||
|
Loading…
x
Reference in New Issue
Block a user