Skip to content

Commit 0e7efab

Browse files
SFML.Net 3 (#277)
* Update SFML.Net to CSFML/SFML 3 - Update all SFML modules to use the latest CSFML methods - Switch to NET Analyzer from StyleCop * Add tests for SFML.System --------- Co-authored-by: Lukas Dürrenberger <[email protected]>
1 parent 4d8fc23 commit 0e7efab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3961
-1075
lines changed

.editorconfig

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ indent_style = space
1717
indent_size = 4
1818
insert_final_newline = false
1919
trim_trailing_whitespace = true
20+
csharp_using_directive_placement = outside_namespace:silent
21+
csharp_prefer_simple_using_statement = true:suggestion
22+
csharp_prefer_braces = true:warning
23+
csharp_style_namespace_declarations = file_scoped:silent
24+
csharp_style_prefer_method_group_conversion = true:silent
25+
csharp_style_prefer_top_level_statements = false:warning
26+
csharp_style_prefer_primary_constructors = true:suggestion
27+
csharp_style_expression_bodied_methods = true:warning
28+
csharp_style_expression_bodied_constructors = true:warning
29+
csharp_style_expression_bodied_operators = true:warning
30+
csharp_style_expression_bodied_properties = true:warning
31+
csharp_style_expression_bodied_indexers = true:warning
32+
csharp_style_expression_bodied_accessors = true:warning
33+
csharp_style_expression_bodied_lambdas = true:silent
34+
csharp_style_expression_bodied_local_functions = false:silent
35+
csharp_indent_labels = no_change
2036

2137
#########################
2238
# File Extension Settings
@@ -350,4 +366,7 @@ dotnet_diagnostic.IDE0130.severity = suggestion
350366
dotnet_diagnostic.IDE0060.severity = suggestion
351367

352368
# CA1805: Do not initialize unnecessarily
353-
dotnet_diagnostic.CA1805.severity = warning
369+
dotnet_diagnostic.CA1805.severity = warning
370+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
371+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
372+
tab_width = 4

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ jobs:
4141
run: dotnet new globaljson --sdk-version ${{ steps.setup-dotnet.outputs.dotnet-version }} --force
4242
- name: Verify SDK Installation
4343
run: dotnet --info
44+
continue-on-error: true
4445

4546
- name: Install SFML.Net Dependencies
4647
run: dotnet restore
4748
- name: Build SFML.Net
4849
run: dotnet build --configuration Release --no-restore
50+
- name: Test SFML.Net
51+
if: matrix.dotnet.name == '.NET 6'
52+
run: dotnet test --configuration Release --no-restore
4953
- name: Pack SFML.Net
5054
run: dotnet pack --configuration Release -o Publish
5155

@@ -58,4 +62,4 @@ jobs:
5862
uses: actions/upload-artifact@v4
5963
with:
6064
name: SFML.Net (${{ matrix.platform.name }} ${{ matrix.dotnet.name }})
61-
path: Publish/SFML.*.*.nupkg
65+
path: Publish/SFML.*.*.nupkg

SFML.CodeStyle.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22

33
<!-- This file contains code style configurations for projects. -->
4-
4+
55
<PropertyGroup>
66
<EnableNETAnalyzers>true</EnableNETAnalyzers>
77
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

SFML.Module.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="CSFML" Version="[2.6.1, 2.7)" />
21+
<PackageReference Include="CSFML" Version="[3.0.0-rc.1, 3.1)" />
2222
</ItemGroup>
2323

2424
</Project>

SFML.NuGet.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<PropertyGroup>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77

8-
<Version>2.6.0</Version>
8+
<Version>3.0.0-rc.1</Version>
99
<Authors>Laurent Gomila</Authors>
1010
<PackageTags>sfml sfml.net</PackageTags>
1111
<Copyright>Copyright © Laurent Gomila</Copyright>

SFML.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@ EndProject
1616
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4BBA7B74-E003-4D9B-826A-43BD6BA48111}"
1717
ProjectSection(SolutionItems) = preProject
1818
.editorconfig = .editorconfig
19+
SFML.Module.props = SFML.Module.props
20+
SFML.NuGet.props = SFML.NuGet.props
21+
SFML.CodeStyle.props = SFML.CodeStyle.props
1922
EndProjectSection
2023
EndProject
24+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFML.System.Test", "test\SFML.System.Test\SFML.System.Test.csproj", "{958AC8B0-2D99-4C65-97C1-2979A090C82D}"
25+
EndProject
26+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{D98B564D-6F79-4429-87C3-ECDDC54F731B}"
27+
EndProject
2128
Global
2229
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2330
Debug|Any CPU = Debug|Any CPU
@@ -88,11 +95,26 @@ Global
8895
{88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x64.Build.0 = Release|x64
8996
{88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x86.ActiveCfg = Release|x86
9097
{88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x86.Build.0 = Release|x86
98+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
99+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Debug|Any CPU.Build.0 = Debug|Any CPU
100+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Debug|x64.ActiveCfg = Debug|x64
101+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Debug|x64.Build.0 = Debug|x64
102+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Debug|x86.ActiveCfg = Debug|x86
103+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Debug|x86.Build.0 = Debug|x86
104+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Release|Any CPU.ActiveCfg = Release|Any CPU
105+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Release|Any CPU.Build.0 = Release|Any CPU
106+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Release|x64.ActiveCfg = Release|x64
107+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Release|x64.Build.0 = Release|x64
108+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Release|x86.ActiveCfg = Release|x86
109+
{958AC8B0-2D99-4C65-97C1-2979A090C82D}.Release|x86.Build.0 = Release|x86
91110
EndGlobalSection
92111
GlobalSection(SolutionProperties) = preSolution
93112
HideSolutionNode = FALSE
94113
EndGlobalSection
95114
GlobalSection(ExtensibilityGlobals) = postSolution
96115
SolutionGuid = {384AFDD8-7EEF-462A-B496-B5F71D0EEF1D}
97116
EndGlobalSection
117+
GlobalSection(NestedProjects) = preSolution
118+
{958AC8B0-2D99-4C65-97C1-2979A090C82D} = {D98B564D-6F79-4429-87C3-ECDDC54F731B}
119+
EndGlobalSection
98120
EndGlobal

examples/netcore/Program.cs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,43 @@
44
using SFML.System;
55
using SFML.Window;
66

7-
namespace netcore
7+
namespace netcore;
8+
9+
internal class Program
810
{
9-
internal class Program
11+
private static void Main()
1012
{
11-
private static void Main()
13+
var shape = new RectangleShape(new Vector2f(100, 100))
1214
{
13-
var shape = new RectangleShape(new Vector2f(100, 100))
14-
{
15-
FillColor = Color.Black
16-
};
17-
18-
var sound = new Sound(GenerateSineWave(frequency: 440.0, volume: .25, seconds: 1));
15+
FillColor = Color.Black
16+
};
1917

20-
var window = new RenderWindow(new VideoMode(800, 600), "SFML running in .NET Core");
21-
window.Closed += (_, _) => window.Close();
18+
var sound = new Sound(GenerateSineWave(frequency: 440.0, volume: .25, seconds: 1));
2219

23-
sound.Play();
20+
var window = new RenderWindow(new VideoMode((800, 600)), "SFML running in .NET Core");
21+
window.Closed += (_, _) => window.Close();
2422

25-
while (window.IsOpen)
26-
{
27-
window.DispatchEvents();
28-
window.Clear(Color.White);
29-
window.Draw(shape);
30-
window.Display();
31-
}
32-
}
23+
sound.Play();
3324

34-
private static SoundBuffer GenerateSineWave(double frequency, double volume, int seconds)
25+
while (window.IsOpen)
3526
{
36-
uint sampleRate = 44100;
37-
var samples = new short[seconds * sampleRate];
27+
window.DispatchEvents();
28+
window.Clear(Color.White);
29+
window.Draw(shape);
30+
window.Display();
31+
}
32+
}
3833

39-
for (var i = 0; i < samples.Length; i++)
40-
{
41-
samples[i] = (short)(Math.Sin(frequency * (2 * Math.PI) * i / sampleRate) * volume * short.MaxValue);
42-
}
34+
private static SoundBuffer GenerateSineWave(double frequency, double volume, int seconds)
35+
{
36+
uint sampleRate = 44100;
37+
var samples = new short[seconds * sampleRate];
4338

44-
return new SoundBuffer(samples, 1, sampleRate);
39+
for (var i = 0; i < samples.Length; i++)
40+
{
41+
samples[i] = (short)(Math.Sin(frequency * (2 * Math.PI) * i / sampleRate) * volume * short.MaxValue);
4542
}
43+
44+
return new SoundBuffer(samples, 1, sampleRate, new SoundChannel[] { SoundChannel.Mono });
4645
}
4746
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"netcore": {
4+
"commandName": "Project",
5+
"nativeDebugging": true
6+
}
7+
}
8+
}

examples/opengl/OpenGL.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private static void Main()
2424
};
2525

2626
// Create the main window
27-
var window = new RenderWindow(new VideoMode(800, 600), "SFML graphics with OpenGL", Styles.Default, contextSettings);
27+
var window = new RenderWindow(new VideoMode((800, 600)), "SFML graphics with OpenGL", Styles.Default, State.Windowed, contextSettings);
2828
window.SetVerticalSyncEnabled(true);
2929

3030
// Initialize OpenTK
@@ -41,7 +41,7 @@ private static void Main()
4141
var background = new Sprite(new Texture("resources/background.jpg"));
4242

4343
// Create a text to display on top of the OpenGL object
44-
var text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf"))
44+
var text = new Text(new Font("resources/sansation.ttf"), "SFML / OpenGL demo")
4545
{
4646
Position = new Vector2f(250, 450),
4747
FillColor = new SFML.Graphics.Color(255, 255, 255, 170)
@@ -212,6 +212,6 @@ private static void OnKeyPressed(object sender, KeyEventArgs e)
212212
/// <summary>
213213
/// Function called when the window is resized
214214
/// </summary>
215-
private static void OnResized(object sender, SizeEventArgs e) => GL.Viewport(0, 0, (int)e.Width, (int)e.Height);
215+
private static void OnResized(object sender, SizeEventArgs e) => GL.Viewport(0, 0, (int)e.Size.X, (int)e.Size.Y);
216216
}
217217
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"opengl": {
4+
"commandName": "Project",
5+
"nativeDebugging": true
6+
}
7+
}
8+
}

examples/shader/Shader.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Draw(IRenderTarget target, RenderStates states)
2727
}
2828
else
2929
{
30-
var error = new Text("Shader not\nsupported", Font)
30+
var error = new Text(Font, "Shader not\nsupported")
3131
{
3232
Position = new Vector2f(320, 200),
3333
CharacterSize = 36
@@ -78,7 +78,7 @@ internal class WaveBlur : Effect
7878
public WaveBlur() : base("wave + blur")
7979
{
8080
// Create the text
81-
_text = new Text
81+
_text = new Text(Font)
8282
{
8383
DisplayedString = "Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n" +
8484
"Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n" +
@@ -98,7 +98,6 @@ public WaveBlur() : base("wave + blur")
9898
"Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n" +
9999
"Duis erat eros, porta in accumsan in, blandit quis sem.\n" +
100100
"In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n",
101-
Font = Font,
102101
CharacterSize = 22,
103102
Position = new Vector2f(30, 20)
104103
};
@@ -178,7 +177,7 @@ internal class Edge : Effect
178177
public Edge() : base("edge post-effect")
179178
{
180179
// Create the off-screen surface
181-
_surface = new RenderTexture(800, 600)
180+
_surface = new RenderTexture((800, 600))
182181
{
183182
Smooth = true
184183
};
@@ -203,7 +202,7 @@ public Edge() : base("edge post-effect")
203202
_entities = new Sprite[6];
204203
for (var i = 0; i < _entities.Length; ++i)
205204
{
206-
_entities[i] = new Sprite(_entityTexture, new IntRect(96 * i, 0, 96, 96));
205+
_entities[i] = new Sprite(_entityTexture, new IntRect((96 * i, 0), (96, 96)));
207206
}
208207

209208
// Load the shader
@@ -263,7 +262,7 @@ internal static class Program
263262
private static void Main()
264263
{
265264
// Create the main window
266-
var window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader");
265+
var window = new RenderWindow(new VideoMode((800, 600)), "SFML.Net Shader");
267266
window.SetVerticalSyncEnabled(true);
268267

269268
// Setup event handlers
@@ -293,14 +292,14 @@ private static void Main()
293292
};
294293

295294
// Create the description text
296-
_description = new Text("Current effect: " + _effects[_current].Name, font, 20)
295+
_description = new Text(font, "Current effect: " + _effects[_current].Name, 20)
297296
{
298297
Position = new Vector2f(10, 530),
299298
FillColor = new Color(80, 80, 80)
300299
};
301300

302301
// Create the instructions text
303-
var instructions = new Text("Press left and right arrows to change the current shader", font, 20)
302+
var instructions = new Text(font, "Press left and right arrows to change the current shader", 20)
304303
{
305304
Position = new Vector2f(280, 555),
306305
FillColor = new Color(80, 80, 80)

examples/visualbasic/OpenGL.vb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Friend Module OpenGL
2020
}
2121

2222
' Create main window
23-
window = New RenderWindow(New VideoMode(800, 600), "SFML graphics with OpenGL (Visual Basic)", Styles.Default, contextSettings)
23+
window = New RenderWindow(New VideoMode((800, 600)), "SFML graphics with OpenGL (Visual Basic)", Styles.Default, State.Windowed, contextSettings)
2424
window.SetVerticalSyncEnabled(True)
2525

2626
' Initialize OpenTK
@@ -31,7 +31,7 @@ Friend Module OpenGL
3131
Dim background = New Sprite(New Texture("resources/background.jpg"))
3232

3333
' Create a text to display on top of the OpenGL object
34-
Dim text = New Text("SFML / OpenGL demo", New Font("resources/sansation.ttf")) With {
34+
Dim text = New Text(New Font("resources/sansation.ttf"), "SFML / OpenGL demo") With {
3535
.Position = New Vector2f(250, 450),
3636
.FillColor = New SFML.Graphics.Color(255, 255, 255, 170)
3737
}
@@ -196,7 +196,7 @@ Friend Module OpenGL
196196
''' Function called when the window is resized
197197
''' </summary>
198198
Public Sub App_Resized(sender As Object, e As SizeEventArgs) Handles window.Resized
199-
GL.Viewport(0, 0, e.Width, e.Height)
199+
GL.Viewport(0, 0, e.Size.X, e.Size.Y)
200200
End Sub
201201

202202
End Module

examples/window/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class SimpleWindow
1818
{
1919
public void Run()
2020
{
21-
var mode = new SFML.Window.VideoMode(800, 600);
21+
var mode = new SFML.Window.VideoMode((800, 600));
2222
var window = new SFML.Graphics.RenderWindow(mode, "SFML works!");
2323
window.KeyPressed += Window_KeyPressed;
2424

0 commit comments

Comments
 (0)