Skip to content

Commit de57c38

Browse files
authored
Add FPS counter and more FPS options
1 parent 1c22b53 commit de57c38

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

src/Artemis.UI/Screens/Settings/Tabs/GeneralTabViewModel.cs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Linq;
@@ -32,27 +32,38 @@ public class GeneralTabViewModel : RoutableScreen
3232
private readonly IAutoRunProvider? _autoRunProvider;
3333
private readonly IProtocolProvider? _protocolProvider;
3434
private readonly IDebugService _debugService;
35+
private readonly IRenderService _renderService;
3536
private readonly PluginSetting<LayerBrushReference> _defaultLayerBrushDescriptor;
3637
private readonly INotificationService _notificationService;
3738
private readonly ISettingsService _settingsService;
3839
private readonly IUpdateService _updateService;
3940
private readonly IWindowService _windowService;
4041
private bool _startupWizardOpen;
4142

42-
public GeneralTabViewModel(IContainer container,
43+
private double _currentFps;
44+
public double CurrentFps
45+
{
46+
get => _currentFps;
47+
set => this.RaiseAndSetIfChanged(ref _currentFps, value);
48+
}
49+
50+
public GeneralTabViewModel(
51+
IContainer container,
4352
ISettingsService settingsService,
4453
IPluginManagementService pluginManagementService,
4554
IDebugService debugService,
4655
IWindowService windowService,
4756
IUpdateService updateService,
48-
INotificationService notificationService)
57+
INotificationService notificationService,
58+
IRenderService renderService)
4959
{
5060
DisplayName = "General";
5161
_settingsService = settingsService;
5262
_debugService = debugService;
5363
_windowService = windowService;
5464
_updateService = updateService;
5565
_notificationService = notificationService;
66+
_renderService = renderService;
5667
_autoRunProvider = container.Resolve<IAutoRunProvider>(IfUnresolved.ReturnDefault);
5768
_protocolProvider = container.Resolve<IProtocolProvider>(IfUnresolved.ReturnDefault);
5869

@@ -81,8 +92,16 @@ public GeneralTabViewModel(IContainer container,
8192
UIAutoRunDelay.SettingChanged += UIAutoRunDelayOnSettingChanged;
8293
EnableMica.SettingChanged += EnableMicaOnSettingChanged;
8394

95+
// FPS hook
96+
_renderService.FrameRendered += OnFrameRendered;
97+
Disposable.Create(() =>
98+
{
99+
_renderService.FrameRendered -= OnFrameRendered;
100+
}).DisposeWith(d);
101+
84102
Dispatcher.UIThread.InvokeAsync(ApplyAutoRun);
85103
Dispatcher.UIThread.Invoke(ApplyProtocolAssociation);
104+
86105
Disposable.Create(() =>
87106
{
88107
UIAutoRun.SettingChanged -= UIAutoRunOnSettingChanged;
@@ -95,6 +114,11 @@ public GeneralTabViewModel(IContainer container,
95114
});
96115
}
97116

117+
private void OnFrameRendered(object? sender, FrameRenderedEventArgs e)
118+
{
119+
CurrentFps = _renderService.FrameRate;
120+
}
121+
98122
public ReactiveCommand<Unit, Unit> ShowLogs { get; }
99123
public ReactiveCommand<Unit, Unit> CheckForUpdate { get; }
100124
public ReactiveCommand<Unit, Unit> ShowSetupWizard { get; }
@@ -122,7 +146,10 @@ public GeneralTabViewModel(IContainer container,
122146
new RenderSettingViewModel("30 FPS", 30),
123147
new RenderSettingViewModel("45 FPS", 45),
124148
new RenderSettingViewModel("60 FPS (lol)", 60),
125-
new RenderSettingViewModel("144 FPS (omegalol)", 144)
149+
new RenderSettingViewModel("120 FPS (omegalol)", 120),
150+
new RenderSettingViewModel("144 FPS (why tho)", 144),
151+
new RenderSettingViewModel("240 FPS (make cpu cry)", 240),
152+
new RenderSettingViewModel("360 FPS (explode pc)", 360)
126153
];
127154

128155
public LayerBrushDescriptor? SelectedLayerBrushDescriptor
@@ -150,7 +177,7 @@ public RenderSettingViewModel? SelectedTargetFrameRate
150177
set
151178
{
152179
if (value != null)
153-
CoreTargetFrameRate.Value = (int) value.Value;
180+
CoreTargetFrameRate.Value = (int)value.Value;
154181
}
155182
}
156183

@@ -180,7 +207,6 @@ private async Task ExecuteCheckForUpdate(CancellationToken cancellationToken)
180207
{
181208
try
182209
{
183-
// If an update was available a popup was shown, no need to continue
184210
if (await _updateService.CheckForUpdate())
185211
return;
186212

@@ -233,12 +259,12 @@ private async Task ApplyAutoRun()
233259
_windowService.ShowExceptionDialog("Failed to apply auto-run", exception);
234260
}
235261
}
236-
262+
237263
private void ApplyProtocolAssociation()
238264
{
239265
if (_protocolProvider == null)
240266
return;
241-
267+
242268
try
243269
{
244270
if (UIUseProtocol.Value)
@@ -256,7 +282,7 @@ private async void UIAutoRunOnSettingChanged(object? sender, EventArgs e)
256282
{
257283
await ApplyAutoRun();
258284
}
259-
285+
260286
private void UIUseProtocolOnSettingChanged(object? sender, EventArgs e)
261287
{
262288
ApplyProtocolAssociation();

0 commit comments

Comments
 (0)