Skip to content
Permalink
Browse files
Merge pull request #7628 from jordan-woyak/stick-shapes
ControllerEmu: Add ability to reshape analog sticks. Make the mapping indicator pretty.
  • Loading branch information
lioncash committed Dec 28, 2018
2 parents f006af4 + c614f5f commit de03019
Show file tree
Hide file tree
Showing 23 changed files with 367 additions and 150 deletions.
@@ -17,6 +17,9 @@

namespace MathUtil
{
constexpr double TAU = 6.2831853071795865;
constexpr double PI = TAU / 2;

template <class T>
constexpr T Clamp(const T val, const T& min, const T& max)
{
@@ -63,10 +63,14 @@ GCPad::GCPad(const unsigned int index) : m_index(index)
}

// sticks
groups.emplace_back(m_main_stick = new ControllerEmu::AnalogStick(
"Main Stick", _trans("Control Stick"), DEFAULT_PAD_STICK_RADIUS));
groups.emplace_back(m_c_stick = new ControllerEmu::AnalogStick("C-Stick", _trans("C Stick"),
DEFAULT_PAD_STICK_RADIUS));
constexpr auto main_gate_radius =
ControlState(MAIN_STICK_GATE_RADIUS) / GCPadStatus::MAIN_STICK_RADIUS;
groups.emplace_back(m_main_stick = new ControllerEmu::OctagonAnalogStick(
"Main Stick", _trans("Control Stick"), main_gate_radius));

constexpr auto c_gate_radius = ControlState(C_STICK_GATE_RADIUS) / GCPadStatus::MAIN_STICK_RADIUS;
groups.emplace_back(m_c_stick = new ControllerEmu::OctagonAnalogStick(
"C-Stick", _trans("C Stick"), c_gate_radius));

// triggers
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
@@ -226,7 +230,8 @@ void GCPad::LoadDefaults(const ControllerInterface& ciface)
m_main_stick->SetControlExpression(4, "LSHIFT"); // Modifier

#elif __APPLE__
m_c_stick->SetControlExpression(4, "Left Control"); // Modifier
// Modifier
m_c_stick->SetControlExpression(4, "Left Control");

// Control Stick
m_main_stick->SetControlExpression(0, "Up Arrow"); // Up
@@ -16,7 +16,7 @@ namespace ControllerEmu
class AnalogStick;
class Buttons;
class MixedTriggers;
}
} // namespace ControllerEmu

enum class PadGroup
{
@@ -45,6 +45,9 @@ class GCPad : public ControllerEmu::EmulatedController

void LoadDefaults(const ControllerInterface& ciface) override;

static const u8 MAIN_STICK_GATE_RADIUS = 87;
static const u8 C_STICK_GATE_RADIUS = 74;

private:
ControllerEmu::Buttons* m_buttons;
ControllerEmu::AnalogStick* m_main_stick;
@@ -57,7 +60,4 @@ class GCPad : public ControllerEmu::EmulatedController
ControllerEmu::BooleanSetting* m_always_connected;

const unsigned int m_index;

// Default analog stick radius for GameCube controllers.
static constexpr ControlState DEFAULT_PAD_STICK_RADIUS = 1.0;
};
@@ -25,9 +25,6 @@ class Attachment : public ControllerEmu::EmulatedController
std::string GetName() const override;

protected:
// Default radius for attachment analog sticks.
static constexpr ControlState DEFAULT_ATTACHMENT_STICK_RADIUS = 1.0;

std::array<u8, 6> m_id{};
std::array<u8, 0x10> m_calibration{};

@@ -83,10 +83,11 @@ Classic::Classic(ExtensionReg& reg) : Attachment(_trans("Classic"), reg)
}

// sticks
groups.emplace_back(m_left_stick = new ControllerEmu::AnalogStick(
_trans("Left Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS));
groups.emplace_back(m_right_stick = new ControllerEmu::AnalogStick(
_trans("Right Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS));
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / LEFT_STICK_RADIUS;
groups.emplace_back(m_left_stick =
new ControllerEmu::OctagonAnalogStick(_trans("Left Stick"), gate_radius));
groups.emplace_back(
m_right_stick = new ControllerEmu::OctagonAnalogStick(_trans("Right Stick"), gate_radius));

// triggers
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
@@ -68,6 +68,8 @@ class Classic : public Attachment
RIGHT_TRIGGER_RANGE = 0x1F,
};

static const u8 STICK_GATE_RADIUS = 0x16;

private:
ControllerEmu::Buttons* m_buttons;
ControllerEmu::MixedTriggers* m_triggers;
@@ -54,8 +54,9 @@ Drums::Drums(ExtensionReg& reg) : Attachment(_trans("Drums"), reg)
}

// stick
groups.emplace_back(
m_stick = new ControllerEmu::AnalogStick(_trans("Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS));
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;
groups.emplace_back(m_stick =
new ControllerEmu::OctagonAnalogStick(_trans("Stick"), gate_radius));

// buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
@@ -76,8 +77,8 @@ void Drums::GetState(u8* const data)
{
const ControllerEmu::AnalogStick::StateData stick_state = m_stick->GetState();

drum_data.sx = static_cast<u8>((stick_state.x * 0x1F) + 0x20);
drum_data.sy = static_cast<u8>((stick_state.y * 0x1F) + 0x20);
drum_data.sx = static_cast<u8>((stick_state.x * STICK_RADIUS) + STICK_CENTER);
drum_data.sy = static_cast<u8>((stick_state.y * STICK_RADIUS) + STICK_CENTER);
}

// TODO: softness maybe
@@ -119,4 +120,4 @@ ControllerEmu::ControlGroup* Drums::GetGroup(DrumsGroup group)
return nullptr;
}
}
}
} // namespace WiimoteEmu
@@ -40,6 +40,12 @@ class Drums : public Attachment
PAD_ORANGE = 0x8000,
};

static const u8 STICK_CENTER = 0x20;
static const u8 STICK_RADIUS = 0x1f;

// TODO: Test real hardware. Is this accurate?
static const u8 STICK_GATE_RADIUS = 0x16;

private:
ControllerEmu::Buttons* m_buttons;
ControllerEmu::Buttons* m_pads;
@@ -83,8 +83,9 @@ Guitar::Guitar(ExtensionReg& reg) : Attachment(_trans("Guitar"), reg)
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "+"));

// stick
groups.emplace_back(
m_stick = new ControllerEmu::AnalogStick(_trans("Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS));
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;
groups.emplace_back(m_stick =
new ControllerEmu::OctagonAnalogStick(_trans("Stick"), gate_radius));

// whammy
groups.emplace_back(m_whammy = new ControllerEmu::Triggers(_trans("Whammy")));
@@ -108,8 +109,8 @@ void Guitar::GetState(u8* const data)
{
const ControllerEmu::AnalogStick::StateData stick_state = m_stick->GetState();

guitar_data.sx = static_cast<u8>((stick_state.x * 0x1F) + 0x20);
guitar_data.sy = static_cast<u8>((stick_state.y * 0x1F) + 0x20);
guitar_data.sx = static_cast<u8>((stick_state.x * STICK_RADIUS) + STICK_CENTER);
guitar_data.sy = static_cast<u8>((stick_state.y * STICK_RADIUS) + STICK_CENTER);
}

// slider bar
@@ -174,4 +175,4 @@ ControllerEmu::ControlGroup* Guitar::GetGroup(GuitarGroup group)
return nullptr;
}
}
}
} // namespace WiimoteEmu
@@ -43,6 +43,12 @@ class Guitar : public Attachment
FRET_ORANGE = 0x8000,
};

static const u8 STICK_CENTER = 0x20;
static const u8 STICK_RADIUS = 0x1f;

// TODO: Test real hardware. Is this accurate?
static const u8 STICK_GATE_RADIUS = 0x16;

private:
ControllerEmu::Buttons* m_buttons;
ControllerEmu::Buttons* m_frets;
@@ -38,8 +38,9 @@ Nunchuk::Nunchuk(ExtensionReg& reg) : Attachment(_trans("Nunchuk"), reg)
m_buttons->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "Z"));

// stick
groups.emplace_back(
m_stick = new ControllerEmu::AnalogStick(_trans("Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS));
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;
groups.emplace_back(m_stick =
new ControllerEmu::OctagonAnalogStick(_trans("Stick"), gate_radius));

// swing
groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing")));
@@ -48,6 +48,7 @@ class Nunchuk : public Attachment
{
STICK_CENTER = 0x80,
STICK_RADIUS = 0x7F,
STICK_GATE_RADIUS = 0x52,
};

void LoadDefaults(const ControllerInterface& ciface) override;
@@ -69,8 +69,9 @@ Turntable::Turntable(ExtensionReg& reg) : Attachment(_trans("Turntable"), reg)
new ControllerEmu::Slider("Table Right", _trans("Right Table")));

// stick
groups.emplace_back(
m_stick = new ControllerEmu::AnalogStick(_trans("Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS));
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;
groups.emplace_back(m_stick =
new ControllerEmu::OctagonAnalogStick(_trans("Stick"), gate_radius));

// effect dial
groups.emplace_back(m_effect_dial = new ControllerEmu::Triggers(_trans("Effect")));
@@ -92,8 +93,8 @@ void Turntable::GetState(u8* const data)
{
const ControllerEmu::AnalogStick::StateData stick_state = m_stick->GetState();

tt_data.sx = static_cast<u8>((stick_state.x * 0x1F) + 0x20);
tt_data.sy = static_cast<u8>((stick_state.y * 0x1F) + 0x20);
tt_data.sx = static_cast<u8>((stick_state.x * STICK_RADIUS) + STICK_CENTER);
tt_data.sy = static_cast<u8>((stick_state.y * STICK_RADIUS) + STICK_CENTER);
}

// left table
@@ -170,4 +171,4 @@ ControllerEmu::ControlGroup* Turntable::GetGroup(TurntableGroup group)
return nullptr;
}
}
}
} // namespace WiimoteEmu
@@ -45,6 +45,12 @@ class Turntable : public Attachment
BUTTON_PLUS = 0x04,
};

static const u8 STICK_CENTER = 0x20;
static const u8 STICK_RADIUS = 0x1f;

// TODO: Test real hardware. Is this accurate?
static const u8 STICK_GATE_RADIUS = 0x16;

private:
ControllerEmu::Buttons* m_buttons;
ControllerEmu::AnalogStick* m_stick;

0 comments on commit de03019

Please sign in to comment.