Skip to content

Commit 825b1e9

Browse files
committed
Add --fps flag and auto-detect GPU for visual effects
- Add --fps command line flag to show FPS/shape count overlay - Auto-detect WPF rendering tier on first run - Enable visual effects only on Tier 2 (full GPU acceleration) - Rename 'Hardware Effects' to 'Visual Effects (blur, glow)'
1 parent 294209d commit 825b1e9

7 files changed

Lines changed: 86 additions & 6 deletions

File tree

App.xaml.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Linq;
34
using System.Runtime.InteropServices;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using System.Windows;
78
using System.Windows.Forms;
9+
using System.Windows.Media;
10+
using BabySmash.Properties;
811
using Updatum;
912
using Application = System.Windows.Application;
1013
using MessageBox = System.Windows.MessageBox;
@@ -26,6 +29,13 @@ public partial class App : Application
2629

2730
private async void Application_Startup(object sender, StartupEventArgs e)
2831
{
32+
// Parse command line arguments
33+
var args = e.Args;
34+
Controller.ShowFps = args.Contains("--fps") || args.Contains("-fps");
35+
36+
// Auto-detect GPU capability on first run
37+
AutoDetectVisualEffects();
38+
2939
// Check for updates BEFORE launching the game
3040
// This way the parent can handle updates before baby takes over
3141
var shouldLaunch = await CheckForUpdatesBeforeLaunchAsync();
@@ -36,6 +46,23 @@ private async void Application_Startup(object sender, StartupEventArgs e)
3646
}
3747
}
3848

49+
private void AutoDetectVisualEffects()
50+
{
51+
// Only auto-detect once (on first run)
52+
if (Settings.Default.EffectsAutoDetected)
53+
return;
54+
55+
// WPF Rendering Tier: 0=software, 1=partial HW, 2=full GPU acceleration
56+
int renderingTier = RenderCapability.Tier >> 16;
57+
58+
// Enable effects only on Tier 2 (full GPU acceleration)
59+
Settings.Default.BitmapEffects = renderingTier >= 2;
60+
Settings.Default.EffectsAutoDetected = true;
61+
Settings.Default.Save();
62+
63+
Debug.WriteLine($"Auto-detected rendering tier {renderingTier}, visual effects: {Settings.Default.BitmapEffects}");
64+
}
65+
3966
private async Task<bool> CheckForUpdatesBeforeLaunchAsync()
4067
{
4168
try

Controller.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class Controller
3939

4040
private static Controller instance = new Controller();
4141

42+
public static bool ShowFps { get; set; }
43+
4244
public bool isOptionsDialogShown { get; set; }
4345
private bool isDrawing = false;
4446
private readonly SpeechSynthesizer objSpeech = new SpeechSynthesizer();
@@ -71,7 +73,7 @@ public void Launch()
7173

7274
foreach (WinForms.Screen s in appScreens)
7375
{
74-
MainWindow m = new MainWindow(this)
76+
MainWindow m = new MainWindow(this, ShowFps)
7577
{
7678
WindowStartupLocation = WindowStartupLocation.Manual,
7779
Left = s.WorkingArea.Left,

MainWindow.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@
9999
<ProgressBar HorizontalAlignment="Left" x:Name="updateProgress" Value="0" Minimum="0" Maximum="100" Margin="0,0,0,0" Height="10" Width="130"/>
100100
</TextBlock>
101101
</StackPanel>
102+
<TextBlock x:Name="fpsLabel" Visibility="Collapsed"
103+
HorizontalAlignment="Right" VerticalAlignment="Top"
104+
Margin="0,10,20,0" FontSize="14" FontWeight="Bold" Foreground="Lime">
105+
<TextBlock.Effect>
106+
<DropShadowEffect ShadowDepth="1" Color="Black" BlurRadius="3"/>
107+
</TextBlock.Effect>
108+
FPS: --
109+
</TextBlock>
102110
<Canvas Name="figuresCanvas"/>
103111
<Canvas Name="mouseDragCanvas"/>
104112
<Canvas Name="mouseCursorCanvas"/>

MainWindow.xaml.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Windows;
1+
using System;
2+
using System.Diagnostics;
3+
using System.Windows;
24
using System.Windows.Controls;
35
using System.Windows.Input;
46
using System.Windows.Media;
@@ -18,6 +20,11 @@ public partial class MainWindow : Window
1820
private UserControl customCursor;
1921
public UserControl CustomCursor { get { return customCursor; } set { customCursor = value; } }
2022

23+
// FPS counter
24+
private int _frameCount;
25+
private readonly Stopwatch _fpsStopwatch = new();
26+
private bool _showFps;
27+
2128
public void AddFigure(UserControl c)
2229
{
2330
this.figuresCanvas.Children.Add(c);
@@ -28,13 +35,31 @@ public void RemoveFigure(UserControl c)
2835
this.figuresCanvas.Children.Remove(c);
2936
}
3037

31-
public MainWindow(Controller c)
38+
public MainWindow(Controller c, bool showFps = false)
3239
{
3340
this.controller = c;
3441
this.DataContext = controller;
42+
_showFps = showFps;
3543
InitializeComponent();
3644

37-
//ResetCanvas();
45+
if (_showFps)
46+
{
47+
fpsLabel.Visibility = Visibility.Visible;
48+
CompositionTarget.Rendering += OnRendering;
49+
_fpsStopwatch.Start();
50+
}
51+
}
52+
53+
private void OnRendering(object sender, EventArgs e)
54+
{
55+
_frameCount++;
56+
if (_fpsStopwatch.ElapsedMilliseconds >= 1000)
57+
{
58+
var fps = _frameCount * 1000.0 / _fpsStopwatch.ElapsedMilliseconds;
59+
fpsLabel.Text = $"FPS: {fps:F0} | Shapes: {figuresCanvas.Children.Count}";
60+
_frameCount = 0;
61+
_fpsStopwatch.Restart();
62+
}
3863
}
3964

4065
protected override void OnMouseWheel(MouseWheelEventArgs e)

Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Properties/Settings.settings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Value Profile="(Default)">True</Value>
1010
</Setting>
1111
<Setting Name="BitmapEffects" Type="System.Boolean" Scope="User">
12-
<Value Profile="(Default)">False</Value>
12+
<Value Profile="(Default)">True</Value>
1313
</Setting>
1414
<Setting Name="ClearAfter" Type="System.Int32" Scope="User">
1515
<Value Profile="(Default)">35</Value>
@@ -35,5 +35,8 @@
3535
<Setting Name="TransparentBackground" Type="System.Boolean" Scope="User">
3636
<Value Profile="(Default)">False</Value>
3737
</Setting>
38+
<Setting Name="EffectsAutoDetected" Type="System.Boolean" Scope="User">
39+
<Value Profile="(Default)">False</Value>
40+
</Setting>
3841
</Settings>
3942
</SettingsFile>

app.config

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<value>True</value>
3131
</setting>
3232
<setting name="BitmapEffects" serializeAs="String">
33-
<value>False</value>
33+
<value>True</value>
3434
</setting>
3535
<setting name="ClearAfter" serializeAs="String">
3636
<value>35</value>
@@ -56,6 +56,9 @@
5656
<setting name="TransparentBackground" serializeAs="String">
5757
<value>False</value>
5858
</setting>
59+
<setting name="EffectsAutoDetected" serializeAs="String">
60+
<value>False</value>
61+
</setting>
5962
</BabySmash.Properties.Settings>
6063
</userSettings>
6164
<startup><supportedRuntime version="v2.0.50727"/></startup>

0 commit comments

Comments
 (0)