@@ -2250,6 +2250,68 @@ static INLINE void input_overlay_get_eightway_state(
22502250 bits_or_bits (out -> data , data , CUSTOM_BINDS_U32_COUNT );
22512251}
22522252
2253+ /**
2254+ * input_overlay_get_analog_state:
2255+ * @out : Overlay input state to be modified
2256+ * @desc : Overlay descriptor handle
2257+ * @base : 0 or 2 for analog_left or analog_right
2258+ * @x : X coordinate
2259+ * @y : Y coordinate
2260+ * @x_dist : X offset from analog center
2261+ * @y_dist : Y offset from analog center
2262+ * @first_touch : Set true if analog was not controlled in previous poll
2263+ *
2264+ * Gets the analog input state based on @x and @y, and applies to @out.
2265+ */
2266+ static void input_overlay_get_analog_state (
2267+ input_overlay_state_t * out , struct overlay_desc * desc ,
2268+ unsigned base , float x , float y , float * x_dist , float * y_dist ,
2269+ bool first_touch )
2270+ {
2271+ float x_val , y_val ;
2272+ float x_val_sat , y_val_sat ;
2273+ const int b = base / 2 ;
2274+
2275+ static float x_center [2 ];
2276+ static float y_center [2 ];
2277+
2278+ if (first_touch )
2279+ {
2280+ unsigned recenter_zone =
2281+ config_get_ptr ()-> uints .input_overlay_analog_recenter_zone ;
2282+
2283+ /* Reset analog center */
2284+ x_center [b ] = desc -> x_shift ;
2285+ y_center [b ] = desc -> y_shift ;
2286+
2287+ if (recenter_zone != 0 )
2288+ {
2289+ /* Get analog state without adjusting center or saturation */
2290+ x_val = (x - desc -> x_shift ) / desc -> range_x ;
2291+ y_val = (y - desc -> y_shift ) / desc -> range_y ;
2292+
2293+ /* Recenter if within zone */
2294+ if ( (x_val * x_val + y_val * y_val ) * 1e4
2295+ < (recenter_zone * recenter_zone )
2296+ || recenter_zone >= 100 )
2297+ {
2298+ x_center [b ] = x ;
2299+ y_center [b ] = y ;
2300+ }
2301+ }
2302+ }
2303+
2304+ * x_dist = x - x_center [b ];
2305+ * y_dist = y - y_center [b ];
2306+ x_val = * x_dist / desc -> range_x ;
2307+ y_val = * y_dist / desc -> range_y ;
2308+ x_val_sat = x_val / desc -> analog_saturate_pct ;
2309+ y_val_sat = y_val / desc -> analog_saturate_pct ;
2310+
2311+ out -> analog [base + 0 ] = clamp_float (x_val_sat , -1.0f , 1.0f ) * 32767.0f ;
2312+ out -> analog [base + 1 ] = clamp_float (y_val_sat , -1.0f , 1.0f ) * 32767.0f ;
2313+ }
2314+
22532315/**
22542316 * input_overlay_coords_inside_hitbox:
22552317 * @desc : Overlay descriptor handle.
@@ -2400,16 +2462,9 @@ static bool input_overlay_poll(
24002462 base = 2 ;
24012463 /* fall-through */
24022464 default :
2403- {
2404- float x_val = x_dist / desc -> range_x ;
2405- float y_val = y_dist / desc -> range_y ;
2406- float x_val_sat = x_val / desc -> analog_saturate_pct ;
2407- float y_val_sat = y_val / desc -> analog_saturate_pct ;
2408- out -> analog [base + 0 ] = clamp_float (x_val_sat , -1.0f , 1.0f )
2409- * 32767.0f ;
2410- out -> analog [base + 1 ] = clamp_float (y_val_sat , -1.0f , 1.0f )
2411- * 32767.0f ;
2412- }
2465+ input_overlay_get_analog_state (
2466+ out , desc , base , x , y ,
2467+ & x_dist , & y_dist , !use_range_mod );
24132468 break ;
24142469 }
24152470
0 commit comments