Skip to content

Commit b07c9ca

Browse files
committed
SFML.Net 3
1 parent 2999135 commit b07c9ca

Some content is hidden

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

50 files changed

+2257
-999
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

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

src/SFML.Audio/Music.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Runtime.InteropServices;
45
using System.Security;
@@ -132,6 +133,16 @@ public Music(byte[] bytes) :
132133
////////////////////////////////////////////////////////////
133134
public uint SampleRate => sfMusic_getSampleRate(CPointer);
134135

136+
////////////////////////////////////////////////////////////
137+
/// <summary>
138+
/// Get the map of position in sample frame to sound channel
139+
/// <para/>
140+
/// This is used to map a sample in the sample stream to a
141+
/// position during spatialisation.
142+
/// </summary>
143+
////////////////////////////////////////////////////////////
144+
public IEnumerable<SoundChannel> ChannelMap => throw new NotImplementedException("TODO CSFML implementation.");
145+
135146
////////////////////////////////////////////////////////////
136147
/// <summary>
137148
/// Number of channels (1 = mono, 2 = stereo)
@@ -165,8 +176,8 @@ public Music(byte[] bytes) :
165176
////////////////////////////////////////////////////////////
166177
public bool Loop
167178
{
168-
get => sfMusic_getLoop(CPointer);
169-
set => sfMusic_setLoop(CPointer, value);
179+
get => sfMusic_isLooping(CPointer);
180+
set => sfMusic_setLooping(CPointer, value);
170181
}
171182

172183
////////////////////////////////////////////////////////////
@@ -421,7 +432,7 @@ public TimeSpan(Time offset, Time length)
421432
private static extern void sfMusic_setPitch(IntPtr music, float pitch);
422433

423434
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
424-
private static extern void sfMusic_setLoop(IntPtr music, bool loop);
435+
private static extern void sfMusic_setLooping(IntPtr music, bool loop);
425436

426437
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
427438
private static extern void sfMusic_setVolume(IntPtr music, float volume);
@@ -442,7 +453,7 @@ public TimeSpan(Time offset, Time length)
442453
private static extern void sfMusic_setPlayingOffset(IntPtr music, Time timeOffset);
443454

444455
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
445-
private static extern bool sfMusic_getLoop(IntPtr music);
456+
private static extern bool sfMusic_isLooping(IntPtr music);
446457

447458
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
448459
private static extern float sfMusic_getPitch(IntPtr music);

src/SFML.Audio/Sound.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,14 @@ public enum SoundStatus
2929
////////////////////////////////////////////////////////////
3030
public class Sound : ObjectBase
3131
{
32-
////////////////////////////////////////////////////////////
33-
/// <summary>
34-
/// Default constructor (invalid sound)
35-
/// </summary>
36-
////////////////////////////////////////////////////////////
37-
public Sound() :
38-
base(sfSound_create())
39-
{
40-
}
41-
4232
////////////////////////////////////////////////////////////
4333
/// <summary>
4434
/// Construct the sound with a buffer
4535
/// </summary>
4636
/// <param name="buffer">Sound buffer containing the audio data to play with the sound</param>
4737
////////////////////////////////////////////////////////////
4838
public Sound(SoundBuffer buffer) :
49-
base(sfSound_create()) => SoundBuffer = buffer;
39+
base(sfSound_create(buffer.CPointer)) => SoundBuffer = buffer;
5040

5141
////////////////////////////////////////////////////////////
5242
/// <summary>
@@ -125,8 +115,8 @@ public SoundBuffer SoundBuffer
125115
////////////////////////////////////////////////////////////
126116
public bool Loop
127117
{
128-
get => sfSound_getLoop(CPointer);
129-
set => sfSound_setLoop(CPointer, value);
118+
get => sfSound_isLooping(CPointer);
119+
set => sfSound_setLooping(CPointer, value);
130120
}
131121

132122
////////////////////////////////////////////////////////////
@@ -282,7 +272,7 @@ public override string ToString()
282272

283273
#region Imports
284274
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
285-
private static extern IntPtr sfSound_create();
275+
private static extern IntPtr sfSound_create(IntPtr soundBuffer);
286276

287277
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
288278
private static extern IntPtr sfSound_copy(IntPtr sound);
@@ -303,10 +293,10 @@ public override string ToString()
303293
private static extern void sfSound_setBuffer(IntPtr sound, IntPtr buffer);
304294

305295
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
306-
private static extern void sfSound_setLoop(IntPtr sound, bool loop);
296+
private static extern void sfSound_setLooping(IntPtr sound, bool loop);
307297

308298
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
309-
private static extern bool sfSound_getLoop(IntPtr sound);
299+
private static extern bool sfSound_isLooping(IntPtr sound);
310300

311301
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
312302
private static extern SoundStatus sfSound_getStatus(IntPtr sound);

src/SFML.Audio/SoundBuffer.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Runtime.InteropServices;
45
using System.Security;
@@ -93,16 +94,20 @@ public SoundBuffer(byte[] bytes) :
9394
/// <param name="samples">Array of samples</param>
9495
/// <param name="channelCount">Channel count</param>
9596
/// <param name="sampleRate">Sample rate</param>
97+
/// <param name="channelMapData">Map of position in sample frame to sound channel</param>
9698
/// <exception cref="LoadingFailedException" />
9799
////////////////////////////////////////////////////////////
98-
public SoundBuffer(short[] samples, uint channelCount, uint sampleRate) :
100+
public SoundBuffer(short[] samples, uint channelCount, uint sampleRate, SoundChannel[] channelMapData) :
99101
base(IntPtr.Zero)
100102
{
101103
unsafe
102104
{
103105
fixed (short* samplesPtr = samples)
104106
{
105-
CPointer = sfSoundBuffer_createFromSamples(samplesPtr, (uint)samples.Length, channelCount, sampleRate);
107+
fixed (SoundChannel* channels = channelMapData)
108+
{
109+
CPointer = sfSoundBuffer_createFromSamples(samplesPtr, (uint)samples.Length, channelCount, sampleRate, channels, (UIntPtr)channelMapData.Length);
110+
}
106111
}
107112
}
108113

@@ -178,6 +183,16 @@ public short[] Samples
178183
}
179184
}
180185

186+
////////////////////////////////////////////////////////////
187+
/// <summary>
188+
/// Get the map of position in sample frame to sound channel
189+
/// <para/>
190+
/// This is used to map a sample in the sample stream to a
191+
/// position during spatialisation.
192+
/// </summary>
193+
////////////////////////////////////////////////////////////
194+
public IEnumerable<SoundChannel> ChannelMap => throw new NotImplementedException("TODO CSFML implementation.");
195+
181196
////////////////////////////////////////////////////////////
182197
/// <summary>
183198
/// Provide a string describing the object
@@ -216,7 +231,7 @@ public override string ToString()
216231
private static extern unsafe IntPtr sfSoundBuffer_createFromMemory(IntPtr data, UIntPtr size);
217232

218233
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
219-
private static extern unsafe IntPtr sfSoundBuffer_createFromSamples(short* samples, ulong sampleCount, uint channelsCount, uint sampleRate);
234+
private static extern unsafe IntPtr sfSoundBuffer_createFromSamples(short* samples, ulong sampleCount, uint channelsCount, uint sampleRate, SoundChannel* channelMapData, UIntPtr channelMapSize);
220235

221236
[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
222237
private static extern IntPtr sfSoundBuffer_copy(IntPtr soundBuffer);

src/SFML.Audio/SoundBufferRecorder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23

34
namespace SFML.Audio
@@ -70,7 +71,7 @@ protected override bool OnProcessSamples(short[] samples)
7071
/// Called when the current capture stops
7172
/// </summary>
7273
////////////////////////////////////////////////////////////
73-
protected override void OnStop() => SoundBuffer = new SoundBuffer(_samplesArray.ToArray(), 1, SampleRate);
74+
protected override void OnStop() => SoundBuffer = new SoundBuffer(_samplesArray.ToArray(), 1, SampleRate, Array.Empty<SoundChannel>()); // TODO pass in a proper array?
7475

7576
private readonly List<short> _samplesArray = new List<short>();
7677
}

src/SFML.Audio/SoundChannel.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace SFML.Audio
2+
{
3+
////////////////////////////////////////////////////////////
4+
/// <summary>
5+
/// Types of sound channels that can be read/written from sound buffers/files
6+
/// <para/>
7+
/// In multi-channel audio, each sound channel can be
8+
/// assigned a position. The position of the channel is
9+
/// used to determine where to place a sound when it
10+
/// is spatialised. Assigning an incorrect sound channel
11+
/// will result in multi-channel audio being positioned
12+
/// incorrectly when using spatialisation.
13+
/// </summary>
14+
////////////////////////////////////////////////////////////
15+
#pragma warning disable CS1591 // TODO: add documentation when available
16+
public enum SoundChannel
17+
{
18+
Unspecified,
19+
Mono,
20+
FrontLeft,
21+
FrontRight,
22+
FrontCenter,
23+
FrontLeftOfCenter,
24+
FrontRightOfCenter,
25+
LowFrequencyEffects,
26+
BackLeft,
27+
BackRight,
28+
BackCenter,
29+
SideLeft,
30+
SideRight,
31+
TopCenter,
32+
TopFrontLeft,
33+
TopFrontRight,
34+
TopFrontCenter,
35+
TopBackLeft,
36+
TopBackRight,
37+
TopBackCenter
38+
}
39+
#pragma warning restore CS1591
40+
}

0 commit comments

Comments
 (0)