@ -186,40 +186,36 @@ void AnalogController::SetBindState(u32 index, float value)
m_half_axis_state [ sub_index ] = u8_value ;
m_half_axis_state [ sub_index ] = u8_value ;
# define MERGE(pos, neg) \
( ( m_half_axis_state [ static_cast < u32 > ( pos ) ] ! = 0 ) ? ( 127u + ( ( m_half_axis_state [ static_cast < u32 > ( pos ) ] + 1u ) / 2u ) ) : \
( 127u - ( m_half_axis_state [ static_cast < u32 > ( neg ) ] / 2u ) ) )
const auto prev_axis_state = m_axis_state ;
const auto prev_axis_state = m_axis_state ;
switch ( static_cast < HalfAxis > ( sub_index ) )
switch ( static_cast < HalfAxis > ( sub_index ) )
{
{
case HalfAxis : : LLeft :
case HalfAxis : : LLeft :
case HalfAxis : : LRight :
case HalfAxis : : LRight :
m_axis_state [ static_cast < u8 > ( Axis : : LeftX ) ] = ( ( m_invert_left_stick & 1u ) ! = 0u ) ?
m_axis_state [ static_cast < u8 > ( Axis : : LeftX ) ] =
MERGE ( HalfAxis : : LLeft , HalfAxis : : LRight ) :
MergeHalfAxes ( m_half_axis_state [ static_cast < size_t > ( HalfAxis : : LLeft ) ] ,
MERGE ( HalfAxis : : LRight , HalfAxis : : LLeft ) ;
m_half_axis_state [ static_cast < size_t > ( HalfAxis : : LRight ) ] , ( m_invert_left_stick & 1 ) ) ;
break ;
break ;
case HalfAxis : : LDown :
case HalfAxis : : LDown :
case HalfAxis : : LUp :
case HalfAxis : : LUp :
m_axis_state [ static_cast < u8 > ( Axis : : LeftY ) ] = ( ( m_invert_left_stick & 2u ) ! = 0u ) ?
m_axis_state [ static_cast < u8 > ( Axis : : LeftY ) ] =
MERGE ( HalfAxis : : LUp , HalfAxis : : LDown ) :
MergeHalfAxes ( m_half_axis_state [ static_cast < size_t > ( HalfAxis : : LUp ) ] ,
MERGE ( HalfAxis : : LDown , HalfAxis : : LUp ) ;
m_half_axis_state [ static_cast < size_t > ( HalfAxis : : LDown ) ] , ( m_invert_left_stick & 2 ) ) ;
break ;
break ;
case HalfAxis : : RLeft :
case HalfAxis : : RLeft :
case HalfAxis : : RRight :
case HalfAxis : : RRight :
m_axis_state [ static_cast < u8 > ( Axis : : RightX ) ] = ( ( m_invert_right_stick & 1u ) ! = 0u ) ?
m_axis_state [ static_cast < u8 > ( Axis : : RightX ) ] =
MERGE ( HalfAxis : : RLeft , HalfAxis : : RRight ) :
MergeHalfAxes ( m_half_axis_state [ static_cast < size_t > ( HalfAxis : : RLeft ) ] ,
MERGE ( HalfAxis : : RRight , HalfAxis : : RLeft ) ;
m_half_axis_state [ static_cast < size_t > ( HalfAxis : : RRight ) ] , ( m_invert_right_stick & 1 ) ) ;
break ;
break ;
case HalfAxis : : RDown :
case HalfAxis : : RDown :
case HalfAxis : : RUp :
case HalfAxis : : RUp :
m_axis_state [ static_cast < u8 > ( Axis : : RightY ) ] = ( ( m_invert_right_stick & 2u ) ! = 0u ) ?
m_axis_state [ static_cast < u8 > ( Axis : : RightY ) ] =
MERGE ( HalfAxis : : RUp , HalfAxis : : RDown ) :
MergeHalfAxes ( m_half_axis_state [ static_cast < size_t > ( HalfAxis : : RUp ) ] ,
MERGE ( HalfAxis : : RDown , HalfAxis : : RUp ) ;
m_half_axis_state [ static_cast < size_t > ( HalfAxis : : RDown ) ] , ( m_invert_right_stick & 2 ) ) ;
break ;
break ;
default :
default :
@ -228,43 +224,38 @@ void AnalogController::SetBindState(u32 index, float value)
if ( m_analog_deadzone > 0.0f )
if ( m_analog_deadzone > 0.0f )
{
{
# define MERGE_F(pos, neg) \
( ( m_half_axis_state [ static_cast < u32 > ( pos ) ] ! = 0 ) ? \
( static_cast < float > ( m_half_axis_state [ static_cast < u32 > ( pos ) ] ) / 255.0f ) : \
( static_cast < float > ( m_half_axis_state [ static_cast < u32 > ( neg ) ] ) / - 255.0f ) )
float pos_x , pos_y ;
float pos_x , pos_y ;
if ( static_cast < HalfAxis > ( sub_index ) < HalfAxis : : RLeft )
if ( static_cast < HalfAxis > ( sub_index ) < HalfAxis : : RLeft )
{
{
pos_x = ( ( m_invert_left_stick & 1u ) ! = 0u ) ? MERGE_F ( HalfAxis : : LLeft , HalfAxis : : LRight ) :
pos_x =
MERGE_F ( HalfAxis : : LRight , HalfAxis : : LLeft ) ;
MergeHalfAxesToFloat ( m_half_axis_state [ static_cast < size_t > ( HalfAxis : : LLeft ) ] ,
pos_y = ( ( m_invert_left_stick & 2u ) ! = 0u ) ? MERGE_F ( HalfAxis : : LUp , HalfAxis : : LDown ) :
m_half_axis_state [ static_cast < size_t > ( HalfAxis : : LRight ) ] , ( m_invert_left_stick & 1 ) ) ;
MERGE_F ( HalfAxis : : LDown , HalfAxis : : LUp ) ;
pos_y =
MergeHalfAxesToFloat ( m_half_axis_state [ static_cast < size_t > ( HalfAxis : : LUp ) ] ,
m_half_axis_state [ static_cast < size_t > ( HalfAxis : : LDown ) ] , ( m_invert_left_stick & 2 ) ) ;
}
}
else
else
{
{
pos_x = ( ( m_invert_right_stick & 1u ) ! = 0u ) ? MERGE_F ( HalfAxis : : RLeft , HalfAxis : : RRight ) :
pos_x =
MERGE_F ( HalfAxis : : RRight , HalfAxis : : RLeft ) ;
MergeHalfAxesToFloat ( m_half_axis_state [ static_cast < size_t > ( HalfAxis : : RLeft ) ] ,
pos_y = ( ( m_invert_right_stick & 2u ) ! = 0u ) ? MERGE_F ( HalfAxis : : RUp , HalfAxis : : RDown ) :
m_half_axis_state [ static_cast < size_t > ( HalfAxis : : RRight ) ] , ( m_invert_right_stick & 1 ) ) ;
MERGE_F ( HalfAxis : : RDown , HalfAxis : : RUp ) ;
pos_y =
MergeHalfAxesToFloat ( m_half_axis_state [ static_cast < size_t > ( HalfAxis : : RUp ) ] ,
m_half_axis_state [ static_cast < size_t > ( HalfAxis : : RDown ) ] , ( m_invert_right_stick & 2 ) ) ;
}
}
if ( InCircularDeadzone ( m_analog_deadzone , pos_x , pos_y ) )
if ( InCircularDeadzone ( m_analog_deadzone , pos_x , pos_y ) )
{
{
// Set to 127 (center).
if ( static_cast < HalfAxis > ( sub_index ) < HalfAxis : : RLeft )
if ( static_cast < HalfAxis > ( sub_index ) < HalfAxis : : RLeft )
m_axis_state [ static_cast < u8 > ( Axis : : LeftX ) ] = m_axis_state [ static_cast < u8 > ( Axis : : LeftY ) ] = 127 ;
m_axis_state [ static_cast < u8 > ( Axis : : LeftX ) ] = m_axis_state [ static_cast < u8 > ( Axis : : LeftY ) ] = AXIS_CENTER ;
else
else
m_axis_state [ static_cast < u8 > ( Axis : : RightX ) ] = m_axis_state [ static_cast < u8 > ( Axis : : RightY ) ] = 127 ;
m_axis_state [ static_cast < u8 > ( Axis : : RightX ) ] = m_axis_state [ static_cast < u8 > ( Axis : : RightY ) ] = AXIS_CENTER ;
}
}
# undef MERGE_F
}
}
if ( std : : memcmp ( m_axis_state . data ( ) , prev_axis_state . data ( ) , m_axis_state . size ( ) ) ! = 0 )
if ( std : : memcmp ( m_axis_state . data ( ) , prev_axis_state . data ( ) , m_axis_state . size ( ) ) ! = 0 )
System : : SetRunaheadReplayFlag ( true ) ;
System : : SetRunaheadReplayFlag ( true ) ;
# undef MERGE
return ;
return ;
}
}