Skip to content

Commit

Permalink
Merge pull request #900 from dlamkins/v1next
Browse files Browse the repository at this point in the history
Graphics setting changes.
  • Loading branch information
dlamkins authored Aug 14, 2023
2 parents 9449012 + 01447cb commit 8b0ea53
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 107 deletions.
3 changes: 1 addition & 2 deletions Blish HUD/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ private void InitDebug() {
/// </summary>
[
Option(OPTION_UNLOCKFPS, 'F'),
Help("Deprecated as of v0.8.0. Instead use the 'Frame Limiter' setting found in the Blish HUD graphics settings section.")
Help("Unlocks the frame limit allowing Blish HUD to render as fast as possible. This will cause higher CPU and GPU utilization.")
]
[Obsolete("Deprecated as of v0.8.0. Instead use the 'Frame Limiter' setting found in the Blish HUD graphics settings section.")]
public bool UnlockFps { get; private set; }

#endregion
Expand Down
18 changes: 11 additions & 7 deletions Blish HUD/GameServices/Graphics/FramerateMethod.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
namespace Blish_HUD.Graphics {
using System.ComponentModel;

namespace Blish_HUD.Graphics {

public enum FramerateMethod : int {
Custom = -1,
SyncWithGame = 0,
LockedTo30Fps = 1,
LockedTo60Fps = 2,
LockedTo90Fps = 3,
Unlimited = 4,
Custom = -1,
SyncWithGame = 0,
LockedTo30Fps = 1,
LockedTo60Fps = 2,
LockedTo90Fps = 3,
[Description("Match Monitor Refresh Rate")]
Unlimited = 4,
TrueUnlimited = 5,
}

}
92 changes: 39 additions & 53 deletions Blish HUD/GameServices/GraphicsService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -175,7 +176,6 @@ public float GetDpiScaleRatio() {
public SettingCollection GraphicsSettings { get; private set; }

private SettingEntry<FramerateMethod> _frameLimiterSetting;
private SettingEntry<bool> _enableVsyncSetting;
private SettingEntry<bool> _smoothCharacterPositionSetting;
private SettingEntry<DpiMethod> _dpiScalingMethodSetting;
private SettingEntry<ManualUISize> _UISizeSetting;
Expand All @@ -187,11 +187,6 @@ public FramerateMethod FrameLimiter {
set => _frameLimiterSetting.Value = value;
}

public bool EnableVsync {
get => _enableVsyncSetting.Value;
set => _enableVsyncSetting.Value = value;
}

public bool SmoothCharacterPosition {
get => _smoothCharacterPositionSetting.Value;
set => _smoothCharacterPositionSetting.Value = value;
Expand Down Expand Up @@ -261,85 +256,76 @@ private void DefineSettings(SettingCollection settings) {
() => Strings.GameServices.GraphicsService.Setting_FramerateLimiter_DisplayName,
() => Strings.GameServices.GraphicsService.Setting_FramerateLimiter_Description);

_enableVsyncSetting = settings.DefineSetting("EnableVsync",
true,
() => Strings.GameServices.GraphicsService.Setting_Vsync_DisplayName,
() => Strings.GameServices.GraphicsService.Setting_Vsync_Description);

if (_frameLimiterSetting.Value == FramerateMethod.SyncWithGame || _frameLimiterSetting.Value == FramerateMethod.Custom) {
// SyncWithGame is no longer supported. It causes more problems than it solves.
// We revert to the default settings for both the framerate limiter and vsync.

// Likewise, Custom framerates are only possible via launch option currently.
// Old versions could enable it, so this fixes that.
_frameLimiterSetting.Value = FramerateMethod.LockedTo90Fps;
_enableVsyncSetting.Value = true;
_frameLimiterSetting.Value = FramerateMethod.LockedTo60Fps;
}

_smoothCharacterPositionSetting = settings.DefineSetting("EnableCharacterPositionBuffer",
true,
() => Strings.GameServices.GraphicsService.Setting_SmoothCharacterPosition_DisplayName,
() => Strings.GameServices.GraphicsService.Setting_SmoothCharacterPosition_Description);

_dpiScalingMethodSetting = settings.DefineSetting(nameof(DpiScalingMethod),
_dpiScalingMethodSetting = settings.DefineSetting(nameof(DpiScalingMethod),
DpiMethod.SyncWithGame,
() => Strings.GameServices.GraphicsService.Setting_DPIScaling_DisplayName,
() => Strings.GameServices.GraphicsService.Setting_DPIScaling_Description);

_UISizeSetting = settings.DefineSetting(nameof(UIScalingMethod),
_UISizeSetting = settings.DefineSetting(nameof(UIScalingMethod),
ManualUISize.SyncWithGame,
() => Strings.GameServices.GraphicsService.Setting_UIScaling_DisplayName,
() => Strings.GameServices.GraphicsService.Setting_UIScaling_Description);



_frameLimiterSetting.SettingChanged += FrameLimiterSettingMethodChanged;
_enableVsyncSetting.SettingChanged += EnableVsyncChanged;
FrameLimiterSettingMethodChanged(_frameLimiterSetting, new ValueChangedEventArgs<FramerateMethod>(_frameLimiterSetting.Value, _frameLimiterSetting.Value));

EnableVsyncChanged(_enableVsyncSetting, new ValueChangedEventArgs<bool>(_enableVsyncSetting.Value, _enableVsyncSetting.Value));
FrameLimiterSettingMethodChanged(_enableVsyncSetting, new ValueChangedEventArgs<FramerateMethod>(_frameLimiterSetting.Value, _frameLimiterSetting.Value));

_frameLimiterSetting.SetExcluded(FramerateMethod.Custom, FramerateMethod.SyncWithGame);
_frameLimiterSetting.SetExcluded(FramerateMethod.Custom, FramerateMethod.SyncWithGame, FramerateMethod.TrueUnlimited);

// User has specified a custom FPS target via launch arg
if (ApplicationSettings.Instance.TargetFramerate > 0) {
// Disable frame limiter setting and update description - user has manually specified via launch arg
_frameLimiterSetting.SetDisabled();
_frameLimiterSetting.GetDescriptionFunc = () => Strings.GameServices.GraphicsService.Setting_FramerateLimiter_Description + Strings.GameServices.GraphicsService.Setting_FramerateLimiter_Locked_Description;

FrameLimiterSettingMethodChanged(_enableVsyncSetting, new ValueChangedEventArgs<FramerateMethod>(FramerateMethod.Custom, FramerateMethod.Custom));
FrameLimiterSettingMethodChanged(_frameLimiterSetting, new ValueChangedEventArgs<FramerateMethod>(FramerateMethod.Custom, FramerateMethod.Custom));
}
}

private void EnableVsyncChanged(object sender, ValueChangedEventArgs<bool> e) {
GraphicsDeviceManager.SynchronizeWithVerticalRetrace = e.NewValue;
GraphicsDeviceManager.ApplyChanges();
// User has unlocked the FPS via launch arg
if (ApplicationSettings.Instance.UnlockFps) {
// Disable frame limiter setting and update description - user has unlocked the FPS via launch arg
_frameLimiterSetting.SetDisabled();
_frameLimiterSetting.GetDescriptionFunc = () => Strings.GameServices.GraphicsService.Setting_FramerateLimiter_Description + Strings.GameServices.GraphicsService.Setting_FramerateLimiter_Locked_Description;

FrameLimiterSettingMethodChanged(_frameLimiterSetting, new ValueChangedEventArgs<FramerateMethod>(FramerateMethod.TrueUnlimited, FramerateMethod.TrueUnlimited));
}
}

private void FrameLimiterSettingMethodChanged(object sender, ValueChangedEventArgs<FramerateMethod> e) {
switch (e.NewValue) {
case FramerateMethod.Custom: // Only enabled via launch options
BlishHud.Instance.IsFixedTimeStep = true;
BlishHud.Instance.TargetElapsedTime = TimeSpan.FromSeconds(1d / ApplicationSettings.Instance.TargetFramerate);
break;
case FramerateMethod.SyncWithGame:
BlishHud.Instance.IsFixedTimeStep = false;
BlishHud.Instance.TargetElapsedTime = TimeSpan.FromMilliseconds(1);
break;
case FramerateMethod.LockedTo30Fps:
BlishHud.Instance.IsFixedTimeStep = true;
BlishHud.Instance.TargetElapsedTime = TimeSpan.FromSeconds(1d / 30d);
break;
case FramerateMethod.LockedTo60Fps:
BlishHud.Instance.IsFixedTimeStep = true;
BlishHud.Instance.TargetElapsedTime = TimeSpan.FromSeconds(1d / 60d);
break;
case FramerateMethod.LockedTo90Fps:
BlishHud.Instance.IsFixedTimeStep = true;
BlishHud.Instance.TargetElapsedTime = TimeSpan.FromSeconds(1d / 90d);
break;
case FramerateMethod.Unlimited:
BlishHud.Instance.IsFixedTimeStep = false;
BlishHud.Instance.TargetElapsedTime = TimeSpan.FromMilliseconds(1);
break;
bool currentVsync = GraphicsDeviceManager.SynchronizeWithVerticalRetrace;

var frameRateLookup = new Dictionary<FramerateMethod, (bool IsFixedTimeStep, TimeSpan TargetElapsedTime, bool VSync)> {
{ FramerateMethod.Custom, (true, TimeSpan.FromSeconds(1d / ApplicationSettings.Instance.TargetFramerate), false) }, // Only enabled with launch args
{ FramerateMethod.SyncWithGame, (false, TimeSpan.FromMilliseconds(1), false) }, // Deprecated
{ FramerateMethod.LockedTo30Fps, (true, TimeSpan.FromSeconds(1d / 30d), false) },
{ FramerateMethod.LockedTo60Fps, (true, TimeSpan.FromSeconds(1d / 60d), false) },
{ FramerateMethod.LockedTo90Fps, (true, TimeSpan.FromSeconds(1d / 90d), false) },
{ FramerateMethod.Unlimited, (false, TimeSpan.FromMilliseconds(1), true) }, // Unlimited with vsync (safe)
{ FramerateMethod.TrueUnlimited, (false, TimeSpan.FromMilliseconds(1), false) } // Unlimited without vsync (unsafe)
};

if (frameRateLookup.TryGetValue(e.NewValue, out var settings)) {
BlishHud.Instance.IsFixedTimeStep = settings.IsFixedTimeStep;
BlishHud.Instance.TargetElapsedTime = settings.TargetElapsedTime;
if (settings.VSync != currentVsync) {
GraphicsDeviceManager.SynchronizeWithVerticalRetrace = settings.VSync;
GraphicsDeviceManager.ApplyChanges();
}
} else {
// Shouldn't be possible unless settings are manually modified
Logger.Warn($"Attempted to set the frame rate limiter to invalid value '{e.NewValue}'. No changes to the frame limiter were made.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ private ViewContainer GetStandardPanel(Panel rootPanel, string title) {
}

private void BuildOverlaySettings(Panel rootPanel) {
GetStandardPanel(rootPanel, Strings.GameServices.OverlayService.OverlaySettingsSection).Show(new SettingsView(GameService.Overlay.OverlaySettings));
GetStandardPanel(rootPanel, Strings.GameServices.OverlayService.OverlayDynamicHUDSection).Show(new SettingsView(GameService.Overlay.DynamicHUDSettings));
GetStandardPanel(rootPanel, Strings.GameServices.GraphicsService.GraphicsSettingsSection).Show(new SettingsView(GameService.Graphics.GraphicsSettings));
GetStandardPanel(rootPanel, Strings.GameServices.DebugService.DebugSettingsSection).Show(new SettingsView(GameService.Debug.DebugSettings));
GetStandardPanel(rootPanel, Strings.Common.BlishHUD + " " + Strings.GameServices.OverlayService.OverlaySettingsSection).Show(new SettingsView(GameService.Overlay.OverlaySettings));
GetStandardPanel(rootPanel, Strings.Common.BlishHUD + " " + Strings.GameServices.OverlayService.OverlayDynamicHUDSection).Show(new SettingsView(GameService.Overlay.DynamicHUDSettings));
GetStandardPanel(rootPanel, Strings.Common.BlishHUD + " " + Strings.GameServices.GraphicsService.GraphicsSettingsSection).Show(new SettingsView(GameService.Graphics.GraphicsSettings));
GetStandardPanel(rootPanel, Strings.Common.BlishHUD + " " + Strings.GameServices.DebugService.DebugSettingsSection).Show(new SettingsView(GameService.Debug.DebugSettings));
}

}
Expand Down
22 changes: 2 additions & 20 deletions Blish HUD/Strings/GameServices/GraphicsService.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions Blish HUD/Strings/GameServices/GraphicsService.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,14 @@
<value>Grafikoptionen</value>
</data>
<data name="Setting_FramerateLimiter_Locked_Description" xml:space="preserve">
<value>(Deaktiviert, da Blish HUD mit --maxfps gestartet wurde)</value>
<value>(Deaktiviert, da Blish HUD mit --maxfps/--unlockfps gestartet wurde)</value>
</data>
<data name="Setting_FramerateLimiter_DisplayName" xml:space="preserve">
<value>FPS-Limitierung</value>
</data>
<data name="Setting_FramerateLimiter_Description" xml:space="preserve">
<value>Diese Methode bestimmte die Bildrate mit der Blish HUD ausgeführt wird.</value>
</data>
<data name="Setting_Vsync_DisplayName" xml:space="preserve">
<value>Vertikale Synchronisierung</value>
</data>
<data name="Setting_Vsync_Description" xml:space="preserve">
<value>Passt die Bildfrequenz von Blish HUD an die Bildwiederholungsrate des Monitors an. Hilft Artefakte aufzulösen, kann aber zu künstlich niedriger Bildwiederholungsrate führen.</value>
</data>
<data name="Setting_SmoothCharacterPosition_DisplayName" xml:space="preserve">
<value>Weiche Charakterposition</value>
</data>
Expand Down
8 changes: 1 addition & 7 deletions Blish HUD/Strings/GameServices/GraphicsService.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,8 @@
<data name="Setting_FramerateLimiter_Description" xml:space="preserve">
<value>La méthode utilisée pour déterminer la fréquence d'image que Blish HUD devrait utiliser.</value>
</data>
<data name="Setting_Vsync_DisplayName" xml:space="preserve">
<value>Activer la synchronisation verticale</value>
</data>
<data name="Setting_Vsync_Description" xml:space="preserve">
<value>Activer la synchronisation verticale limite la fréquence d'images de Blish HUD au taux de raffraîchissement de l'écran pour empêcher les problèmes de coupure d'image.</value>
</data>
<data name="Setting_FramerateLimiter_Locked_Description" xml:space="preserve">
<value>(Désactivé car Blish HUD a été lancé avec le paramètre --maxfps)</value>
<value>(Désactivé car Blish HUD a été lancé avec le paramètre --maxfps/--unlockfps)</value>
</data>
<data name="Setting_SmoothCharacterPosition_DisplayName" xml:space="preserve">
<value>Position du personnage lissée</value>
Expand Down
8 changes: 1 addition & 7 deletions Blish HUD/Strings/GameServices/GraphicsService.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,8 @@
<data name="Setting_FramerateLimiter_Description" xml:space="preserve">
<value>The method used to determine the framerate that Blish HUD should run at.</value>
</data>
<data name="Setting_Vsync_DisplayName" xml:space="preserve">
<value>Enable Vsync</value>
</data>
<data name="Setting_Vsync_Description" xml:space="preserve">
<value>Enabling Vsync limits the frame rate of Blish HUD to the monitor refresh rate to prevent screen tearing.</value>
</data>
<data name="Setting_FramerateLimiter_Locked_Description" xml:space="preserve">
<value>(Disabled because Blish HUD was started with --maxfps specified)</value>
<value>(Disabled because Blish HUD was started with --maxfps/--unlockfps specified)</value>
</data>
<data name="Setting_SmoothCharacterPosition_DisplayName" xml:space="preserve">
<value>Smooth Character Position</value>
Expand Down

0 comments on commit 8b0ea53

Please sign in to comment.