Skip to content

Commit 35aefa8

Browse files
authored
Overlays: Allow uninterrupted control during overlay_next swap (libretro#18578)
- When overlay_next is pressed, block only that touch pointer - Move desc touch masks to similar descs in the next overlay so that range_mod carries over
1 parent 5b78c73 commit 35aefa8

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

input/input_driver.c

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,6 +2960,40 @@ void input_overlay_load_active(
29602960
(ol->active->flags & OVERLAY_FULL_SCREEN));
29612961
}
29622962

2963+
/**
2964+
* input_overlay_next_move_touch_masks
2965+
* @ol : Overlay handle.
2966+
*
2967+
* Finds similar descs in the next overlay (i.e. same location and type)
2968+
* and moves touch masks from active overlay to next.
2969+
*/
2970+
void input_overlay_next_move_touch_masks(input_overlay_t *ol)
2971+
{
2972+
const struct overlay *active = ol->active;
2973+
const struct overlay *next = ol->overlays + ol->next_index;
2974+
size_t i, j;
2975+
2976+
for (i = 0; i < active->size; i++)
2977+
{
2978+
struct overlay_desc *desc = active->descs + i;
2979+
2980+
if (desc->old_touch_mask)
2981+
{
2982+
for (j = 0; j < next->size; j++)
2983+
{
2984+
struct overlay_desc *desc2 = next->descs + j;
2985+
2986+
if ( desc2->type == desc->type
2987+
&& fabs(desc2->x - desc->x) < 0.01f
2988+
&& fabs(desc2->y - desc->y) < 0.01f)
2989+
desc2->old_touch_mask = desc->old_touch_mask;
2990+
}
2991+
2992+
desc->old_touch_mask = 0;
2993+
}
2994+
}
2995+
}
2996+
29632997
/**
29642998
* input_overlay_poll_clear:
29652999
* @ol : overlay handle
@@ -3562,6 +3596,7 @@ static void input_poll_overlay(
35623596
input_overlay_state_t old_ol_state;
35633597
int i, j;
35643598
input_overlay_t *ol = (input_overlay_t*)ol_data;
3599+
int blocked_touch_idx = -1;
35653600
uint16_t key_mod = 0;
35663601
uint16_t ptrdev_touch_mask = 0;
35673602
uint16_t hitbox_touch_mask = 0;
@@ -3580,6 +3615,7 @@ static void input_poll_overlay(
35803615
bool osk_state_changed = false;
35813616

35823617
static int old_ptr_count;
3618+
static int old_blocked_touch_idx;
35833619
static int16_t old_ptrdev_touch_mask;
35843620
static int16_t old_hitbox_touch_mask;
35853621

@@ -3667,14 +3703,24 @@ static void input_poll_overlay(
36673703
int old_i = input_st->old_touch_index_lut[i];
36683704
bool hitbox_pressed = false;
36693705

3670-
/* Keep each touch pointer dedicated to the same input type
3671-
* (hitbox or pointing device) from the previous poll */
36723706
if (old_i != -1)
36733707
{
3708+
/* Keep each touch pointer dedicated to the same input type
3709+
* (hitbox or pointing device) from the previous poll */
36743710
if (BIT16_GET(old_hitbox_touch_mask, old_i))
36753711
BIT16_SET(hitbox_touch_mask, i);
36763712
else if (BIT16_GET(old_ptrdev_touch_mask, old_i))
36773713
BIT16_SET(ptrdev_touch_mask, i);
3714+
3715+
/* Skip blocked touch pointer and freeze any overlay_next
3716+
* input until the blocked touch is removed */
3717+
if (old_i == old_blocked_touch_idx)
3718+
{
3719+
blocked_touch_idx = i;
3720+
if (BIT256_GET(old_ol_state.buttons, RARCH_OVERLAY_NEXT))
3721+
BIT256_SET(ol_state->buttons, RARCH_OVERLAY_NEXT);
3722+
continue;
3723+
}
36783724
}
36793725

36803726
memset(&polled_data, 0, sizeof(struct input_overlay_state));
@@ -3691,6 +3737,10 @@ static void input_poll_overlay(
36913737

36923738
if (hitbox_pressed)
36933739
{
3740+
/* Block touch pointer if overlay_next was pressed */
3741+
if (BIT256_GET(polled_data.buttons, RARCH_OVERLAY_NEXT))
3742+
blocked_touch_idx = i;
3743+
36943744
bits_or_bits(ol_state->buttons.data,
36953745
polled_data.buttons.data,
36963746
ARRAY_SIZE(polled_data.buttons.data));
@@ -3839,8 +3889,7 @@ static void input_poll_overlay(
38393889
if ( current_input->keypress_vibrate
38403890
&& settings->bools.vibrate_on_keypress
38413891
&& ol_state->touch_count
3842-
&& ol_state->touch_count >= old_ol_state.touch_count
3843-
&& !(ol->flags & INPUT_OVERLAY_BLOCKED))
3892+
&& ol_state->touch_count >= old_ol_state.touch_count)
38443893
{
38453894
if ( osk_state_changed
38463895
|| bits_any_different(
@@ -3853,6 +3902,7 @@ static void input_poll_overlay(
38533902

38543903
old_hitbox_touch_mask = hitbox_touch_mask;
38553904
old_ptrdev_touch_mask = ptrdev_touch_mask;
3905+
old_blocked_touch_idx = blocked_touch_idx;
38563906
ptr_state->device_mask = 0;
38573907
}
38583908
#endif

input/input_overlay.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,15 @@ void input_overlay_load_active(
460460
enum overlay_visibility *visibility,
461461
input_overlay_t *ol, float opacity);
462462

463+
/**
464+
* input_overlay_next_move_touch_masks
465+
* @ol : Overlay handle.
466+
*
467+
* Finds similar descs in the next overlay (i.e. same location and type)
468+
* and moves touch masks from active overlay to next.
469+
*/
470+
void input_overlay_next_move_touch_masks(input_overlay_t *ol);
471+
463472
/**
464473
* input_overlay_set_scale_factor:
465474
* @ol : Overlay handle.

retroarch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3990,6 +3990,8 @@ bool command_event(enum event_command cmd, void *data)
39903990
if (!ol)
39913991
return false;
39923992

3993+
input_overlay_next_move_touch_masks(ol);
3994+
39933995
ol->index = ol->next_index;
39943996
ol->active = &ol->overlays[ol->index];
39953997

@@ -4000,7 +4002,6 @@ bool command_event(enum event_command cmd, void *data)
40004002
input_overlay_load_active(input_st->overlay_visibility,
40014003
ol, input_overlay_opacity);
40024004

4003-
ol->flags |= INPUT_OVERLAY_BLOCKED;
40044005
ol->next_index =
40054006
(unsigned)((ol->index + 1) % ol->size);
40064007

0 commit comments

Comments
 (0)