mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-13 09:54:32 +00:00
Controller: Skip runahead replay when analog is unchanged
Slight CPU usage reduction at idle.
This commit is contained in:
@@ -186,11 +186,13 @@ void AnalogController::SetBindState(u32 index, float value)
|
||||
return;
|
||||
|
||||
m_half_axis_state[sub_index] = u8_value;
|
||||
System::SetRunaheadReplayFlag();
|
||||
|
||||
#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;
|
||||
|
||||
switch (static_cast<HalfAxis>(sub_index))
|
||||
{
|
||||
case HalfAxis::LLeft:
|
||||
@@ -244,7 +246,6 @@ void AnalogController::SetBindState(u32 index, float value)
|
||||
{
|
||||
pos_x = ((m_invert_right_stick & 1u) != 0u) ? MERGE_F(HalfAxis::RLeft, HalfAxis::RRight) :
|
||||
MERGE_F(HalfAxis::RRight, HalfAxis::RLeft);
|
||||
;
|
||||
pos_y = ((m_invert_right_stick & 2u) != 0u) ? MERGE_F(HalfAxis::RUp, HalfAxis::RDown) :
|
||||
MERGE_F(HalfAxis::RDown, HalfAxis::RUp);
|
||||
}
|
||||
@@ -260,6 +261,9 @@ void AnalogController::SetBindState(u32 index, float value)
|
||||
#undef MERGE_F
|
||||
}
|
||||
|
||||
if (std::memcmp(m_axis_state.data(), prev_axis_state.data(), m_axis_state.size()) != 0)
|
||||
System::SetRunaheadReplayFlag();
|
||||
|
||||
#undef MERGE
|
||||
|
||||
return;
|
||||
|
||||
@@ -110,6 +110,8 @@ void AnalogJoystick::SetBindState(u32 index, float value)
|
||||
((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;
|
||||
|
||||
switch (static_cast<HalfAxis>(sub_index))
|
||||
{
|
||||
case HalfAxis::LLeft:
|
||||
@@ -163,7 +165,6 @@ void AnalogJoystick::SetBindState(u32 index, float value)
|
||||
{
|
||||
pos_x = ((m_invert_right_stick & 1u) != 0u) ? MERGE_F(HalfAxis::RLeft, HalfAxis::RRight) :
|
||||
MERGE_F(HalfAxis::RRight, HalfAxis::RLeft);
|
||||
;
|
||||
pos_y = ((m_invert_right_stick & 2u) != 0u) ? MERGE_F(HalfAxis::RUp, HalfAxis::RDown) :
|
||||
MERGE_F(HalfAxis::RDown, HalfAxis::RUp);
|
||||
}
|
||||
@@ -179,6 +180,9 @@ void AnalogJoystick::SetBindState(u32 index, float value)
|
||||
#undef MERGE_F
|
||||
}
|
||||
|
||||
if (std::memcmp(m_axis_state.data(), prev_axis_state.data(), m_axis_state.size()) != 0)
|
||||
System::SetRunaheadReplayFlag();
|
||||
|
||||
#undef MERGE
|
||||
|
||||
return;
|
||||
|
||||
@@ -117,12 +117,16 @@ void JogCon::SetBindState(u32 index, float value)
|
||||
return;
|
||||
|
||||
m_half_axis_state[sub_index] = u8_value;
|
||||
System::SetRunaheadReplayFlag();
|
||||
|
||||
const s8 prev_steering_state = m_steering_state;
|
||||
|
||||
m_steering_state =
|
||||
(m_half_axis_state[static_cast<u32>(HalfAxis::SteeringRight)] != 0) ?
|
||||
static_cast<s8>((m_half_axis_state[static_cast<u32>(HalfAxis::SteeringRight)] / 2)) :
|
||||
-static_cast<s8>((static_cast<u32>(m_half_axis_state[static_cast<u32>(HalfAxis::SteeringLeft)]) + 1) / 2);
|
||||
|
||||
if (m_steering_state != prev_steering_state)
|
||||
System::SetRunaheadReplayFlag();
|
||||
}
|
||||
|
||||
const u16 bit = u16(1) << static_cast<u8>(index);
|
||||
|
||||
Reference in New Issue
Block a user