2017-02-09 03:15:43 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h"
|
|
|
|
|
2018-12-29 19:56:35 +00:00
|
|
|
#include <algorithm>
|
2017-02-09 03:15:43 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "Common/Common.h"
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
2017-02-26 20:00:24 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
|
|
|
MixedTriggers::MixedTriggers(const std::string& name_)
|
2017-02-25 05:35:02 +00:00
|
|
|
: ControlGroup(name_, GroupType::MixedTriggers)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.9));
|
2018-12-29 19:56:35 +00:00
|
|
|
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0.0, 0, 25));
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-29 19:56:35 +00:00
|
|
|
void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlState* analog,
|
2018-12-30 16:52:45 +00:00
|
|
|
bool adjusted) const
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2018-12-29 19:56:35 +00:00
|
|
|
const ControlState threshold = numeric_settings[SETTING_THRESHOLD]->GetValue();
|
|
|
|
ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue();
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2018-12-29 19:56:35 +00:00
|
|
|
// Return raw values. (used in UI)
|
|
|
|
if (!adjusted)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2018-12-29 19:56:35 +00:00
|
|
|
deadzone = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int trigger_count = int(controls.size() / 2);
|
|
|
|
for (int i = 0; i != trigger_count; ++i)
|
|
|
|
{
|
|
|
|
ControlState button_value = controls[i]->control_ref->State();
|
|
|
|
ControlState analog_value = controls[trigger_count + i]->control_ref->State();
|
|
|
|
|
|
|
|
// Apply deadzone:
|
|
|
|
analog_value = std::max(0.0, analog_value - deadzone) / (1.0 - deadzone);
|
|
|
|
button_value = std::max(0.0, button_value - deadzone) / (1.0 - deadzone);
|
|
|
|
|
|
|
|
// Apply threshold:
|
|
|
|
if (button_value > threshold)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2018-12-29 19:56:35 +00:00
|
|
|
// Fully activate analog:
|
|
|
|
analog_value = 1.0;
|
|
|
|
|
|
|
|
// Activate button:
|
|
|
|
*digital |= bitmasks[i];
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
2018-12-29 19:56:35 +00:00
|
|
|
|
|
|
|
analog[i] = analog_value;
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-29 19:56:35 +00:00
|
|
|
|
|
|
|
ControlState MixedTriggers::GetDeadzone() const
|
|
|
|
{
|
|
|
|
return numeric_settings[SETTING_DEADZONE]->GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlState MixedTriggers::GetThreshold() const
|
|
|
|
{
|
|
|
|
return numeric_settings[SETTING_THRESHOLD]->GetValue();
|
|
|
|
}
|
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
} // namespace ControllerEmu
|