Skip to content

Commit c596659

Browse files
devvoidPerksey
authored andcommitted
Add IsRunningSlowlyThreshold (#15)
* Add IsRunningSlowlyThreshold * Remove extra < * Add IsRunningSlowlyThreshold * Add IsRunningSlowly to the proposal * Update docs for IsRunningSlowly to match new implementation * Update some documentation text, add newlines for easier reading * Documentation improvements Remove all "gets and sets" for consistency, remove defaults since those are in WindowOptions, and correct a few things that aren't true anymore. * Typo in comment * Add missing enums * Throw exception if requested ISilkPlatform is not applicable * Use backticks around all type names for consistency * Better document the platform-picking system * More docs, change exception type * Add docs to ISilkPlatform * Missed a slash * Documentation in GlfwPlatform * Remove default from GlfwWindow constructor What the proposal originally suggested isn't possible, since WindowOptions.Default isn't a compile-time constant. * Add newline * Wrong cref * Add newline * Calculate fps instead of storing it directly * Replace tabs with spaces for consistency * Missed newline * Accidental paste * .NET platform -> native backend Co-Authored-By: Dylan Perks <[email protected]> * Replace reflection-related docs with what it actually does Co-Authored-By: Dylan Perks <[email protected]> * Don't round the results * Don't throw exception if an improper platform is set * Update documentation to match recent changes * IsRunningSlowlyThreshold -> RunningSlowTolerance * Update IsRunningSlowly to RunningSlowTolerance
1 parent 69e6e4d commit c596659

File tree

10 files changed

+380
-167
lines changed

10 files changed

+380
-167
lines changed

documentation/proposals/Proposal - Windowing.md

Lines changed: 318 additions & 140 deletions
Large diffs are not rendered by default.

src/Windowing/Silk.NET.Windowing.Common/Enums/WindowBorder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Silk.NET.Windowing.Common
1111
public enum WindowBorder
1212
{
1313
/// <summary>
14-
/// The window can be resized by grabbing its border.
14+
/// The window can be resized by clicking and dragging its border.
1515
/// </summary>
1616
Resizable = 0,
1717

src/Windowing/Silk.NET.Windowing.Common/Interfaces/ISilkPlatform.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@
55

66
namespace Silk.NET.Windowing.Common
77
{
8+
/// <summary>
9+
/// An interface that provides windowing for its respective native backend.
10+
/// </summary>
811
public interface ISilkPlatform
912
{
13+
/// <summary>
14+
/// Gets a value indicating whether this <see cref="ISilkPlatform"/> should be used, based on the
15+
/// current runtime/environment.
16+
/// </summary>
1017
bool IsApplicable { get; }
1118

19+
/// <summary>
20+
/// Creates a window with the given options.
21+
/// </summary>
22+
/// <param name="options">The initial settings this window should open with.</param>
23+
/// <returns>An implementation of <see cref="IWindow"/></returns>
1224
IWindow GetWindow(WindowOptions options);
1325
}
14-
}
26+
}

src/Windowing/Silk.NET.Windowing.Common/Interfaces/IWindow.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ public interface IWindow : IWindowProperties, IWindowFunctions, IWindowEvents
1818
IntPtr Handle { get; }
1919

2020
/// <summary>
21-
/// If true, the window has failed to reach the target framerate for five consecutive frames. You can use this
22-
/// to do things such as lowering visual fidelity to increase framerates on lower-end machines.
21+
/// If true, the window has failed to reach the target framerate for multiple consecutive frames, as defined
22+
/// in <see cref="IWindowProperties.RunningSlowTolerance"/>. You can use this to do things such as lowering
23+
/// visual fidelity to increase framerates on lower-end machines.
2324
/// </summary>
2425
bool IsRunningSlowly { get; }
2526
}

src/Windowing/Silk.NET.Windowing.Common/Interfaces/IWindowProperties.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ namespace Silk.NET.Windowing.Common
1313
public interface IWindowProperties
1414
{
1515
/// <summary>
16-
/// Gets or sets whether or not the window is visible.
16+
/// Whether or not the window is visible.
1717
/// </summary>
1818
bool IsVisible { get; set; }
1919

2020
/// <summary>
2121
/// If true, both updates and rendering will happen on the same thread. If false, both updating and rendering
22-
/// will be run on their own threads. Default is true.
22+
/// will be run on their own threads.
2323
/// </summary>
2424
bool UseSingleThreadedWindow { get; }
2525

2626
/// <summary>
27-
/// The position of the window. Integer vector. If set to -1, use the backend default.
28-
/// Default is -1 for both components.
27+
/// The position of the window. If set to -1, use the backend default.
2928
/// </summary>
3029
/// <remarks>
3130
/// <para>
@@ -35,7 +34,7 @@ public interface IWindowProperties
3534
Point Position { get; set; }
3635

3736
/// <summary>
38-
/// Gets or sets the size of the window in pixels.
37+
/// The size of the window in pixels.
3938
/// </summary>
4039
/// <remarks>
4140
/// <para>
@@ -55,7 +54,7 @@ public interface IWindowProperties
5554
double UpdatesPerSecond { get; set; }
5655

5756
/// <summary>
58-
/// Gets the graphics API the window will use.
57+
/// The graphics API to use, and associated configurations.
5958
/// </summary>
6059
GraphicsAPI API { get; }
6160

@@ -65,18 +64,24 @@ public interface IWindowProperties
6564
string Title { get; set; }
6665

6766
/// <summary>
68-
/// Gets or sets the window state.
67+
/// The window state.
6968
/// </summary>
7069
WindowState WindowState { get; set; }
7170

7271
/// <summary>
73-
/// Gets or sets the window border.
72+
/// The window border.
7473
/// </summary>
7574
WindowBorder WindowBorder { get; set; }
7675

7776
/// <summary>
78-
/// Gets or sets the VSync mode.
77+
/// The VSync mode.
7978
/// </summary>
8079
VSyncMode VSync { get; set; }
80+
81+
/// <summary>
82+
/// The number of frames the window needs to be running slowly for before <see cref="IWindow.IsRunningSlowly"/>
83+
/// is set to true.
84+
/// </summary>
85+
int RunningSlowTolerance { get; set; }
8186
}
8287
}

src/Windowing/Silk.NET.Windowing.Common/WindowOptions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ public struct WindowOptions : IWindowProperties
4444

4545
/// <inheritdoc />
4646
public VSyncMode VSync { get; set; }
47+
48+
/// <inheritdoc />
49+
public int RunningSlowTolerance { get; set; }
4750

4851
/// <summary>
4952
/// Creates a new WindowOptions struct, with sensible defaults.
5053
/// </summary>
5154
public WindowOptions(bool isVisible, bool useSingleThreadedWindow, Point position, Size size,
5255
double framesPerSecond,
5356
double updatesPerSecond, GraphicsAPI api, string title, WindowState windowState, WindowBorder windowBorder,
54-
VSyncMode vSync)
57+
VSyncMode vSync, int isRunningSlowlyThreshold)
5558
{
5659
IsVisible = isVisible;
5760
UseSingleThreadedWindow = useSingleThreadedWindow;
@@ -64,13 +67,14 @@ public WindowOptions(bool isVisible, bool useSingleThreadedWindow, Point positio
6467
WindowState = windowState;
6568
WindowBorder = windowBorder;
6669
VSync = vSync;
70+
RunningSlowTolerance = isRunningSlowlyThreshold;
6771
}
6872

6973
/// <summary>
7074
/// Convinience wrapper around creating a new WindowProperties with the default values.
7175
/// </summary>
7276
public static WindowOptions Default { get; } = new WindowOptions(true, true, new Point(-1, -1),
7377
new Size(1280, 720), 0.0, 0.0, GraphicsAPI.Default,
74-
"Silk.NET Window", WindowState.Normal, WindowBorder.Resizable, VSyncMode.On);
78+
"Silk.NET Window", WindowState.Normal, WindowBorder.Resizable, VSyncMode.On, 5);
7579
}
7680
}

src/Windowing/Silk.NET.Windowing.Desktop/GlfwPlatform.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99

1010
namespace Silk.NET.Windowing.Desktop
1111
{
12+
/// <summary>
13+
/// A GLFW-based backend.
14+
/// </summary>
1215
public class GlfwPlatform : ISilkPlatform
1316
{
17+
/// <inheritdoc />
1418
public bool IsApplicable
1519
{
1620
get
@@ -26,6 +30,7 @@ public bool IsApplicable
2630
}
2731
}
2832

33+
/// <inheritdoc />
2934
public IWindow GetWindow(WindowOptions options)
3035
{
3136
return new GlfwWindow(options);

src/Windowing/Silk.NET.Windowing.Desktop/GlfwWindow.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ public class GlfwWindow : IWindow
5858
private double updatePeriod;
5959
private double renderPeriod;
6060

61-
private double updatesPerSecond;
62-
private double framesPerSecond;
63-
6461
/// <summary>
6562
/// Create and open a new GlfwWindow.
6663
/// </summary>
@@ -137,13 +134,17 @@ public GlfwWindow(WindowOptions options)
137134
WindowState = options.WindowState;
138135
Position = options.Position;
139136
VSync = options.VSync;
137+
RunningSlowTolerance = options.RunningSlowTolerance;
140138

141139
InitializeCallbacks();
142140
}
143141
}
142+
143+
/// <inheritdoc />
144+
public int RunningSlowTolerance { get; set; }
144145

145146
/// <inheritdoc />
146-
public bool IsRunningSlowly => _isRunningSlowlyTries > 5;
147+
public bool IsRunningSlowly => _isRunningSlowlyTries > RunningSlowTolerance;
147148

148149
/// <inheritdoc />
149150
public bool IsVisible
@@ -219,12 +220,11 @@ public Size Size
219220
}
220221

221222
/// <inheritdoc />
222-
public double FramesPerSecond {
223-
get => framesPerSecond;
223+
public double FramesPerSecond
224+
{
225+
get => 1.0 / renderPeriod;
224226
set
225227
{
226-
framesPerSecond = value;
227-
228228
if (value <= double.Epsilon) {
229229
renderPeriod = 0.0;
230230
return;
@@ -237,11 +237,9 @@ public double FramesPerSecond {
237237
/// <inheritdoc />
238238
public double UpdatesPerSecond
239239
{
240-
get => updatesPerSecond;
240+
get => 1.0 / updatePeriod;
241241
set
242242
{
243-
updatesPerSecond = value;
244-
245243
if (value <= double.Epsilon) {
246244
updatePeriod = 0.0;
247245
return;

src/Windowing/Silk.NET.Windowing/Silk.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public static class Silk
2222
/// <summary>
2323
/// Reflects over the current AppDomain in an attempt to resolve an <see cref="ISilkPlatform" />.
2424
/// </summary>
25-
/// <exception cref="NotSupportedException">Thrown f no applicable <see cref="ISilkPlatform" /> was found.</exception>
25+
/// <exception cref="NotSupportedException">
26+
/// Thrown if no applicable <see cref="ISilkPlatform" /> was found.
27+
/// </exception>
2628
public static void Init()
2729
{
2830
var glfwPlatform = new GlfwPlatform();

src/Windowing/Silk.NET.Windowing/Window.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@
77

88
namespace Silk.NET.Windowing
99
{
10+
/// <summary>
11+
/// Convenience wrapper for easily creating a Silk.NET window.
12+
/// </summary>
1013
public static class Window
1114
{
15+
/// <summary>
16+
/// Create a window on the current platform.
17+
/// </summary>
18+
/// <param name="options">The window to use.</param>
19+
/// <returns>A Silk.NET window using the current platform.</returns>
1220
public static IWindow Create(WindowOptions options)
1321
{
1422
if (Silk.CurrentPlatform == null) {

0 commit comments

Comments
 (0)