2020-11-17 16:40:19 -05:00
|
|
|
|
using ARMeilleure.Translation;
|
|
|
|
|
using ARMeilleure.Translation.PTC;
|
2020-05-02 22:00:53 -04:00
|
|
|
|
using Gdk;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
|
using OpenTK.Input;
|
2021-03-02 17:45:33 -05:00
|
|
|
|
using Ryujinx.Common;
|
2020-08-02 10:41:24 -04:00
|
|
|
|
using Ryujinx.Common.Configuration;
|
2020-05-02 22:00:53 -04:00
|
|
|
|
using Ryujinx.Common.Configuration.Hid;
|
2020-12-15 21:19:07 -05:00
|
|
|
|
using Ryujinx.Configuration;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
using Ryujinx.Graphics.OpenGL;
|
2020-04-02 20:10:02 -04:00
|
|
|
|
using Ryujinx.HLE.HOS.Services.Hid;
|
2021-01-08 03:14:13 -05:00
|
|
|
|
using Ryujinx.Modules.Motion;
|
|
|
|
|
using Ryujinx.Ui.Widgets;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-03-02 17:45:33 -05:00
|
|
|
|
using System.Diagnostics;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Ui
|
|
|
|
|
{
|
2021-03-02 17:45:33 -05:00
|
|
|
|
using Switch = HLE.Switch;
|
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
public class GlRenderer : GLWidget
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
Memory Read/Write Tracking using Region Handles (#1272)
* WIP Range Tracking
- Texture invalidation seems to have large problems
- Buffer/Pool invalidation may have problems
- Mirror memory tracking puts an additional `add` in compiled code, we likely just want to make HLE access slower if this is the final solution.
- Native project is in the messiest possible location.
- [HACK] JIT memory access always uses native "fast" path
- [HACK] Trying some things with texture invalidation and views.
It works :)
Still a few hacks, messy things, slow things
More work in progress stuff (also move to memory project)
Quite a bit faster now.
- Unmapping GPU VA and CPU VA will now correctly update write tracking regions, and invalidate textures for the former.
- The Virtual range list is now non-overlapping like the physical one.
- Fixed some bugs where regions could leak.
- Introduced a weird bug that I still need to track down (consistent invalid buffer in MK8 ribbon road)
Move some stuff.
I think we'll eventually just put the dll and so for this in a nuget package.
Fix rebase.
[WIP] MultiRegionHandle variable size ranges
- Avoid reprotecting regions that change often (needs some tweaking)
- There's still a bug in buffers, somehow.
- Might want different api for minimum granularity
Fix rebase issue
Commit everything needed for software only tracking.
Remove native components.
Remove more native stuff.
Cleanup
Use a separate window for the background context, update opentk. (fixes linux)
Some experimental changes
Should get things working up to scratch - still need to try some things with flush/modification and res scale.
Include address with the region action.
Initial work to make range tracking work
Still a ton of bugs
Fix some issues with the new stuff.
* Fix texture flush instability
There's still some weird behaviour, but it's much improved without this. (textures with cpu modified data were flushing over it)
* Find the destination texture for Buffer->Texture full copy
Greatly improves performance for nvdec videos (with range tracking)
* Further improve texture tracking
* Disable Memory Tracking for view parents
This is a temporary approach to better match behaviour on master (where invalidations would be soaked up by views, rather than trigger twice)
The assumption is that when views are created to a texture, they will cover all of its data anyways. Of course, this can easily be improved in future.
* Introduce some tracking tests.
WIP
* Complete base tests.
* Add more tests for multiregion, fix existing test.
* Cleanup Part 1
* Remove unnecessary code from memory tracking
* Fix some inconsistencies with 3D texture rule.
* Add dispose tests.
* Use a background thread for the background context.
Rather than setting and unsetting a context as current, doing the work on a dedicated thread with signals seems to be a bit faster.
Also nerf the multithreading test a bit.
* Copy to texture with matching alignment
This extends the copy to work for some videos with unusual size, such as tutorial videos in SMO. It will only occur if the destination texture already exists at XCount size.
* Track reads for buffer copies. Synchronize new buffers before copying overlaps.
* Remove old texture flushing mechanisms.
Range tracking all the way, baby.
* Wake the background thread when disposing.
Avoids a deadlock when games are closed.
* Address Feedback 1
* Separate TextureCopy instance for background thread
Also `BackgroundContextWorker.InBackground` for a more sensible idenfifier for if we're in a background thread.
* Add missing XML docs.
* Address Feedback
* Maybe I should start drinking coffee.
* Some more feedback.
* Remove flush warning, Refocus window after making background context
2020-10-16 16:18:35 -04:00
|
|
|
|
static GlRenderer()
|
|
|
|
|
{
|
|
|
|
|
OpenTK.Graphics.GraphicsContext.ShareContexts = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
private const int SwitchPanelWidth = 1280;
|
2020-02-18 06:34:57 -05:00
|
|
|
|
private const int SwitchPanelHeight = 720;
|
2020-05-02 22:00:53 -04:00
|
|
|
|
private const int TargetFps = 60;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
public ManualResetEvent WaitEvent { get; set; }
|
|
|
|
|
|
2020-03-06 21:40:06 -05:00
|
|
|
|
public static event EventHandler<StatusUpdatedEventArgs> StatusUpdatedEvent;
|
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
|
private bool _isActive;
|
|
|
|
|
private bool _isStopped;
|
|
|
|
|
private bool _isFocused;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
private double _mouseX;
|
|
|
|
|
private double _mouseY;
|
2020-05-02 22:00:53 -04:00
|
|
|
|
private bool _mousePressed;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
private bool _toggleFullscreen;
|
2020-11-18 18:15:44 -05:00
|
|
|
|
private bool _toggleDockedMode;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
private readonly long _ticksPerFrame;
|
|
|
|
|
|
|
|
|
|
private long _ticks = 0;
|
|
|
|
|
|
2021-03-02 17:45:33 -05:00
|
|
|
|
private readonly Stopwatch _chrono;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
|
private readonly Switch _device;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
private Renderer _renderer;
|
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
private HotkeyButtons _prevHotkeyButtons;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-09-29 17:32:42 -04:00
|
|
|
|
private Client _dsuClient;
|
|
|
|
|
|
2020-08-02 10:41:24 -04:00
|
|
|
|
private GraphicsDebugLevel _glLogLevel;
|
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
|
private readonly ManualResetEvent _exitEvent;
|
2021-02-15 16:48:21 -05:00
|
|
|
|
|
2021-03-02 17:45:33 -05:00
|
|
|
|
// Hide Cursor
|
|
|
|
|
const int CursorHideIdleTime = 8; // seconds
|
|
|
|
|
private static readonly Cursor _invisibleCursor = new Cursor(Display.Default, CursorType.BlankCursor);
|
|
|
|
|
private long _lastCursorMoveTime;
|
|
|
|
|
private bool _hideCursorOnIdle;
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
2020-08-02 10:41:24 -04:00
|
|
|
|
public GlRenderer(Switch device, GraphicsDebugLevel glLogLevel)
|
2020-03-14 17:36:56 -04:00
|
|
|
|
: base (GetGraphicsMode(),
|
2020-02-18 06:34:57 -05:00
|
|
|
|
3, 3,
|
2020-12-01 18:23:43 -05:00
|
|
|
|
glLogLevel == GraphicsDebugLevel.None
|
|
|
|
|
? GraphicsContextFlags.ForwardCompatible
|
2020-08-02 10:41:24 -04:00
|
|
|
|
: GraphicsContextFlags.ForwardCompatible | GraphicsContextFlags.Debug)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
|
|
|
|
WaitEvent = new ManualResetEvent(false);
|
|
|
|
|
|
|
|
|
|
_device = device;
|
|
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
|
Initialized += GLRenderer_Initialized;
|
|
|
|
|
Destroyed += GLRenderer_Destroyed;
|
|
|
|
|
ShuttingDown += GLRenderer_ShuttingDown;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
Initialize();
|
|
|
|
|
|
2021-03-02 17:45:33 -05:00
|
|
|
|
_chrono = new Stopwatch();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2021-03-02 17:45:33 -05:00
|
|
|
|
_ticksPerFrame = Stopwatch.Frequency / TargetFps;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
AddEvents((int)(EventMask.ButtonPressMask
|
|
|
|
|
| EventMask.ButtonReleaseMask
|
|
|
|
|
| EventMask.PointerMotionMask
|
|
|
|
|
| EventMask.KeyPressMask
|
|
|
|
|
| EventMask.KeyReleaseMask));
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
|
Shown += Renderer_Shown;
|
2020-08-02 10:41:24 -04:00
|
|
|
|
|
2020-09-29 17:32:42 -04:00
|
|
|
|
_dsuClient = new Client();
|
|
|
|
|
|
2020-08-02 10:41:24 -04:00
|
|
|
|
_glLogLevel = glLogLevel;
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
|
|
|
|
_exitEvent = new ManualResetEvent(false);
|
2021-03-02 17:45:33 -05:00
|
|
|
|
|
|
|
|
|
_hideCursorOnIdle = ConfigurationState.Instance.HideCursorOnIdle;
|
|
|
|
|
_lastCursorMoveTime = Stopwatch.GetTimestamp();
|
|
|
|
|
|
|
|
|
|
ConfigurationState.Instance.HideCursorOnIdle.Event += HideCursorStateChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HideCursorStateChanged(object sender, ReactiveEventArgs<bool> state)
|
|
|
|
|
{
|
|
|
|
|
Gtk.Application.Invoke(delegate
|
|
|
|
|
{
|
|
|
|
|
_hideCursorOnIdle = state.NewValue;
|
|
|
|
|
|
|
|
|
|
if (_hideCursorOnIdle)
|
|
|
|
|
{
|
|
|
|
|
_lastCursorMoveTime = Stopwatch.GetTimestamp();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Window.Cursor = null;
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-14 17:36:56 -04:00
|
|
|
|
private static GraphicsMode GetGraphicsMode()
|
|
|
|
|
{
|
2020-05-02 22:00:53 -04:00
|
|
|
|
return Environment.OSVersion.Platform == PlatformID.Unix ? new GraphicsMode(new ColorFormat(24)) : new GraphicsMode(new ColorFormat());
|
2020-03-14 17:36:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-13 12:43:29 -05:00
|
|
|
|
private void GLRenderer_ShuttingDown(object sender, EventArgs args)
|
|
|
|
|
{
|
2020-02-14 05:52:34 -05:00
|
|
|
|
_device.DisposeGpu();
|
2020-09-29 17:32:42 -04:00
|
|
|
|
_dsuClient?.Dispose();
|
2020-02-13 12:43:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 19:56:19 -05:00
|
|
|
|
private void Parent_FocusOutEvent(object o, Gtk.FocusOutEventArgs args)
|
|
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
|
_isFocused = false;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Parent_FocusInEvent(object o, Gtk.FocusInEventArgs args)
|
|
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
|
_isFocused = true;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GLRenderer_Destroyed(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-03-02 17:45:33 -05:00
|
|
|
|
ConfigurationState.Instance.HideCursorOnIdle.Event -= HideCursorStateChanged;
|
|
|
|
|
|
2020-09-29 17:32:42 -04:00
|
|
|
|
_dsuClient?.Dispose();
|
2020-02-13 12:43:29 -05:00
|
|
|
|
Dispose();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void Renderer_Shown(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
|
_isFocused = this.ParentWindow.State.HasFlag(Gdk.WindowState.Focused);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HandleScreenState(KeyboardState keyboard)
|
|
|
|
|
{
|
2020-05-02 22:00:53 -04:00
|
|
|
|
bool toggleFullscreen = keyboard.IsKeyDown(OpenTK.Input.Key.F11)
|
2020-02-18 06:34:57 -05:00
|
|
|
|
|| ((keyboard.IsKeyDown(OpenTK.Input.Key.AltLeft)
|
|
|
|
|
|| keyboard.IsKeyDown(OpenTK.Input.Key.AltRight))
|
2020-02-13 12:43:29 -05:00
|
|
|
|
&& keyboard.IsKeyDown(OpenTK.Input.Key.Enter))
|
2020-05-02 22:00:53 -04:00
|
|
|
|
|| keyboard.IsKeyDown(OpenTK.Input.Key.Escape);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-02-13 12:43:29 -05:00
|
|
|
|
bool fullScreenToggled = ParentWindow.State.HasFlag(Gdk.WindowState.Fullscreen);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-02-13 12:43:29 -05:00
|
|
|
|
if (toggleFullscreen != _toggleFullscreen)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
2020-02-13 12:43:29 -05:00
|
|
|
|
if (toggleFullscreen)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
2020-02-13 12:43:29 -05:00
|
|
|
|
if (fullScreenToggled)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
2020-02-13 12:43:29 -05:00
|
|
|
|
ParentWindow.Unfullscreen();
|
|
|
|
|
(Toplevel as MainWindow)?.ToggleExtraWidgets(true);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
2020-02-13 12:43:29 -05:00
|
|
|
|
else
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
2020-02-13 12:43:29 -05:00
|
|
|
|
if (keyboard.IsKeyDown(OpenTK.Input.Key.Escape))
|
|
|
|
|
{
|
2021-01-14 17:30:52 -05:00
|
|
|
|
if (!ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
|
2020-03-29 08:47:37 -04:00
|
|
|
|
{
|
|
|
|
|
Exit();
|
|
|
|
|
}
|
2020-02-13 12:43:29 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ParentWindow.Fullscreen();
|
|
|
|
|
(Toplevel as MainWindow)?.ToggleExtraWidgets(false);
|
|
|
|
|
}
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-13 12:43:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_toggleFullscreen = toggleFullscreen;
|
2020-11-18 18:15:44 -05:00
|
|
|
|
|
|
|
|
|
bool toggleDockedMode = keyboard.IsKeyDown(OpenTK.Input.Key.F9);
|
|
|
|
|
|
|
|
|
|
if (toggleDockedMode != _toggleDockedMode)
|
|
|
|
|
{
|
|
|
|
|
if (toggleDockedMode)
|
|
|
|
|
{
|
|
|
|
|
ConfigurationState.Instance.System.EnableDockedMode.Value =
|
|
|
|
|
!ConfigurationState.Instance.System.EnableDockedMode.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_toggleDockedMode = toggleDockedMode;
|
2021-03-02 17:45:33 -05:00
|
|
|
|
|
|
|
|
|
if (_hideCursorOnIdle)
|
|
|
|
|
{
|
|
|
|
|
long cursorMoveDelta = Stopwatch.GetTimestamp() - _lastCursorMoveTime;
|
|
|
|
|
Window.Cursor = (cursorMoveDelta >= CursorHideIdleTime * Stopwatch.Frequency) ? _invisibleCursor : null;
|
|
|
|
|
}
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GLRenderer_Initialized(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-02-14 05:52:34 -05:00
|
|
|
|
// Release the GL exclusivity that OpenTK gave us as we aren't going to use it in GTK Thread.
|
2020-02-11 19:56:19 -05:00
|
|
|
|
GraphicsContext.MakeCurrent(null);
|
|
|
|
|
|
|
|
|
|
WaitEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnConfigureEvent(EventConfigure evnt)
|
|
|
|
|
{
|
2020-05-02 22:00:53 -04:00
|
|
|
|
bool result = base.OnConfigureEvent(evnt);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-02-18 06:34:57 -05:00
|
|
|
|
Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
|
|
|
|
|
|
|
|
|
|
_renderer.Window.SetSize(evnt.Width * monitor.ScaleFactor, evnt.Height * monitor.ScaleFactor);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
IsRenderHandler = true;
|
|
|
|
|
|
|
|
|
|
_chrono.Restart();
|
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
|
_isActive = true;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
Gtk.Window parent = this.Toplevel as Gtk.Window;
|
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
parent.FocusInEvent += Parent_FocusInEvent;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
parent.FocusOutEvent += Parent_FocusOutEvent;
|
|
|
|
|
|
|
|
|
|
Gtk.Application.Invoke(delegate
|
|
|
|
|
{
|
|
|
|
|
parent.Present();
|
2020-11-17 16:40:19 -05:00
|
|
|
|
|
|
|
|
|
string titleNameSection = string.IsNullOrWhiteSpace(_device.Application.TitleName) ? string.Empty
|
|
|
|
|
: $" - {_device.Application.TitleName}";
|
|
|
|
|
|
|
|
|
|
string titleVersionSection = string.IsNullOrWhiteSpace(_device.Application.DisplayVersion) ? string.Empty
|
|
|
|
|
: $" v{_device.Application.DisplayVersion}";
|
|
|
|
|
|
|
|
|
|
string titleIdSection = string.IsNullOrWhiteSpace(_device.Application.TitleIdText) ? string.Empty
|
|
|
|
|
: $" ({_device.Application.TitleIdText.ToUpper()})";
|
|
|
|
|
|
|
|
|
|
string titleArchSection = _device.Application.TitleIs64Bit ? " (64-bit)" : " (32-bit)";
|
|
|
|
|
|
|
|
|
|
parent.Title = $"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}";
|
2020-02-11 19:56:19 -05:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Thread renderLoopThread = new Thread(Render)
|
|
|
|
|
{
|
|
|
|
|
Name = "GUI.RenderLoop"
|
|
|
|
|
};
|
|
|
|
|
renderLoopThread.Start();
|
|
|
|
|
|
2020-12-09 17:36:08 -05:00
|
|
|
|
Thread nvStutterWorkaround = new Thread(NVStutterWorkaround)
|
|
|
|
|
{
|
|
|
|
|
Name = "GUI.NVStutterWorkaround"
|
|
|
|
|
};
|
|
|
|
|
nvStutterWorkaround.Start();
|
|
|
|
|
|
2020-02-11 19:56:19 -05:00
|
|
|
|
MainLoop();
|
|
|
|
|
|
|
|
|
|
renderLoopThread.Join();
|
2020-12-09 17:36:08 -05:00
|
|
|
|
nvStutterWorkaround.Join();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
Exit();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 17:36:08 -05:00
|
|
|
|
private void NVStutterWorkaround()
|
|
|
|
|
{
|
|
|
|
|
while (_isActive)
|
|
|
|
|
{
|
|
|
|
|
// When NVIDIA Threaded Optimization is on, the driver will snapshot all threads in the system whenever the application creates any new ones.
|
|
|
|
|
// The ThreadPool has something called a "GateThread" which terminates itself after some inactivity.
|
|
|
|
|
// However, it immediately starts up again, since the rules regarding when to terminate and when to start differ.
|
|
|
|
|
// This creates a new thread every second or so.
|
|
|
|
|
// The main problem with this is that the thread snapshot can take 70ms, is on the OpenGL thread and will delay rendering any graphics.
|
|
|
|
|
// This is a little over budget on a frame time of 16ms, so creates a large stutter.
|
|
|
|
|
// The solution is to keep the ThreadPool active so that it never has a reason to terminate the GateThread.
|
|
|
|
|
|
|
|
|
|
// TODO: This should be removed when the issue with the GateThread is resolved.
|
|
|
|
|
|
|
|
|
|
ThreadPool.QueueUserWorkItem((state) => { });
|
|
|
|
|
Thread.Sleep(300);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 19:56:19 -05:00
|
|
|
|
protected override bool OnButtonPressEvent(EventButton evnt)
|
|
|
|
|
{
|
|
|
|
|
_mouseX = evnt.X;
|
|
|
|
|
_mouseY = evnt.Y;
|
|
|
|
|
|
|
|
|
|
if (evnt.Button == 1)
|
|
|
|
|
{
|
|
|
|
|
_mousePressed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnButtonReleaseEvent(EventButton evnt)
|
|
|
|
|
{
|
|
|
|
|
if (evnt.Button == 1)
|
|
|
|
|
{
|
|
|
|
|
_mousePressed = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMotionNotifyEvent(EventMotion evnt)
|
|
|
|
|
{
|
|
|
|
|
if (evnt.Device.InputSource == InputSource.Mouse)
|
|
|
|
|
{
|
|
|
|
|
_mouseX = evnt.X;
|
|
|
|
|
_mouseY = evnt.Y;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 17:45:33 -05:00
|
|
|
|
if (_hideCursorOnIdle)
|
|
|
|
|
{
|
|
|
|
|
_lastCursorMoveTime = Stopwatch.GetTimestamp();
|
|
|
|
|
}
|
2021-02-15 16:48:21 -05:00
|
|
|
|
|
2020-02-11 19:56:19 -05:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 06:34:57 -05:00
|
|
|
|
protected override void OnGetPreferredHeight(out int minimumHeight, out int naturalHeight)
|
|
|
|
|
{
|
|
|
|
|
Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
|
|
|
|
|
|
|
|
|
|
// If the monitor is at least 1080p, use the Switch panel size as minimal size.
|
|
|
|
|
if (monitor.Geometry.Height >= 1080)
|
|
|
|
|
{
|
|
|
|
|
minimumHeight = SwitchPanelHeight;
|
|
|
|
|
}
|
|
|
|
|
// Otherwise, we default minimal size to 480p 16:9.
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
minimumHeight = 480;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
naturalHeight = minimumHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnGetPreferredWidth(out int minimumWidth, out int naturalWidth)
|
|
|
|
|
{
|
|
|
|
|
Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
|
|
|
|
|
|
|
|
|
|
// If the monitor is at least 1080p, use the Switch panel size as minimal size.
|
|
|
|
|
if (monitor.Geometry.Height >= 1080)
|
|
|
|
|
{
|
|
|
|
|
minimumWidth = SwitchPanelWidth;
|
|
|
|
|
}
|
|
|
|
|
// Otherwise, we default minimal size to 480p 16:9.
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
minimumWidth = 854;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
naturalWidth = minimumWidth;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 19:56:19 -05:00
|
|
|
|
public void Exit()
|
|
|
|
|
{
|
2020-09-29 17:32:42 -04:00
|
|
|
|
_dsuClient?.Dispose();
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
|
|
|
|
if (_isStopped)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
|
_isStopped = true;
|
|
|
|
|
_isActive = false;
|
|
|
|
|
|
|
|
|
|
_exitEvent.WaitOne();
|
|
|
|
|
_exitEvent.Dispose();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
|
|
|
|
if (!(_device.Gpu.Renderer is Renderer))
|
|
|
|
|
{
|
2020-11-12 18:15:34 -05:00
|
|
|
|
throw new NotSupportedException($"GPU renderer must be an OpenGL renderer when using {typeof(Renderer).Name}!");
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_renderer = (Renderer)_device.Gpu.Renderer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Render()
|
|
|
|
|
{
|
2020-02-14 05:52:34 -05:00
|
|
|
|
// First take exclusivity on the OpenGL context.
|
Memory Read/Write Tracking using Region Handles (#1272)
* WIP Range Tracking
- Texture invalidation seems to have large problems
- Buffer/Pool invalidation may have problems
- Mirror memory tracking puts an additional `add` in compiled code, we likely just want to make HLE access slower if this is the final solution.
- Native project is in the messiest possible location.
- [HACK] JIT memory access always uses native "fast" path
- [HACK] Trying some things with texture invalidation and views.
It works :)
Still a few hacks, messy things, slow things
More work in progress stuff (also move to memory project)
Quite a bit faster now.
- Unmapping GPU VA and CPU VA will now correctly update write tracking regions, and invalidate textures for the former.
- The Virtual range list is now non-overlapping like the physical one.
- Fixed some bugs where regions could leak.
- Introduced a weird bug that I still need to track down (consistent invalid buffer in MK8 ribbon road)
Move some stuff.
I think we'll eventually just put the dll and so for this in a nuget package.
Fix rebase.
[WIP] MultiRegionHandle variable size ranges
- Avoid reprotecting regions that change often (needs some tweaking)
- There's still a bug in buffers, somehow.
- Might want different api for minimum granularity
Fix rebase issue
Commit everything needed for software only tracking.
Remove native components.
Remove more native stuff.
Cleanup
Use a separate window for the background context, update opentk. (fixes linux)
Some experimental changes
Should get things working up to scratch - still need to try some things with flush/modification and res scale.
Include address with the region action.
Initial work to make range tracking work
Still a ton of bugs
Fix some issues with the new stuff.
* Fix texture flush instability
There's still some weird behaviour, but it's much improved without this. (textures with cpu modified data were flushing over it)
* Find the destination texture for Buffer->Texture full copy
Greatly improves performance for nvdec videos (with range tracking)
* Further improve texture tracking
* Disable Memory Tracking for view parents
This is a temporary approach to better match behaviour on master (where invalidations would be soaked up by views, rather than trigger twice)
The assumption is that when views are created to a texture, they will cover all of its data anyways. Of course, this can easily be improved in future.
* Introduce some tracking tests.
WIP
* Complete base tests.
* Add more tests for multiregion, fix existing test.
* Cleanup Part 1
* Remove unnecessary code from memory tracking
* Fix some inconsistencies with 3D texture rule.
* Add dispose tests.
* Use a background thread for the background context.
Rather than setting and unsetting a context as current, doing the work on a dedicated thread with signals seems to be a bit faster.
Also nerf the multithreading test a bit.
* Copy to texture with matching alignment
This extends the copy to work for some videos with unusual size, such as tutorial videos in SMO. It will only occur if the destination texture already exists at XCount size.
* Track reads for buffer copies. Synchronize new buffers before copying overlaps.
* Remove old texture flushing mechanisms.
Range tracking all the way, baby.
* Wake the background thread when disposing.
Avoids a deadlock when games are closed.
* Address Feedback 1
* Separate TextureCopy instance for background thread
Also `BackgroundContextWorker.InBackground` for a more sensible idenfifier for if we're in a background thread.
* Add missing XML docs.
* Address Feedback
* Maybe I should start drinking coffee.
* Some more feedback.
* Remove flush warning, Refocus window after making background context
2020-10-16 16:18:35 -04:00
|
|
|
|
_renderer.InitializeBackgroundContext(GraphicsContext);
|
|
|
|
|
Gtk.Window parent = Toplevel as Gtk.Window;
|
|
|
|
|
parent.Present();
|
2020-02-14 05:52:34 -05:00
|
|
|
|
GraphicsContext.MakeCurrent(WindowInfo);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-11-17 16:40:19 -05:00
|
|
|
|
_device.Gpu.Renderer.Initialize(_glLogLevel);
|
2020-02-14 05:52:34 -05:00
|
|
|
|
|
|
|
|
|
// Make sure the first frame is not transparent.
|
|
|
|
|
GL.ClearColor(OpenTK.Color.Black);
|
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
|
|
|
|
SwapBuffers();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-11-17 16:40:19 -05:00
|
|
|
|
_device.Gpu.InitializeShaderCache();
|
|
|
|
|
Translator.IsReadyForTranslation.Set();
|
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
|
while (_isActive)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
|
if (_isStopped)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-14 05:52:34 -05:00
|
|
|
|
_ticks += _chrono.ElapsedTicks;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-02-14 05:52:34 -05:00
|
|
|
|
_chrono.Restart();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-02-14 05:52:34 -05:00
|
|
|
|
if (_device.WaitFifo())
|
|
|
|
|
{
|
2020-10-13 16:54:42 -04:00
|
|
|
|
_device.Statistics.RecordFifoStart();
|
2020-02-14 05:52:34 -05:00
|
|
|
|
_device.ProcessFrame();
|
2020-10-13 16:54:42 -04:00
|
|
|
|
_device.Statistics.RecordFifoEnd();
|
2020-02-14 05:52:34 -05:00
|
|
|
|
}
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-12-17 13:39:52 -05:00
|
|
|
|
while (_device.ConsumeFrameAvailable())
|
2020-07-06 22:41:07 -04:00
|
|
|
|
{
|
2020-12-17 13:39:52 -05:00
|
|
|
|
_device.PresentFrame(SwapBuffers);
|
2020-07-06 22:41:07 -04:00
|
|
|
|
}
|
2020-05-04 18:10:01 -04:00
|
|
|
|
|
2020-02-14 05:52:34 -05:00
|
|
|
|
if (_ticks >= _ticksPerFrame)
|
|
|
|
|
{
|
2020-12-17 13:39:52 -05:00
|
|
|
|
string dockedMode = ConfigurationState.Instance.System.EnableDockedMode ? "Docked" : "Handheld";
|
|
|
|
|
float scale = Graphics.Gpu.GraphicsConfig.ResScale;
|
|
|
|
|
if (scale != 1)
|
|
|
|
|
{
|
|
|
|
|
dockedMode += $" ({scale}x)";
|
|
|
|
|
}
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-03-06 21:40:06 -05:00
|
|
|
|
StatusUpdatedEvent?.Invoke(this, new StatusUpdatedEventArgs(
|
2020-05-04 18:10:01 -04:00
|
|
|
|
_device.EnableDeviceVsync,
|
|
|
|
|
dockedMode,
|
2020-12-15 21:19:07 -05:00
|
|
|
|
ConfigurationState.Instance.Graphics.AspectRatio.Value.ToText(),
|
2020-03-24 17:54:09 -04:00
|
|
|
|
$"Game: {_device.Statistics.GetGameFrameRate():00.00} FPS",
|
2020-10-13 16:54:42 -04:00
|
|
|
|
$"FIFO: {_device.Statistics.GetFifoPercent():0.00} %",
|
2020-05-02 22:00:53 -04:00
|
|
|
|
$"GPU: {_renderer.GpuVendor}"));
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-02-14 05:52:34 -05:00
|
|
|
|
_ticks = Math.Min(_ticks - _ticksPerFrame, _ticksPerFrame);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SwapBuffers()
|
|
|
|
|
{
|
|
|
|
|
OpenTK.Graphics.GraphicsContext.CurrentContext.SwapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MainLoop()
|
|
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
|
while (_isActive)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
2020-02-15 06:30:53 -05:00
|
|
|
|
UpdateFrame();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
// Polling becomes expensive if it's not slept
|
|
|
|
|
Thread.Sleep(1);
|
|
|
|
|
}
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
|
|
|
|
_exitEvent.Set();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool UpdateFrame()
|
|
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
|
if (!_isActive)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
|
if (_isStopped)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
|
if (_isFocused)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
2020-02-15 06:30:53 -05:00
|
|
|
|
Gtk.Application.Invoke(delegate
|
|
|
|
|
{
|
2020-06-16 14:28:02 -04:00
|
|
|
|
KeyboardState keyboard = OpenTK.Input.Keyboard.GetState();
|
|
|
|
|
|
|
|
|
|
HandleScreenState(keyboard);
|
|
|
|
|
|
|
|
|
|
if (keyboard.IsKeyDown(OpenTK.Input.Key.Delete))
|
|
|
|
|
{
|
|
|
|
|
if (!ParentWindow.State.HasFlag(Gdk.WindowState.Fullscreen))
|
|
|
|
|
{
|
|
|
|
|
Ptc.Continue();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-15 06:30:53 -05:00
|
|
|
|
});
|
2020-05-02 22:00:53 -04:00
|
|
|
|
}
|
2020-02-15 06:30:53 -05:00
|
|
|
|
|
2020-08-23 16:54:11 -04:00
|
|
|
|
List<GamepadInput> gamepadInputs = new List<GamepadInput>(NpadDevices.MaxControllers);
|
2020-09-29 17:32:42 -04:00
|
|
|
|
List<SixAxisInput> motionInputs = new List<SixAxisInput>(NpadDevices.MaxControllers);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-09-29 17:32:42 -04:00
|
|
|
|
MotionDevice motionDevice = new MotionDevice(_dsuClient);
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
2020-08-23 16:54:11 -04:00
|
|
|
|
foreach (InputConfig inputConfig in ConfigurationState.Instance.Hid.InputConfig.Value)
|
2020-05-02 22:00:53 -04:00
|
|
|
|
{
|
|
|
|
|
ControllerKeys currentButton = 0;
|
|
|
|
|
JoystickPosition leftJoystick = new JoystickPosition();
|
|
|
|
|
JoystickPosition rightJoystick = new JoystickPosition();
|
|
|
|
|
KeyboardInput? hidKeyboard = null;
|
|
|
|
|
|
|
|
|
|
int leftJoystickDx = 0;
|
|
|
|
|
int leftJoystickDy = 0;
|
|
|
|
|
int rightJoystickDx = 0;
|
|
|
|
|
int rightJoystickDy = 0;
|
|
|
|
|
|
2020-09-29 17:32:42 -04:00
|
|
|
|
if (inputConfig.EnableMotion)
|
|
|
|
|
{
|
|
|
|
|
motionDevice.RegisterController(inputConfig.PlayerIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
if (inputConfig is KeyboardConfig keyboardConfig)
|
2020-02-15 06:30:53 -05:00
|
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
|
if (_isFocused)
|
2020-05-02 22:00:53 -04:00
|
|
|
|
{
|
|
|
|
|
// Keyboard Input
|
|
|
|
|
KeyboardController keyboardController = new KeyboardController(keyboardConfig);
|
2020-02-15 06:30:53 -05:00
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
currentButton = keyboardController.GetButtons();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
(leftJoystickDx, leftJoystickDy) = keyboardController.GetLeftStick();
|
|
|
|
|
(rightJoystickDx, rightJoystickDy) = keyboardController.GetRightStick();
|
|
|
|
|
|
|
|
|
|
leftJoystick = new JoystickPosition
|
|
|
|
|
{
|
|
|
|
|
Dx = leftJoystickDx,
|
|
|
|
|
Dy = leftJoystickDy
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
rightJoystick = new JoystickPosition
|
|
|
|
|
{
|
|
|
|
|
Dx = rightJoystickDx,
|
|
|
|
|
Dy = rightJoystickDy
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (ConfigurationState.Instance.Hid.EnableKeyboard)
|
|
|
|
|
{
|
|
|
|
|
hidKeyboard = keyboardController.GetKeysDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hidKeyboard.HasValue)
|
|
|
|
|
{
|
|
|
|
|
hidKeyboard = new KeyboardInput
|
|
|
|
|
{
|
|
|
|
|
Modifier = 0,
|
|
|
|
|
Keys = new int[0x8]
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ConfigurationState.Instance.Hid.EnableKeyboard)
|
|
|
|
|
{
|
|
|
|
|
_device.Hid.Keyboard.Update(hidKeyboard.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (inputConfig is Common.Configuration.Hid.ControllerConfig controllerConfig)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
2020-05-02 22:00:53 -04:00
|
|
|
|
// Controller Input
|
|
|
|
|
JoystickController joystickController = new JoystickController(controllerConfig);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
currentButton |= joystickController.GetButtons();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
(leftJoystickDx, leftJoystickDy) = joystickController.GetLeftStick();
|
|
|
|
|
(rightJoystickDx, rightJoystickDy) = joystickController.GetRightStick();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
leftJoystick = new JoystickPosition
|
|
|
|
|
{
|
|
|
|
|
Dx = controllerConfig.LeftJoycon.InvertStickX ? -leftJoystickDx : leftJoystickDx,
|
|
|
|
|
Dy = controllerConfig.LeftJoycon.InvertStickY ? -leftJoystickDy : leftJoystickDy
|
|
|
|
|
};
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
rightJoystick = new JoystickPosition
|
|
|
|
|
{
|
|
|
|
|
Dx = controllerConfig.RightJoycon.InvertStickX ? -rightJoystickDx : rightJoystickDx,
|
|
|
|
|
Dy = controllerConfig.RightJoycon.InvertStickY ? -rightJoystickDy : rightJoystickDy
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
currentButton |= _device.Hid.UpdateStickButtons(leftJoystick, rightJoystick);
|
|
|
|
|
|
2020-10-28 15:52:07 -04:00
|
|
|
|
motionDevice.Poll(inputConfig, inputConfig.Slot);
|
2020-09-29 17:32:42 -04:00
|
|
|
|
|
|
|
|
|
SixAxisInput sixAxisInput = new SixAxisInput()
|
|
|
|
|
{
|
|
|
|
|
PlayerId = (HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex,
|
|
|
|
|
Accelerometer = motionDevice.Accelerometer,
|
|
|
|
|
Gyroscope = motionDevice.Gyroscope,
|
|
|
|
|
Rotation = motionDevice.Rotation,
|
|
|
|
|
Orientation = motionDevice.Orientation
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
motionInputs.Add(sixAxisInput);
|
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
gamepadInputs.Add(new GamepadInput
|
|
|
|
|
{
|
|
|
|
|
PlayerId = (HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex,
|
|
|
|
|
Buttons = currentButton,
|
|
|
|
|
LStick = leftJoystick,
|
|
|
|
|
RStick = rightJoystick
|
|
|
|
|
});
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-09-29 17:32:42 -04:00
|
|
|
|
if (inputConfig.ControllerType == Common.Configuration.Hid.ControllerType.JoyconPair)
|
|
|
|
|
{
|
|
|
|
|
if (!inputConfig.MirrorInput)
|
|
|
|
|
{
|
2020-10-28 15:52:07 -04:00
|
|
|
|
motionDevice.Poll(inputConfig, inputConfig.AltSlot);
|
2020-09-29 17:32:42 -04:00
|
|
|
|
|
|
|
|
|
sixAxisInput = new SixAxisInput()
|
|
|
|
|
{
|
|
|
|
|
PlayerId = (HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex,
|
|
|
|
|
Accelerometer = motionDevice.Accelerometer,
|
|
|
|
|
Gyroscope = motionDevice.Gyroscope,
|
|
|
|
|
Rotation = motionDevice.Rotation,
|
|
|
|
|
Orientation = motionDevice.Orientation
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
motionInputs.Add(sixAxisInput);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
2020-08-23 16:54:11 -04:00
|
|
|
|
_device.Hid.Npads.Update(gamepadInputs);
|
2020-09-29 17:32:42 -04:00
|
|
|
|
_device.Hid.Npads.UpdateSixAxis(motionInputs);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
|
if(_isFocused)
|
2020-06-26 06:30:16 -04:00
|
|
|
|
{
|
2020-08-23 16:54:11 -04:00
|
|
|
|
// Hotkeys
|
|
|
|
|
HotkeyButtons currentHotkeyButtons = KeyboardController.GetHotkeyButtons(OpenTK.Input.Keyboard.GetState());
|
|
|
|
|
|
|
|
|
|
if (currentHotkeyButtons.HasFlag(HotkeyButtons.ToggleVSync) &&
|
|
|
|
|
!_prevHotkeyButtons.HasFlag(HotkeyButtons.ToggleVSync))
|
|
|
|
|
{
|
|
|
|
|
_device.EnableDeviceVsync = !_device.EnableDeviceVsync;
|
|
|
|
|
}
|
2020-06-26 06:30:16 -04:00
|
|
|
|
|
2020-08-23 16:54:11 -04:00
|
|
|
|
_prevHotkeyButtons = currentHotkeyButtons;
|
|
|
|
|
}
|
2020-06-26 06:30:16 -04:00
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
//Touchscreen
|
2020-02-11 19:56:19 -05:00
|
|
|
|
bool hasTouch = false;
|
|
|
|
|
|
|
|
|
|
// Get screen touch position from left mouse click
|
|
|
|
|
// OpenTK always captures mouse events, even if out of focus, so check if window is focused.
|
2020-12-01 18:23:43 -05:00
|
|
|
|
if (_isFocused && _mousePressed)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
2020-12-15 21:19:07 -05:00
|
|
|
|
float aspectWidth = SwitchPanelHeight * ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat();
|
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
int screenWidth = AllocatedWidth;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
int screenHeight = AllocatedHeight;
|
|
|
|
|
|
2020-12-15 21:19:07 -05:00
|
|
|
|
if (AllocatedWidth > AllocatedHeight * aspectWidth / SwitchPanelHeight)
|
2020-02-11 19:56:19 -05:00
|
|
|
|
{
|
2020-12-15 21:19:07 -05:00
|
|
|
|
screenWidth = (int)(AllocatedHeight * aspectWidth) / SwitchPanelHeight;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-12-15 21:19:07 -05:00
|
|
|
|
screenHeight = (AllocatedWidth * SwitchPanelHeight) / (int)aspectWidth;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 22:00:53 -04:00
|
|
|
|
int startX = (AllocatedWidth - screenWidth) >> 1;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
int startY = (AllocatedHeight - screenHeight) >> 1;
|
|
|
|
|
|
|
|
|
|
int endX = startX + screenWidth;
|
|
|
|
|
int endY = startY + screenHeight;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_mouseX >= startX &&
|
|
|
|
|
_mouseY >= startY &&
|
|
|
|
|
_mouseX < endX &&
|
|
|
|
|
_mouseY < endY)
|
|
|
|
|
{
|
|
|
|
|
int screenMouseX = (int)_mouseX - startX;
|
|
|
|
|
int screenMouseY = (int)_mouseY - startY;
|
|
|
|
|
|
2020-12-15 21:19:07 -05:00
|
|
|
|
int mX = (screenMouseX * (int)aspectWidth) / screenWidth;
|
2020-02-18 06:34:57 -05:00
|
|
|
|
int mY = (screenMouseY * SwitchPanelHeight) / screenHeight;
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
TouchPoint currentPoint = new TouchPoint
|
|
|
|
|
{
|
2020-04-02 20:10:02 -04:00
|
|
|
|
X = (uint)mX,
|
|
|
|
|
Y = (uint)mY,
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
// Placeholder values till more data is acquired
|
|
|
|
|
DiameterX = 10,
|
|
|
|
|
DiameterY = 10,
|
2020-05-02 22:00:53 -04:00
|
|
|
|
Angle = 90
|
2020-02-11 19:56:19 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hasTouch = true;
|
|
|
|
|
|
2020-04-02 20:10:02 -04:00
|
|
|
|
_device.Hid.Touchscreen.Update(currentPoint);
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hasTouch)
|
|
|
|
|
{
|
2020-04-02 20:10:02 -04:00
|
|
|
|
_device.Hid.Touchscreen.Update();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 20:10:02 -04:00
|
|
|
|
_device.Hid.DebugPad.Update();
|
2020-02-11 19:56:19 -05:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|