Fix TAS input

This commit is contained in:
Pokechu22 2022-10-04 16:36:12 -07:00
parent 854e6bdb8d
commit 7a5a2e04dd
6 changed files with 98 additions and 39 deletions

View File

@ -39,10 +39,34 @@ void BalanceBoardExt::BuildDesiredExtensionState(DesiredExtensionState* target_s
const double total_weight = DEFAULT_WEIGHT * weight; // kilograms
const auto top_right = total_weight * (1 + balance_state.x + balance_state.y) / 4;
const auto bottom_right = total_weight * (1 + balance_state.x - balance_state.y) / 4;
const auto top_left = total_weight * (1 - balance_state.x + balance_state.y) / 4;
const auto bottom_left = total_weight * (1 - balance_state.x - balance_state.y) / 4;
auto top_right = total_weight * (1 + balance_state.x + balance_state.y) / 4;
auto bottom_right = total_weight * (1 + balance_state.x - balance_state.y) / 4;
auto top_left = total_weight * (1 - balance_state.x + balance_state.y) / 4;
auto bottom_left = total_weight * (1 - balance_state.x - balance_state.y) / 4;
if (m_input_override_function)
{
if (const std::optional<ControlState> top_right_override =
m_input_override_function(BALANCE_GROUP, TOP_RIGHT_SENSOR, top_right))
{
top_right = *top_right_override;
}
if (const std::optional<ControlState> bottom_right_override =
m_input_override_function(BALANCE_GROUP, BOTTOM_RIGHT_SENSOR, bottom_right))
{
bottom_right = *bottom_right_override;
}
if (const std::optional<ControlState> top_left_override =
m_input_override_function(BALANCE_GROUP, TOP_LEFT_SENSOR, top_left))
{
top_left = *top_left_override;
}
if (const std::optional<ControlState> bottom_left_override =
m_input_override_function(BALANCE_GROUP, BOTTOM_LEFT_SENSOR, bottom_left))
{
bottom_left = *bottom_left_override;
}
}
DataFormat bb_data = {};

View File

@ -33,6 +33,13 @@ public:
};
static_assert(sizeof(DataFormat) == 12, "Wrong size");
static constexpr const char* BALANCE_GROUP = "Balance";
static constexpr const char* TOP_RIGHT_SENSOR = "TR";
static constexpr const char* BOTTOM_RIGHT_SENSOR = "BR";
static constexpr const char* TOP_LEFT_SENSOR = "TL";
static constexpr const char* BOTTOM_LEFT_SENSOR = "BL";
BalanceBoardExt(BalanceBoard* owner);
static constexpr float DEFAULT_WEIGHT = 63.5; // kilograms; no specific meaning to this value

View File

@ -238,6 +238,25 @@ TASSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int defaul
return value;
}
QDoubleSpinBox* TASInputWindow::CreateWeightSliderValuePair(std::string_view group_name,
std::string_view control_name,
InputOverrider* overrider,
QBoxLayout* layout, int min, int max,
QKeySequence shortcut_key_sequence,
QWidget* shortcut_widget)
{
QDoubleSpinBox* value =
CreateWeightSliderValuePair(layout, min, max, shortcut_key_sequence, shortcut_widget);
InputOverrider::OverrideFunction func = [this, value](ControlState controller_state) {
return GetSpinBox(value, controller_state);
};
overrider->AddFunction(group_name, control_name, std::move(func));
return value;
}
// The shortcut_widget argument needs to specify the container widget that will be hidden/shown.
// This is done to avoid ambigous shortcuts
QDoubleSpinBox* TASInputWindow::CreateWeightSliderValuePair(QBoxLayout* layout, int min, int max,
@ -306,6 +325,27 @@ std::optional<ControlState> TASInputWindow::GetSpinBox(TASSpinBox* spin, int zer
return (spin->GetValue() - zero) / scale;
}
std::optional<ControlState> TASInputWindow::GetSpinBox(QDoubleSpinBox* spin,
ControlState controller_state)
{
if (m_use_controller->isChecked())
{
if (!m_spinbox_most_recent_values_double.count(spin) ||
m_spinbox_most_recent_values_double[spin] != controller_state)
{
QueueOnObjectBlocking(spin, [spin, controller_state] { spin->setValue(controller_state); });
}
m_spinbox_most_recent_values_double[spin] = controller_state;
}
else
{
m_spinbox_most_recent_values_double.clear();
}
return spin->value();
}
void TASInputWindow::changeEvent(QEvent* const event)
{
if (event->type() == QEvent::ActivationChange)

View File

@ -69,6 +69,11 @@ protected:
TASSpinBox* CreateSliderValuePair(QBoxLayout* layout, int default_, int max,
QKeySequence shortcut_key_sequence, Qt::Orientation orientation,
QWidget* shortcut_widget);
QDoubleSpinBox* CreateWeightSliderValuePair(std::string_view group_name,
std::string_view control_name,
InputOverrider* overrider, QBoxLayout* layout,
int min, int max, QKeySequence shortcut_key_sequence,
QWidget* shortcut_widget);
QDoubleSpinBox* CreateWeightSliderValuePair(QBoxLayout* layout, int min, int max,
QKeySequence shortcut_key_sequence,
QWidget* shortcut_widget);
@ -86,4 +91,7 @@ private:
ControlState controller_state);
std::optional<ControlState> GetSpinBox(TASSpinBox* spin, int zero, ControlState controller_state,
ControlState scale);
std::optional<ControlState> GetSpinBox(QDoubleSpinBox* spin, ControlState controller_state);
std::map<QDoubleSpinBox*, u16> m_spinbox_most_recent_values_double;
};

View File

@ -121,15 +121,23 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
auto* bal_top_layout = new QHBoxLayout;
m_top_left_balance_value = CreateWeightSliderValuePair(
bal_top_layout, -34, 68, balance_tl_shortcut_key_sequence, m_balance_board_box);
WiimoteEmu::BalanceBoardExt::BALANCE_GROUP, WiimoteEmu::BalanceBoardExt::TOP_LEFT_SENSOR,
&m_balance_board_overrider, bal_top_layout, -34, 68, balance_tl_shortcut_key_sequence,
m_balance_board_box);
m_top_right_balance_value = CreateWeightSliderValuePair(
bal_top_layout, -34, 68, balance_tr_shortcut_key_sequence, m_balance_board_box);
WiimoteEmu::BalanceBoardExt::BALANCE_GROUP, WiimoteEmu::BalanceBoardExt::TOP_RIGHT_SENSOR,
&m_balance_board_overrider, bal_top_layout, -34, 68, balance_tr_shortcut_key_sequence,
m_balance_board_box);
auto* bal_bottom_layout = new QHBoxLayout;
m_bottom_left_balance_value = CreateWeightSliderValuePair(
bal_bottom_layout, -34, 68, balance_bl_shortcut_key_sequence, m_balance_board_box);
WiimoteEmu::BalanceBoardExt::BALANCE_GROUP, WiimoteEmu::BalanceBoardExt::BOTTOM_LEFT_SENSOR,
&m_balance_board_overrider, bal_bottom_layout, -34, 68, balance_bl_shortcut_key_sequence,
m_balance_board_box);
m_bottom_right_balance_value = CreateWeightSliderValuePair(
bal_bottom_layout, -34, 68, balance_br_shortcut_key_sequence, m_balance_board_box);
WiimoteEmu::BalanceBoardExt::BALANCE_GROUP, WiimoteEmu::BalanceBoardExt::BOTTOM_RIGHT_SENSOR,
&m_balance_board_overrider, bal_bottom_layout, -34, 68, balance_br_shortcut_key_sequence,
m_balance_board_box);
auto* bal_weight_layout = new QHBoxLayout;
m_total_weight_value = CreateWeightSliderValuePair(
@ -630,35 +638,6 @@ void WiiTASInputWindow::UpdateInputOverrideFunction()
if (m_active_extension == WiimoteEmu::ExtensionNumber::CLASSIC)
GetExtension()->SetInputOverrideFunction(m_classic_overrider.GetInputOverrideFunction());
/*
if (rpt.HasExt() && m_balance_board_box->isVisible())
{
using WiimoteEmu::BalanceBoard;
u8* const ext_data = rpt.GetExtDataPtr();
BalanceBoard::DataFormat bb_data = Common::BitCastPtr<BalanceBoard::DataFormat>(ext_data);
// TODO: Reading the existing values, but then just clobbering them instead of using them if
// controller input is enabled
double top_right = BalanceBoard::ConvertToKilograms(Common::swap16(bb_data.top_right));
double bottom_right = BalanceBoard::ConvertToKilograms(Common::swap16(bb_data.bottom_right));
double top_left = BalanceBoard::ConvertToKilograms(Common::swap16(bb_data.top_left));
double bottom_left = BalanceBoard::ConvertToKilograms(Common::swap16(bb_data.bottom_left));
top_right = m_top_right_balance_value->value();
bottom_right = m_bottom_right_balance_value->value();
top_left = m_top_left_balance_value->value();
bottom_left = m_bottom_left_balance_value->value();
bb_data.top_right = Common::swap16(BalanceBoard::ConvertToSensorWeight(top_right));
bb_data.bottom_right = Common::swap16(BalanceBoard::ConvertToSensorWeight(bottom_right));
bb_data.top_left = Common::swap16(BalanceBoard::ConvertToSensorWeight(top_left));
bb_data.bottom_left = Common::swap16(BalanceBoard::ConvertToSensorWeight(bottom_left));
bb_data.temperature = BalanceBoard::TEMPERATURE;
bb_data.battery = 0x83;
Common::BitCastPtr<BalanceBoard::DataFormat>(ext_data) = bb_data;
key.Encrypt(ext_data, 0, sizeof(BalanceBoard::DataFormat));
}
*/
if (m_active_extension == WiimoteEmu::ExtensionNumber::BALANCE_BOARD)
GetExtension()->SetInputOverrideFunction(m_balance_board_overrider.GetInputOverrideFunction());
}

View File

@ -49,6 +49,7 @@ private:
InputOverrider m_wiimote_overrider;
InputOverrider m_nunchuk_overrider;
InputOverrider m_classic_overrider;
InputOverrider m_balance_board_overrider;
TASCheckBox* m_a_button;
TASCheckBox* m_b_button;