Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds gamepad exit hotkeys (plus and minus) to the input section #504

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
13d2498
test
Goodfeat Oct 22, 2024
8074a4d
Fixed a visual bug in "input settings", when switching between player…
Goodfeat Oct 30, 2024
25499cb
Merge branch 'GreemDev:master' into master
Goodfeat Nov 2, 2024
d83da7d
Fixed the logic of saving the input section. Added a new dialog box w…
Goodfeat Nov 2, 2024
ea061cf
Merge branch 'GreemDev:master' into master
Goodfeat Nov 3, 2024
ca7c171
Merge branch 'GreemDev:master' into master
Goodfeat Nov 4, 2024
4bab858
Merge branch 'GreemDev:master' into master
Goodfeat Nov 9, 2024
7da4a91
Merge branch 'GreemDev:master' into master
Goodfeat Nov 10, 2024
b9012e2
code cleaning
Goodfeat Nov 10, 2024
267aaca
Merge branch 'GreemDev:master' into master
Goodfeat Nov 10, 2024
7c30426
Merge branch 'GreemDev:master' into master
Goodfeat Nov 10, 2024
5bfa01b
Merge branch 'GreemDev:master' into master
Goodfeat Nov 12, 2024
d7bd165
Merge branch 'GreemDev:master' into master
Goodfeat Nov 20, 2024
ff90b68
Merge branch 'GreemDev:master' into master
Goodfeat Nov 23, 2024
a158a93
Merge branch 'GreemDev:master' into master
Goodfeat Nov 24, 2024
3e3de18
Merge branch 'GreemDev:master' into master
Goodfeat Nov 30, 2024
39e8283
Merge branch 'master' of https://github.com/Goodfeat/Ryujinx_alt
Goodfeat Dec 14, 2024
cd43362
Merge branch 'GreemDev:master' into master
Goodfeat Dec 22, 2024
7f59781
Merge branch 'GreemDev:master' into master
Goodfeat Dec 24, 2024
be2aa5a
Merge branch 'Ryubing:master' into master
Goodfeat Dec 30, 2024
007d3bc
Merge branch 'Ryubing:master' into master
Goodfeat Jan 8, 2025
37b4dd2
Added new option "exit by pressing plus and minus buttons" to the inp…
Goodfeat Jan 8, 2025
b6667a8
multiple fixes, variable typo fixes, adherence to a certain style. Fi…
Goodfeat Jan 8, 2025
c20452b
Fixed a bug where the emulator would still terminate the game when pr…
Goodfeat Jan 8, 2025
1c6390c
minor bugs fixed
Goodfeat Jan 8, 2025
0c503e1
Update SettingsViewModel.cs
Goodfeat Jan 8, 2025
33fefb1
Merge branch 'master' into master
Goodfeat Jan 8, 2025
06cd539
Merge branch 'master' into master
Goodfeat Jan 10, 2025
864cd57
Merge branch 'master' into master
Goodfeat Jan 10, 2025
3352d70
Update SettingsViewModel.cs
Goodfeat Jan 11, 2025
01e22f1
newline brace
GreemDev Jan 11, 2025
78e7a30
add back a comment that was removed for no reason
GreemDev Jan 11, 2025
de18c49
Merge branch 'master' into master
Goodfeat Jan 11, 2025
11f1922
fix specialExitEmulator -> SpecialExitEmulator, Added description to…
Goodfeat Jan 11, 2025
f75efbe
oops, rename to"SpecialExitEmulator"
Goodfeat Jan 11, 2025
2ec032c
Added description in another file
Goodfeat Jan 11, 2025
44de9b3
Merge branch 'master' into master
Goodfeat Jan 11, 2025
fe484e8
Merge branch 'master' into master
Goodfeat Jan 12, 2025
8576320
Merge branch 'master' into master
Goodfeat Jan 14, 2025
d8a3af0
Merge branch 'master' into master
Goodfeat Jan 15, 2025
ac19f8d
Merge branch 'master' into master
Goodfeat Jan 16, 2025
0c78c57
Merge branch 'master' into master
Goodfeat Jan 16, 2025
bfe6f7b
Merge branch 'master' into master
Goodfeat Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/Ryujinx.Input.SDL2/SDL2Gamepad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,23 @@ public GamepadStateSnapshot GetStateSnapshot()
return IGamepad.GetStateSnapshot(this);
}

private static bool hotButtonMinus = false;
private static bool hotExit = false;

public bool SpecialExit()
{
if (hotButtonMinus)
{
hotButtonMinus = false;
return hotExit;
}
return hotExit = false;
}

public GamepadStateSnapshot GetMappedStateSnapshot()
{
GamepadStateSnapshot rawState = GetStateSnapshot();
GamepadStateSnapshot result = default;

lock (_userMappingLock)
{
if (_buttonsUserMapping.Count == 0)
Expand All @@ -270,6 +282,28 @@ public GamepadStateSnapshot GetMappedStateSnapshot()
if (!entry.IsValid)
continue;

if (GamepadButtonInputId.Minus == entry.To)
{
if (rawState.IsPressed(entry.From) && !hotButtonMinus)
{
hotButtonMinus = true;
}
else if (!result.IsPressed(entry.From) && hotButtonMinus)
{
hotButtonMinus = false;
}
}

if (GamepadButtonInputId.Plus == entry.To)
{
if (rawState.IsPressed(entry.To) && hotButtonMinus)
{

hotExit = true;
}

}

// Do not touch state of button already pressed
if (!result.IsPressed(entry.To))
{
Expand Down Expand Up @@ -376,5 +410,7 @@ public bool IsPressed(GamepadButtonInputId inputId)

return SDL_GameControllerGetButton(_gamepadHandle, _buttonsDriverMapping[(int)inputId]) == 1;
}


}
}
5 changes: 5 additions & 0 deletions src/Ryujinx.Input.SDL2/SDL2Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ public GamepadStateSnapshot GetMappedStateSnapshot()
return result;
}

public bool SpecialExit()
{
return false;
}

public GamepadStateSnapshot GetStateSnapshot()
{
throw new NotSupportedException();
Expand Down
4 changes: 4 additions & 0 deletions src/Ryujinx.Input.SDL2/SDL2Mouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public SDL2Mouse(SDL2MouseDriver driver)
{
_driver = driver;
}
public bool SpecialExit()
{
return false;
}

public Vector2 GetPosition()
{
Expand Down
12 changes: 10 additions & 2 deletions src/Ryujinx.Input/HLE/NpadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.Common.Configuration.Hid.Controller.Motion;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Gpu;
using Ryujinx.HLE.HOS.Services.Hid;
using System;
using System.Collections.Concurrent;
Expand Down Expand Up @@ -273,15 +274,21 @@ private void UpdateMotionInput(MotionConfigController motionConfig)
}
}

public void Update()
public bool Update()
{

// _gamepad may be altered by other threads
var gamepad = _gamepad;

if (gamepad != null && GamepadDriver != null)
{
State = gamepad.GetMappedStateSnapshot();

if (gamepad.SpecialExit())
{
return true;
}

if (_config is StandardControllerInputConfig controllerConfig && controllerConfig.Motion.EnableMotion)
{
if (controllerConfig.Motion.MotionBackend == MotionInputBackendType.GamepadDriver)
Expand Down Expand Up @@ -334,6 +341,7 @@ public void Update()
State = default;
_leftMotionInput = null;
}
return false;
}

public GamepadInput GetHLEInputState()
Expand Down
11 changes: 8 additions & 3 deletions src/Ryujinx.Input/HLE/NpadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ public void Initialize(Switch device, List<InputConfig> inputConfig, bool enable
ReloadConfiguration(inputConfig, enableKeyboard, enableMouse);
}

public void Update(float aspectRatio = 1)
public bool Update(float aspectRatio = 1)
{
bool specialExit = false;

lock (_lock)
{
List<GamepadInput> hleInputStates = new();
Expand All @@ -225,9 +227,10 @@ public void Update(float aspectRatio = 1)
DriverConfigurationUpdate(ref controller, inputConfig);

controller.UpdateUserConfiguration(inputConfig);
controller.Update();
controller.UpdateRumble(_device.Hid.Npads.GetRumbleQueue(playerIndex));

specialExit = controller.Update(); //hotkey press check
controller.UpdateRumble(_device.Hid.Npads.GetRumbleQueue(playerIndex));

inputState = controller.GetHLEInputState();

inputState.Buttons |= _device.Hid.UpdateStickButtons(inputState.LStick, inputState.RStick);
Expand Down Expand Up @@ -315,6 +318,8 @@ public void Update(float aspectRatio = 1)

_device.TamperMachine.UpdateInput(hleInputStates);
}

return specialExit;
}

internal InputConfig GetPlayerInputConfigByIndex(int index)
Expand Down
6 changes: 6 additions & 0 deletions src/Ryujinx.Input/IGamepad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public interface IGamepad : IDisposable
/// <returns>A remapped snaphost of the state of the gamepad.</returns>
GamepadStateSnapshot GetMappedStateSnapshot();

/// <summary>
/// Gets the state if the minus and plus buttons were pressed on the gamepad.
/// </summary>
/// <returns>returns true if the buttons were pressed.</returns>
bool SpecialExit();

/// <summary>
/// Get a snaphost of the state of the gamepad.
/// </summary>
Expand Down
30 changes: 26 additions & 4 deletions src/Ryujinx/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Ryujinx.Ava.UI.Models;
using Ryujinx.Ava.UI.Renderer;
using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Ava.UI.Views.Main;
using Ryujinx.Ava.UI.Windows;
using Ryujinx.Ava.Utilities;
using Ryujinx.Ava.Utilities.AppLibrary;
Expand Down Expand Up @@ -70,6 +71,7 @@ internal class AppHost
private const float MaxResolutionScale = 4.0f; // Max resolution hotkeys can scale to before wrapping.
private const int TargetFps = 60;
private const float VolumeDelta = 0.05f;
static bool SpecialExit = false;

private static readonly Cursor _invisibleCursor = new(StandardCursorType.None);
private readonly nint _invisibleCursorWin;
Expand All @@ -96,6 +98,7 @@ internal class AppHost
private bool _isCursorInRenderer = true;
private bool _ignoreCursorState = false;


private enum CursorStates
{
CursorIsHidden,
Expand Down Expand Up @@ -503,10 +506,15 @@ public void Start()
_viewModel.Volume = ConfigurationState.Instance.System.AudioVolume.Value;

MainLoop();

Exit();
}

public bool IsSpecialExit()
{
return SpecialExit;
}

private void UpdateIgnoreMissingServicesState(object sender, ReactiveEventArgs<bool> args)
{
if (Device != null)
Expand Down Expand Up @@ -589,6 +597,7 @@ private void Exit()

_isStopped = true;
Stop();

}

public void DisposeContext()
Expand Down Expand Up @@ -1023,12 +1032,12 @@ private void Window_BoundsChanged(object sender, Size e)
}

private void MainLoop()
{
{
while (UpdateFrame())
{
// Polling becomes expensive if it's not slept.
Thread.Sleep(1);
}

}

private void RenderLoop()
Expand Down Expand Up @@ -1135,6 +1144,7 @@ public void UpdateStatus()
string dockedMode = ConfigurationState.Instance.System.EnableDockedMode ? LocaleManager.Instance[LocaleKeys.Docked] : LocaleManager.Instance[LocaleKeys.Handheld];
string vSyncMode = Device.VSyncMode.ToString();


UpdateShaderCount();

if (GraphicsConfig.ResScale != 1)
Expand Down Expand Up @@ -1200,7 +1210,17 @@ private bool UpdateFrame()
return false;
}

NpadManager.Update(ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat());
if (NpadManager.Update(ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat()))
{
if (ConfigurationState.Instance.Hid.specialExitEmulator.Value == 1)
{
SpecialExit = true; // close App
}
if (ConfigurationState.Instance.Hid.specialExitEmulator.Value > 0)
{
_isActive = false; //close game
}
}

if (_viewModel.IsActive)
{
Expand Down Expand Up @@ -1335,6 +1355,8 @@ private bool UpdateFrame()

Device.Hid.DebugPad.Update();



return true;
}

Expand Down
Loading
Loading