diff --git a/Directory.Build.targets b/Directory.Build.targets index 37458a8..9c5362f 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -33,7 +33,7 @@ 10.0.19043.0 10.0.19043.0 - 10.0.22621.35-preview + 10.0.22621.38 x64;ARM64 win-x64;win-arm64 diff --git a/Directory.Packages.props b/Directory.Packages.props index 093b2a1..f431925 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,33 +1,33 @@ - 2.2.5 + 2.2.6 10.0.26100 - 2.0.1 + 2.1.1 3.0.0-preview.4.1 - + - - + + - + - + - + @@ -36,7 +36,7 @@ - + diff --git a/samples/Alimer.Samples/Graphics/DrawMeshSample.cs b/samples/Alimer.Samples/Graphics/DrawMeshSample.cs index d4aa332..03bacfe 100644 --- a/samples/Alimer.Samples/Graphics/DrawMeshSample.cs +++ b/samples/Alimer.Samples/Graphics/DrawMeshSample.cs @@ -45,7 +45,7 @@ public DrawMeshSample(IServiceRegistry services, Window mainWindow) MeshImporter meshImporter = new(); MeshAsset meshAsset = meshImporter.Import(Path.Combine(meshesPath, "DamagedHelmet.glb"), Services).Result; - Span vertices = new VertexPositionNormalTexture[meshAsset.Data.VertexCount]; + Span vertices = stackalloc VertexPositionNormalTexture[meshAsset.Data!.VertexCount]; for (int i = 0; i < meshAsset.Data.VertexCount; i++) { vertices[i] = new VertexPositionNormalTexture(meshAsset.Data.Positions[i], meshAsset.Data.Normals[i], meshAsset.Data.Texcoords[i]); @@ -56,7 +56,7 @@ public DrawMeshSample(IServiceRegistry services, Window mainWindow) //_indexBuffer = ToDispose(GraphicsDevice.CreateBuffer(data.Indices, BufferUsage.Index)); _vertexBuffer = ToDispose(GraphicsDevice.CreateBuffer(vertices, BufferUsage.Vertex)); _indexBuffer = ToDispose(GraphicsDevice.CreateBuffer(meshAsset.Data.Indices!.AsSpan(), BufferUsage.Index)); - _indexCount = (uint)meshAsset.Data.Indices.Length; + _indexCount = (uint)meshAsset.Data!.Indices.Length; _constantBuffer = ToDispose(GraphicsDevice.CreateBuffer((ulong)sizeof(Matrix4x4), BufferUsage.Constant, CpuAccessMode.Write)); diff --git a/samples/Alimer.Samples/GraphicsSampleBase.cs b/samples/Alimer.Samples/GraphicsSampleBase.cs index 453347b..6948489 100644 --- a/samples/Alimer.Samples/GraphicsSampleBase.cs +++ b/samples/Alimer.Samples/GraphicsSampleBase.cs @@ -35,7 +35,7 @@ protected GraphicsBuffer CreateBuffer(List initialData, return GraphicsDevice.CreateBuffer(dataSpan, usage, cpuAccess); } - protected Stream OpenEmbeddedAssetStream(string name) => typeof(GraphicsSampleBase).Assembly!.GetManifestResourceStream(name); + protected Stream OpenEmbeddedAssetStream(string name) => typeof(GraphicsSampleBase).Assembly!.GetManifestResourceStream(name)!; protected byte[] ReadEmbeddedAssetBytes(string name) { using Stream stream = OpenEmbeddedAssetStream(name); diff --git a/src/Alimer.Applications/Alimer.Applications.csproj b/src/Alimer.Applications/Alimer.Applications.csproj index bd1d098..c62a74c 100644 --- a/src/Alimer.Applications/Alimer.Applications.csproj +++ b/src/Alimer.Applications/Alimer.Applications.csproj @@ -20,7 +20,7 @@ - + diff --git a/src/Alimer.Applications/Platforms/Standard/SDLClipboard.cs b/src/Alimer.Applications/Platforms/Standard/SDLClipboard.cs index b186813..662dbec 100644 --- a/src/Alimer.Applications/Platforms/Standard/SDLClipboard.cs +++ b/src/Alimer.Applications/Platforms/Standard/SDLClipboard.cs @@ -1,13 +1,13 @@ // Copyright (c) Amer Koleci and Contributors. // Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. -using static SDL.SDL3; +using static SDL3.SDL3; namespace Alimer.Input; partial class ClipboardImplementation : IClipboard { - public bool HasText => SDL_HasClipboardText() == SDL_TRUE; + public bool HasText => SDL_HasClipboardText(); public Task GetTextAsync() { diff --git a/src/Alimer.Applications/Platforms/Standard/SDLPlatform.cs b/src/Alimer.Applications/Platforms/Standard/SDLPlatform.cs index 9cf556e..d524868 100644 --- a/src/Alimer.Applications/Platforms/Standard/SDLPlatform.cs +++ b/src/Alimer.Applications/Platforms/Standard/SDLPlatform.cs @@ -2,10 +2,9 @@ // Licensed under the MIT License (MIT). See LICENSE in the repository root for more information. using Alimer.Input; -using static SDL.SDL3; -using SDL; +using static SDL3.SDL3; +using SDL3; using System.Runtime.InteropServices; -using static SDL.SDL_EventType; using System.Runtime.CompilerServices; namespace Alimer; @@ -24,7 +23,7 @@ public SDLPlatform() { //SDL_LogSetPriority(SDL_LogCategory.Error, SDL_LogPriority.Debug); //SDL_LogSetPriority(SDL_LogCategory.SDL_LOG_CATEGORY_ERROR, SDL_LogPriority.SDL_LOG_PRIORITY_DEBUG); - SDL_SetLogOutputFunction(&OnLog, IntPtr.Zero); + SDL_SetLogOutputFunction(OnLog); int version = SDL_GetVersion(); string? revision = SDL_GetRevision(); @@ -34,7 +33,7 @@ public SDLPlatform() SDL_VERSIONNUM_MICRO(version)); // Init SDL3 - if (SDL_Init(SDL_InitFlags.SDL_INIT_VIDEO | SDL_InitFlags.SDL_INIT_TIMER | SDL_InitFlags.SDL_INIT_GAMEPAD) != 0) + if (SDL_Init(SDL_InitFlags.Video | SDL_InitFlags.Timer | SDL_InitFlags.Gamepad) != 0) { Log.Error($"Unable to initialize SDL: {SDL_GetError()}"); throw new Exception(""); @@ -42,7 +41,7 @@ public SDLPlatform() Log.Info($@"SDL3 Initialized SDL3 Version: {SDL_VERSIONNUM_MAJOR(version)}.{SDL_VERSIONNUM_MINOR(version)}.{SDL_VERSIONNUM_MICRO(version)} - SDL3 Revision: {SDL3.SDL_GetRevision()}" + SDL3 Revision: {SDL_GetRevision()}" ); _input = new SDLInput(this); @@ -104,7 +103,7 @@ private void PollEvents() do { - eventsRead = SDL_PeepEvents(_events, SDL_EventAction.SDL_GETEVENT, SDL_EventType.SDL_EVENT_FIRST, SDL_EventType.SDL_EVENT_LAST); + eventsRead = SDL_PeepEvents(_events, SDL_EventAction.GetEvent, SDL_EventType.First, SDL_EventType.Last); for (int i = 0; i < eventsRead; i++) { HandleSDLEvent(_events[i]); @@ -114,13 +113,13 @@ private void PollEvents() private void HandleSDLEvent(SDL_Event evt) { - if (evt.Type >= SDL_EventType.SDL_EVENT_DISPLAY_FIRST && evt.Type <= SDL_EventType.SDL_EVENT_DISPLAY_LAST) + if (evt.type >= SDL_EventType.DisplayFirst && evt.type <= SDL_EventType.DisplayLast) { HandleDisplayEvent(evt.display); return; } - if (evt.Type >= SDL_EventType.SDL_EVENT_WINDOW_FIRST && evt.Type <= SDL_EventType.SDL_EVENT_WINDOW_LAST) + if (evt.type >= SDL_EventType.WindowFirst && evt.type <= SDL_EventType.WindowLast) { HandleWindowEvent(in evt.window); return; @@ -128,8 +127,8 @@ private void HandleSDLEvent(SDL_Event evt) switch (evt.type) { - case (uint)SDL_EVENT_QUIT: - case (uint)SDL_EVENT_TERMINATING: + case SDL_EventType.Quit: + case SDL_EventType.Terminating: _exitRequested = true; break; } @@ -154,10 +153,8 @@ internal void WindowClosed(SDL_WindowID windowID) _idLookup.Remove(windowID); } - [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])] - private static void OnLog(IntPtr _, SDL_LogCategory category, SDL_LogPriority priority, byte* messagePtr) + private static void OnLog(SDL_LogCategory category, SDL_LogPriority priority, string? message) { - string? message = PtrToStringUTF8(messagePtr); Log.Info($"SDL: {message}"); } } diff --git a/src/Alimer.Applications/Platforms/Standard/SDLWindow.cs b/src/Alimer.Applications/Platforms/Standard/SDLWindow.cs index 64370f9..bb709f2 100644 --- a/src/Alimer.Applications/Platforms/Standard/SDLWindow.cs +++ b/src/Alimer.Applications/Platforms/Standard/SDLWindow.cs @@ -4,9 +4,8 @@ using Vortice.Mathematics; using Alimer.Graphics; using System.Runtime.InteropServices; -using static SDL.SDL3; -using static SDL.SDL_EventType; -using SDL; +using static SDL3.SDL3; +using SDL3; namespace Alimer; @@ -17,44 +16,43 @@ internal unsafe class SDLWindow : Window private bool _minimized; private bool _isFullscreen; - public readonly SDL_Window* SDLWindowHandle; + public readonly SDL_Window SDLWindowHandle; public readonly SDL_WindowID Id; public SDLWindow(SDLPlatform platform, WindowFlags flags) { _platform = platform; - SDL_WindowFlags sdlWindowFlags = SDL_WindowFlags.SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WindowFlags.SDL_WINDOW_HIDDEN | SDL_WindowFlags.SDL_WINDOW_VULKAN; + SDL_WindowFlags sdlWindowFlags = SDL_WindowFlags.HighPixelDensity | SDL_WindowFlags.Hidden | SDL_WindowFlags.Vulkan; if ((flags & WindowFlags.Borderless) != 0) - sdlWindowFlags |= SDL_WindowFlags.SDL_WINDOW_BORDERLESS; + sdlWindowFlags |= SDL_WindowFlags.Borderless; if ((flags & WindowFlags.Resizable) != 0) - sdlWindowFlags |= SDL_WindowFlags.SDL_WINDOW_RESIZABLE; + sdlWindowFlags |= SDL_WindowFlags.Resizable; if ((flags & WindowFlags.Fullscreen) != 0) { - sdlWindowFlags |= SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; + sdlWindowFlags |= SDL_WindowFlags.Fullscreen; _isFullscreen = true; } if ((flags & WindowFlags.Maximized) != 0) { - sdlWindowFlags |= SDL_WindowFlags.SDL_WINDOW_MAXIMIZED; + sdlWindowFlags |= SDL_WindowFlags.Maximized; } _title = "Alimer"; - SDLWindowHandle = SDL_CreateWindow((Utf8String)_title, 1200, 800, sdlWindowFlags); - if (SDLWindowHandle == null) + SDLWindowHandle = SDL_CreateWindow(_title, 1200, 800, sdlWindowFlags); + if (SDLWindowHandle.IsNull) { Log.Error($"SDL_CreateWindow Failed: {SDL_GetError()}"); return; } Id = SDL_GetWindowID(SDLWindowHandle); - SDL_SetWindowPosition(SDLWindowHandle, (int)SDL_WINDOWPOS_CENTERED, (int)SDL_WINDOWPOS_CENTERED); - int width, height; - SDL_GetWindowSizeInPixels(SDLWindowHandle, &width, &height); + SDL_SetWindowPosition(SDLWindowHandle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); + SDL_GetWindowSizeInPixels(SDLWindowHandle, out int width, out int height); _clientSize = new(width, height); // Native handle @@ -116,7 +114,7 @@ public override bool IsFullscreen if (_isFullscreen != value) { _isFullscreen = value; - SDL_SetWindowFullscreen(SDLWindowHandle, value ? SDL_TRUE : SDL_FALSE); + SDL_SetWindowFullscreen(SDLWindowHandle, value); } } } @@ -126,8 +124,7 @@ public override Int2 Position { get { - int x, y; - _ = SDL_GetWindowPosition(SDLWindowHandle, &x, &y); + _ = SDL_GetWindowPosition(SDLWindowHandle, out int x, out int y); return new Int2(x, y); } set @@ -150,12 +147,12 @@ public override Int2 Position public void Show() { - SDL_ShowWindow(SDLWindowHandle); + _ = SDL_ShowWindow(SDLWindowHandle); } protected override void SetTitle(string title) { - SDL_SetWindowTitle(SDLWindowHandle, title); + _ = SDL_SetWindowTitle(SDLWindowHandle, title); } public void HandleEvent(in SDL_WindowEvent evt) diff --git a/src/Alimer.Physics/PhysicsSystem.cs b/src/Alimer.Physics/PhysicsSystem.cs index 0d79ed5..2745806 100644 --- a/src/Alimer.Physics/PhysicsSystem.cs +++ b/src/Alimer.Physics/PhysicsSystem.cs @@ -63,11 +63,16 @@ public override void Update(AppTime time) [ModuleInitializer] public static void Initialize() { - if (Foundation.Init() == false) + if (Foundation.Init(false) == false) { throw new InvalidOperationException("[JoltPhysics] Failed to initialize Foundation"); } + Foundation.SetTraceHandler((message) => + { + Log.Trace(message); + }); + #if DEBUG Foundation.SetAssertFailureHandler((inExpression, inMessage, inFile, inLine) => { diff --git a/src/Alimer.Physics/RigidBodyComponent.cs b/src/Alimer.Physics/RigidBodyComponent.cs index b023fcf..8725756 100644 --- a/src/Alimer.Physics/RigidBodyComponent.cs +++ b/src/Alimer.Physics/RigidBodyComponent.cs @@ -22,7 +22,7 @@ public MotionType MotionType return; _motionType = value; - if (Handle != null) + if (Handle.IsNotNull) { Handle.MotionType = value.ToJolt(); } @@ -58,7 +58,7 @@ public float Mass _mass = value; // TODO: Update Jolt mass? - if(Handle != null) + if(Handle.IsNotNull) { } } @@ -68,7 +68,7 @@ public override Matrix4x4 PhysicsWorldTransform { get { - if (Handle is null) + if (Handle.IsNull) return Matrix4x4.Identity; return Handle.GetWorldTransform(); @@ -76,20 +76,20 @@ public override Matrix4x4 PhysicsWorldTransform set { // TODO: Update Jolt WorldTransform? - if (Handle != null) + if (Handle.IsNotNull) { } } } - internal Body? Handle { get; private set; } + internal Body Handle; internal BodyID BodyID { get; private set; } protected override void OnAttach() { base.OnAttach(); - if (Handle != null) + if (Handle.IsNotNull) { Simulation!.BodyInterface.DestroyBody(Handle.ID); } @@ -113,7 +113,7 @@ protected override void OnAttach() // Add it to the world bodyInterface.AddBody(Handle, (MotionType == MotionType.Static) ? Activation.DontActivate : Activation.Activate); - Simulation.RigidBodies.Add(BodyID, this); + Simulation.RigidBodies.Add(BodyID, this); } protected override void OnDetach() diff --git a/src/Alimer.Rendering/MeshData.cs b/src/Alimer.Rendering/MeshData.cs index cdc28da..deaecdc 100644 --- a/src/Alimer.Rendering/MeshData.cs +++ b/src/Alimer.Rendering/MeshData.cs @@ -6,7 +6,7 @@ namespace Alimer.Rendering; -public sealed class MeshData +public struct MeshData { public MeshData() { @@ -17,7 +17,7 @@ public MeshData() /// public int VertexCount { get; set; } - public Vector3[] Positions { get; set; } = []; + public required Vector3[] Positions { get; set; } public Vector3[]? Normals { get; set; } public Vector3[]? Tangents { get; set; } public Vector2[]? Texcoords { get; set; } diff --git a/src/assets/Alimer.Assets/Graphics/MeshAsset.cs b/src/assets/Alimer.Assets/Graphics/MeshAsset.cs index d3fb4a0..fa2efdd 100644 --- a/src/assets/Alimer.Assets/Graphics/MeshAsset.cs +++ b/src/assets/Alimer.Assets/Graphics/MeshAsset.cs @@ -11,5 +11,5 @@ namespace Alimer.Assets.Graphics; /// public class MeshAsset : AssetWithSource { - public MeshData? Data { get; set; } + public MeshData Data { get; set; } }