mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
ControlGroup/Force: Return state data by value
Ensures that an array of sufficient size is always used and doesn't put the responsibility on the caller. It also allows for direct assignment.
This commit is contained in:
@ -29,18 +29,23 @@ Force::Force(const std::string& name_) : ControlGroup(name_, GroupType::Force)
|
||||
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
|
||||
}
|
||||
|
||||
void Force::GetState(ControlState* axis)
|
||||
Force::StateData Force::GetState()
|
||||
{
|
||||
StateData state_data;
|
||||
const ControlState deadzone = numeric_settings[0]->GetValue();
|
||||
|
||||
for (u32 i = 0; i < 6; i += 2)
|
||||
{
|
||||
ControlState tmpf = 0;
|
||||
const ControlState state =
|
||||
controls[i + 1]->control_ref->State() - controls[i]->control_ref->State();
|
||||
|
||||
ControlState tmpf = 0;
|
||||
if (fabs(state) > deadzone)
|
||||
tmpf = ((state - (deadzone * sign(state))) / (1 - deadzone));
|
||||
*axis++ = tmpf;
|
||||
|
||||
state_data[i / 2] = tmpf;
|
||||
}
|
||||
|
||||
return state_data;
|
||||
}
|
||||
} // namespace ControllerEmu
|
||||
|
@ -14,11 +14,13 @@ namespace ControllerEmu
|
||||
class Force : public ControlGroup
|
||||
{
|
||||
public:
|
||||
using StateData = std::array<ControlState, 3>;
|
||||
|
||||
explicit Force(const std::string& name);
|
||||
|
||||
void GetState(ControlState* axis);
|
||||
StateData GetState();
|
||||
|
||||
private:
|
||||
std::array<ControlState, 3> m_swing{};
|
||||
StateData m_swing{};
|
||||
};
|
||||
} // namespace ControllerEmu
|
||||
|
Reference in New Issue
Block a user