Skip to content

Commit

Permalink
Rename to VSyncMode internally, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm committed Jan 14, 2024
1 parent e6916ea commit 30552cc
Show file tree
Hide file tree
Showing 30 changed files with 335 additions and 365 deletions.
130 changes: 66 additions & 64 deletions src/Ryujinx.Ava/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
using IRenderer = Ryujinx.Graphics.GAL.IRenderer;
using Key = Ryujinx.Input.Key;
using MouseButton = Ryujinx.Input.MouseButton;
using PresentIntervalState = Ryujinx.Common.Configuration.PresentIntervalState;
using ScalingFilter = Ryujinx.Common.Configuration.ScalingFilter;
using Size = Avalonia.Size;
using Switch = Ryujinx.HLE.Switch;
using VSyncMode = Ryujinx.Common.Configuration.VSyncMode;

namespace Ryujinx.Ava
{
Expand Down Expand Up @@ -190,9 +190,9 @@ public AppHost(
ConfigurationState.Instance.Graphics.ScalingFilter.Event += UpdateScalingFilter;
ConfigurationState.Instance.Graphics.ScalingFilterLevel.Event += UpdateScalingFilterLevel;
ConfigurationState.Instance.Graphics.EnableColorSpacePassthrough.Event += UpdateColorSpacePassthrough;
ConfigurationState.Instance.Graphics.PresentIntervalState.Event += UpdatePresentIntervalState;
ConfigurationState.Instance.Graphics.CustomPresentInterval.Event += UpdateCustomPresentIntervalValue;
ConfigurationState.Instance.Graphics.EnableCustomPresentInterval.Event += UpdateCustomPresentIntervalEnabled;
ConfigurationState.Instance.Graphics.VSyncMode.Event += UpdateVSyncMode;
ConfigurationState.Instance.Graphics.CustomVSyncInterval.Event += UpdateCustomVSyncIntervalValue;
ConfigurationState.Instance.Graphics.EnableCustomVSyncInterval.Event += UpdateCustomVSyncIntervalEnabled;

ConfigurationState.Instance.System.EnableInternetAccess.Event += UpdateEnableInternetAccessState;
ConfigurationState.Instance.Multiplayer.LanInterfaceId.Event += UpdateLanInterfaceIdState;
Expand Down Expand Up @@ -240,34 +240,66 @@ private void UpdateColorSpacePassthrough(object sender, ReactiveEventArgs<bool>
_renderer.Window?.SetColorSpacePassthrough((bool)ConfigurationState.Instance.Graphics.EnableColorSpacePassthrough.Value);
}

private void UpdatePresentIntervalState(object sender, ReactiveEventArgs<PresentIntervalState> e)
public void UpdateVSyncMode(object sender, ReactiveEventArgs<VSyncMode> e)
{
if (Device != null)
{
Device.PresentIntervalState = e.NewValue;
Device.UpdatePresentInterval();
Device.VSyncMode = e.NewValue;
Device.UpdateVSyncInterval();
}
//vulkan present mode may change in response, so recreate the swapchain
_renderer.Window?.ChangePresentIntervalState((Ryujinx.Graphics.GAL.PresentIntervalState)e.NewValue);
ConfigurationState.Instance.Graphics.PresentIntervalState.Value = e.NewValue;
_renderer.Window?.ChangeVSyncMode((Ryujinx.Graphics.GAL.VSyncMode)e.NewValue);

_viewModel.ShowCustomVSyncIntervalPicker = (e.NewValue == VSyncMode.Custom);

ConfigurationState.Instance.Graphics.VSyncMode.Value = e.NewValue;
ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
}

private void UpdateCustomPresentIntervalValue(object sender, ReactiveEventArgs<int> e)
public void VSyncModeToggle()
{
VSyncMode oldVSyncMode = Device.VSyncMode;
VSyncMode newVSyncMode = VSyncMode.Switch;
bool customVSyncIntervalEnabled = ConfigurationState.Instance.Graphics.EnableCustomVSyncInterval.Value;

switch (oldVSyncMode)
{
case VSyncMode.Switch:
newVSyncMode = VSyncMode.Unbounded;
break;
case VSyncMode.Unbounded:
if (customVSyncIntervalEnabled)
{
newVSyncMode = VSyncMode.Custom;
}
else
{
newVSyncMode = VSyncMode.Switch;
}

break;
case VSyncMode.Custom:
newVSyncMode = VSyncMode.Switch;
break;
}
UpdateVSyncMode(this, new ReactiveEventArgs<VSyncMode>(oldVSyncMode, newVSyncMode));
}

private void UpdateCustomVSyncIntervalValue(object sender, ReactiveEventArgs<int> e)
{
if (Device != null)
{
Device.TargetPresentInterval = e.NewValue;
Device.UpdatePresentInterval();
Device.TargetVSyncInterval = e.NewValue;
Device.UpdateVSyncInterval();
}
}

private void UpdateCustomPresentIntervalEnabled(object sender, ReactiveEventArgs<bool> e)
private void UpdateCustomVSyncIntervalEnabled(object sender, ReactiveEventArgs<bool> e)
{
if (Device != null)
{
Device.CustomPresentIntervalEnabled = e.NewValue;
Device.UpdatePresentInterval();
Device.CustomVSyncIntervalEnabled = e.NewValue;
Device.UpdateVSyncInterval();
}
}

Expand Down Expand Up @@ -550,12 +582,6 @@ private void HideCursorState_Changed(object sender, ReactiveEventArgs<HideCursor
}
}

public void UpdatePresentInterval(PresentIntervalState presentIntervalState)
{
PresentIntervalState oldState = ConfigurationState.Instance.Graphics.PresentIntervalState.Value;
UpdatePresentIntervalState(this, new ReactiveEventArgs<PresentIntervalState>(oldState, presentIntervalState));
}

public async Task<bool> LoadGuestApplication()
{
InitializeSwitchInstance();
Expand Down Expand Up @@ -819,7 +845,7 @@ private void InitializeSwitchInstance()
_viewModel.UiHandler,
(SystemLanguage)ConfigurationState.Instance.System.Language.Value,
(RegionCode)ConfigurationState.Instance.System.Region.Value,
ConfigurationState.Instance.Graphics.PresentIntervalState,
ConfigurationState.Instance.Graphics.VSyncMode,
ConfigurationState.Instance.System.EnableDockedMode,
ConfigurationState.Instance.System.EnablePtc,
ConfigurationState.Instance.System.EnableInternetAccess,
Expand All @@ -834,7 +860,7 @@ private void InitializeSwitchInstance()
ConfigurationState.Instance.System.UseHypervisor,
ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value,
ConfigurationState.Instance.Multiplayer.Mode,
ConfigurationState.Instance.Graphics.CustomPresentInterval.Value);
ConfigurationState.Instance.Graphics.CustomVSyncInterval.Value);

Device = new Switch(configuration);
}
Expand Down Expand Up @@ -960,7 +986,7 @@ private void RenderLoop()
Device.Gpu.InitializeShaderCache(_gpuCancellationTokenSource.Token);
Translator.IsReadyForTranslation.Set();

_renderer.Window.ChangePresentIntervalState((Ryujinx.Graphics.GAL.PresentIntervalState)Device.PresentIntervalState);
_renderer.Window.ChangeVSyncMode((Ryujinx.Graphics.GAL.VSyncMode)Device.VSyncMode);

while (_isActive)
{
Expand Down Expand Up @@ -1008,15 +1034,15 @@ public void UpdateStatus()
{
// Run a status update only when a frame is to be drawn. This prevents from updating the ui and wasting a render when no frame is queued.
string dockedMode = ConfigurationState.Instance.System.EnableDockedMode ? LocaleManager.Instance[LocaleKeys.Docked] : LocaleManager.Instance[LocaleKeys.Handheld];
string presentIntervalState = Device.PresentIntervalState.ToString();
string vSyncMode = Device.VSyncMode.ToString();

if (GraphicsConfig.ResScale != 1)
{
dockedMode += $" ({GraphicsConfig.ResScale}x)";
}

StatusUpdatedEvent?.Invoke(this, new StatusUpdatedEventArgs(
presentIntervalState,
vSyncMode,
LocaleManager.Instance[LocaleKeys.VolumeShort] + $": {(int)(Device.GetVolume() * 100)}%",
ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.Vulkan ? "Vulkan" : "OpenGL",
dockedMode,
Expand Down Expand Up @@ -1108,40 +1134,16 @@ private bool UpdateFrame()
{
switch (currentHotkeyState)
{
//todo default
case KeyboardHotkeyState.TogglePresentIntervalState:
PresentIntervalState oldState = Device.PresentIntervalState;
PresentIntervalState newState;
if (oldState == PresentIntervalState.Switch)
{
newState = PresentIntervalState.Unbounded;
}
else if (oldState == PresentIntervalState.Unbounded)
{
if (ConfigurationState.Instance.Graphics.EnableCustomPresentInterval)
{
newState = PresentIntervalState.Custom;
}
else
{
newState = PresentIntervalState.Switch;
}
}
else
{
newState = PresentIntervalState.Switch;
}
UpdatePresentIntervalState(this, new ReactiveEventArgs<PresentIntervalState>(oldState, newState));
_viewModel.ShowCustomPresentIntervalPicker =
(newState == PresentIntervalState.Custom);
case KeyboardHotkeyState.ToggleVSyncMode:
VSyncModeToggle();
break;
case KeyboardHotkeyState.CustomPresentIntervalDecrement:
Device.DecrementCustomPresentInterval();
_viewModel.CustomPresentInterval -= 1;
case KeyboardHotkeyState.CustomVSyncIntervalDecrement:
Device.DecrementCustomVSyncInterval();
_viewModel.CustomVSyncInterval -= 1;
break;
case KeyboardHotkeyState.CustomPresentIntervalIncrement:
Device.IncrementCustomPresentInterval();
_viewModel.CustomPresentInterval += 1;
case KeyboardHotkeyState.CustomVSyncIntervalIncrement:
Device.IncrementCustomVSyncInterval();
_viewModel.CustomVSyncInterval += 1;
break;
case KeyboardHotkeyState.Screenshot:
ScreenshotRequested = true;
Expand Down Expand Up @@ -1228,9 +1230,9 @@ private KeyboardHotkeyState GetHotkeyState()
{
KeyboardHotkeyState state = KeyboardHotkeyState.None;

if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.PresentIntervalState))
if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.VSyncMode))
{
state = KeyboardHotkeyState.TogglePresentIntervalState;
state = KeyboardHotkeyState.ToggleVSyncMode;
}
else if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Screenshot))
{
Expand Down Expand Up @@ -1264,13 +1266,13 @@ private KeyboardHotkeyState GetHotkeyState()
{
state = KeyboardHotkeyState.VolumeDown;
}
else if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.CustomPresentIntervalIncrement))
else if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.CustomVSyncIntervalIncrement))
{
state = KeyboardHotkeyState.CustomPresentIntervalIncrement;
state = KeyboardHotkeyState.CustomVSyncIntervalIncrement;
}
else if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.CustomPresentIntervalDecrement))
else if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.CustomVSyncIntervalDecrement))
{
state = KeyboardHotkeyState.CustomPresentIntervalDecrement;
state = KeyboardHotkeyState.CustomVSyncIntervalDecrement;
}

return state;
Expand Down
30 changes: 15 additions & 15 deletions src/Ryujinx.Ava/Assets/Locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,25 @@
"SettingsTabSystemSystemLanguageTraditionalChinese": "Traditional Chinese",
"SettingsTabSystemSystemTimeZone": "System Time Zone:",
"SettingsTabSystemSystemTime": "System Time:",
"SettingsTabSystemPresentIntervalState": "VSync:",
"SettingsTabSystemEnableCustomPresentInterval": "Enable custom refresh rate (Experimental)",
"SettingsTabSystemPresentIntervalStateSwitch": "On",
"SettingsTabSystemPresentIntervalStateUnbounded": "Off",
"SettingsTabSystemPresentIntervalStateCustom": "Custom Refresh Rate",
"SettingsTabSystemPresentIntervalStateTooltip": "Emulated Vertical Sync. 'On' emulates the Switch's refresh rate of 60Hz. 'Off' is an unbounded refresh rate.",
"SettingsTabSystemPresentIntervalStateTooltipCustom": "Emulated Vertical Sync. 'On' emulates the Switch's refresh rate of 60Hz. 'Off' is an unbounded refresh rate. 'Custom' emulates the specified custom refresh rate.",
"SettingsTabSystemEnableCustomPresentIntervalTooltip": "Allows the user to specify an emulated refresh rate. In some titles, this may speed up or slow down the rate of gameplay logic. In other titles, it may allow for capping FPS at some multiple of the refresh rate, or lead to unpredictable behavior. This is an experimental feature, with no guarantees for how gameplay will be affected. \n\nLeave OFF if unsure.",
"SettingsTabSystemCustomPresentIntervalValueTooltip": "The custom refresh rate target value.",
"SettingsTabSystemCustomPresentIntervalSliderTooltip": "The custom refresh rate, as a percentage of the normal Switch refresh rate.",
"SettingsTabSystemCustomPresentIntervalValue": "Custom Refresh Rate Value:",
"SettingsTabSystemVSyncMode": "VSync:",
"SettingsTabSystemEnableCustomVSyncInterval": "Enable custom refresh rate (Experimental)",
"SettingsTabSystemVSyncModeSwitch": "On",
"SettingsTabSystemVSyncModeUnbounded": "Off",
"SettingsTabSystemVSyncModeCustom": "Custom Refresh Rate",
"SettingsTabSystemVSyncModeTooltip": "Emulated Vertical Sync. 'On' emulates the Switch's refresh rate of 60Hz. 'Off' is an unbounded refresh rate.",
"SettingsTabSystemVSyncModeTooltipCustom": "Emulated Vertical Sync. 'On' emulates the Switch's refresh rate of 60Hz. 'Off' is an unbounded refresh rate. 'Custom' emulates the specified custom refresh rate.",
"SettingsTabSystemEnableCustomVSyncIntervalTooltip": "Allows the user to specify an emulated refresh rate. In some titles, this may speed up or slow down the rate of gameplay logic. In other titles, it may allow for capping FPS at some multiple of the refresh rate, or lead to unpredictable behavior. This is an experimental feature, with no guarantees for how gameplay will be affected. \n\nLeave OFF if unsure.",
"SettingsTabSystemCustomVSyncIntervalValueTooltip": "The custom refresh rate target value.",
"SettingsTabSystemCustomVSyncIntervalSliderTooltip": "The custom refresh rate, as a percentage of the normal Switch refresh rate.",
"SettingsTabSystemCustomVSyncIntervalValue": "Custom Refresh Rate Value:",
"SettingsTabSystemEnablePptc": "PPTC (Profiled Persistent Translation Cache)",
"SettingsTabSystemEnableFsIntegrityChecks": "FS Integrity Checks",
"SettingsTabSystemAudioBackend": "Audio Backend:",
"SettingsTabSystemAudioBackendDummy": "Dummy",
"SettingsTabSystemAudioBackendOpenAL": "OpenAL",
"SettingsTabSystemAudioBackendSoundIO": "SoundIO",
"SettingsTabSystemAudioBackendSDL2": "SDL2",
"SettingsTabSystemCustomPresentInterval": "Interval",
"SettingsTabSystemCustomVSyncInterval": "Interval",
"SettingsTabSystemHacks": "Hacks",
"SettingsTabSystemHacksNote": "May cause instability",
"SettingsTabSystemExpandDramSize": "Use alternative memory layout (Developers)",
Expand Down Expand Up @@ -585,13 +585,13 @@
"RyujinxUpdater": "Ryujinx Updater",
"SettingsTabHotkeys": "Keyboard Hotkeys",
"SettingsTabHotkeysHotkeys": "Keyboard Hotkeys",
"SettingsTabHotkeysTogglePresentIntervalStateHotkey": "Toggle Present Interval state:",
"SettingsTabHotkeysToggleVSyncModeHotkey": "Toggle VSync mode:",
"SettingsTabHotkeysScreenshotHotkey": "Screenshot:",
"SettingsTabHotkeysShowUiHotkey": "Show UI:",
"SettingsTabHotkeysPauseHotkey": "Pause:",
"SettingsTabHotkeysToggleMuteHotkey": "Mute:",
"SettingsTabHotkeysIncrementCustomPresentIntervalHotkey": "Raise custom refresh interval",
"SettingsTabHotkeysDecrementCustomPresentIntervalHotkey": "Lower custom refresh interval",
"SettingsTabHotkeysIncrementCustomVSyncIntervalHotkey": "Raise custom refresh rate",
"SettingsTabHotkeysDecrementCustomVSyncIntervalHotkey": "Lower custom refresh rate",
"ControllerMotionTitle": "Motion Control Settings",
"ControllerRumbleTitle": "Rumble Settings",
"SettingsSelectThemeFileDialogTitle": "Select Theme File",
Expand Down
6 changes: 3 additions & 3 deletions src/Ryujinx.Ava/Common/KeyboardHotkeyState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Ryujinx.Ava.Common
public enum KeyboardHotkeyState
{
None,
TogglePresentIntervalState,
ToggleVSyncMode,
Screenshot,
ShowUi,
Pause,
Expand All @@ -12,7 +12,7 @@ public enum KeyboardHotkeyState
ResScaleDown,
VolumeUp,
VolumeDown,
CustomPresentIntervalIncrement,
CustomPresentIntervalDecrement,
CustomVSyncIntervalIncrement,
CustomVSyncIntervalDecrement,
}
}
6 changes: 3 additions & 3 deletions src/Ryujinx.Ava/UI/Models/StatusUpdatedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Ryujinx.Ava.UI.Models
{
internal class StatusUpdatedEventArgs : EventArgs
{
public string PresentIntervalState { get; }
public string VSyncMode { get; }
public string VolumeStatus { get; }
public string GpuBackend { get; }
public string AspectRatio { get; }
Expand All @@ -13,9 +13,9 @@ internal class StatusUpdatedEventArgs : EventArgs
public string GameStatus { get; }
public string GpuName { get; }

public StatusUpdatedEventArgs(string presentIntervalState, string volumeStatus, string gpuBackend, string dockedMode, string aspectRatio, string gameStatus, string fifoStatus, string gpuName)
public StatusUpdatedEventArgs(string vSyncMode, string volumeStatus, string gpuBackend, string dockedMode, string aspectRatio, string gameStatus, string fifoStatus, string gpuName)
{
PresentIntervalState = presentIntervalState;
VSyncMode = vSyncMode;
VolumeStatus = volumeStatus;
GpuBackend = gpuBackend;
DockedMode = dockedMode;
Expand Down
Loading

0 comments on commit 30552cc

Please sign in to comment.