Move input_state code to input_common.c

This commit is contained in:
twinaphex 2015-11-24 01:19:48 +01:00
parent 075a4891dc
commit 909ee01012
3 changed files with 98 additions and 82 deletions

View File

@ -22,6 +22,7 @@
#include "input_common.h"
#include "input_keymaps.h"
#include "input_remapping.h"
#include "../general.h"
#include "../verbosity.h"
@ -628,3 +629,85 @@ void input_poll(void)
rarch_cmd_poll(driver->command);
#endif
}
/**
* input_state:
* @port : user number.
* @device : device identifier of user.
* @idx : index value of user.
* @id : identifier of key pressed by user.
*
* Input state callback function.
*
* Returns: Non-zero if the given key (identified by @id) was pressed by the user
* (assigned to @port).
**/
int16_t input_state(unsigned port, unsigned device,
unsigned idx, unsigned id)
{
size_t i;
const struct retro_keybind *libretro_input_binds[MAX_USERS];
int16_t res = 0;
settings_t *settings = config_get_ptr();
driver_t *driver = driver_get_ptr();
global_t *global = global_get_ptr();
const input_driver_t *input = driver ?
(const input_driver_t*)driver->input : NULL;
for (i = 0; i < MAX_USERS; i++)
libretro_input_binds[i] = settings->input.binds[i];
device &= RETRO_DEVICE_MASK;
if (global->bsv.movie && global->bsv.movie_playback)
{
int16_t ret;
if (bsv_movie_get_input(global->bsv.movie, &ret))
return ret;
global->bsv.movie_end = true;
}
if (settings->input.remap_binds_enable)
input_remapping_state(port, &device, &idx, &id);
if (!driver->flushing_input && !driver->block_libretro_input)
{
if (((id < RARCH_FIRST_META_KEY) || (device == RETRO_DEVICE_KEYBOARD)))
res = input->input_state(driver->input_data, libretro_input_binds, port, device, idx, id);
#ifdef HAVE_OVERLAY
input_state_overlay(&res, port, device, idx, id);
#endif
}
/* Don't allow turbo for D-pad. */
if (device == RETRO_DEVICE_JOYPAD && (id < RETRO_DEVICE_ID_JOYPAD_UP ||
id > RETRO_DEVICE_ID_JOYPAD_RIGHT))
{
/*
* Apply turbo button if activated.
*
* If turbo button is held, all buttons pressed except
* for D-pad will go into a turbo mode. Until the button is
* released again, the input state will be modulated by a
* periodic pulse defined by the configured duty cycle.
*/
if (res && global->turbo.frame_enable[port])
global->turbo.enable[port] |= (1 << id);
else if (!res)
global->turbo.enable[port] &= ~(1 << id);
if (global->turbo.enable[port] & (1 << id))
{
/* if turbo button is enabled for this key ID */
res = res && ((global->turbo.count % settings->input.turbo_period)
< settings->input.turbo_duty_cycle);
}
}
if (global->bsv.movie && !global->bsv.movie_playback)
bsv_movie_set_input(global->bsv.movie, res);
return res;
}

View File

@ -130,6 +130,21 @@ bool check_block_hotkey(bool enable_hotkey);
**/
void input_poll(void);
/**
* input_state:
* @port : user number.
* @device : device identifier of user.
* @idx : index value of user.
* @id : identifier of key pressed by user.
*
* Input state callback function.
*
* Returns: Non-zero if the given key (identified by @id) was pressed by the user
* (assigned to @port).
**/
int16_t input_state(unsigned port, unsigned device,
unsigned idx, unsigned id);
#ifdef __cplusplus
}
#endif

View File

@ -98,88 +98,6 @@ static void video_frame(const void *data, unsigned width,
video_driver_frame(data, width, height, pitch, msg);
}
/**
* input_state:
* @port : user number.
* @device : device identifier of user.
* @idx : index value of user.
* @id : identifier of key pressed by user.
*
* Input state callback function.
*
* Returns: Non-zero if the given key (identified by @id) was pressed by the user
* (assigned to @port).
**/
static int16_t input_state(unsigned port, unsigned device,
unsigned idx, unsigned id)
{
size_t i;
const struct retro_keybind *libretro_input_binds[MAX_USERS];
int16_t res = 0;
settings_t *settings = config_get_ptr();
driver_t *driver = driver_get_ptr();
global_t *global = global_get_ptr();
const input_driver_t *input = driver ?
(const input_driver_t*)driver->input : NULL;
for (i = 0; i < MAX_USERS; i++)
libretro_input_binds[i] = settings->input.binds[i];
device &= RETRO_DEVICE_MASK;
if (global->bsv.movie && global->bsv.movie_playback)
{
int16_t ret;
if (bsv_movie_get_input(global->bsv.movie, &ret))
return ret;
global->bsv.movie_end = true;
}
if (settings->input.remap_binds_enable)
input_remapping_state(port, &device, &idx, &id);
if (!driver->flushing_input && !driver->block_libretro_input)
{
if (((id < RARCH_FIRST_META_KEY) || (device == RETRO_DEVICE_KEYBOARD)))
res = input->input_state(driver->input_data, libretro_input_binds, port, device, idx, id);
#ifdef HAVE_OVERLAY
input_state_overlay(&res, port, device, idx, id);
#endif
}
/* Don't allow turbo for D-pad. */
if (device == RETRO_DEVICE_JOYPAD && (id < RETRO_DEVICE_ID_JOYPAD_UP ||
id > RETRO_DEVICE_ID_JOYPAD_RIGHT))
{
/*
* Apply turbo button if activated.
*
* If turbo button is held, all buttons pressed except
* for D-pad will go into a turbo mode. Until the button is
* released again, the input state will be modulated by a
* periodic pulse defined by the configured duty cycle.
*/
if (res && global->turbo.frame_enable[port])
global->turbo.enable[port] |= (1 << id);
else if (!res)
global->turbo.enable[port] &= ~(1 << id);
if (global->turbo.enable[port] & (1 << id))
{
/* if turbo button is enabled for this key ID */
res = res && ((global->turbo.count % settings->input.turbo_period)
< settings->input.turbo_duty_cycle);
}
}
if (global->bsv.movie && !global->bsv.movie_playback)
bsv_movie_set_input(global->bsv.movie, res);
return res;
}
/**
* retro_set_default_callbacks:
* @data : pointer to retro_callbacks object