Skip to content

Commit 887e5cf

Browse files
committed
SFML.Net 3
1 parent 2999135 commit 887e5cf

Some content is hidden

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

55 files changed

+2298
-1042
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.sln

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1818
.editorconfig = .editorconfig
1919
EndProjectSection
2020
EndProject
21+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{0A84335E-59C1-4969-9F5F-4D42DC7F2BFC}"
22+
EndProject
23+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFML.System.Test", "test\SFML.System.Test\SFML.System.Test.csproj", "{90D86010-580C-4D2A-8AD1-C18CD982C5A0}"
24+
EndProject
2125
Global
2226
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2327
Debug|Any CPU = Debug|Any CPU
@@ -88,10 +92,25 @@ Global
8892
{88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x64.Build.0 = Release|x64
8993
{88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x86.ActiveCfg = Release|x86
9094
{88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x86.Build.0 = Release|x86
95+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
96+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
97+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|x64.ActiveCfg = Debug|x64
98+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|x64.Build.0 = Debug|x64
99+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|x86.ActiveCfg = Debug|x86
100+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|x86.Build.0 = Debug|x86
101+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
102+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|Any CPU.Build.0 = Release|Any CPU
103+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|x64.ActiveCfg = Release|x64
104+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|x64.Build.0 = Release|x64
105+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|x86.ActiveCfg = Release|x86
106+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|x86.Build.0 = Release|x86
91107
EndGlobalSection
92108
GlobalSection(SolutionProperties) = preSolution
93109
HideSolutionNode = FALSE
94110
EndGlobalSection
111+
GlobalSection(NestedProjects) = preSolution
112+
{90D86010-580C-4D2A-8AD1-C18CD982C5A0} = {0A84335E-59C1-4969-9F5F-4D42DC7F2BFC}
113+
EndGlobalSection
95114
GlobalSection(ExtensibilityGlobals) = postSolution
96115
SolutionGuid = {384AFDD8-7EEF-462A-B496-B5F71D0EEF1D}
97116
EndGlobalSection

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
}

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
}

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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
/// Sounds will play at gain 1 when they are positioned
11+
/// within the inner angle of the cone. Sounds will play
12+
/// at outerGain when they are positioned outside the
13+
/// outer angle of the cone. The gain declines linearly
14+
/// from 1 to outerGain as the sound moves from the inner
15+
/// angle to the outer angle.
16+
/// </summary>
17+
////////////////////////////////////////////////////////////
18+
public struct Cone
19+
{
20+
/// <summary>Inner angle</summary>
21+
public Angle InnerAngle;
22+
23+
/// <summary>Outer angle</summary>
24+
public Angle OuterAngle;
25+
26+
/// <summary>Outer angle</summary>
27+
public float OuterGain;
28+
29+
[StructLayout(LayoutKind.Sequential)]
30+
internal struct MarshalData
31+
{
32+
public float InnerAngleDegrees;
33+
public float OuterAngleDegrees;
34+
public float OuterGain;
35+
}
36+
37+
// Return a marshalled version of the instance, that can directly be passed to the C API
38+
internal MarshalData Marshal()
39+
{
40+
var data = new MarshalData
41+
{
42+
InnerAngleDegrees = InnerAngle.Degrees,
43+
OuterAngleDegrees = OuterAngle.Degrees,
44+
OuterGain = OuterGain
45+
};
46+
47+
return data;
48+
}
49+
}
50+
}

src/SFML.Audio/Listener.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Runtime.InteropServices;
23
using System.Security;
34
using SFML.System;
@@ -52,6 +53,29 @@ public static Vector3f Direction
5253
set => sfListener_setDirection(value);
5354
}
5455

56+
////////////////////////////////////////////////////////////
57+
/// <summary>
58+
/// The velocity of the listener in the scene (default is (0, 0, -1))
59+
/// </summary>
60+
////////////////////////////////////////////////////////////
61+
public static Vector3f Velocity
62+
{
63+
get => throw new NotImplementedException("TODO Implement when CSFML is ready.");
64+
set => throw new NotImplementedException("TODO Implement when CSFML is ready.");
65+
}
66+
67+
////////////////////////////////////////////////////////////
68+
/// <summary>
69+
/// The cone defines how directional attenuation is applied.
70+
/// The default cone of a sound is {2 * PI, 2 * PI, 1}.
71+
/// </summary>
72+
////////////////////////////////////////////////////////////
73+
public static Cone Cone
74+
{
75+
get => throw new NotImplementedException("TODO Implement when CSFML is ready.");
76+
set => throw new NotImplementedException("TODO Implement when CSFML is ready.");
77+
}
78+
5579
////////////////////////////////////////////////////////////
5680
/// <summary>
5781
/// The up vector is the vector that points upward from the

0 commit comments

Comments
 (0)