mirror of https://github.com/ppy/SDL3-CS.git
Refactorings + auto styling
This commit is contained in:
parent
8003b85aa2
commit
913afa5b4f
|
|
@ -21,7 +21,7 @@
|
|||
<Product>SDL3-CS</Product>
|
||||
<PackageReleaseNotes>Automated release.</PackageReleaseNotes>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://github.com/ppy/osu-framework</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/ppy/osu-framework</RepositoryUrl>
|
||||
<PackageProjectUrl>https://github.com/ppy/SDL3-CS</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/ppy/SDL3-CS</RepositoryUrl>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ using System;
|
|||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
var finder = (UnfriendlyMethodFinder)context.SyntaxReceiver!;
|
||||
|
||||
foreach (var kvp in finder.Methods)
|
||||
{
|
||||
string filename = kvp.Key;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -12,16 +13,16 @@ namespace SDL3.SourceGeneration
|
|||
{
|
||||
public class UnfriendlyMethodFinder : ISyntaxReceiver
|
||||
{
|
||||
public readonly Dictionary<string, List<GeneratedMethod>> Methods = new();
|
||||
public readonly Dictionary<string, List<GeneratedMethod>> Methods = new Dictionary<string, List<GeneratedMethod>>();
|
||||
|
||||
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
|
||||
{
|
||||
if (syntaxNode is MethodDeclarationSyntax method)
|
||||
{
|
||||
string name = method.Identifier.ValueText;
|
||||
bool isUnsafe = name.StartsWith($"{Helper.UnsafePrefix}SDL_");
|
||||
bool isUnsafe = name.StartsWith($"{Helper.UnsafePrefix}SDL_", StringComparison.Ordinal);
|
||||
|
||||
if (!name.StartsWith("SDL_") && !isUnsafe)
|
||||
if (!name.StartsWith("SDL_", StringComparison.Ordinal) && !isUnsafe)
|
||||
return;
|
||||
|
||||
if (method.ParameterList.Parameters.Any(p => p.Identifier.IsKind(SyntaxKind.ArgListKeyword)))
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using osu.Framework.Allocation;
|
||||
using SDL;
|
||||
using static SDL.SDL3;
|
||||
|
||||
|
|
@ -13,15 +12,15 @@ namespace SDL3.Tests
|
|||
{
|
||||
private bool flash;
|
||||
private ObjectHandle<MyWindow> objectHandle { get; }
|
||||
private SDL_Window* SDLWindowHandle;
|
||||
private SDL_Renderer* Renderer;
|
||||
private SDL_Window* sdlWindowHandle;
|
||||
private SDL_Renderer* renderer;
|
||||
private readonly bool initSuccess;
|
||||
|
||||
private const SDL_InitFlags initFlags = SDL_InitFlags.SDL_INIT_VIDEO | SDL_InitFlags.SDL_INIT_GAMEPAD;
|
||||
private const SDL_InitFlags init_flags = SDL_InitFlags.SDL_INIT_VIDEO | SDL_InitFlags.SDL_INIT_GAMEPAD;
|
||||
|
||||
public MyWindow()
|
||||
{
|
||||
if (SDL_InitSubSystem(initFlags) < 0)
|
||||
if (SDL_InitSubSystem(init_flags) < 0)
|
||||
throw new InvalidOperationException($"failed to initialise SDL. Error: {SDL_GetError()}");
|
||||
|
||||
initSuccess = true;
|
||||
|
|
@ -42,6 +41,7 @@ namespace SDL3.Tests
|
|||
private static SDL_bool wndProc(IntPtr userdata, MSG* message)
|
||||
{
|
||||
var handle = new ObjectHandle<MyWindow>(userdata);
|
||||
|
||||
if (handle.GetTarget(out var window))
|
||||
{
|
||||
Console.WriteLine($"from {window}, message: {message->message}");
|
||||
|
|
@ -90,8 +90,8 @@ namespace SDL3.Tests
|
|||
|
||||
public void Create()
|
||||
{
|
||||
SDLWindowHandle = SDL_CreateWindow("hello"u8, 800, 600, SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL_WindowFlags.SDL_WINDOW_HIGH_PIXEL_DENSITY);
|
||||
Renderer = SDL_CreateRenderer(SDLWindowHandle, (byte*)null, SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC);
|
||||
sdlWindowHandle = SDL_CreateWindow("hello"u8, 800, 600, SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL_WindowFlags.SDL_WINDOW_HIGH_PIXEL_DENSITY);
|
||||
renderer = SDL_CreateRenderer(sdlWindowHandle, (byte*)null, SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC);
|
||||
}
|
||||
|
||||
private void handleEvent(SDL_Event e)
|
||||
|
|
@ -116,11 +116,11 @@ namespace SDL3.Tests
|
|||
break;
|
||||
|
||||
case SDL_Keycode.SDLK_F10:
|
||||
SDL_SetWindowFullscreen(SDLWindowHandle, SDL_bool.SDL_FALSE);
|
||||
SDL_SetWindowFullscreen(sdlWindowHandle, SDL_bool.SDL_FALSE);
|
||||
break;
|
||||
|
||||
case SDL_Keycode.SDLK_F11:
|
||||
SDL_SetWindowFullscreen(SDLWindowHandle, SDL_bool.SDL_TRUE);
|
||||
SDL_SetWindowFullscreen(sdlWindowHandle, SDL_bool.SDL_TRUE);
|
||||
break;
|
||||
|
||||
case SDL_Keycode.SDLK_j:
|
||||
|
|
@ -134,6 +134,7 @@ namespace SDL3.Tests
|
|||
|
||||
int count;
|
||||
var bindings = SDL_GetGamepadBindings(gamepad, &count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var binding = *bindings[i];
|
||||
|
|
@ -217,9 +218,9 @@ namespace SDL3.Tests
|
|||
|
||||
pollEvents();
|
||||
|
||||
SDL_SetRenderDrawColorFloat(Renderer, SDL_sinf(frame) / 2 + 0.5f, SDL_cosf(frame) / 2 + 0.5f, 0.3f, 1.0f);
|
||||
SDL_RenderClear(Renderer);
|
||||
SDL_RenderPresent(Renderer);
|
||||
SDL_SetRenderDrawColorFloat(renderer, SDL_sinf(frame) / 2 + 0.5f, SDL_cosf(frame) / 2 + 0.5f, 0.3f, 1.0f);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
frame += 0.015f;
|
||||
|
||||
|
|
@ -230,7 +231,7 @@ namespace SDL3.Tests
|
|||
public void Dispose()
|
||||
{
|
||||
if (initSuccess)
|
||||
SDL_QuitSubSystem(initFlags);
|
||||
SDL_QuitSubSystem(init_flags);
|
||||
|
||||
objectHandle.Dispose();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace osu.Framework.Allocation
|
||||
namespace SDL3.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper on <see cref="GCHandle" /> that supports the <see cref="IDisposable" /> pattern.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace SDL3.Tests
|
|||
{
|
||||
public static class Program
|
||||
{
|
||||
private static void Main()
|
||||
public static void Main()
|
||||
{
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CanBeReplacedWithTryCastAndCheckForNull/@EntryIndexedValue">WARNING</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckForReferenceEqualityInstead_002E1/@EntryIndexedValue">WARNING</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckForReferenceEqualityInstead_002E2/@EntryIndexedValue">WARNING</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ClassNeverInstantiated_002EGlobal/@EntryIndexedValue">HINT</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ClassNeverInstantiated_002ELocal/@EntryIndexedValue">WARNING</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ClassWithVirtualMembersNeverInherited_002EGlobal/@EntryIndexedValue">HINT</s:String>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace SDL
|
|||
{
|
||||
/// <summary>
|
||||
/// Denotes a manually defined constant.
|
||||
/// Such consants should be excluded from ClangSharp generation to prevent warnings or duplicate definitions.
|
||||
/// Such constants should be excluded from ClangSharp generation to prevent warnings or duplicate definitions.
|
||||
/// Handled by <c>get_manually_written_symbols()</c> in generate_bindings.py.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace SDL
|
||||
{
|
||||
|
|
@ -10,6 +11,7 @@ namespace SDL
|
|||
|
||||
public static partial class SDL3
|
||||
{
|
||||
[MustDisposeResource]
|
||||
public static unsafe SDLArray<SDL_CameraDeviceID>? SDL_GetCameraDevices()
|
||||
{
|
||||
int count;
|
||||
|
|
@ -17,6 +19,7 @@ namespace SDL
|
|||
return SDLArray.Create(array, count);
|
||||
}
|
||||
|
||||
[MustDisposeResource]
|
||||
public static unsafe SDLArray<SDL_CameraSpec>? SDL_GetCameraDeviceSupportedFormats(SDL_CameraDeviceID devid)
|
||||
{
|
||||
int count;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace SDL
|
|||
{
|
||||
/// <summary>
|
||||
/// Denotes a C <c>typedef</c> that is expressed as an enum in C#.
|
||||
/// These need to be manually signaled to ClagnSharp so it uses the custom enum type instaed of the underlying type.
|
||||
/// These need to be manually signaled to ClangSharp so it uses the custom enum type instead of the underlying type.
|
||||
/// Handled by <c>get_typedefs()</c> in generate_bindings.py.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Enum)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue