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])
|
let logFiles = try fileManager.contentsOfDirectory(at: logsDirectory, includingPropertiesForKeys: [.creationDateKey])
|
||||||
.filter {
|
.filter {
|
||||||
let filename = $0.lastPathComponent
|
let filename = $0.lastPathComponent
|
||||||
guard filename.hasPrefix("Ryujinx_ios_") && filename.hasSuffix(".log") else {
|
guard filename.hasPrefix("MeloNX_") && filename.hasSuffix(".log") else {
|
||||||
return false
|
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 {
|
guard let logDate = dateFormatter.date(from: dateString) else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -157,6 +157,21 @@ namespace Ryujinx.Common.Configuration
|
|||||||
}
|
}
|
||||||
else
|
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())
|
if (OperatingSystem.IsMacOS())
|
||||||
{
|
{
|
||||||
// NOTE: Should evaluate to "~/Library/Logs/Ryujinx/".
|
// 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
|
// 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
|
try
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,6 @@ namespace Ryujinx.Common
|
|||||||
|
|
||||||
public static bool IsFlatHubBuild => IsValid && ReleaseChannelOwner.Equals(FlatHubChannelOwner);
|
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();
|
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);
|
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();
|
gamepad.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -9,18 +9,8 @@ namespace Ryujinx.Input.SDL2
|
|||||||
{
|
{
|
||||||
private readonly Dictionary<int, string> _gamepadsInstanceIdsMapping;
|
private readonly Dictionary<int, string> _gamepadsInstanceIdsMapping;
|
||||||
private readonly List<string> _gamepadsIds;
|
private readonly List<string> _gamepadsIds;
|
||||||
private readonly object _lock = new object();
|
|
||||||
|
|
||||||
public ReadOnlySpan<string> GamepadsIds
|
public ReadOnlySpan<string> GamepadsIds => _gamepadsIds.ToArray();
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
return _gamepadsIds.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string DriverName => "SDL2";
|
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);
|
Guid guid = SDL_JoystickGetDeviceGUID(joystickIndex);
|
||||||
|
|
||||||
// Add a unique identifier to the start of the GUID in case of duplicates.
|
|
||||||
|
|
||||||
if (guid == Guid.Empty)
|
if (guid == Guid.Empty)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string id;
|
return joystickIndex + "-" + guid;
|
||||||
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
int guidIndex = 0;
|
|
||||||
id = guidIndex + "-" + guid;
|
|
||||||
|
|
||||||
while (_gamepadsIds.Contains(id))
|
|
||||||
{
|
|
||||||
id = (++guidIndex) + "-" + guid;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return id;
|
private static int GetJoystickIndexByGamepadId(string id)
|
||||||
|
{
|
||||||
|
string[] data = id.Split("-");
|
||||||
|
|
||||||
|
if (data.Length != 6 || !int.TryParse(data[0], out int joystickIndex))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetJoystickIndexByGamepadId(string id)
|
return joystickIndex;
|
||||||
{
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
return _gamepadsIds.IndexOf(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleJoyStickDisconnected(int joystickInstanceId)
|
private void HandleJoyStickDisconnected(int joystickInstanceId)
|
||||||
@ -85,11 +64,7 @@ namespace Ryujinx.Input.SDL2
|
|||||||
if (_gamepadsInstanceIdsMapping.TryGetValue(joystickInstanceId, out string id))
|
if (_gamepadsInstanceIdsMapping.TryGetValue(joystickInstanceId, out string id))
|
||||||
{
|
{
|
||||||
_gamepadsInstanceIdsMapping.Remove(joystickInstanceId);
|
_gamepadsInstanceIdsMapping.Remove(joystickInstanceId);
|
||||||
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
_gamepadsIds.Remove(id);
|
_gamepadsIds.Remove(id);
|
||||||
}
|
|
||||||
|
|
||||||
OnGamepadDisconnected?.Invoke(id);
|
OnGamepadDisconnected?.Invoke(id);
|
||||||
}
|
}
|
||||||
@ -99,13 +74,6 @@ namespace Ryujinx.Input.SDL2
|
|||||||
{
|
{
|
||||||
if (SDL_IsGameController(joystickDeviceId) == SDL_bool.SDL_TRUE)
|
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);
|
string id = GenerateGamepadId(joystickDeviceId);
|
||||||
|
|
||||||
if (id == null)
|
if (id == null)
|
||||||
@ -113,12 +81,16 @@ namespace Ryujinx.Input.SDL2
|
|||||||
return;
|
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))
|
if (_gamepadsInstanceIdsMapping.TryAdd(joystickInstanceId, id))
|
||||||
{
|
|
||||||
lock (_lock)
|
|
||||||
{
|
{
|
||||||
_gamepadsIds.Add(id);
|
_gamepadsIds.Add(id);
|
||||||
}
|
|
||||||
|
|
||||||
OnGamepadConnected?.Invoke(id);
|
OnGamepadConnected?.Invoke(id);
|
||||||
}
|
}
|
||||||
@ -132,16 +104,12 @@ namespace Ryujinx.Input.SDL2
|
|||||||
SDL2Driver.Instance.OnJoyStickConnected -= HandleJoyStickConnected;
|
SDL2Driver.Instance.OnJoyStickConnected -= HandleJoyStickConnected;
|
||||||
SDL2Driver.Instance.OnJoystickDisconnected -= HandleJoyStickDisconnected;
|
SDL2Driver.Instance.OnJoystickDisconnected -= HandleJoyStickDisconnected;
|
||||||
|
|
||||||
// Simulate a full disconnect when disposing
|
|
||||||
foreach (string id in _gamepadsIds)
|
foreach (string id in _gamepadsIds)
|
||||||
{
|
{
|
||||||
OnGamepadDisconnected?.Invoke(id);
|
OnGamepadDisconnected?.Invoke(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
_gamepadsIds.Clear();
|
_gamepadsIds.Clear();
|
||||||
}
|
|
||||||
|
|
||||||
SDL2Driver.Instance.Dispose();
|
SDL2Driver.Instance.Dispose();
|
||||||
}
|
}
|
||||||
@ -162,6 +130,11 @@ namespace Ryujinx.Input.SDL2
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id != GenerateGamepadId(joystickIndex))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
IntPtr gamepadHandle = SDL_GameControllerOpen(joystickIndex);
|
IntPtr gamepadHandle = SDL_GameControllerOpen(joystickIndex);
|
||||||
|
|
||||||
if (gamepadHandle == IntPtr.Zero)
|
if (gamepadHandle == IntPtr.Zero)
|
||||||
|
@ -53,7 +53,7 @@ namespace Ryujinx.SDL2.Common
|
|||||||
return;
|
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_PS4_RUMBLE, "1");
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "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);
|
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>>();
|
_registeredWindowHandlers = new ConcurrentDictionary<uint, Action<SDL_Event>>();
|
||||||
_worker = new Thread(EventWorker);
|
_worker = new Thread(EventWorker);
|
||||||
_isRunning = true;
|
_isRunning = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user