dolphin/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUAccelerometer.cpp
Filoppi d43a06ff6a IMUAccelerometer: consistency of BoundCount checks
Similar to the guitar, only control[0] was checked, and that felt random.
2021-05-19 20:51:34 +03:00

46 lines
1.3 KiB
C++

// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/IMUAccelerometer.h"
#include <algorithm>
#include <memory>
#include "Common/Common.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
namespace ControllerEmu
{
IMUAccelerometer::IMUAccelerometer(std::string name_, std::string ui_name_)
: ControlGroup(std::move(name_), std::move(ui_name_), GroupType::IMUAccelerometer)
{
AddInput(Translate, _trans("Up"));
AddInput(Translate, _trans("Down"));
AddInput(Translate, _trans("Left"));
AddInput(Translate, _trans("Right"));
AddInput(Translate, _trans("Forward"));
AddInput(Translate, _trans("Backward"));
}
bool IMUAccelerometer::AreInputsBound() const
{
return std::all_of(controls.begin(), controls.end(),
[](const auto& control) { return control->control_ref->BoundCount() > 0; });
}
std::optional<IMUAccelerometer::StateData> IMUAccelerometer::GetState() const
{
if (!AreInputsBound())
return std::nullopt;
StateData state;
state.x = (controls[2]->GetState() - controls[3]->GetState());
state.y = (controls[5]->GetState() - controls[4]->GetState());
state.z = (controls[0]->GetState() - controls[1]->GetState());
return state;
}
} // namespace ControllerEmu