WiimoteEmu: Major renaming and cleanup.

This commit is contained in:
Jordan Woyak
2019-01-01 08:32:39 -06:00
parent b1f350ab1c
commit 0d1fbe7bbc
64 changed files with 4140 additions and 3185 deletions

View File

@ -9,6 +9,11 @@
#include <QLabel>
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/Extension/Classic.h"
#include "Core/HW/WiimoteEmu/Extension/Drums.h"
#include "Core/HW/WiimoteEmu/Extension/Guitar.h"
#include "Core/HW/WiimoteEmu/Extension/Nunchuk.h"
#include "Core/HW/WiimoteEmu/Extension/Turntable.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/InputConfig.h"

View File

@ -16,7 +16,7 @@
#include "DolphinQt/Config/Mapping/MappingWindow.h"
#include "DolphinQt/Config/Mapping/WiimoteEmuExtension.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
#include "InputCommon/ControllerEmu/Setting/BooleanSetting.h"
#include "InputCommon/InputConfig.h"
@ -40,12 +40,13 @@ void WiimoteEmuGeneral::CreateMainLayout()
m_main_layout->addWidget(CreateGroupBox(
tr("Hotkeys"), Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Hotkeys)));
auto* extension_group = Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Extension);
auto* extension_group =
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments);
auto* extension = CreateGroupBox(tr("Extension"), extension_group);
auto* ce_extension = static_cast<ControllerEmu::Extension*>(extension_group);
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(extension_group);
m_extension_combo = new QComboBox();
for (const auto& attachment : ce_extension->attachments)
for (const auto& attachment : ce_extension->GetAttachmentList())
{
// TODO: Figure out how to localize this
m_extension_combo->addItem(QString::fromStdString(attachment->GetName()));
@ -88,18 +89,18 @@ void WiimoteEmuGeneral::OnAttachmentChanged(int extension)
m_extension_widget->ChangeExtensionType(value_map[value]);
auto* ce_extension = static_cast<ControllerEmu::Extension*>(
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Extension));
ce_extension->switch_extension = extension;
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
ce_extension->SetSelectedAttachment(extension);
SaveSettings();
}
void WiimoteEmuGeneral::Update()
{
auto* ce_extension = static_cast<ControllerEmu::Extension*>(
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Extension));
auto* ce_extension = static_cast<ControllerEmu::Attachments*>(
Wiimote::GetWiimoteGroup(GetPort(), WiimoteEmu::WiimoteGroup::Attachments));
m_extension_combo->setCurrentIndex(ce_extension->switch_extension);
m_extension_combo->setCurrentIndex(ce_extension->GetSelectedAttachment());
}
void WiimoteEmuGeneral::LoadSettings()

View File

@ -350,9 +350,9 @@ void MainWindow::CreateComponents()
m_gc_tas_input_windows[controller_id]->GetValues(pad_status);
});
Movie::SetWiiInputManip([this](u8* input_data, WiimoteEmu::ReportFeatures rptf, int controller_id,
int ext, wiimote_key key) {
m_wii_tas_input_windows[controller_id]->GetValues(input_data, rptf, ext, key);
Movie::SetWiiInputManip([this](WiimoteCommon::DataReportBuilder& rpt, int controller_id, int ext,
const WiimoteEmu::EncryptionKey& key) {
m_wii_tas_input_windows[controller_id]->GetValues(rpt, ext, key);
});
m_jit_widget = new JITWidget(this);

View File

@ -14,10 +14,16 @@
#include "Common/FileUtil.h"
#include "Core/Core.h"
#include "Core/HW/WiimoteEmu/Attachment/Classic.h"
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
#include "Core/HW/WiimoteCommon/DataReport.h"
#include "Core/HW/WiimoteEmu/Encryption.h"
#include "Core/HW/WiimoteEmu/Extension/Classic.h"
#include "Core/HW/WiimoteEmu/Extension/Nunchuk.h"
#include "Core/HW/WiimoteEmu/Extension/Classic.h"
#include "Core/HW/WiimoteEmu/Extension/Nunchuk.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/Camera.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "DolphinQt/QtUtils/AspectRatioWidget.h"
@ -27,6 +33,8 @@
#include "InputCommon/InputConfig.h"
using namespace WiimoteCommon;
WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(parent), m_num(num)
{
const QKeySequence ir_x_shortcut_key_sequence = QKeySequence(Qt::ALT + Qt::Key_F);
@ -255,7 +263,7 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
if (Core::IsRunning())
{
ext = static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(num))
->CurrentExtension();
->GetActiveExtensionNumber();
}
else
{
@ -318,22 +326,20 @@ void WiiTASInputWindow::UpdateExt(u8 ext)
}
}
void WiiTASInputWindow::GetValues(u8* report_data, WiimoteEmu::ReportFeatures rptf, int ext,
wiimote_key key)
void WiiTASInputWindow::GetValues(DataReportBuilder& rpt, int ext,
const WiimoteEmu::EncryptionKey& key)
{
if (!isVisible())
return;
UpdateExt(ext);
u8* const buttons_data = rptf.core_size ? (report_data + rptf.GetCoreOffset()) : nullptr;
u8* const accel_data = rptf.accel_size ? (report_data + rptf.GetAccelOffset()) : nullptr;
u8* const ir_data = rptf.ir_size ? (report_data + rptf.GetIROffset()) : nullptr;
u8* const ext_data = rptf.ext_size ? (report_data + rptf.GetExtOffset()) : nullptr;
if (m_remote_buttons_box->isVisible() && buttons_data)
if (m_remote_buttons_box->isVisible() && rpt.HasCore())
{
u16& buttons = (reinterpret_cast<wm_buttons*>(buttons_data))->hex;
DataReportBuilder::CoreData core;
rpt.GetCoreData(&core);
u16& buttons = core.hex;
GetButton<u16>(m_a_button, buttons, WiimoteEmu::Wiimote::BUTTON_A);
GetButton<u16>(m_b_button, buttons, WiimoteEmu::Wiimote::BUTTON_B);
GetButton<u16>(m_1_button, buttons, WiimoteEmu::Wiimote::BUTTON_ONE);
@ -345,34 +351,28 @@ void WiiTASInputWindow::GetValues(u8* report_data, WiimoteEmu::ReportFeatures rp
GetButton<u16>(m_up_button, buttons, WiimoteEmu::Wiimote::PAD_UP);
GetButton<u16>(m_down_button, buttons, WiimoteEmu::Wiimote::PAD_DOWN);
GetButton<u16>(m_right_button, buttons, WiimoteEmu::Wiimote::PAD_RIGHT);
rpt.SetCoreData(core);
}
if (m_remote_orientation_box->isVisible() && accel_data && buttons_data)
if (m_remote_orientation_box->isVisible() && rpt.HasAccel())
{
wm_accel& accel = *reinterpret_cast<wm_accel*>(accel_data);
//wm_buttons& buttons = *reinterpret_cast<wm_buttons*>(buttons_data);
// FYI: Interleaved reports may behave funky as not all data is always available.
// TODO: lsb
u16 accel_x = (accel.x << 2); // & (buttons.acc_x_lsb & 0b11);
u16 accel_y = (accel.y << 2); // & ((buttons.acc_y_lsb & 0b1) << 1);
u16 accel_z = (accel.z << 2); // &((buttons.acc_z_lsb & 0b1) << 1);
DataReportBuilder::AccelData accel;
rpt.GetAccelData(&accel);
GetSpinBoxU16(m_remote_orientation_x_value, accel_x);
GetSpinBoxU16(m_remote_orientation_y_value, accel_y);
GetSpinBoxU16(m_remote_orientation_z_value, accel_z);
GetSpinBoxU16(m_remote_orientation_x_value, accel.x);
GetSpinBoxU16(m_remote_orientation_y_value, accel.y);
GetSpinBoxU16(m_remote_orientation_z_value, accel.z);
accel.x = accel_x >> 2;
accel.y = accel_y >> 2;
accel.z = accel_z >> 2;
// TODO: lsb
//buttons.acc_x_lsb = accel_x & 0b11;
//buttons.acc_y_lsb = (accel_y >> 1) & 0b1;
//buttons.acc_z_lsb = (accel_z >> 1) & 0b1;
rpt.SetAccelData(accel);
}
if (m_ir_box->isVisible() && ir_data && !m_use_controller->isChecked())
if (m_ir_box->isVisible() && rpt.HasIR() && !m_use_controller->isChecked())
{
u8* const ir_data = rpt.GetIRDataPtr();
u16 y = m_ir_y_value->value();
std::array<u16, 4> x;
x[0] = m_ir_x_value->value();
@ -380,18 +380,19 @@ void WiiTASInputWindow::GetValues(u8* report_data, WiimoteEmu::ReportFeatures rp
x[2] = x[0] - 10;
x[3] = x[1] + 10;
u8 mode;
// Mode 5 not supported in core anyway.
// TODO: Can just use ir_size to determine mode
if (rptf.ext_size)
mode = (rptf.GetExtOffset() - rptf.GetIROffset()) == 10 ? 1 : 3;
else
mode = (rptf.total_size - rptf.GetIROffset()) == 10 ? 1 : 3;
// FYI: This check is not entirely foolproof.
// TODO: IR "full" mode not implemented.
u8 mode = WiimoteEmu::CameraLogic::IR_MODE_BASIC;
if (mode == 1)
if (rpt.GetIRDataSize() == sizeof(WiimoteEmu::IRExtended) * 4)
mode = WiimoteEmu::CameraLogic::IR_MODE_EXTENDED;
else if (rpt.GetIRDataSize() == sizeof(WiimoteEmu::IRFull) * 2)
mode = WiimoteEmu::CameraLogic::IR_MODE_FULL;
if (mode == WiimoteEmu::CameraLogic::IR_MODE_BASIC)
{
memset(ir_data, 0xFF, sizeof(wm_ir_basic) * 2);
wm_ir_basic* const ir_basic = reinterpret_cast<wm_ir_basic*>(ir_data);
memset(ir_data, 0xFF, sizeof(WiimoteEmu::IRBasic) * 2);
auto* const ir_basic = reinterpret_cast<WiimoteEmu::IRBasic*>(ir_data);
for (int i = 0; i < 2; ++i)
{
if (x[i * 2] < 1024 && y < 768)
@ -416,8 +417,8 @@ void WiiTASInputWindow::GetValues(u8* report_data, WiimoteEmu::ReportFeatures rp
{
// TODO: this code doesnt work, resulting in no IR TAS inputs in e.g. wii sports menu when no
// remote extension is used
memset(ir_data, 0xFF, sizeof(wm_ir_extended) * 4);
wm_ir_extended* const ir_extended = reinterpret_cast<wm_ir_extended*>(ir_data);
memset(ir_data, 0xFF, sizeof(WiimoteEmu::IRExtended) * 4);
auto* const ir_extended = reinterpret_cast<WiimoteEmu::IRExtended*>(ir_data);
for (size_t i = 0; i < x.size(); ++i)
{
if (x[i] < 1024 && y < 768)
@ -434,9 +435,11 @@ void WiiTASInputWindow::GetValues(u8* report_data, WiimoteEmu::ReportFeatures rp
}
}
if (ext_data && m_nunchuk_stick_box->isVisible())
if (rpt.HasExt() && m_nunchuk_stick_box->isVisible())
{
wm_nc& nunchuk = *reinterpret_cast<wm_nc*>(ext_data);
u8* const ext_data = rpt.GetExtDataPtr();
auto& nunchuk = *reinterpret_cast<WiimoteEmu::Nunchuk::DataFormat*>(ext_data);
GetSpinBoxU8(m_nunchuk_stick_x_value, nunchuk.jx);
GetSpinBoxU8(m_nunchuk_stick_y_value, nunchuk.jy);
@ -462,13 +465,15 @@ void WiiTASInputWindow::GetValues(u8* report_data, WiimoteEmu::ReportFeatures rp
GetButton<u8>(m_z_button, nunchuk.bt.hex, WiimoteEmu::Nunchuk::BUTTON_Z);
nunchuk.bt.hex ^= 0b11;
WiimoteEncrypt(&key, reinterpret_cast<u8*>(&nunchuk), 0, sizeof(wm_nc));
key.Encrypt(reinterpret_cast<u8*>(&nunchuk), 0, sizeof(nunchuk));
}
if (m_classic_left_stick_box->isVisible())
{
wm_classic_extension& cc = *reinterpret_cast<wm_classic_extension*>(ext_data);
WiimoteDecrypt(&key, reinterpret_cast<u8*>(&cc), 0, sizeof(wm_classic_extension));
u8* const ext_data = rpt.GetExtDataPtr();
auto& cc = *reinterpret_cast<WiimoteEmu::Classic::DataFormat*>(ext_data);
key.Decrypt(reinterpret_cast<u8*>(&cc), 0, sizeof(cc));
cc.bt.hex ^= 0xFFFF;
GetButton<u16>(m_classic_a_button, cc.bt.hex, WiimoteEmu::Classic::BUTTON_A);
@ -498,13 +503,13 @@ void WiiTASInputWindow::GetValues(u8* report_data, WiimoteEmu::ReportFeatures rp
GetSpinBoxU8(m_classic_right_stick_y_value, ry);
cc.ry = ry;
u8 lx = cc.regular_data.lx;
u8 lx = cc.lx;
GetSpinBoxU8(m_classic_left_stick_x_value, lx);
cc.regular_data.lx = lx;
cc.lx = lx;
u8 ly = cc.regular_data.ly;
u8 ly = cc.ly;
GetSpinBoxU8(m_classic_left_stick_y_value, ly);
cc.regular_data.ly = ly;
cc.ly = ly;
u8 rt = cc.rt;
GetSpinBoxU8(m_right_trigger_value, rt);
@ -515,6 +520,6 @@ void WiiTASInputWindow::GetValues(u8* report_data, WiimoteEmu::ReportFeatures rp
cc.lt1 = lt & 0b111;
cc.lt2 = (lt >> 3) & 0b11;
WiimoteEncrypt(&key, reinterpret_cast<u8*>(&cc), 0, sizeof(wm_classic_extension));
key.Encrypt(reinterpret_cast<u8*>(&cc), 0, sizeof(cc));
}
}

View File

@ -6,21 +6,27 @@
#include "DolphinQt/TAS/TASInputWindow.h"
namespace WiimoteCommon
{
class DataReportBuilder;
}
namespace WiimoteEmu
{
struct ReportFeatures;
class EncryptionKey;
}
class QCheckBox;
class QGroupBox;
class QSpinBox;
struct wiimote_key;
class WiiTASInputWindow : public TASInputWindow
{
Q_OBJECT
public:
explicit WiiTASInputWindow(QWidget* parent, int num);
void GetValues(u8* input_data, WiimoteEmu::ReportFeatures rptf, int ext, wiimote_key key);
void GetValues(WiimoteCommon::DataReportBuilder& rpt, int ext,
const WiimoteEmu::EncryptionKey& key);
private:
void UpdateExt(u8 ext);