From 5e268d25d7586162a27f94d24c94f09e42a57f9b Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sat, 8 May 2021 21:25:29 +0200 Subject: [PATCH] early-access version 1666 --- README.md | 2 +- src/core/file_sys/vfs_real.cpp | 14 ++++++++++++++ src/input_common/sdl/sdl_impl.cpp | 22 +++++++++++++++------- src/yuzu/configuration/input_profiles.cpp | 4 ++++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c3c919d0a..77db81c9c 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1665. +This is the source code for early-access 1666. ## Legal Notice diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 40329d385..eb6630567 100755 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -93,9 +93,23 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); + // Current usages of CreateFile expect to delete the contents of an existing file. + if (FS::IsFile(path)) { + FS::IOFile temp{path, FS::FileAccessMode::Write, FS::FileType::BinaryFile}; + + if (!temp.IsOpen()) { + return nullptr; + } + + temp.Close(); + + return OpenFile(path, perms); + } + if (!FS::NewFile(path)) { return nullptr; } + return OpenFile(path, perms); } diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 4fe9e0166..f574ed81f 100755 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp @@ -69,14 +69,18 @@ public: SDL_GameController* game_controller) : guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose}, sdl_controller{game_controller, &SDL_GameControllerClose} { + EnableMotion(); + } - if (game_controller) { - if (SDL_GameControllerHasSensor(game_controller, SDL_SENSOR_ACCEL)) { - SDL_GameControllerSetSensorEnabled(game_controller, SDL_SENSOR_ACCEL, SDL_TRUE); + void EnableMotion() { + if (sdl_controller) { + SDL_GameController* controller = sdl_controller.get(); + if (SDL_GameControllerHasSensor(controller, SDL_SENSOR_ACCEL) && !has_accel) { + SDL_GameControllerSetSensorEnabled(controller, SDL_SENSOR_ACCEL, SDL_TRUE); has_accel = true; } - if (SDL_GameControllerHasSensor(game_controller, SDL_SENSOR_GYRO)) { - SDL_GameControllerSetSensorEnabled(game_controller, SDL_SENSOR_GYRO, SDL_TRUE); + if (SDL_GameControllerHasSensor(controller, SDL_SENSOR_GYRO) && !has_gyro) { + SDL_GameControllerSetSensorEnabled(controller, SDL_SENSOR_GYRO, SDL_TRUE); has_gyro = true; } } @@ -93,13 +97,11 @@ public: last_motion_update = event.timestamp; switch (event.sensor) { case SDL_SENSOR_ACCEL: { - const Common::Vec3f acceleration = {-event.data[0], event.data[2], -event.data[1]}; motion.SetAcceleration(acceleration / 9.8f); break; } case SDL_SENSOR_GYRO: { - const Common::Vec3f gyroscope = {event.data[0], -event.data[2], event.data[1]}; motion.SetGyroscope(gyroscope / (6.283f * 1.05f)); break; @@ -791,6 +793,10 @@ SDLState::SDLState() { RegisterFactory("sdl", vibration_factory); RegisterFactory("sdl", motion_factory); + // Tell SDL2 to use the hidapi driver. This will allow joycons to be detected as a + // GameController and not a generic one + SDL_SetHint("SDL_JOYSTICK_HIDAPI_JOY_CONS", "1"); + // If the frontend is going to manage the event loop, then we don't start one here start_thread = SDL_WasInit(SDL_INIT_JOYSTICK) == 0; if (start_thread && SDL_Init(SDL_INIT_JOYSTICK) < 0) { @@ -1156,6 +1162,8 @@ MotionMapping SDLState::GetMotionMappingForDevice(const Common::ParamPackage& pa return {}; } + joystick->EnableMotion(); + if (!joystick->HasGyro() && !joystick->HasAccel()) { return {}; } diff --git a/src/yuzu/configuration/input_profiles.cpp b/src/yuzu/configuration/input_profiles.cpp index 61662ad58..333eeb84e 100755 --- a/src/yuzu/configuration/input_profiles.cpp +++ b/src/yuzu/configuration/input_profiles.cpp @@ -31,6 +31,10 @@ std::filesystem::path GetNameWithoutExtension(std::filesystem::path filename) { InputProfiles::InputProfiles() { const auto input_profile_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "input"; + if (!FS::IsDir(input_profile_loc)) { + return; + } + FS::IterateDirEntries( input_profile_loc, [this](const std::filesystem::path& full_path) {