Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions PushNuGetLocal.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Param(
[Parameter(Mandatory, Position = 0)]
[string]$LocalSource
)

dotnet build -c Release
if ($LASTEXITCODE -ne 0) {
Write-Error "Build failed"
exit 1
}

$count = 0
$packages = (Get-ChildItem src/*/bin/Release/*.nupkg)
foreach ($package in $packages) {
Write-Progress "Pushing packages" -CurrentOperation "Pushing $($package.Name)" -PercentComplete (($count * 100.0) / $packages.Length)

nuget add $package.FullName -Source $LocalSource

if ($LASTEXITCODE -ne 0) {
Write-Error "Unable to push $($package.Name)"
exit 1
}

$count++
}

Write-Progress "Done" -Completed
Write-Output "Successfully pushed $count packages"
2 changes: 1 addition & 1 deletion SFML.Module.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSFML" Version="[3.0.0, 3.1)" />
<PackageReference Include="CSFML" Version="3.1.0" />
</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>3.0.0</Version>
<Version>3.1.0</Version>
<Authors>Laurent Gomila</Authors>
<PackageTags>sfml sfml.net</PackageTags>
<Copyright>Copyright © Laurent Gomila</Copyright>
Expand Down
29 changes: 29 additions & 0 deletions examples/opengl/OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@ private static void Main()
FillColor = new SFML.Graphics.Color(255, 255, 255, 170)
};

var test = text.Font.GetInfo();
Console.WriteLine(test);
Console.WriteLine(text.Font.GetAscent(32));
Console.WriteLine(text.Font.GetDescent(32));
var glyphs = text.GetShapedGlyphs();
foreach (var glyph in glyphs)
{
Console.WriteLine($"{glyph} would be nice if it works");
}

foreach (var vert in text.GetVertexData())
{
Console.WriteLine(vert);
}

foreach (var vert in text.GetOutlineVertexData())
{
Console.WriteLine(vert);
}

text.SetGlyphPreProcessor((ref Text.ShapedGlyph glyph, ref uint style, ref Color color, ref Color outlineColor, ref float thickness,
object data) =>
{
Console.WriteLine("huuuu");
color = new Color((uint)Random.Shared.Next());
thickness += 0.01f;
}, null);
text.DisplayedString = "A test, huh!";

// Make the window the active target for OpenGL calls
_ = window.SetActive();

Expand Down
25 changes: 25 additions & 0 deletions examples/sound/Sound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ internal static class Program
/// </summary>
private static void Main()
{
PlaybackDevice.SetNotificationCallback((notification, _) =>
{
Console.WriteLine(notification);
});

var buffer = new SoundBuffer("resources/canary.wav");
// Create a sound instance and play it
var sound = new Sound(buffer);
sound.Play();
Console.WriteLine(PlaybackDevice.GetDefaultDevice());
foreach (var device in PlaybackDevice.GetAvailableDevices())
{
Console.WriteLine($"{device}, set: {PlaybackDevice.SetDevice(device)}, Freq: {PlaybackDevice.GetDeviceSampleRate()}, Default: {PlaybackDevice.IsDefaultDevice()}");
}

Console.WriteLine(PlaybackDevice.GetDevice());
Console.WriteLine(PlaybackDevice.SetDeviceToDefault());
Console.WriteLine(PlaybackDevice.GetDevice());
Console.WriteLine(PlaybackDevice.SetDeviceToNull());
Console.WriteLine(PlaybackDevice.GetDevice());

sound.Stop();

PlaybackDevice.SetNotificationCallback(null);

// Play a sound
PlaySound();
Console.Clear();
Expand Down
11 changes: 11 additions & 0 deletions examples/window/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
using System;
using Version = SFML.System.Version;

namespace window;

internal static class Program
{
private static void Main()
{
var version = Version.GetVersion();
Console.WriteLine(version.Major);
Console.WriteLine(version.Minor);
Console.WriteLine(version.Patch);
Console.WriteLine(version.IsRelease);
Console.WriteLine(version.String);

Console.WriteLine("Press ESC key to close window");
var window = new SimpleWindow();
window.Run();
Expand All @@ -28,6 +36,9 @@ public void Run()
FillColor = SFML.Graphics.Color.Blue
};

circle.MiterLimit = 2;
Console.WriteLine(circle.MiterLimit);

// Start the game loop
while (window.IsOpen)
{
Expand Down
209 changes: 209 additions & 0 deletions src/SFML.Audio/PlaybackDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
using System;
using System.Runtime.InteropServices;
using System.Security;
using SFML.System;

namespace SFML.Audio;

////////////////////////////////////////////////////////////
/// <summary>
/// Queries state over sound stuff
/// </summary>
////////////////////////////////////////////////////////////
public static class PlaybackDevice
{
////////////////////////////////////////////////////////////
/// <summary>
/// Enumeration of the playback device notifications.
/// </summary>
////////////////////////////////////////////////////////////
public enum Notification
{
/// <summary>Playback device has been started. </summary>
Started,

/// <summary>Playback device has been stopped. </summary>
Stopped,

/// <summary>Playback device has been rerouted (Generated on platforms that support automatic stream routing).</summary>
Rerouted,

/// <summary>Playback device interruption has begun (Generated on Apple mobile platforms).</summary>
InterruptionBegan,

/// <summary>Playback device interruption has ended (Generated on Apple mobile platforms).</summary>
InterruptionEnded,

/// <summary>Playback device has been unlocked (Generated by Emscripten/WebAudio).</summary>
Unlocked
}

////////////////////////////////////////////////////////////
/// <summary>
/// Callable that is called to notify of changes to the playback device state.
/// </summary>
////////////////////////////////////////////////////////////
public delegate void NotificationCallback(Notification notification, object userData);

////////////////////////////////////////////////////////////
/// <summary>
/// Get a list of the names of all available audio playback devices
/// </summary>
/// <returns>An array of strings containing the device names or empty if no devices are available</returns>
////////////////////////////////////////////////////////////
public static string[] GetAvailableDevices()
{
unsafe
{
var length = new UIntPtr(0);
var buffer = sfPlaybackDevice_getAvailableDevices(ref length);
var devices = new string[length.ToUInt64()];
for (ulong i = 0; i < length.ToUInt64(); i++)
{
devices[i] = Marshal.PtrToStringAnsi(*buffer);
buffer++;
}
return devices;
}
}

////////////////////////////////////////////////////////////
/// <summary>
/// Get the name of the default audio playback device
/// </summary>
/// <returns>The name of the default audio playback device or NULL if there is none</returns>
////////////////////////////////////////////////////////////
public static string GetDefaultDevice()
{
var device = sfPlaybackDevice_getDefaultDevice();
return device == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(device);
}

////////////////////////////////////////////////////////////
/// <summary>
/// Set the audio playback device
/// </summary>
/// <param name="device"></param>
/// <returns>True, if it was able to set the requested device</returns>
////////////////////////////////////////////////////////////
public static bool SetDevice(string device) => sfPlaybackDevice_setDevice(device);

////////////////////////////////////////////////////////////
/// <summary>
/// Set the audio playback device to the default
/// </summary>
/// <returns>True, if it was able to set the audio playback device to the default device</returns>
////////////////////////////////////////////////////////////
public static bool SetDeviceToDefault() => sfPlaybackDevice_setDeviceToDefault();

////////////////////////////////////////////////////////////
/// <summary>
/// Set the audio playback device to the null device
/// </summary>
/// <returns>True, if it was able to set the audio playback device to the null device</returns>
////////////////////////////////////////////////////////////
public static bool SetDeviceToNull() => sfPlaybackDevice_setDeviceToNull();

////////////////////////////////////////////////////////////
/// <summary>
/// Get the name of the current audio playback device
/// </summary>
/// <returns>The name of the current audio playback device or null if there is none</returns>
////////////////////////////////////////////////////////////
public static string GetDevice()
{
var device = sfPlaybackDevice_getDevice();
return device == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(device);
}

////////////////////////////////////////////////////////////
/// <summary>
/// Gets the sample rate of the current audio playback device
/// </summary>
/// <returns>The sample rate of the current audio playback device or 0 if there is none</returns>
////////////////////////////////////////////////////////////
public static uint GetDeviceSampleRate() => sfPlaybackDevice_getDeviceSampleRate();

////////////////////////////////////////////////////////////
/// <summary>
/// Check if the current playback device is the default device
/// </summary>
/// <returns>
/// True, if the current playback device is the default device.
/// Also false, if there is no current playback device.
/// </returns>
////////////////////////////////////////////////////////////
public static bool IsDefaultDevice() => sfPlaybackDevice_isDefaultDevice();

////////////////////////////////////////////////////////////
/// <summary>
/// Set a callback that should be called to notify of changes to the playback device state
///
/// Warning: Do not attempt to alter the device state from
/// within this callback. This includes changing the device
/// and even creating/destroying sound objects since that
/// could indirectly cause the playback device to be
/// created/destroyed. Also do not attempt to set the
/// notification callback from within this callback. Doing
/// so will result in a deadlock.
///
/// When receiving a notification via this callback, store
/// the information somewhere and react on it from another
/// thread e.g. the main thread within the application.
/// </summary>
/// <param name="callback">The callback to be called, pass null to remove the current callback</param>
/// <param name="userData">User data that will be passed to the callback</param>
////////////////////////////////////////////////////////////
public static void SetNotificationCallback(NotificationCallback callback, object userData = null)
{
if (callback is null)
{
sfPlaybackDevice_setNotificationCallback(IntPtr.Zero, IntPtr.Zero);
return;
}

_internalDeviceNotificationCallback = (notification, _) => callback(notification, userData);
sfPlaybackDevice_setNotificationCallback(Marshal.GetFunctionPointerForDelegate(_internalDeviceNotificationCallback), IntPtr.Zero);
}


private static InternalDeviceNotificationCallback _internalDeviceNotificationCallback;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void InternalDeviceNotificationCallback(Notification notification, IntPtr userData);

#region Imports

[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern unsafe IntPtr* sfPlaybackDevice_getAvailableDevices(ref UIntPtr count);

[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern IntPtr sfPlaybackDevice_getDefaultDevice();

[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool sfPlaybackDevice_setDevice(string device);

[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool sfPlaybackDevice_setDeviceToDefault();

[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool sfPlaybackDevice_setDeviceToNull();

[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern IntPtr sfPlaybackDevice_getDevice();

[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern uint sfPlaybackDevice_getDeviceSampleRate();

[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool sfPlaybackDevice_isDefaultDevice();

[DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern void sfPlaybackDevice_setNotificationCallback(IntPtr callback, IntPtr userData);

#endregion
}
Loading