Start refactoring this - overlay_ptr needs to become a static

global variable confined inside retroarch.c
This commit is contained in:
twinaphex 2019-07-10 04:43:19 +02:00
parent b564441097
commit 94af95e1b9
4 changed files with 97 additions and 170 deletions

View File

@ -61,11 +61,6 @@ struct input_mapper
input_bits_t buttons[MAX_USERS];
};
static bool input_mapper_button_pressed(input_mapper_t *handle, unsigned port, unsigned id)
{
return BIT256_GET(handle->buttons[port], id);
}
input_mapper_t *input_mapper_new(void)
{
input_mapper_t* handle = (input_mapper_t*)
@ -79,27 +74,20 @@ input_mapper_t *input_mapper_new(void)
void input_mapper_free(input_mapper_t *handle)
{
if (!handle)
return;
if (handle)
free (handle);
}
void input_mapper_poll(input_mapper_t *handle)
void input_mapper_poll(input_mapper_t *handle,
input_overlay_t *overlay_pointer,
void *settings_data,
unsigned max_users,
bool poll_overlay)
{
unsigned i, j;
input_bits_t current_input;
settings_t *settings = config_get_ptr();
unsigned max_users =
*(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
settings_t *settings = (settings_t*)settings_data;
bool key_event[RARCH_CUSTOM_BIND_LIST_END] = { false };
#ifdef HAVE_OVERLAY
bool poll_overlay = input_overlay_is_alive(overlay_ptr) ? true : false;
#endif
#ifdef HAVE_MENU
if (menu_driver_is_alive())
return;
#endif
memset(handle->keys, 0, sizeof(handle->keys));
@ -125,7 +113,7 @@ void input_mapper_poll(input_mapper_t *handle)
unsigned current_button_value = BIT256_GET(current_input, j);
#ifdef HAVE_OVERLAY
if (poll_overlay && i == 0)
current_button_value |= input_overlay_key_pressed(overlay_ptr, j);
current_button_value |= input_overlay_key_pressed(overlay_pointer, j);
#endif
if ((current_button_value == 1) && (j != remap_button))
{
@ -167,15 +155,13 @@ void input_mapper_poll(input_mapper_t *handle)
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++)
{
bool remap_valid;
unsigned remap_button;
unsigned remap_button =
settings->uints.input_remap_ids[i][j];
unsigned current_button_value = BIT256_GET(current_input, j);
#ifdef HAVE_OVERLAY
if (poll_overlay && i == 0)
current_button_value |= input_overlay_key_pressed(overlay_ptr, j);
current_button_value |= input_overlay_key_pressed(overlay_pointer, j);
#endif
remap_button =
settings->uints.input_remap_ids[i][j];
remap_valid = (current_button_value == 1) &&
(j != remap_button) && (remap_button != RARCH_UNMAPPED);
@ -219,16 +205,16 @@ void input_mapper_poll(input_mapper_t *handle)
}
else
{
int invert = 1;
unsigned remap_axis_bind = remap_axis - RARCH_FIRST_CUSTOM_BIND;
if (remap_axis_bind < sizeof(handle->analog_value[i]))
{
int invert = 1;
if ( (k % 2 == 0 && remap_axis % 2 != 0) ||
(k % 2 != 0 && remap_axis % 2 == 0)
)
invert = -1;
if (remap_axis_bind < sizeof(handle->analog_value[i]))
{
handle->analog_value[i][
remap_axis_bind] =
current_axis_value * invert;
@ -258,13 +244,10 @@ void input_mapper_state(
unsigned idx,
unsigned id)
{
if (!handle)
return;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (input_mapper_button_pressed(handle, port, id))
if (BIT256_GET(handle->buttons[port], id))
*ret = 1;
break;
case RETRO_DEVICE_ANALOG:
@ -292,5 +275,4 @@ void input_mapper_state(
default:
break;
}
return;
}

View File

@ -35,7 +35,11 @@ input_mapper_t *input_mapper_new(void);
void input_mapper_free(input_mapper_t *handle);
void input_mapper_poll(input_mapper_t *handle);
void input_mapper_poll(input_mapper_t *handle,
input_overlay_t *overlay_pointer,
void *settings_data,
unsigned max_users,
bool poll_overlay);
bool input_mapper_key_pressed(input_mapper_t *handle, int key);

View File

@ -236,8 +236,6 @@ void input_overlay_next(input_overlay_t *ol, float opacity);
bool input_overlay_key_pressed(input_overlay_t *ol, unsigned key);
bool input_overlay_is_alive(input_overlay_t *ol);
void input_overlay_loaded(retro_task_t *task,
void *task_data, void *user_data, const char *err);

View File

@ -3858,9 +3858,6 @@ static void input_overlay_scale(struct overlay *ol, float scale)
{
size_t i;
if (!ol)
return;
if (ol->block_scale)
scale = 1.0f;
@ -3956,9 +3953,6 @@ static void input_overlay_free_overlays(input_overlay_t *ol)
{
size_t i;
if (!ol)
return;
for (i = 0; i < ol->size; i++)
input_overlay_free_overlay(&ol->overlays[i]);
@ -3969,9 +3963,6 @@ static void input_overlay_free_overlays(input_overlay_t *ol)
static void input_overlay_load_active(input_overlay_t *ol, float opacity)
{
if (!ol)
return;
if (ol->iface->load)
ol->iface->load(ol->iface_data, ol->active->load_images,
ol->active->load_images_size);
@ -3983,20 +3974,6 @@ static void input_overlay_load_active(input_overlay_t *ol, float opacity)
ol->iface->full_screen(ol->iface_data, ol->active->full_screen);
}
/**
* input_overlay_enable:
* @enable : Enable or disable the overlay
*
* Enable or disable the overlay.
**/
static void input_overlay_enable(input_overlay_t *ol, bool enable)
{
ol->enable = enable;
if (ol->iface->enable)
ol->iface->enable(ol->iface_data, enable);
}
/**
* inside_hitbox:
* @desc : Overlay descriptor handle.
@ -4134,9 +4111,7 @@ static void input_overlay_poll(
static void input_overlay_update_desc_geom(input_overlay_t *ol,
struct overlay_desc *desc)
{
if (!desc || !desc->image.pixels)
return;
if (!desc->movable)
if (!desc->image.pixels || !desc->movable)
return;
if (ol->iface->vertex_geom)
@ -4296,7 +4271,12 @@ void input_overlay_loaded(retro_task_t *task,
ol->iface_data = video_driver_get_ptr_internal(true);
input_overlay_load_active(ol, data->overlay_opacity);
input_overlay_enable(ol, data->overlay_enable);
/* Enable or disable the overlay. */
ol->enable = data->overlay_enable;
if (ol->iface->enable)
ol->iface->enable(ol->iface_data, data->overlay_enable);
input_overlay_set_scale_factor(ol, data->overlay_scale);
@ -4382,13 +4362,6 @@ void input_overlay_set_alpha_mod(input_overlay_t *ol, float mod)
}
}
bool input_overlay_is_alive(input_overlay_t *ol)
{
if (ol)
return ol->alive;
return false;
}
bool input_overlay_key_pressed(input_overlay_t *ol, unsigned key)
{
input_overlay_state_t *ol_state = ol ? &ol->overlay_state : NULL;
@ -4555,51 +4528,6 @@ static void input_poll_overlay(input_overlay_t *ol, float opacity,
else
input_overlay_poll_clear(ol, opacity);
}
static void input_state_overlay(input_overlay_t *ol, int16_t *ret,
unsigned port, unsigned device, unsigned idx,
unsigned id)
{
input_overlay_state_t *ol_state = ol ? &ol->overlay_state : NULL;
if (!ol || port != 0)
return;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (input_overlay_key_pressed(ol, id))
*ret |= 1;
break;
case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST)
{
#if 0
RARCH_LOG("UDLR %u %u %u %u\n",
OVERLAY_GET_KEY(ol_state, RETROK_UP),
OVERLAY_GET_KEY(ol_state, RETROK_DOWN),
OVERLAY_GET_KEY(ol_state, RETROK_LEFT),
OVERLAY_GET_KEY(ol_state, RETROK_RIGHT)
);
#endif
if (OVERLAY_GET_KEY(ol_state, id))
*ret |= 1;
}
break;
case RETRO_DEVICE_ANALOG:
{
unsigned base = 0;
if (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT)
base = 2;
if (id == RETRO_DEVICE_ID_ANALOG_Y)
base += 1;
if (ol_state && ol_state->analog[base])
*ret = ol_state->analog[base];
}
break;
}
}
#endif
/* INPUT REMOTE */
@ -4903,7 +4831,26 @@ static void input_poll(void)
#endif
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
input_mapper_poll(input_driver_mapper);
{
#ifdef HAVE_OVERLAY
bool overlay_is_alive = (overlay_ptr && overlay_ptr->alive);
#else
bool overlay_is_alive = false;
#endif
#ifdef HAVE_MENU
bool do_poll = menu_driver_is_alive() ? false : true;
#else
bool do_poll = true;
#endif
if (do_poll)
input_mapper_poll(input_driver_mapper,
overlay_ptr,
settings,
max_users,
overlay_is_alive
);
}
#ifdef HAVE_COMMAND
if (input_driver_command)
@ -4952,7 +4899,7 @@ static void input_poll(void)
#endif
}
static int16_t input_state_internal(
static int16_t input_state_device(
int16_t ret,
unsigned port, unsigned device,
unsigned idx, unsigned id,
@ -4960,18 +4907,54 @@ static int16_t input_state_internal(
{
int16_t res = 0;
settings_t *settings = configuration_settings;
#ifdef HAVE_OVERLAY
int16_t res_overlay = 0;
if (overlay_ptr && port == 0)
{
input_overlay_state_t *ol_state = &overlay_ptr->overlay_state;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (input_overlay_key_pressed(overlay_ptr, id))
res_overlay |= 1;
break;
case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST)
{
#if 0
RARCH_LOG("UDLR %u %u %u %u\n",
OVERLAY_GET_KEY(ol_state, RETROK_UP),
OVERLAY_GET_KEY(ol_state, RETROK_DOWN),
OVERLAY_GET_KEY(ol_state, RETROK_LEFT),
OVERLAY_GET_KEY(ol_state, RETROK_RIGHT)
);
#endif
if (OVERLAY_GET_KEY(ol_state, id))
res_overlay |= 1;
}
break;
case RETRO_DEVICE_ANALOG:
{
unsigned base = 0;
if (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT)
base = 2;
if (id == RETRO_DEVICE_ID_ANALOG_Y)
base += 1;
if (ol_state && ol_state->analog[base])
res_overlay = ol_state->analog[base];
}
break;
}
}
#endif
switch (device)
{
case RETRO_DEVICE_JOYPAD:
{
#ifdef HAVE_OVERLAY
int16_t res_overlay = 0;
if (overlay_ptr)
input_state_overlay(overlay_ptr,
&res_overlay, port, device, idx, id);
#endif
#ifdef HAVE_NETWORKGAMEPAD
if (input_driver_remote)
if (input_remote_key_pressed(id, port))
@ -5039,13 +5022,6 @@ static int16_t input_state_internal(
case RETRO_DEVICE_MOUSE:
{
#ifdef HAVE_OVERLAY
int16_t res_overlay = 0;
if (overlay_ptr)
input_state_overlay(overlay_ptr,
&res_overlay, port, device, idx, id);
#endif
if (id < RARCH_FIRST_META_KEY)
{
bool bind_valid = libretro_input_binds[port]
@ -5078,16 +5054,6 @@ static int16_t input_state_internal(
case RETRO_DEVICE_KEYBOARD:
{
#ifdef HAVE_OVERLAY
int16_t res_overlay = 0;
#endif
#ifdef HAVE_OVERLAY
if (overlay_ptr)
input_state_overlay(overlay_ptr,
&res_overlay, port, device, idx, id);
#endif
res = ret;
#ifdef HAVE_OVERLAY
@ -5104,13 +5070,6 @@ static int16_t input_state_internal(
case RETRO_DEVICE_LIGHTGUN:
{
#ifdef HAVE_OVERLAY
int16_t res_overlay = 0;
if (overlay_ptr)
input_state_overlay(overlay_ptr,
&res_overlay, port, device, idx, id);
#endif
if (id < RARCH_FIRST_META_KEY)
{
bool bind_valid = libretro_input_binds[port]
@ -5143,16 +5102,6 @@ static int16_t input_state_internal(
case RETRO_DEVICE_ANALOG:
{
#ifdef HAVE_OVERLAY
int16_t res_overlay = 0;
#endif
#ifdef HAVE_OVERLAY
if (overlay_ptr)
input_state_overlay(overlay_ptr,
&res_overlay, port, device, idx, id);
#endif
#ifdef HAVE_NETWORKGAMEPAD
if (input_driver_remote)
{
@ -5220,12 +5169,6 @@ static int16_t input_state_internal(
case RETRO_DEVICE_POINTER:
{
#ifdef HAVE_OVERLAY
int16_t res_overlay = 0;
if (overlay_ptr)
input_state_overlay(overlay_ptr,
&res_overlay, port, device, idx, id);
#endif
if (id < RARCH_FIRST_META_KEY)
{
bool bind_valid = libretro_input_binds[port]
@ -5303,7 +5246,7 @@ int16_t input_state(unsigned port, unsigned device,
&& !input_driver_block_libretro_input)
{
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
if (input_state_internal(ret, port, device, idx, i, true))
if (input_state_device(ret, port, device, idx, i, true))
res |= (1 << i);
}
if (BSV_MOVIE_IS_PLAYBACK_OFF())
@ -5316,7 +5259,7 @@ int16_t input_state(unsigned port, unsigned device,
if ( !input_driver_flushing_input
&& !input_driver_block_libretro_input)
result = input_state_internal(ret, port, device, idx, id, false);
result = input_state_device(ret, port, device, idx, id, false);
if (BSV_MOVIE_IS_PLAYBACK_OFF())
{