mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Merge pull request #7262 from lioncash/force
ControlGroup: Return state data via GetState() by value where applicable
This commit is contained in:
@ -36,20 +36,20 @@ AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_,
|
||||
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
|
||||
}
|
||||
|
||||
void AnalogStick::GetState(ControlState* const x, ControlState* const y)
|
||||
AnalogStick::StateData AnalogStick::GetState()
|
||||
{
|
||||
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
||||
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
||||
ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
||||
ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
||||
|
||||
ControlState radius = numeric_settings[SETTING_RADIUS]->GetValue();
|
||||
ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue();
|
||||
ControlState m = controls[4]->control_ref->State();
|
||||
const ControlState radius = numeric_settings[SETTING_RADIUS]->GetValue();
|
||||
const ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue();
|
||||
const ControlState m = controls[4]->control_ref->State();
|
||||
|
||||
ControlState ang = atan2(yy, xx);
|
||||
ControlState ang_sin = sin(ang);
|
||||
ControlState ang_cos = cos(ang);
|
||||
const ControlState ang = atan2(y, x);
|
||||
const ControlState ang_sin = sin(ang);
|
||||
const ControlState ang_cos = cos(ang);
|
||||
|
||||
ControlState dist = sqrt(xx * xx + yy * yy);
|
||||
ControlState dist = sqrt(x * x + y * y);
|
||||
|
||||
// dead zone code
|
||||
dist = std::max(0.0, dist - deadzone);
|
||||
@ -63,10 +63,9 @@ void AnalogStick::GetState(ControlState* const x, ControlState* const y)
|
||||
if (m)
|
||||
dist *= 0.5;
|
||||
|
||||
yy = std::max(-1.0, std::min(1.0, ang_sin * dist));
|
||||
xx = std::max(-1.0, std::min(1.0, ang_cos * dist));
|
||||
y = std::max(-1.0, std::min(1.0, ang_sin * dist));
|
||||
x = std::max(-1.0, std::min(1.0, ang_cos * dist));
|
||||
|
||||
*y = yy;
|
||||
*x = xx;
|
||||
return {x, y};
|
||||
}
|
||||
} // namespace ControllerEmu
|
||||
|
@ -18,10 +18,16 @@ public:
|
||||
SETTING_DEADZONE,
|
||||
};
|
||||
|
||||
struct StateData
|
||||
{
|
||||
ControlState x{};
|
||||
ControlState y{};
|
||||
};
|
||||
|
||||
// The GameCube controller and Wiimote attachments have a different default radius
|
||||
AnalogStick(const char* name, ControlState default_radius);
|
||||
AnalogStick(const char* name, const char* ui_name, ControlState default_radius);
|
||||
|
||||
void GetState(ControlState* x, ControlState* y);
|
||||
StateData GetState();
|
||||
};
|
||||
} // namespace ControllerEmu
|
||||
|
@ -39,18 +39,18 @@ Cursor::Cursor(const std::string& name_) : ControlGroup(name_, GroupType::Cursor
|
||||
boolean_settings.emplace_back(std::make_unique<BooleanSetting>(_trans("Auto-Hide"), false));
|
||||
}
|
||||
|
||||
void Cursor::GetState(ControlState* const x, ControlState* const y, ControlState* const z,
|
||||
const bool adjusted)
|
||||
Cursor::StateData Cursor::GetState(const bool adjusted)
|
||||
{
|
||||
const ControlState zz = controls[4]->control_ref->State() - controls[5]->control_ref->State();
|
||||
|
||||
// silly being here
|
||||
if (zz > m_z)
|
||||
m_z = std::min(m_z + 0.1, zz);
|
||||
else if (zz < m_z)
|
||||
m_z = std::max(m_z - 0.1, zz);
|
||||
if (zz > m_state.z)
|
||||
m_state.z = std::min(m_state.z + 0.1, zz);
|
||||
else if (zz < m_state.z)
|
||||
m_state.z = std::max(m_state.z - 0.1, zz);
|
||||
|
||||
*z = m_z;
|
||||
StateData result;
|
||||
result.z = m_state.z;
|
||||
|
||||
if (m_autohide_timer > -1)
|
||||
{
|
||||
@ -69,11 +69,11 @@ void Cursor::GetState(ControlState* const x, ControlState* const y, ControlState
|
||||
}
|
||||
|
||||
// hide
|
||||
bool autohide = boolean_settings[1]->GetValue() && m_autohide_timer < 0;
|
||||
const bool autohide = boolean_settings[1]->GetValue() && m_autohide_timer < 0;
|
||||
if (controls[6]->control_ref->State() > 0.5 || autohide)
|
||||
{
|
||||
*x = 10000;
|
||||
*y = 0;
|
||||
result.x = 10000;
|
||||
result.y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -90,28 +90,30 @@ void Cursor::GetState(ControlState* const x, ControlState* const y, ControlState
|
||||
{
|
||||
// deadzone to avoid the cursor slowly drifting
|
||||
if (std::abs(xx) > deadzone)
|
||||
m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0);
|
||||
m_state.x = MathUtil::Clamp(m_state.x + xx * SPEED_MULTIPLIER, -1.0, 1.0);
|
||||
if (std::abs(yy) > deadzone)
|
||||
m_y = MathUtil::Clamp(m_y + yy * SPEED_MULTIPLIER, -1.0, 1.0);
|
||||
m_state.y = MathUtil::Clamp(m_state.y + yy * SPEED_MULTIPLIER, -1.0, 1.0);
|
||||
|
||||
// recenter
|
||||
if (controls[7]->control_ref->State() > 0.5)
|
||||
{
|
||||
m_x = 0.0;
|
||||
m_y = 0.0;
|
||||
m_state.x = 0.0;
|
||||
m_state.y = 0.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_x = xx;
|
||||
m_y = yy;
|
||||
m_state.x = xx;
|
||||
m_state.y = yy;
|
||||
}
|
||||
|
||||
*x = m_x;
|
||||
*y = m_y;
|
||||
result.x = m_state.x;
|
||||
result.y = m_state.y;
|
||||
}
|
||||
|
||||
m_prev_xx = xx;
|
||||
m_prev_yy = yy;
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace ControllerEmu
|
||||
|
@ -13,9 +13,16 @@ namespace ControllerEmu
|
||||
class Cursor : public ControlGroup
|
||||
{
|
||||
public:
|
||||
struct StateData
|
||||
{
|
||||
ControlState x{};
|
||||
ControlState y{};
|
||||
ControlState z{};
|
||||
};
|
||||
|
||||
explicit Cursor(const std::string& name);
|
||||
|
||||
void GetState(ControlState* x, ControlState* y, ControlState* z, bool adjusted = false);
|
||||
StateData GetState(bool adjusted = false);
|
||||
|
||||
private:
|
||||
// This is used to reduce the cursor speed for relative input
|
||||
@ -25,9 +32,7 @@ private:
|
||||
// Sets the length for the auto-hide timer
|
||||
static constexpr int TIMER_VALUE = 500;
|
||||
|
||||
ControlState m_x = 0.0;
|
||||
ControlState m_y = 0.0;
|
||||
ControlState m_z = 0.0;
|
||||
StateData m_state;
|
||||
|
||||
int m_autohide_timer = TIMER_VALUE;
|
||||
ControlState m_prev_xx;
|
||||
|
@ -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
|
||||
|
@ -30,14 +30,14 @@ Slider::Slider(const std::string& name_) : Slider(name_, name_)
|
||||
{
|
||||
}
|
||||
|
||||
void Slider::GetState(ControlState* const slider)
|
||||
Slider::StateData Slider::GetState()
|
||||
{
|
||||
const ControlState deadzone = numeric_settings[0]->GetValue();
|
||||
const ControlState state = controls[1]->control_ref->State() - controls[0]->control_ref->State();
|
||||
|
||||
if (fabs(state) > deadzone)
|
||||
*slider = (state - (deadzone * sign(state))) / (1 - deadzone);
|
||||
else
|
||||
*slider = 0;
|
||||
return {(state - (deadzone * sign(state))) / (1 - deadzone)};
|
||||
|
||||
return {0.0};
|
||||
}
|
||||
} // namespace ControllerEmu
|
||||
|
@ -13,9 +13,14 @@ namespace ControllerEmu
|
||||
class Slider : public ControlGroup
|
||||
{
|
||||
public:
|
||||
struct StateData
|
||||
{
|
||||
ControlState value{};
|
||||
};
|
||||
|
||||
Slider(const std::string& name_, const std::string& ui_name_);
|
||||
explicit Slider(const std::string& name_);
|
||||
|
||||
void GetState(ControlState* slider);
|
||||
StateData GetState();
|
||||
};
|
||||
} // namespace ControllerEmu
|
||||
|
@ -31,7 +31,7 @@ Tilt::Tilt(const std::string& name_) : ControlGroup(name_, GroupType::Tilt)
|
||||
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Angle"), 0.9, 0, 180));
|
||||
}
|
||||
|
||||
void Tilt::GetState(ControlState* const x, ControlState* const y, const bool step)
|
||||
Tilt::StateData Tilt::GetState(const bool step)
|
||||
{
|
||||
// this is all a mess
|
||||
|
||||
@ -80,18 +80,17 @@ void Tilt::GetState(ControlState* const x, ControlState* const y, const bool ste
|
||||
// silly
|
||||
if (step)
|
||||
{
|
||||
if (xx > m_tilt[0])
|
||||
m_tilt[0] = std::min(m_tilt[0] + 0.1, xx);
|
||||
else if (xx < m_tilt[0])
|
||||
m_tilt[0] = std::max(m_tilt[0] - 0.1, xx);
|
||||
if (xx > m_tilt.x)
|
||||
m_tilt.x = std::min(m_tilt.x + 0.1, xx);
|
||||
else if (xx < m_tilt.x)
|
||||
m_tilt.x = std::max(m_tilt.x - 0.1, xx);
|
||||
|
||||
if (yy > m_tilt[1])
|
||||
m_tilt[1] = std::min(m_tilt[1] + 0.1, yy);
|
||||
else if (yy < m_tilt[1])
|
||||
m_tilt[1] = std::max(m_tilt[1] - 0.1, yy);
|
||||
if (yy > m_tilt.y)
|
||||
m_tilt.y = std::min(m_tilt.y + 0.1, yy);
|
||||
else if (yy < m_tilt.y)
|
||||
m_tilt.y = std::max(m_tilt.y - 0.1, yy);
|
||||
}
|
||||
|
||||
*y = m_tilt[1] * angle;
|
||||
*x = m_tilt[0] * angle;
|
||||
return {m_tilt.x * angle, m_tilt.y * angle};
|
||||
}
|
||||
} // namespace ControllerEmu
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
||||
#include "InputCommon/ControllerInterface/Device.h"
|
||||
@ -14,11 +13,17 @@ namespace ControllerEmu
|
||||
class Tilt : public ControlGroup
|
||||
{
|
||||
public:
|
||||
struct StateData
|
||||
{
|
||||
ControlState x{};
|
||||
ControlState y{};
|
||||
};
|
||||
|
||||
explicit Tilt(const std::string& name);
|
||||
|
||||
void GetState(ControlState* x, ControlState* y, bool step = true);
|
||||
StateData GetState(bool step = true);
|
||||
|
||||
private:
|
||||
std::array<ControlState, 2> m_tilt{};
|
||||
StateData m_tilt;
|
||||
};
|
||||
} // namespace ControllerEmu
|
||||
|
@ -21,12 +21,15 @@ Triggers::Triggers(const std::string& name_) : ControlGroup(name_, GroupType::Tr
|
||||
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
|
||||
}
|
||||
|
||||
void Triggers::GetState(ControlState* analog)
|
||||
Triggers::StateData Triggers::GetState()
|
||||
{
|
||||
const size_t trigger_count = controls.size();
|
||||
const ControlState deadzone = numeric_settings[0]->GetValue();
|
||||
|
||||
for (size_t i = 0; i < trigger_count; ++i, ++analog)
|
||||
*analog = std::max(controls[i]->control_ref->State() - deadzone, 0.0) / (1 - deadzone);
|
||||
StateData result(trigger_count);
|
||||
for (size_t i = 0; i < trigger_count; ++i)
|
||||
result.data[i] = std::max(controls[i]->control_ref->State() - deadzone, 0.0) / (1 - deadzone);
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace ControllerEmu
|
||||
|
@ -5,6 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
||||
#include "InputCommon/ControllerInterface/Device.h"
|
||||
|
||||
@ -13,8 +15,16 @@ namespace ControllerEmu
|
||||
class Triggers : public ControlGroup
|
||||
{
|
||||
public:
|
||||
struct StateData
|
||||
{
|
||||
StateData() = default;
|
||||
explicit StateData(std::size_t trigger_count) : data(trigger_count) {}
|
||||
|
||||
std::vector<ControlState> data;
|
||||
};
|
||||
|
||||
explicit Triggers(const std::string& name);
|
||||
|
||||
void GetState(ControlState* analog);
|
||||
StateData GetState();
|
||||
};
|
||||
} // namespace ControllerEmu
|
||||
|
Reference in New Issue
Block a user