Skip to content

Commit

Permalink
SFML.Net 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Marioalexsan committed Oct 4, 2024
1 parent 2999135 commit e0455a4
Show file tree
Hide file tree
Showing 63 changed files with 3,856 additions and 1,055 deletions.
21 changes: 20 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ indent_style = space
indent_size = 4
insert_final_newline = false
trim_trailing_whitespace = true
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:warning
csharp_style_namespace_declarations = file_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = false:warning
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_expression_bodied_methods = true:warning
csharp_style_expression_bodied_constructors = true:warning
csharp_style_expression_bodied_operators = true:warning
csharp_style_expression_bodied_properties = true:warning
csharp_style_expression_bodied_indexers = true:warning
csharp_style_expression_bodied_accessors = true:warning
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_indent_labels = no_change

#########################
# File Extension Settings
Expand Down Expand Up @@ -350,4 +366,7 @@ dotnet_diagnostic.IDE0130.severity = suggestion
dotnet_diagnostic.IDE0060.severity = suggestion

# CA1805: Do not initialize unnecessarily
dotnet_diagnostic.CA1805.severity = warning
dotnet_diagnostic.CA1805.severity = warning
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
run: dotnet restore
- name: Build SFML.Net
run: dotnet build --configuration Release --no-restore
# FIXME: Run tests on .NET 7 / 8 / 9
- name: Test SFML.Net
if: matrix.dotnet.name == '.NET 6'
run: dotnet test --configuration Release --no-restore
- name: Pack SFML.Net
run: dotnet pack --configuration Release -o Publish

Expand All @@ -58,4 +62,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: SFML.Net (${{ matrix.platform.name }} ${{ matrix.dotnet.name }})
path: Publish/SFML.*.*.nupkg
path: Publish/SFML.*.*.nupkg
2 changes: 1 addition & 1 deletion SFML.CodeStyle.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- This file contains code style configurations for projects. -->

<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
Expand Down
2 changes: 1 addition & 1 deletion SFML.Module.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSFML" Version="[2.6.1, 2.7)" />
<PackageReference Include="CSFML" Version="[3.0.0, 3.1)" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion SFML.NuGet.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

<Version>2.6.0</Version>
<Version>3.0.0-alpha1</Version>
<Authors>Laurent Gomila</Authors>
<PackageTags>sfml sfml.net</PackageTags>
<Copyright>Copyright © Laurent Gomila</Copyright>
Expand Down
19 changes: 19 additions & 0 deletions SFML.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{0A84335E-59C1-4969-9F5F-4D42DC7F2BFC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFML.System.Test", "test\SFML.System.Test\SFML.System.Test.csproj", "{90D86010-580C-4D2A-8AD1-C18CD982C5A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -88,10 +92,25 @@ Global
{88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x64.Build.0 = Release|x64
{88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x86.ActiveCfg = Release|x86
{88DD6B5D-3013-4737-A77C-EC2563FCED38}.Release|x86.Build.0 = Release|x86
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|x64.ActiveCfg = Debug|x64
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|x64.Build.0 = Debug|x64
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|x86.ActiveCfg = Debug|x86
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Debug|x86.Build.0 = Debug|x86
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|Any CPU.Build.0 = Release|Any CPU
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|x64.ActiveCfg = Release|x64
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|x64.Build.0 = Release|x64
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|x86.ActiveCfg = Release|x86
{90D86010-580C-4D2A-8AD1-C18CD982C5A0}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{90D86010-580C-4D2A-8AD1-C18CD982C5A0} = {0A84335E-59C1-4969-9F5F-4D42DC7F2BFC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {384AFDD8-7EEF-462A-B496-B5F71D0EEF1D}
EndGlobalSection
Expand Down
55 changes: 27 additions & 28 deletions examples/netcore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,43 @@
using SFML.System;
using SFML.Window;

namespace netcore
namespace netcore;

internal class Program
{
internal class Program
private static void Main()
{
private static void Main()
var shape = new RectangleShape(new Vector2f(100, 100))
{
var shape = new RectangleShape(new Vector2f(100, 100))
{
FillColor = Color.Black
};

var sound = new Sound(GenerateSineWave(frequency: 440.0, volume: .25, seconds: 1));
FillColor = Color.Black
};

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

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

while (window.IsOpen)
{
window.DispatchEvents();
window.Clear(Color.White);
window.Draw(shape);
window.Display();
}
}
sound.Play();

private static SoundBuffer GenerateSineWave(double frequency, double volume, int seconds)
while (window.IsOpen)
{
uint sampleRate = 44100;
var samples = new short[seconds * sampleRate];
window.DispatchEvents();
window.Clear(Color.White);
window.Draw(shape);
window.Display();
}
}

for (var i = 0; i < samples.Length; i++)
{
samples[i] = (short)(Math.Sin(frequency * (2 * Math.PI) * i / sampleRate) * volume * short.MaxValue);
}
private static SoundBuffer GenerateSineWave(double frequency, double volume, int seconds)
{
uint sampleRate = 44100;
var samples = new short[seconds * sampleRate];

return new SoundBuffer(samples, 1, sampleRate);
for (var i = 0; i < samples.Length; i++)
{
samples[i] = (short)(Math.Sin(frequency * (2 * Math.PI) * i / sampleRate) * volume * short.MaxValue);
}

return new SoundBuffer(samples, 1, sampleRate, new SoundChannel[] { SoundChannel.Mono });
}
}
6 changes: 3 additions & 3 deletions examples/opengl/OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void Main()
};

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

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

// Create a text to display on top of the OpenGL object
var text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf"))
var text = new Text(new Font("resources/sansation.ttf"), "SFML / OpenGL demo")
{
Position = new Vector2f(250, 450),
FillColor = new SFML.Graphics.Color(255, 255, 255, 170)
Expand Down Expand Up @@ -212,6 +212,6 @@ private static void OnKeyPressed(object sender, KeyEventArgs e)
/// <summary>
/// Function called when the window is resized
/// </summary>
private static void OnResized(object sender, SizeEventArgs e) => GL.Viewport(0, 0, (int)e.Width, (int)e.Height);
private static void OnResized(object sender, SizeEventArgs e) => GL.Viewport(0, 0, (int)e.Size.X, (int)e.Size.Y);
}
}
15 changes: 7 additions & 8 deletions examples/shader/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Draw(IRenderTarget target, RenderStates states)
}
else
{
var error = new Text("Shader not\nsupported", Font)
var error = new Text(Font, "Shader not\nsupported")
{
Position = new Vector2f(320, 200),
CharacterSize = 36
Expand Down Expand Up @@ -78,7 +78,7 @@ internal class WaveBlur : Effect
public WaveBlur() : base("wave + blur")
{
// Create the text
_text = new Text
_text = new Text(Font)
{
DisplayedString = "Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n" +
"Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n" +
Expand All @@ -98,7 +98,6 @@ public WaveBlur() : base("wave + blur")
"Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n" +
"Duis erat eros, porta in accumsan in, blandit quis sem.\n" +
"In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n",
Font = Font,
CharacterSize = 22,
Position = new Vector2f(30, 20)
};
Expand Down Expand Up @@ -178,7 +177,7 @@ internal class Edge : Effect
public Edge() : base("edge post-effect")
{
// Create the off-screen surface
_surface = new RenderTexture(800, 600)
_surface = new RenderTexture((800, 600))
{
Smooth = true
};
Expand All @@ -203,7 +202,7 @@ public Edge() : base("edge post-effect")
_entities = new Sprite[6];
for (var i = 0; i < _entities.Length; ++i)
{
_entities[i] = new Sprite(_entityTexture, new IntRect(96 * i, 0, 96, 96));
_entities[i] = new Sprite(_entityTexture, new IntRect((96 * i, 0), (96, 96)));
}

// Load the shader
Expand Down Expand Up @@ -263,7 +262,7 @@ internal static class Program
private static void Main()
{
// Create the main window
var window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader");
var window = new RenderWindow(new VideoMode((800, 600)), "SFML.Net Shader");
window.SetVerticalSyncEnabled(true);

// Setup event handlers
Expand Down Expand Up @@ -293,14 +292,14 @@ private static void Main()
};

// Create the description text
_description = new Text("Current effect: " + _effects[_current].Name, font, 20)
_description = new Text(font, "Current effect: " + _effects[_current].Name, 20)
{
Position = new Vector2f(10, 530),
FillColor = new Color(80, 80, 80)
};

// Create the instructions text
var instructions = new Text("Press left and right arrows to change the current shader", font, 20)
var instructions = new Text(font, "Press left and right arrows to change the current shader", 20)
{
Position = new Vector2f(280, 555),
FillColor = new Color(80, 80, 80)
Expand Down
6 changes: 3 additions & 3 deletions examples/visualbasic/OpenGL.vb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Friend Module OpenGL
}

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

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

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

End Module
2 changes: 1 addition & 1 deletion examples/window/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class SimpleWindow
{
public void Run()
{
var mode = new SFML.Window.VideoMode(800, 600);
var mode = new SFML.Window.VideoMode((800, 600));
var window = new SFML.Graphics.RenderWindow(mode, "SFML works!");
window.KeyPressed += Window_KeyPressed;

Expand Down
64 changes: 64 additions & 0 deletions src/SFML.Audio/Cone.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Runtime.InteropServices;
using SFML.System;

namespace SFML.Audio
{
////////////////////////////////////////////////////////////
/// <summary>
/// Structure defining the properties of a directional cone
/// <para/>
/// When set on the listener, sounds will play at gain 1 when
/// they are positioned within the inner angle of the cone.
/// Sounds will play at outerGain when they are positioned
/// outside the outer angle of the cone.
/// The gain declines linearly from 1 to outerGain as the
/// sound moves from the inner angle to the outer angle.
/// <para/>
/// When set on sound sources, they will play at gain 1 when the
/// listener is positioned within the inner angle of the cone.
/// Sounds will play at `outerGain` when the listener is
/// positioned outside the outer angle of the cone.
/// The gain declines linearly from 1 to outerGain as the
/// listener moves from the inner angle to the outer angle.
/// </summary>
////////////////////////////////////////////////////////////
public struct Cone
{
/// <summary>Inner angle</summary>
public Angle InnerAngle;

/// <summary>Outer angle</summary>
public Angle OuterAngle;

/// <summary>Outer angle</summary>
public float OuterGain;

[StructLayout(LayoutKind.Sequential)]
internal struct MarshalData
{
public float InnerAngleDegrees;
public float OuterAngleDegrees;
public float OuterGain;
}

internal Cone(MarshalData data)
{
InnerAngle = Angle.FromDegrees(data.InnerAngleDegrees);
OuterAngle = Angle.FromDegrees(data.OuterAngleDegrees);
OuterGain = data.OuterGain;
}

// Return a marshalled version of the instance, that can directly be passed to the C API
internal MarshalData Marshal()
{
var data = new MarshalData
{
InnerAngleDegrees = InnerAngle.Degrees,
OuterAngleDegrees = OuterAngle.Degrees,
OuterGain = OuterGain
};

return data;
}
}
}
Loading

0 comments on commit e0455a4

Please sign in to comment.