From 8acc085dec594ddfddea78b2f701ffc38605acb7 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 30 Mar 2018 13:57:50 +0200 Subject: [PATCH] (input_overlay.c) Get rid of some forward declarations --- input/input_overlay.c | 294 ++++++++++++++++++++++-------------------- 1 file changed, 156 insertions(+), 138 deletions(-) diff --git a/input/input_overlay.c b/input/input_overlay.c index 136117e7fe..99d57895bf 100644 --- a/input/input_overlay.c +++ b/input/input_overlay.c @@ -72,8 +72,121 @@ struct input_overlay input_overlay_t *overlay_ptr = NULL; +/** + * input_overlay_add_inputs: + * @ol : pointer to overlay + * @port : the user to show the inputs of + * + * Adds inputs from current_input to the overlay, so it's displayed + * returns true if an input that is pressed will change the overlay + */ +static bool input_overlay_add_inputs_inner(overlay_desc_t *desc, + unsigned port, unsigned analog_dpad_mode) +{ + switch(desc->type) + { + case OVERLAY_TYPE_BUTTONS: + { + unsigned i; + bool all_buttons_pressed = false; + + /*Check each bank of the mask*/ + for (i = 0; i < ARRAY_SIZE(desc->button_mask.data); ++i) + { + /*Get bank*/ + uint32_t bank_mask = BITS_GET_ELEM(desc->button_mask,i); + unsigned id = i * 32; + + /*Worth pursuing? Have we got any bits left in here?*/ + while (bank_mask) + { + /*If this bit is set then we need to query the pad + *The button must be pressed.*/ + if (bank_mask & 1) + { + /* Light up the button if pressed */ + if (input_state(port, RETRO_DEVICE_JOYPAD, 0, id)) + { + all_buttons_pressed = true; + desc->updated = true; + } + else + { + /*we need ALL of the inputs to be active*/ + all_buttons_pressed = false; + desc->updated = false; + + /*abort*/ + return false; + } + } + + bank_mask >>= 1; + ++id; + } + } + + return all_buttons_pressed; + } + + case OVERLAY_TYPE_ANALOG_LEFT: + case OVERLAY_TYPE_ANALOG_RIGHT: + { + unsigned int index = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ? + RETRO_DEVICE_INDEX_ANALOG_RIGHT : RETRO_DEVICE_INDEX_ANALOG_LEFT; + + float analog_x = input_state(port, RETRO_DEVICE_ANALOG, + index, RETRO_DEVICE_ID_ANALOG_X); + float analog_y = input_state(port, RETRO_DEVICE_ANALOG, + index, RETRO_DEVICE_ID_ANALOG_Y); + float dx = (analog_x/0x8000)*(desc->range_x/2); + float dy = (analog_y/0x8000)*(desc->range_y/2); + + desc->delta_x = dx; + desc->delta_y = dy; + + /*Maybe use some option here instead of 0, only display + changes greater than some magnitude. + */ + if ((dx * dx) > 0 || (dy*dy) > 0) + return true; + } + break; + + case OVERLAY_TYPE_KEYBOARD: + if (input_state(port, RETRO_DEVICE_KEYBOARD, 0, desc->retro_key_idx)) + { + desc->updated = true; + return true; + } + break; + + default: + break; + } + + return false; +} + static bool input_overlay_add_inputs(input_overlay_t *ol, - unsigned port, unsigned analog_dpad_mode); + unsigned port, unsigned analog_dpad_mode) +{ + unsigned i; + bool button_pressed = false; + input_overlay_state_t *ol_state = &ol->overlay_state; + + if (!ol_state) + return false; + + for (i = 0; i < ol->active->size; i++) + { + overlay_desc_t *desc = &(ol->active->descs[i]); + button_pressed |= input_overlay_add_inputs_inner(desc, + port, analog_dpad_mode); + } + + return button_pressed; +} /** * input_overlay_scale: * @ol : Overlay handle. @@ -234,7 +347,8 @@ static void input_overlay_enable(input_overlay_t *ol, bool enable) * Check whether the given @x and @y coordinates of the overlay * descriptor @desc is inside the overlay descriptor's hitbox. * - * Returns: true (1) if X, Y coordinates are inside a hitbox, otherwise false (0). + * Returns: true (1) if X, Y coordinates are inside a hitbox, + * otherwise false (0). **/ static bool inside_hitbox(const struct overlay_desc *desc, float x, float y) { @@ -305,7 +419,9 @@ static void input_overlay_poll( { case OVERLAY_TYPE_BUTTONS: { - bits_or_bits(out->buttons.data, desc->button_mask.data, ARRAY_SIZE(desc->button_mask.data)); + bits_or_bits(out->buttons.data, + desc->button_mask.data, + ARRAY_SIZE(desc->button_mask.data)); if (BIT256_GET(desc->button_mask, RARCH_OVERLAY_NEXT)) ol->next_index = desc->next_index; @@ -317,15 +433,19 @@ static void input_overlay_poll( break; default: { - float x_val = x_dist / desc->range_x; - float y_val = y_dist / desc->range_y; - float x_val_sat = x_val / desc->analog_saturate_pct; - float y_val_sat = y_val / desc->analog_saturate_pct; + float x_val = x_dist / desc->range_x; + float y_val = y_dist / desc->range_y; + float x_val_sat = x_val / desc->analog_saturate_pct; + float y_val_sat = y_val / desc->analog_saturate_pct; - unsigned int base = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ? 2 : 0; + unsigned int base = + (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) + ? 2 : 0; - out->analog[base + 0] = clamp_float(x_val_sat, -1.0f, 1.0f) * 32767.0f; - out->analog[base + 1] = clamp_float(y_val_sat, -1.0f, 1.0f) * 32767.0f; + out->analog[base + 0] = clamp_float(x_val_sat, -1.0f, 1.0f) + * 32767.0f; + out->analog[base + 1] = clamp_float(y_val_sat, -1.0f, 1.0f) + * 32767.0f; } break; } @@ -498,9 +618,12 @@ void input_overlay_loaded(void *task_data, void *user_data, const char *err) } #endif - if (!data->overlay_enable || !video_driver_overlay_interface(&iface) || !iface) + if ( !data->overlay_enable || + !video_driver_overlay_interface(&iface) || + !iface) { - RARCH_ERR("Overlay interface is not present in video driver, or not enabled.\n"); + RARCH_ERR("Overlay interface is not present in video driver," + " or not enabled.\n"); goto abort_load; } @@ -532,14 +655,16 @@ abort_load: free(data); } -void input_overlay_set_visibility(int overlay_idx,enum overlay_visibility vis) +void input_overlay_set_visibility(int overlay_idx, + enum overlay_visibility vis) { - int i; input_overlay_t *ol = overlay_ptr; if (!visibility) { - visibility = (enum overlay_visibility *)calloc(MAX_VISIBILITY,sizeof(enum overlay_visibility)); + unsigned i; + visibility = (enum overlay_visibility *)calloc( + MAX_VISIBILITY, sizeof(enum overlay_visibility)); for (i = 0; i < MAX_VISIBILITY; i++) visibility[i] = OVERLAY_VISIBILITY_DEFAULT; @@ -612,7 +737,8 @@ bool input_overlay_key_pressed(input_overlay_t *ol, unsigned key) * * Poll pressed buttons/keys on currently active overlay. **/ -void input_poll_overlay(input_overlay_t *ol, float opacity, unsigned analog_dpad_mode, +void input_poll_overlay(input_overlay_t *ol, float opacity, + unsigned analog_dpad_mode, float axis_threshold) { rarch_joypad_info_t joypad_info; @@ -661,7 +787,9 @@ void input_poll_overlay(input_overlay_t *ol, float opacity, unsigned analog_dpad else ol->blocked = false; - bits_or_bits(ol_state->buttons.data, polled_data.buttons.data, ARRAY_SIZE(polled_data.buttons.data)); + bits_or_bits(ol_state->buttons.data, + polled_data.buttons.data, + ARRAY_SIZE(polled_data.buttons.data)); for (j = 0; j < ARRAY_SIZE(ol_state->keys); j++) ol_state->keys[j] |= polled_data.keys[j]; @@ -753,7 +881,9 @@ void input_poll_overlay(input_overlay_t *ol, float opacity, unsigned analog_dpad } if (settings->bools.input_overlay_show_physical_inputs) - button_pressed = input_overlay_add_inputs(ol, settings->uints.input_overlay_show_physical_inputs_port, analog_dpad_mode); + button_pressed = input_overlay_add_inputs(ol, + settings->uints.input_overlay_show_physical_inputs_port, + analog_dpad_mode); if (button_pressed || polled) input_overlay_post_poll(ol, opacity); @@ -779,12 +909,14 @@ void input_state_overlay(input_overlay_t *ol, int16_t *ret, case RETRO_DEVICE_KEYBOARD: if (id < RETROK_LAST) { - /*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) - );*/ +#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; } @@ -803,117 +935,3 @@ void input_state_overlay(input_overlay_t *ol, int16_t *ret, break; } } -/** - * input_overlay_add_inputs: - * @ol : pointer to overlay - * @port : the user to show the inputs of - * - * Adds inputs from current_input to the overlay, so it's displayed - * returns true if an input that is pressed will change the overlay - */ -static bool input_overlay_add_inputs_inner(overlay_desc_t *desc, - unsigned port, unsigned analog_dpad_mode) -{ - switch(desc->type) - { - case OVERLAY_TYPE_BUTTONS: - { - unsigned i; - unsigned id; - uint32_t bank_mask; - bool all_buttons_pressed = false; - - /*Check each bank of the mask*/ - for (i=0; ibutton_mask.data); ++i) - { - /*Get bank*/ - bank_mask = BITS_GET_ELEM(desc->button_mask,i); - id = i*32; - - /*Worth pursuing? Have we got any bits left in here?*/ - while (bank_mask) - { - /*If this bit is set then we need to query the pad - *The button must be pressed.*/ - if (bank_mask & 1) - { - /* Light up the button if pressed */ - if (input_state(port, RETRO_DEVICE_JOYPAD, 0, id)) - { - all_buttons_pressed = true; - desc->updated = true; - } - else - { - /*we need ALL of the inputs to be active*/ - all_buttons_pressed = false; - desc->updated = false; - - /*abort*/ - return false; - } - } - - bank_mask >>= 1; - ++id; - } - } - - return all_buttons_pressed; - } - - case OVERLAY_TYPE_ANALOG_LEFT: - case OVERLAY_TYPE_ANALOG_RIGHT: - { - unsigned int index = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ? - RETRO_DEVICE_INDEX_ANALOG_RIGHT : RETRO_DEVICE_INDEX_ANALOG_LEFT; - - float analog_x = input_state(port, RETRO_DEVICE_ANALOG, index, RETRO_DEVICE_ID_ANALOG_X); - float analog_y = input_state(port, RETRO_DEVICE_ANALOG, index, RETRO_DEVICE_ID_ANALOG_Y); - float dx = (analog_x/0x8000)*(desc->range_x/2); - float dy = (analog_y/0x8000)*(desc->range_y/2); - - desc->delta_x = dx; - desc->delta_y = dy; - - /*Maybe use some option here instead of 0, only display - changes greater than some magnitude. - */ - if ((dx * dx) > 0 || (dy*dy) > 0) - return true; - } - break; - - case OVERLAY_TYPE_KEYBOARD: - if (input_state(port, RETRO_DEVICE_KEYBOARD, 0, desc->retro_key_idx)) - { - desc->updated = true; - return true; - } - break; - - default: - break; - } - - return false; -} - -static bool input_overlay_add_inputs(input_overlay_t *ol, - unsigned port, unsigned analog_dpad_mode) -{ - unsigned i; - bool button_pressed = false; - input_overlay_state_t *ol_state = &ol->overlay_state; - - if (!ol_state) - return false; - - for (i = 0; i < ol->active->size; i++) - { - overlay_desc_t *desc = &(ol->active->descs[i]); - button_pressed |= input_overlay_add_inputs_inner(desc, port, analog_dpad_mode); - } - - return button_pressed; -}