mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-10 22:49:00 +01:00
ControllerEmu: Round input floats instead of casting, part 2
Like 3bc4968 but for Wii Remote extensions. I'm doing this to ensure that TAS input values will still roundtrip after the next commit.
This commit is contained in:
parent
cb16d20f2d
commit
8fd25259ee
@ -86,7 +86,7 @@ Classic::Classic() : Extension1stParty("Classic", _trans("Classic Controller"))
|
||||
}
|
||||
|
||||
// sticks
|
||||
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / CAL_STICK_RANGE;
|
||||
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / CAL_STICK_RADIUS;
|
||||
groups.emplace_back(m_left_stick =
|
||||
new ControllerEmu::OctagonAnalogStick(_trans("Left Stick"), gate_radius));
|
||||
groups.emplace_back(
|
||||
@ -116,8 +116,8 @@ void Classic::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
const ControllerEmu::AnalogStick::StateData left_stick_state =
|
||||
m_left_stick->GetState(m_input_override_function);
|
||||
|
||||
const u8 x = static_cast<u8>(LEFT_STICK_CENTER + (left_stick_state.x * LEFT_STICK_RADIUS));
|
||||
const u8 y = static_cast<u8>(LEFT_STICK_CENTER + (left_stick_state.y * LEFT_STICK_RADIUS));
|
||||
const u8 x = MapFloat<u8>(left_stick_state.x, LEFT_STICK_CENTER, 0, LEFT_STICK_RANGE);
|
||||
const u8 y = MapFloat<u8>(left_stick_state.y, LEFT_STICK_CENTER, 0, LEFT_STICK_RANGE);
|
||||
|
||||
classic_data.SetLeftStick({x, y});
|
||||
}
|
||||
@ -127,8 +127,8 @@ void Classic::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
const ControllerEmu::AnalogStick::StateData right_stick_data =
|
||||
m_right_stick->GetState(m_input_override_function);
|
||||
|
||||
const u8 x = static_cast<u8>(RIGHT_STICK_CENTER + (right_stick_data.x * RIGHT_STICK_RADIUS));
|
||||
const u8 y = static_cast<u8>(RIGHT_STICK_CENTER + (right_stick_data.y * RIGHT_STICK_RADIUS));
|
||||
const u8 x = MapFloat<u8>(right_stick_data.x, RIGHT_STICK_CENTER, 0, RIGHT_STICK_RANGE);
|
||||
const u8 y = MapFloat<u8>(right_stick_data.y, RIGHT_STICK_CENTER, 0, RIGHT_STICK_RANGE);
|
||||
|
||||
classic_data.SetRightStick({x, y});
|
||||
}
|
||||
@ -141,8 +141,8 @@ void Classic::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
m_triggers->GetState(&buttons, classic_trigger_bitmasks.data(), triggers,
|
||||
m_input_override_function);
|
||||
|
||||
const u8 lt = static_cast<u8>(triggers[0] * TRIGGER_RANGE);
|
||||
const u8 rt = static_cast<u8>(triggers[1] * TRIGGER_RANGE);
|
||||
const u8 lt = MapFloat<u8>(triggers[0], 0, 0, TRIGGER_RANGE);
|
||||
const u8 rt = MapFloat<u8>(triggers[1], 0, 0, TRIGGER_RANGE);
|
||||
|
||||
classic_data.SetLeftTrigger(lt);
|
||||
classic_data.SetRightTrigger(rt);
|
||||
|
@ -205,13 +205,14 @@ public:
|
||||
static constexpr u8 STICK_GATE_RADIUS = 0x61;
|
||||
|
||||
static constexpr u8 CAL_STICK_CENTER = 0x80;
|
||||
static constexpr u8 CAL_STICK_RANGE = 0x7f;
|
||||
static constexpr u8 CAL_STICK_RADIUS = 0x7f;
|
||||
static constexpr u8 CAL_STICK_RANGE = 0xff;
|
||||
|
||||
static constexpr u8 LEFT_STICK_CENTER = CAL_STICK_CENTER >> (CAL_STICK_BITS - LEFT_STICK_BITS);
|
||||
static constexpr u8 LEFT_STICK_RADIUS = CAL_STICK_RANGE >> (CAL_STICK_BITS - LEFT_STICK_BITS);
|
||||
static constexpr u8 LEFT_STICK_RANGE = CAL_STICK_RANGE >> (CAL_STICK_BITS - LEFT_STICK_BITS);
|
||||
|
||||
static constexpr u8 RIGHT_STICK_CENTER = CAL_STICK_CENTER >> (CAL_STICK_BITS - RIGHT_STICK_BITS);
|
||||
static constexpr u8 RIGHT_STICK_RADIUS = CAL_STICK_RANGE >> (CAL_STICK_BITS - RIGHT_STICK_BITS);
|
||||
static constexpr u8 RIGHT_STICK_RANGE = CAL_STICK_RANGE >> (CAL_STICK_BITS - RIGHT_STICK_BITS);
|
||||
|
||||
static constexpr u8 TRIGGER_RANGE = 0x1F;
|
||||
|
||||
|
@ -44,12 +44,12 @@ void DrawsomeTablet::BuildDesiredExtensionState(DesiredExtensionState* target_st
|
||||
// the "Drawsome" game expects you to go "off screen" a bit to access some menu items.
|
||||
constexpr u16 MIN_Y = 0x15ff + 0x100;
|
||||
constexpr u16 MAX_Y = 0x00;
|
||||
constexpr double CENTER_X = (MAX_X + MIN_X) / 2.0;
|
||||
constexpr double CENTER_Y = (MAX_Y + MIN_Y) / 2.0;
|
||||
constexpr u16 CENTER_X = (MAX_X + MIN_X + 1) / 2;
|
||||
constexpr u16 CENTER_Y = (MAX_Y + MIN_Y + 1) / 2;
|
||||
|
||||
const auto stylus_state = m_stylus->GetState(m_input_override_function);
|
||||
const auto stylus_x = u16(std::lround(CENTER_X + stylus_state.x * (MAX_X - CENTER_X)));
|
||||
const auto stylus_y = u16(std::lround(CENTER_Y + stylus_state.y * (MAX_Y - CENTER_Y)));
|
||||
const u16 stylus_x = MapFloat<u16>(stylus_state.x, CENTER_X, MIN_X, MAX_X);
|
||||
const u16 stylus_y = MapFloat<u16>(-stylus_state.y, CENTER_Y, MAX_Y, MIN_Y);
|
||||
|
||||
tablet_data.stylus_x1 = u8(stylus_x);
|
||||
tablet_data.stylus_x2 = u8(stylus_x >> 8);
|
||||
@ -75,7 +75,7 @@ void DrawsomeTablet::BuildDesiredExtensionState(DesiredExtensionState* target_st
|
||||
constexpr u16 MAX_PRESSURE = 0x7ff;
|
||||
|
||||
const auto touch_state = m_touch->GetState(m_input_override_function);
|
||||
const auto pressure = u16(std::lround(touch_state.data[0] * MAX_PRESSURE));
|
||||
const u16 pressure = MapFloat<u16>(touch_state.data[0], 0, 0, MAX_PRESSURE);
|
||||
|
||||
tablet_data.pressure1 = u8(pressure);
|
||||
tablet_data.pressure2 = u8(pressure >> 8);
|
||||
|
@ -87,6 +87,8 @@ void Drums::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
const ControllerEmu::AnalogStick::StateData stick_state =
|
||||
m_stick->GetState(m_input_override_function);
|
||||
|
||||
state.stick_x = MapFloat<u8>(stick_state.x, STICK_CENTER, STICK_MIN, STICK_MAX);
|
||||
state.stick_y = MapFloat<u8>(stick_state.y, STICK_CENTER, STICK_MIN, STICK_MAX);
|
||||
state.stick_x = MapFloat(stick_state.x, STICK_CENTER, STICK_MIN, STICK_MAX);
|
||||
state.stick_y = MapFloat(stick_state.y, STICK_CENTER, STICK_MIN, STICK_MAX);
|
||||
}
|
||||
|
@ -104,8 +104,8 @@ void Guitar::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
const ControllerEmu::AnalogStick::StateData stick_state =
|
||||
m_stick->GetState(m_input_override_function);
|
||||
|
||||
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);
|
||||
guitar_data.sx = MapFloat<u8>(stick_state.x, STICK_CENTER, 0, STICK_RANGE);
|
||||
guitar_data.sy = MapFloat<u8>(stick_state.y, STICK_CENTER, 0, STICK_RANGE);
|
||||
}
|
||||
|
||||
// slider bar
|
||||
@ -126,7 +126,7 @@ void Guitar::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
// whammy bar
|
||||
const ControllerEmu::Triggers::StateData whammy_state =
|
||||
m_whammy->GetState(m_input_override_function);
|
||||
guitar_data.whammy = static_cast<u8>(whammy_state.data[0] * 0x1F);
|
||||
guitar_data.whammy = MapFloat<u8>(whammy_state.data[0], 0, 0, 0x1F);
|
||||
|
||||
// buttons
|
||||
m_buttons->GetState(&guitar_data.bt, guitar_button_bitmasks.data(), m_input_override_function);
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
|
||||
static const u8 STICK_CENTER = 0x20;
|
||||
static const u8 STICK_RADIUS = 0x1f;
|
||||
static const u8 STICK_RANGE = 0x3f;
|
||||
|
||||
// TODO: Test real hardware. Is this accurate?
|
||||
static const u8 STICK_GATE_RADIUS = 0x16;
|
||||
|
@ -70,8 +70,8 @@ void Nunchuk::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
bool override_occurred = false;
|
||||
const ControllerEmu::AnalogStick::StateData stick_state =
|
||||
m_stick->GetState(m_input_override_function, &override_occurred);
|
||||
nc_data.jx = u8(STICK_CENTER + stick_state.x * STICK_RADIUS);
|
||||
nc_data.jy = u8(STICK_CENTER + stick_state.y * STICK_RADIUS);
|
||||
nc_data.jx = MapFloat<u8>(stick_state.x, STICK_CENTER, 0, STICK_RANGE);
|
||||
nc_data.jy = MapFloat<u8>(stick_state.y, STICK_CENTER, 0, STICK_RANGE);
|
||||
|
||||
if (!override_occurred)
|
||||
{
|
||||
|
@ -166,6 +166,7 @@ public:
|
||||
|
||||
static constexpr u8 STICK_CENTER = 0x80;
|
||||
static constexpr u8 STICK_RADIUS = 0x7F;
|
||||
static constexpr u8 STICK_RANGE = 0xFF;
|
||||
|
||||
void LoadDefaults(const ControllerInterface& ciface) override;
|
||||
|
||||
|
@ -64,8 +64,9 @@ void Shinkansen::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
// guesses).
|
||||
const u8 brake_values[] = {0, 53, 79, 105, 132, 159, 187, 217, 250};
|
||||
const u8 power_values[] = {255, 229, 208, 189, 170, 153, 135, 118, 101, 85, 68, 51, 35, 17};
|
||||
state.brake = brake_values[size_t(analog[0] * (sizeof(brake_values) - 1))];
|
||||
state.power = power_values[size_t(analog[1] * (sizeof(power_values) - 1))];
|
||||
// Not casting from size_t would trigger a static assert in MapFloat due to its use of llround
|
||||
state.brake = brake_values[MapFloat(analog[0], 0, 0, static_cast<int>(sizeof(brake_values) - 1))];
|
||||
state.power = power_values[MapFloat(analog[1], 0, 0, static_cast<int>(sizeof(power_values) - 1))];
|
||||
|
||||
// Note: This currently assumes a little-endian host.
|
||||
const u16 button_bitmasks[] = {
|
||||
|
@ -89,14 +89,14 @@ void Turntable::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
const ControllerEmu::AnalogStick::StateData stick_state =
|
||||
m_stick->GetState(m_input_override_function);
|
||||
|
||||
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);
|
||||
tt_data.sx = MapFloat<u8>(stick_state.x, STICK_CENTER, 0, STICK_RANGE);
|
||||
tt_data.sy = MapFloat<u8>(stick_state.y, STICK_CENTER, 0, STICK_RANGE);
|
||||
}
|
||||
|
||||
// left table
|
||||
{
|
||||
const ControllerEmu::Slider::StateData lt = m_left_table->GetState(m_input_override_function);
|
||||
const s8 tt = static_cast<s8>(lt.value * TABLE_RANGE);
|
||||
const s8 tt = MapFloat<u8>(lt.value, 0, 0, TABLE_RANGE);
|
||||
|
||||
tt_data.ltable1 = tt;
|
||||
tt_data.ltable2 = tt >> 5;
|
||||
@ -105,7 +105,7 @@ void Turntable::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
// right table
|
||||
{
|
||||
const ControllerEmu::Slider::StateData rt = m_right_table->GetState(m_input_override_function);
|
||||
const s8 tt = static_cast<s8>(rt.value * TABLE_RANGE);
|
||||
const s8 tt = MapFloat<u8>(rt.value, 0, 0, TABLE_RANGE);
|
||||
|
||||
tt_data.rtable1 = tt;
|
||||
tt_data.rtable2 = tt >> 1;
|
||||
@ -116,7 +116,7 @@ void Turntable::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
// effect dial
|
||||
{
|
||||
const auto dial_state = m_effect_dial->GetState(m_input_override_function);
|
||||
const u8 dial = static_cast<u8>(dial_state.value * EFFECT_DIAL_RANGE) + EFFECT_DIAL_CENTER;
|
||||
const u8 dial = MapFloat<u8>(dial_state.value, EFFECT_DIAL_CENTER, 0, EFFECT_DIAL_RANGE);
|
||||
|
||||
tt_data.dial1 = dial;
|
||||
tt_data.dial2 = dial >> 3;
|
||||
@ -126,7 +126,7 @@ void Turntable::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
{
|
||||
const ControllerEmu::Slider::StateData cfs = m_crossfade->GetState(m_input_override_function);
|
||||
|
||||
tt_data.slider = static_cast<u8>((cfs.value * CROSSFADE_RANGE) + CROSSFADE_CENTER);
|
||||
tt_data.slider = MapFloat<u8>(cfs.value, CROSSFADE_CENTER, 0, CROSSFADE_RANGE);
|
||||
}
|
||||
|
||||
// buttons
|
||||
|
@ -78,6 +78,7 @@ public:
|
||||
static constexpr int STICK_BIT_COUNT = 6;
|
||||
static constexpr u8 STICK_CENTER = (1 << STICK_BIT_COUNT) / 2;
|
||||
static constexpr u8 STICK_RADIUS = STICK_CENTER - 1;
|
||||
static constexpr u8 STICK_RANGE = (1 << STICK_BIT_COUNT) - 1;
|
||||
// TODO: Test real hardware. Is this accurate?
|
||||
static constexpr u8 STICK_GATE_RADIUS = 0x16;
|
||||
|
||||
@ -86,11 +87,11 @@ public:
|
||||
|
||||
static constexpr int EFFECT_DIAL_BIT_COUNT = 5;
|
||||
static constexpr u8 EFFECT_DIAL_CENTER = (1 << EFFECT_DIAL_BIT_COUNT) / 2;
|
||||
static constexpr u8 EFFECT_DIAL_RANGE = EFFECT_DIAL_CENTER - 1;
|
||||
static constexpr u8 EFFECT_DIAL_RANGE = (1 << EFFECT_DIAL_BIT_COUNT) - 1;
|
||||
|
||||
static constexpr int CROSSFADE_BIT_COUNT = 4;
|
||||
static constexpr u8 CROSSFADE_CENTER = (1 << CROSSFADE_BIT_COUNT) / 2;
|
||||
static constexpr u8 CROSSFADE_RANGE = CROSSFADE_CENTER - 1;
|
||||
static constexpr u8 CROSSFADE_RANGE = (1 << CROSSFADE_BIT_COUNT) - 1;
|
||||
|
||||
private:
|
||||
ControllerEmu::Buttons* m_buttons;
|
||||
|
Loading…
x
Reference in New Issue
Block a user