forked from MeloNX/MeloNX
Fix controller and logging
This commit is contained in:
parent
14ce5102fb
commit
0bfca4c488
Binary file not shown.
@ -52,11 +52,11 @@ struct LogFileView: View {
|
||||
let logFiles = try fileManager.contentsOfDirectory(at: logsDirectory, includingPropertiesForKeys: [.creationDateKey])
|
||||
.filter {
|
||||
let filename = $0.lastPathComponent
|
||||
guard filename.hasPrefix("Ryujinx_ios_") && filename.hasSuffix(".log") else {
|
||||
guard filename.hasPrefix("MeloNX_") && filename.hasSuffix(".log") else {
|
||||
return false
|
||||
}
|
||||
|
||||
let dateString = filename.replacingOccurrences(of: "Ryujinx_ios_", with: "").replacingOccurrences(of: ".log", with: "")
|
||||
let dateString = filename.replacingOccurrences(of: "MeloNX_", with: "").replacingOccurrences(of: ".log", with: "")
|
||||
guard let logDate = dateFormatter.date(from: dateString) else {
|
||||
return false
|
||||
}
|
||||
|
@ -157,6 +157,21 @@ namespace Ryujinx.Common.Configuration
|
||||
}
|
||||
else
|
||||
{
|
||||
if (OperatingSystem.IsIOS())
|
||||
{
|
||||
logDir = Path.Combine(BaseDirPath, "Logs");
|
||||
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(logDir);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.Application, $"Logging directory could not be created '{logDir}'");
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
// NOTE: Should evaluate to "~/Library/Logs/Ryujinx/".
|
||||
|
@ -68,10 +68,8 @@ namespace Ryujinx.Common.Logging.Targets
|
||||
}
|
||||
}
|
||||
|
||||
string version = ReleaseInformation.Version;
|
||||
|
||||
// Get path for the current time
|
||||
path = Path.Combine(logDir.FullName, $"Ryujinx_{version}_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.log");
|
||||
path = Path.Combine(logDir.FullName, $"MeloNX_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.log");
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -26,6 +26,6 @@ namespace Ryujinx.Common
|
||||
|
||||
public static bool IsFlatHubBuild => IsValid && ReleaseChannelOwner.Equals(FlatHubChannelOwner);
|
||||
|
||||
public static string Version => IsValid ? BuildVersion : Assembly.GetEntryAssembly()!.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "";
|
||||
public static string Version => "ios";
|
||||
}
|
||||
}
|
||||
|
@ -1179,11 +1179,15 @@ namespace Ryujinx.Headless.SDL2
|
||||
gamepad.Dispose();
|
||||
}
|
||||
|
||||
foreach (string id in _inputManager.GamepadDriver.GamepadsIds)
|
||||
string[] gamepadsIdsArray = _inputManager.GamepadDriver.GamepadsIds.ToArray();
|
||||
|
||||
foreach (string id in gamepadsIdsArray)
|
||||
{
|
||||
gamepad = _inputManager.GamepadDriver.GetGamepad(id);
|
||||
|
||||
Logger.Info?.Print(LogClass.Application, $"- {id} (\"{gamepad.Name}\")");
|
||||
string gamepadsIdsString = $"- {id} (\"{gamepad.Name}\")";
|
||||
|
||||
Logger.Info?.Print(LogClass.Application, gamepadsIdsString);
|
||||
|
||||
gamepad.Dispose();
|
||||
}
|
||||
|
@ -9,18 +9,8 @@ namespace Ryujinx.Input.SDL2
|
||||
{
|
||||
private readonly Dictionary<int, string> _gamepadsInstanceIdsMapping;
|
||||
private readonly List<string> _gamepadsIds;
|
||||
private readonly object _lock = new object();
|
||||
|
||||
public ReadOnlySpan<string> GamepadsIds
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _gamepadsIds.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
public ReadOnlySpan<string> GamepadsIds => _gamepadsIds.ToArray();
|
||||
|
||||
public string DriverName => "SDL2";
|
||||
|
||||
@ -45,39 +35,28 @@ namespace Ryujinx.Input.SDL2
|
||||
}
|
||||
}
|
||||
|
||||
private string GenerateGamepadId(int joystickIndex)
|
||||
private static string GenerateGamepadId(int joystickIndex)
|
||||
{
|
||||
Guid guid = SDL_JoystickGetDeviceGUID(joystickIndex);
|
||||
|
||||
// Add a unique identifier to the start of the GUID in case of duplicates.
|
||||
|
||||
if (guid == Guid.Empty)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string id;
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
int guidIndex = 0;
|
||||
id = guidIndex + "-" + guid;
|
||||
|
||||
while (_gamepadsIds.Contains(id))
|
||||
{
|
||||
id = (++guidIndex) + "-" + guid;
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
return joystickIndex + "-" + guid;
|
||||
}
|
||||
|
||||
private int GetJoystickIndexByGamepadId(string id)
|
||||
private static int GetJoystickIndexByGamepadId(string id)
|
||||
{
|
||||
lock (_lock)
|
||||
string[] data = id.Split("-");
|
||||
|
||||
if (data.Length != 6 || !int.TryParse(data[0], out int joystickIndex))
|
||||
{
|
||||
return _gamepadsIds.IndexOf(id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return joystickIndex;
|
||||
}
|
||||
|
||||
private void HandleJoyStickDisconnected(int joystickInstanceId)
|
||||
@ -85,11 +64,7 @@ namespace Ryujinx.Input.SDL2
|
||||
if (_gamepadsInstanceIdsMapping.TryGetValue(joystickInstanceId, out string id))
|
||||
{
|
||||
_gamepadsInstanceIdsMapping.Remove(joystickInstanceId);
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_gamepadsIds.Remove(id);
|
||||
}
|
||||
_gamepadsIds.Remove(id);
|
||||
|
||||
OnGamepadDisconnected?.Invoke(id);
|
||||
}
|
||||
@ -99,13 +74,6 @@ namespace Ryujinx.Input.SDL2
|
||||
{
|
||||
if (SDL_IsGameController(joystickDeviceId) == SDL_bool.SDL_TRUE)
|
||||
{
|
||||
if (_gamepadsInstanceIdsMapping.ContainsKey(joystickInstanceId))
|
||||
{
|
||||
// Sometimes a JoyStick connected event fires after the app starts even though it was connected before
|
||||
// so it is rejected to avoid doubling the entries.
|
||||
return;
|
||||
}
|
||||
|
||||
string id = GenerateGamepadId(joystickDeviceId);
|
||||
|
||||
if (id == null)
|
||||
@ -113,12 +81,16 @@ namespace Ryujinx.Input.SDL2
|
||||
return;
|
||||
}
|
||||
|
||||
// Sometimes a JoyStick connected event fires after the app starts even though it was connected before
|
||||
// so it is rejected to avoid doubling the entries.
|
||||
if (_gamepadsIds.Contains(id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_gamepadsInstanceIdsMapping.TryAdd(joystickInstanceId, id))
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_gamepadsIds.Add(id);
|
||||
}
|
||||
_gamepadsIds.Add(id);
|
||||
|
||||
OnGamepadConnected?.Invoke(id);
|
||||
}
|
||||
@ -131,17 +103,13 @@ namespace Ryujinx.Input.SDL2
|
||||
{
|
||||
SDL2Driver.Instance.OnJoyStickConnected -= HandleJoyStickConnected;
|
||||
SDL2Driver.Instance.OnJoystickDisconnected -= HandleJoyStickDisconnected;
|
||||
|
||||
// Simulate a full disconnect when disposing
|
||||
|
||||
foreach (string id in _gamepadsIds)
|
||||
{
|
||||
OnGamepadDisconnected?.Invoke(id);
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_gamepadsIds.Clear();
|
||||
}
|
||||
_gamepadsIds.Clear();
|
||||
|
||||
SDL2Driver.Instance.Dispose();
|
||||
}
|
||||
@ -162,6 +130,11 @@ namespace Ryujinx.Input.SDL2
|
||||
return null;
|
||||
}
|
||||
|
||||
if (id != GenerateGamepadId(joystickIndex))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
IntPtr gamepadHandle = SDL_GameControllerOpen(joystickIndex);
|
||||
|
||||
if (gamepadHandle == IntPtr.Zero)
|
||||
|
@ -53,7 +53,7 @@ namespace Ryujinx.SDL2.Common
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_SetHint(SDL_HINT_APP_NAME, "Ryujinx");
|
||||
SDL_SetHint(SDL_HINT_APP_NAME, "MeloNX");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||
@ -95,13 +95,6 @@ namespace Ryujinx.SDL2.Common
|
||||
|
||||
SDL_EventState(SDL_EventType.SDL_CONTROLLERSENSORUPDATE, SDL_DISABLE);
|
||||
|
||||
// string gamepadDbPath = Path.Combine(ReleaseInformation.GetBaseApplicationDirectory(), "SDL_GameControllerDB.txt");
|
||||
|
||||
// if (File.Exists(gamepadDbPath))
|
||||
// {
|
||||
// SDL_GameControllerAddMappingsFromFile(gamepadDbPath);
|
||||
// }
|
||||
|
||||
_registeredWindowHandlers = new ConcurrentDictionary<uint, Action<SDL_Event>>();
|
||||
_worker = new Thread(EventWorker);
|
||||
_isRunning = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user