early-access version 1698
This commit is contained in:
parent
26aa465a3d
commit
a2ba3b7d14
4 changed files with 136 additions and 44 deletions
|
@ -1,7 +1,7 @@
|
||||||
yuzu emulator early access
|
yuzu emulator early access
|
||||||
=============
|
=============
|
||||||
|
|
||||||
This is the source code for early-access 1697.
|
This is the source code for early-access 1698.
|
||||||
|
|
||||||
## Legal Notice
|
## Legal Notice
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,8 @@ struct OffsetOfCalculator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (next - start) * sizeof(MemberType) + Offset;
|
return static_cast<ptrdiff_t>(static_cast<size_t>(next - start) * sizeof(MemberType) +
|
||||||
|
Offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr std::ptrdiff_t OffsetOf(MemberType ParentType::*member) {
|
static constexpr std::ptrdiff_t OffsetOf(MemberType ParentType::*member) {
|
||||||
|
|
|
@ -214,6 +214,22 @@ public:
|
||||||
sdl_controller.reset(controller);
|
sdl_controller.reset(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsJoyconLeft() {
|
||||||
|
if (!sdl_controller) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const std::string name = SDL_GameControllerName(sdl_controller.get());
|
||||||
|
return name.find("Joy-Con Left") != std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsJoyconRight() {
|
||||||
|
if (!sdl_controller) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const std::string name = SDL_GameControllerName(sdl_controller.get());
|
||||||
|
return name.find("Joy-Con Right") != std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct State {
|
struct State {
|
||||||
std::unordered_map<int, bool> buttons;
|
std::unordered_map<int, bool> buttons;
|
||||||
|
@ -858,6 +874,7 @@ SDLState::~SDLState() {
|
||||||
std::vector<Common::ParamPackage> SDLState::GetInputDevices() {
|
std::vector<Common::ParamPackage> SDLState::GetInputDevices() {
|
||||||
std::scoped_lock lock(joystick_map_mutex);
|
std::scoped_lock lock(joystick_map_mutex);
|
||||||
std::vector<Common::ParamPackage> devices;
|
std::vector<Common::ParamPackage> devices;
|
||||||
|
std::unordered_map<int, std::shared_ptr<SDLJoystick>> joycon_pairs;
|
||||||
for (const auto& [key, value] : joystick_map) {
|
for (const auto& [key, value] : joystick_map) {
|
||||||
for (const auto& joystick : value) {
|
for (const auto& joystick : value) {
|
||||||
if (auto* const controller = joystick->GetSDLGameController()) {
|
if (auto* const controller = joystick->GetSDLGameController()) {
|
||||||
|
@ -869,6 +886,9 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() {
|
||||||
{"guid", joystick->GetGUID()},
|
{"guid", joystick->GetGUID()},
|
||||||
{"port", std::to_string(joystick->GetPort())},
|
{"port", std::to_string(joystick->GetPort())},
|
||||||
});
|
});
|
||||||
|
if (joystick->IsJoyconLeft()) {
|
||||||
|
joycon_pairs[joystick->GetPort()] = joystick;
|
||||||
|
}
|
||||||
} else if (auto* const joy = joystick->GetSDLJoystick()) {
|
} else if (auto* const joy = joystick->GetSDLJoystick()) {
|
||||||
std::string name = fmt::format("{} {}", SDL_JoystickName(joy), joystick->GetPort());
|
std::string name = fmt::format("{} {}", SDL_JoystickName(joy), joystick->GetPort());
|
||||||
devices.emplace_back(Common::ParamPackage{
|
devices.emplace_back(Common::ParamPackage{
|
||||||
|
@ -880,6 +900,27 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Add dual controllers
|
||||||
|
for (const auto& [key, value] : joystick_map) {
|
||||||
|
for (const auto& joystick : value) {
|
||||||
|
if (joystick->IsJoyconRight()) {
|
||||||
|
if (!joycon_pairs.contains(joystick->GetPort())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto joystick2 = joycon_pairs.at(joystick->GetPort());
|
||||||
|
|
||||||
|
std::string name =
|
||||||
|
fmt::format("{} {}", "Nintendo Dual Joy-Con", joystick->GetPort());
|
||||||
|
devices.emplace_back(Common::ParamPackage{
|
||||||
|
{"class", "sdl"},
|
||||||
|
{"display", std::move(name)},
|
||||||
|
{"guid", joystick->GetGUID()},
|
||||||
|
{"guid2", joystick2->GetGUID()},
|
||||||
|
{"port", std::to_string(joystick->GetPort())},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1073,58 +1114,88 @@ ButtonMapping SDLState::GetButtonMappingForDevice(const Common::ParamPackage& pa
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
|
const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
|
||||||
|
const auto joystick2 = GetSDLJoystickByGUID(params.Get("guid2", ""), params.Get("port", 0));
|
||||||
|
|
||||||
auto* controller = joystick->GetSDLGameController();
|
auto* controller = joystick->GetSDLGameController();
|
||||||
if (controller == nullptr) {
|
if (controller == nullptr) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool invert =
|
const bool is_switch =
|
||||||
SDL_GameControllerGetType(controller) != SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
|
SDL_GameControllerGetType(controller) == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
|
||||||
|
|
||||||
|
auto sl_button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
|
||||||
|
auto sr_button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
|
||||||
|
|
||||||
|
if (joystick->IsJoyconLeft()) {
|
||||||
|
sl_button = SDL_CONTROLLER_BUTTON_PADDLE2;
|
||||||
|
sr_button = SDL_CONTROLLER_BUTTON_PADDLE4;
|
||||||
|
}
|
||||||
|
if (joystick->IsJoyconRight()) {
|
||||||
|
sl_button = SDL_CONTROLLER_BUTTON_PADDLE3;
|
||||||
|
sr_button = SDL_CONTROLLER_BUTTON_PADDLE1;
|
||||||
|
}
|
||||||
|
|
||||||
// This list is missing ZL/ZR since those are not considered buttons in SDL GameController.
|
// This list is missing ZL/ZR since those are not considered buttons in SDL GameController.
|
||||||
// We will add those afterwards
|
// We will add those afterwards
|
||||||
// This list also excludes Screenshot since theres not really a mapping for that
|
// This list also excludes Screenshot since theres not really a mapping for that
|
||||||
using ButtonBindings =
|
using ButtonBindings =
|
||||||
std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>;
|
std::array<std::tuple<bool, Settings::NativeButton::Values, SDL_GameControllerButton>, 17>;
|
||||||
const ButtonBindings switch_to_sdl_button{{
|
const ButtonBindings switch_to_sdl_button{{
|
||||||
{Settings::NativeButton::A, invert ? SDL_CONTROLLER_BUTTON_B : SDL_CONTROLLER_BUTTON_A},
|
{false, Settings::NativeButton::A,
|
||||||
{Settings::NativeButton::B, invert ? SDL_CONTROLLER_BUTTON_A : SDL_CONTROLLER_BUTTON_B},
|
is_switch ? SDL_CONTROLLER_BUTTON_A : SDL_CONTROLLER_BUTTON_B},
|
||||||
{Settings::NativeButton::X, invert ? SDL_CONTROLLER_BUTTON_Y : SDL_CONTROLLER_BUTTON_X},
|
{false, Settings::NativeButton::B,
|
||||||
{Settings::NativeButton::Y, invert ? SDL_CONTROLLER_BUTTON_X : SDL_CONTROLLER_BUTTON_Y},
|
is_switch ? SDL_CONTROLLER_BUTTON_B : SDL_CONTROLLER_BUTTON_A},
|
||||||
{Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK},
|
{false, Settings::NativeButton::X,
|
||||||
{Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK},
|
is_switch ? SDL_CONTROLLER_BUTTON_X : SDL_CONTROLLER_BUTTON_Y},
|
||||||
{Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER},
|
{false, Settings::NativeButton::Y,
|
||||||
{Settings::NativeButton::R, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER},
|
is_switch ? SDL_CONTROLLER_BUTTON_Y : SDL_CONTROLLER_BUTTON_X},
|
||||||
{Settings::NativeButton::Plus, SDL_CONTROLLER_BUTTON_START},
|
{true, Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK},
|
||||||
{Settings::NativeButton::Minus, SDL_CONTROLLER_BUTTON_BACK},
|
{false, Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK},
|
||||||
{Settings::NativeButton::DLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT},
|
{true, Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER},
|
||||||
{Settings::NativeButton::DUp, SDL_CONTROLLER_BUTTON_DPAD_UP},
|
{false, Settings::NativeButton::R, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER},
|
||||||
{Settings::NativeButton::DRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT},
|
{false, Settings::NativeButton::Plus, SDL_CONTROLLER_BUTTON_START},
|
||||||
{Settings::NativeButton::DDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN},
|
{true, Settings::NativeButton::Minus, SDL_CONTROLLER_BUTTON_BACK},
|
||||||
{Settings::NativeButton::SL, SDL_CONTROLLER_BUTTON_LEFTSHOULDER},
|
{true, Settings::NativeButton::DLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT},
|
||||||
{Settings::NativeButton::SR, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER},
|
{true, Settings::NativeButton::DUp, SDL_CONTROLLER_BUTTON_DPAD_UP},
|
||||||
{Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE},
|
{true, Settings::NativeButton::DRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT},
|
||||||
|
{true, Settings::NativeButton::DDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN},
|
||||||
|
{true, Settings::NativeButton::SL, sl_button},
|
||||||
|
{true, Settings::NativeButton::SR, sr_button},
|
||||||
|
{false, Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// Add the missing bindings for ZL/ZR
|
// Add the missing bindings for ZL/ZR
|
||||||
using ZBindings =
|
using ZBindings =
|
||||||
std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>;
|
std::array<std::tuple<bool, Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>;
|
||||||
static constexpr ZBindings switch_to_sdl_axis{{
|
static constexpr ZBindings switch_to_sdl_axis{{
|
||||||
{Settings::NativeButton::ZL, SDL_CONTROLLER_AXIS_TRIGGERLEFT},
|
{true, Settings::NativeButton::ZL, SDL_CONTROLLER_AXIS_TRIGGERLEFT},
|
||||||
{Settings::NativeButton::ZR, SDL_CONTROLLER_AXIS_TRIGGERRIGHT},
|
{false, Settings::NativeButton::ZR, SDL_CONTROLLER_AXIS_TRIGGERRIGHT},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
ButtonMapping mapping;
|
ButtonMapping mapping;
|
||||||
mapping.reserve(switch_to_sdl_button.size() + switch_to_sdl_axis.size());
|
mapping.reserve(switch_to_sdl_button.size() + switch_to_sdl_axis.size());
|
||||||
|
|
||||||
for (const auto& [switch_button, sdl_button] : switch_to_sdl_button) {
|
for (const auto& [is_left, switch_button, sdl_button] : switch_to_sdl_button) {
|
||||||
const auto& binding = SDL_GameControllerGetBindForButton(controller, sdl_button);
|
const auto& binding = SDL_GameControllerGetBindForButton(controller, sdl_button);
|
||||||
|
if (params.Has("guid2") && is_left) {
|
||||||
|
mapping.insert_or_assign(
|
||||||
|
switch_button,
|
||||||
|
BuildParamPackageForBinding(joystick2->GetPort(), joystick2->GetGUID(), binding));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
mapping.insert_or_assign(
|
mapping.insert_or_assign(
|
||||||
switch_button,
|
switch_button,
|
||||||
BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding));
|
BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding));
|
||||||
}
|
}
|
||||||
for (const auto& [switch_button, sdl_axis] : switch_to_sdl_axis) {
|
for (const auto& [is_left, switch_button, sdl_axis] : switch_to_sdl_axis) {
|
||||||
const auto& binding = SDL_GameControllerGetBindForAxis(controller, sdl_axis);
|
const auto& binding = SDL_GameControllerGetBindForAxis(controller, sdl_axis);
|
||||||
|
if (params.Has("guid2") && is_left) {
|
||||||
|
mapping.insert_or_assign(
|
||||||
|
switch_button,
|
||||||
|
BuildParamPackageForBinding(joystick2->GetPort(), joystick2->GetGUID(), binding));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
mapping.insert_or_assign(
|
mapping.insert_or_assign(
|
||||||
switch_button,
|
switch_button,
|
||||||
BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding));
|
BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding));
|
||||||
|
@ -1138,6 +1209,7 @@ AnalogMapping SDLState::GetAnalogMappingForDevice(const Common::ParamPackage& pa
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
|
const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
|
||||||
|
const auto joystick2 = GetSDLJoystickByGUID(params.Get("guid2", ""), params.Get("port", 0));
|
||||||
auto* controller = joystick->GetSDLGameController();
|
auto* controller = joystick->GetSDLGameController();
|
||||||
if (controller == nullptr) {
|
if (controller == nullptr) {
|
||||||
return {};
|
return {};
|
||||||
|
@ -1148,10 +1220,17 @@ AnalogMapping SDLState::GetAnalogMappingForDevice(const Common::ParamPackage& pa
|
||||||
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX);
|
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX);
|
||||||
const auto& binding_left_y =
|
const auto& binding_left_y =
|
||||||
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY);
|
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY);
|
||||||
mapping.insert_or_assign(Settings::NativeAnalog::LStick,
|
if (params.Has("guid2")) {
|
||||||
BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(),
|
mapping.insert_or_assign(
|
||||||
binding_left_x.value.axis,
|
Settings::NativeAnalog::LStick,
|
||||||
binding_left_y.value.axis));
|
BuildParamPackageForAnalog(joystick2->GetPort(), joystick2->GetGUID(),
|
||||||
|
binding_left_x.value.axis, binding_left_y.value.axis));
|
||||||
|
} else {
|
||||||
|
mapping.insert_or_assign(
|
||||||
|
Settings::NativeAnalog::LStick,
|
||||||
|
BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(),
|
||||||
|
binding_left_x.value.axis, binding_left_y.value.axis));
|
||||||
|
}
|
||||||
const auto& binding_right_x =
|
const auto& binding_right_x =
|
||||||
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX);
|
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX);
|
||||||
const auto& binding_right_y =
|
const auto& binding_right_y =
|
||||||
|
@ -1168,20 +1247,32 @@ MotionMapping SDLState::GetMotionMappingForDevice(const Common::ParamPackage& pa
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
|
const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
|
||||||
|
const auto joystick2 = GetSDLJoystickByGUID(params.Get("guid2", ""), params.Get("port", 0));
|
||||||
auto* controller = joystick->GetSDLGameController();
|
auto* controller = joystick->GetSDLGameController();
|
||||||
if (controller == nullptr) {
|
if (controller == nullptr) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MotionMapping mapping = {};
|
||||||
joystick->EnableMotion();
|
joystick->EnableMotion();
|
||||||
|
|
||||||
if (!joystick->HasGyro() && !joystick->HasAccel()) {
|
if (joystick->HasGyro() || joystick->HasAccel()) {
|
||||||
return {};
|
mapping.insert_or_assign(Settings::NativeMotion::MotionRight,
|
||||||
|
BuildMotionParam(joystick->GetPort(), joystick->GetGUID()));
|
||||||
|
}
|
||||||
|
if (params.Has("guid2")) {
|
||||||
|
joystick2->EnableMotion();
|
||||||
|
if (joystick2->HasGyro() || joystick2->HasAccel()) {
|
||||||
|
mapping.insert_or_assign(Settings::NativeMotion::MotionLeft,
|
||||||
|
BuildMotionParam(joystick2->GetPort(), joystick2->GetGUID()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (joystick->HasGyro() || joystick->HasAccel()) {
|
||||||
|
mapping.insert_or_assign(Settings::NativeMotion::MotionLeft,
|
||||||
|
BuildMotionParam(joystick->GetPort(), joystick->GetGUID()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionMapping mapping = {};
|
|
||||||
mapping.insert_or_assign(Settings::NativeMotion::MotionLeft,
|
|
||||||
BuildMotionParam(joystick->GetPort(), joystick->GetGUID()));
|
|
||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
namespace Polling {
|
namespace Polling {
|
||||||
|
|
|
@ -404,12 +404,16 @@ void QtSoftwareKeyboardDialog::ShowTextCheckDialog(
|
||||||
|
|
||||||
OverlayDialog dialog(this, system, QString{}, QString::fromStdU16String(text_check_message),
|
OverlayDialog dialog(this, system, QString{}, QString::fromStdU16String(text_check_message),
|
||||||
tr("Cancel"), tr("OK"), Qt::AlignCenter);
|
tr("Cancel"), tr("OK"), Qt::AlignCenter);
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() != QDialog::Accepted) {
|
||||||
emit SubmitNormalText(SwkbdResult::Ok, current_text);
|
StartInputThread();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
StartInputThread();
|
auto text = ui->topOSK->currentIndex() == 1
|
||||||
|
? ui->text_edit_osk->toPlainText().toStdU16String()
|
||||||
|
: ui->line_edit_osk->text().toStdU16String();
|
||||||
|
|
||||||
|
emit SubmitNormalText(SwkbdResult::Ok, std::move(text));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -480,11 +484,7 @@ void QtSoftwareKeyboardDialog::open() {
|
||||||
void QtSoftwareKeyboardDialog::reject() {
|
void QtSoftwareKeyboardDialog::reject() {
|
||||||
// Pressing the ESC key in a dialog calls QDialog::reject().
|
// Pressing the ESC key in a dialog calls QDialog::reject().
|
||||||
// We will override this behavior to the "Cancel" action on the software keyboard.
|
// We will override this behavior to the "Cancel" action on the software keyboard.
|
||||||
if (is_inline) {
|
TranslateButtonPress(HIDButton::X);
|
||||||
emit SubmitInlineText(SwkbdReplyType::DecidedCancel, current_text, cursor_position);
|
|
||||||
} else {
|
|
||||||
emit SubmitNormalText(SwkbdResult::Cancel, current_text);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtSoftwareKeyboardDialog::keyPressEvent(QKeyEvent* event) {
|
void QtSoftwareKeyboardDialog::keyPressEvent(QKeyEvent* event) {
|
||||||
|
|
Loading…
Reference in a new issue