Skip to content

Commit 289182b

Browse files
committed
Update SFML.Net to CSFML/SFML 3
- Update all SFML modules to use the latest CSFML methods - Switch to NET Analyzer from StyleCop
1 parent 4d8fc23 commit 289182b

Some content is hidden

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

65 files changed

+3083
-1074
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

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ 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
2124
Global

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

src/SFML.Audio/Cone.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Runtime.InteropServices;
2+
using SFML.System;
3+
4+
namespace SFML.Audio
5+
{
6+
////////////////////////////////////////////////////////////
7+
/// <summary>
8+
/// Structure defining the properties of a directional cone
9+
/// <para/>
10+
/// When set on the listener, sounds will play at gain 1 when
11+
/// they are positioned within the inner angle of the cone.
12+
/// Sounds will play at outerGain when they are positioned
13+
/// outside the outer angle of the cone.
14+
/// The gain declines linearly from 1 to outerGain as the
15+
/// sound moves from the inner angle to the outer angle.
16+
/// <para/>
17+
/// When set on sound sources, they will play at gain 1 when the
18+
/// listener is positioned within the inner angle of the cone.
19+
/// Sounds will play at `outerGain` when the listener is
20+
/// positioned outside the outer angle of the cone.
21+
/// The gain declines linearly from 1 to outerGain as the
22+
/// listener moves from the inner angle to the outer angle.
23+
/// </summary>
24+
////////////////////////////////////////////////////////////
25+
public struct Cone
26+
{
27+
/// <summary>Inner angle</summary>
28+
public Angle InnerAngle;
29+
30+
/// <summary>Outer angle</summary>
31+
public Angle OuterAngle;
32+
33+
/// <summary>Outer angle</summary>
34+
public float OuterGain;
35+
36+
[StructLayout(LayoutKind.Sequential)]
37+
internal struct MarshalData
38+
{
39+
public float InnerAngleDegrees;
40+
public float OuterAngleDegrees;
41+
public float OuterGain;
42+
}
43+
44+
internal Cone(MarshalData data)
45+
{
46+
InnerAngle = Angle.FromDegrees(data.InnerAngleDegrees);
47+
OuterAngle = Angle.FromDegrees(data.OuterAngleDegrees);
48+
OuterGain = data.OuterGain;
49+
}
50+
51+
// Return a marshalled version of the instance, that can directly be passed to the C API
52+
internal MarshalData Marshal()
53+
{
54+
var data = new MarshalData
55+
{
56+
InnerAngleDegrees = InnerAngle.Degrees,
57+
OuterAngleDegrees = OuterAngle.Degrees,
58+
OuterGain = OuterGain
59+
};
60+
61+
return data;
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)