early-access version 1698

This commit is contained in:
pineappleEA 2021-05-20 04:30:17 +02:00
parent 26aa465a3d
commit a2ba3b7d14
4 changed files with 136 additions and 44 deletions

View file

@ -1,7 +1,7 @@
yuzu emulator early access
=============
This is the source code for early-access 1697.
This is the source code for early-access 1698.
## Legal Notice

View file

@ -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) {

View file

@ -214,6 +214,22 @@ public:
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:
struct State {
std::unordered_map<int, bool> buttons;
@ -858,6 +874,7 @@ SDLState::~SDLState() {
std::vector<Common::ParamPackage> SDLState::GetInputDevices() {
std::scoped_lock lock(joystick_map_mutex);
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& joystick : value) {
if (auto* const controller = joystick->GetSDLGameController()) {
@ -869,6 +886,9 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() {
{"guid", joystick->GetGUID()},
{"port", std::to_string(joystick->GetPort())},
});
if (joystick->IsJoyconLeft()) {
joycon_pairs[joystick->GetPort()] = joystick;
}
} else if (auto* const joy = joystick->GetSDLJoystick()) {
std::string name = fmt::format("{} {}", SDL_JoystickName(joy), joystick->GetPort());
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;
}
@ -1073,58 +1114,88 @@ ButtonMapping SDLState::GetButtonMappingForDevice(const Common::ParamPackage& pa
return {};
}
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();
if (controller == nullptr) {
return {};
}
const bool invert =
SDL_GameControllerGetType(controller) != SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
const bool is_switch =
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.
// We will add those afterwards
// This list also excludes Screenshot since theres not really a mapping for that
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{{
{Settings::NativeButton::A, invert ? SDL_CONTROLLER_BUTTON_B : SDL_CONTROLLER_BUTTON_A},
{Settings::NativeButton::B, invert ? SDL_CONTROLLER_BUTTON_A : SDL_CONTROLLER_BUTTON_B},
{Settings::NativeButton::X, invert ? SDL_CONTROLLER_BUTTON_Y : SDL_CONTROLLER_BUTTON_X},
{Settings::NativeButton::Y, invert ? SDL_CONTROLLER_BUTTON_X : SDL_CONTROLLER_BUTTON_Y},
{Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK},
{Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK},
{Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER},
{Settings::NativeButton::R, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER},
{Settings::NativeButton::Plus, SDL_CONTROLLER_BUTTON_START},
{Settings::NativeButton::Minus, SDL_CONTROLLER_BUTTON_BACK},
{Settings::NativeButton::DLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT},
{Settings::NativeButton::DUp, SDL_CONTROLLER_BUTTON_DPAD_UP},
{Settings::NativeButton::DRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT},
{Settings::NativeButton::DDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN},
{Settings::NativeButton::SL, SDL_CONTROLLER_BUTTON_LEFTSHOULDER},
{Settings::NativeButton::SR, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER},
{Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE},
{false, Settings::NativeButton::A,
is_switch ? SDL_CONTROLLER_BUTTON_A : SDL_CONTROLLER_BUTTON_B},
{false, Settings::NativeButton::B,
is_switch ? SDL_CONTROLLER_BUTTON_B : SDL_CONTROLLER_BUTTON_A},
{false, Settings::NativeButton::X,
is_switch ? SDL_CONTROLLER_BUTTON_X : SDL_CONTROLLER_BUTTON_Y},
{false, Settings::NativeButton::Y,
is_switch ? SDL_CONTROLLER_BUTTON_Y : SDL_CONTROLLER_BUTTON_X},
{true, Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK},
{false, Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK},
{true, Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER},
{false, Settings::NativeButton::R, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER},
{false, Settings::NativeButton::Plus, SDL_CONTROLLER_BUTTON_START},
{true, Settings::NativeButton::Minus, SDL_CONTROLLER_BUTTON_BACK},
{true, Settings::NativeButton::DLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT},
{true, Settings::NativeButton::DUp, SDL_CONTROLLER_BUTTON_DPAD_UP},
{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
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{{
{Settings::NativeButton::ZL, SDL_CONTROLLER_AXIS_TRIGGERLEFT},
{Settings::NativeButton::ZR, SDL_CONTROLLER_AXIS_TRIGGERRIGHT},
{true, Settings::NativeButton::ZL, SDL_CONTROLLER_AXIS_TRIGGERLEFT},
{false, Settings::NativeButton::ZR, SDL_CONTROLLER_AXIS_TRIGGERRIGHT},
}};
ButtonMapping mapping;
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);
if (params.Has("guid2") && is_left) {
mapping.insert_or_assign(
switch_button,
BuildParamPackageForBinding(joystick2->GetPort(), joystick2->GetGUID(), binding));
continue;
}
mapping.insert_or_assign(
switch_button,
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);
if (params.Has("guid2") && is_left) {
mapping.insert_or_assign(
switch_button,
BuildParamPackageForBinding(joystick2->GetPort(), joystick2->GetGUID(), binding));
continue;
}
mapping.insert_or_assign(
switch_button,
BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding));
@ -1138,6 +1209,7 @@ AnalogMapping SDLState::GetAnalogMappingForDevice(const Common::ParamPackage& pa
return {};
}
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();
if (controller == nullptr) {
return {};
@ -1148,10 +1220,17 @@ AnalogMapping SDLState::GetAnalogMappingForDevice(const Common::ParamPackage& pa
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX);
const auto& binding_left_y =
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY);
mapping.insert_or_assign(Settings::NativeAnalog::LStick,
if (params.Has("guid2")) {
mapping.insert_or_assign(
Settings::NativeAnalog::LStick,
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));
binding_left_x.value.axis, binding_left_y.value.axis));
}
const auto& binding_right_x =
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX);
const auto& binding_right_y =
@ -1168,20 +1247,32 @@ MotionMapping SDLState::GetMotionMappingForDevice(const Common::ParamPackage& pa
return {};
}
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();
if (controller == nullptr) {
return {};
}
MotionMapping mapping = {};
joystick->EnableMotion();
if (!joystick->HasGyro() && !joystick->HasAccel()) {
return {};
if (joystick->HasGyro() || joystick->HasAccel()) {
mapping.insert_or_assign(Settings::NativeMotion::MotionRight,
BuildMotionParam(joystick->GetPort(), joystick->GetGUID()));
}
MotionMapping mapping = {};
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()));
}
}
return mapping;
}
namespace Polling {

View file

@ -404,12 +404,16 @@ void QtSoftwareKeyboardDialog::ShowTextCheckDialog(
OverlayDialog dialog(this, system, QString{}, QString::fromStdU16String(text_check_message),
tr("Cancel"), tr("OK"), Qt::AlignCenter);
if (dialog.exec() == QDialog::Accepted) {
emit SubmitNormalText(SwkbdResult::Ok, current_text);
if (dialog.exec() != QDialog::Accepted) {
StartInputThread();
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;
}
}
@ -480,11 +484,7 @@ void QtSoftwareKeyboardDialog::open() {
void QtSoftwareKeyboardDialog::reject() {
// Pressing the ESC key in a dialog calls QDialog::reject().
// We will override this behavior to the "Cancel" action on the software keyboard.
if (is_inline) {
emit SubmitInlineText(SwkbdReplyType::DecidedCancel, current_text, cursor_position);
} else {
emit SubmitNormalText(SwkbdResult::Cancel, current_text);
}
TranslateButtonPress(HIDButton::X);
}
void QtSoftwareKeyboardDialog::keyPressEvent(QKeyEvent* event) {