diff --git a/src/UltralightNet/Renderer.cs b/src/UltralightNet/Renderer.cs index 32a8907b2..1b8c0070f 100755 --- a/src/UltralightNet/Renderer.cs +++ b/src/UltralightNet/Renderer.cs @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using UltralightNet.LowStuff; +using UltralightNet.Gamepad; namespace UltralightNet; @@ -38,6 +39,24 @@ public static Handle ulCreateRenderer(in ULConfig config) [DllImport(LibUltralight)] public static extern void ulLogMemoryUsage(Handle renderer); + + [LibraryImport(LibUltralight)] + public static extern bool ulStartRemoteInspectorServer(Handle renderer, ReadOnlySpan address, ushort port); + + [LibraryImport(LibUltralight)] + public static extern bool ulStartRemoteInspectorServer(Handle renderer, [MarshalAs(UnmanagedType.LPStr)]ReadOnlySpan address, ushort port); + + [DllImport(LibUltralight)] + public static extern void ulSetGamepadDetails(Handle renderer, uint index, ULString id, uint axisCount, uint buttonCount); + + [DllImport(LibUltralight)] + public static extern void ulFireGamepadEvent(Handle renderer, GamepadEvent gamepadEvent); + + [DllImport(LibUltralight)] + public static extern void ulFireGamepadAxisEvent(Handle renderer, GamepadAxisEvent gamepadAxisEvent); + + [DllImport(LibUltralight)] + public static extern void ulFireGamepadButtonEvent(Handle renderer, GamepadButtonEvent gamepadButtonEvent); } public unsafe class Renderer : INativeContainer, INativeContainerInterface, IEquatable @@ -102,6 +121,18 @@ public Session DefaultSession public void PurgeMemory() { Methods.ulPurgeMemory(Handle); GC.KeepAlive(this); } public void LogMemoryUsage() { Methods.ulLogMemoryUsage(Handle); GC.KeepAlive(this); } + public void StartRemoteInspectorServer(ReadOnlySpan address, ushort port){ + throw new NotImplementedException(); + bool result = Methods.ulStartRemoteInspectorServer(Handle, address, port); + GC.KeepAlive(this); + if(!result) throw new System.Net.WebException("Failed to start remote inspector server."); + } + + public void SetGamepadDetails(uint index, ReadOnlySpan id, uint axisCount, uint buttonCount) => throw new NotImplementedException(); + public void FireGamepadEvent(GamepadEvent gamepadEvent) => throw new NotImplementedException(); + public void FireGamepadAxisEvent(GamepadAxisEvent gamepadAxisEvent) => throw new NotImplementedException(); + public void FireGamepadButtonEvent(GamepadButtonEvent gamepadbuttonEvent) => throw new NotImplementedException(); + [SuppressMessage("Usage", "CA1816: Call GC.SupressFinalize correctly")] public override void Dispose() { diff --git a/src/UltralightNet/Structs/ULFontLoader.cs b/src/UltralightNet/Structs/ULFontLoader.cs index 26f425dd5..71d4df93b 100644 --- a/src/UltralightNet/Structs/ULFontLoader.cs +++ b/src/UltralightNet/Structs/ULFontLoader.cs @@ -1,4 +1,3 @@ -using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace UltralightNet; @@ -101,7 +100,7 @@ readonly get public delegate* unmanaged[Cdecl] __GetFallbackFontForCharacters; public delegate* unmanaged[Cdecl] __Load; - public void Dispose() => throw new NotImplementedException(); + public void Dispose() => ULPlatform.Free(in this); #pragma warning disable CS8909 public readonly bool Equals(ULFontLoader other) => __GetFallbackFont == other.__GetFallbackFont && __GetFallbackFontForCharacters == other.__GetFallbackFontForCharacters && __Load == other.__Load; diff --git a/src/UltralightNet/Structs/ULGamepadEvent.cs b/src/UltralightNet/Structs/ULGamepadEvent.cs new file mode 100644 index 000000000..db1e359e2 --- /dev/null +++ b/src/UltralightNet/Structs/ULGamepadEvent.cs @@ -0,0 +1,34 @@ +namespace UltralightNet.Gamepad; + +/// The various types. +public enum GamepadEventType : int +{ + /// This event type should be fired when a gamepad is connected. + /// You will need to previously declare the gamepad, its index, and details about + /// its axis and button layout via prior to calling + /// . + /// + Connected, + /// This event type should be fired when a gamepad is disconnected. + Disconnected +} + +/// Event representing a change in gamepad connection state +/// The type of this GamepadEvent. +/// The index of the gamepad. +/// +public record struct GamepadEvent(GamepadEventType Type, uint Index); + +/// Event representing a change in gamepad axis state (eg, pressing a stick in a certain direction). +/// The index of the gamepad. +/// The index of the axis whose value has changed. +/// The new value of the axis.
This value should be normalized to the range [-1.0, 1.0]. +/// +public record struct GamepadAxisEvent(uint Index, uint Axis, double Value); + +/// Event representing a change in gamepad button state (eg, pressing a button on a gamepad). +/// The index of the gamepad. +/// The index of the button whose value has changed. +/// The new value of the button.
This value should be normalized to the range [-1.0, 1.0], with any value greater than 0.0 to be considered "pressed". +/// +public record struct GamepadButtonEvent(uint Index, uint Button, double Value); diff --git a/src/UltralightNet/ULConfig.cs b/src/UltralightNet/ULConfig.cs index 85659c844..08a392802 100755 --- a/src/UltralightNet/ULConfig.cs +++ b/src/UltralightNet/ULConfig.cs @@ -172,10 +172,10 @@ public unsafe struct _ULConfig : IDisposable /// The max amount of time (in seconds) to allow to run per call. /// The library will attempt to throttle timers and/or reschedule work if this time budget is exceeded. - public double MaxUpdateTime = 1.0 / 100.0; + public double MaxUpdateTime = 1.0 / 200.0; /// The alignment (in bytes) of the BitmapSurface when using the CPU renderer. - /// You can set this to '0' to perform no padding (row_bytes will always be width * 4) at a slight cost to performance. + /// You can set this to '0' to perform no padding (row_bytes will always be width * Bpp) at a slight cost to performance. public uint BitmapAlignment = 16; /// @@ -271,7 +271,7 @@ public struct ULConfig : IEquatable public uint NumRendererThreads = 0; /// - public double MaxUpdateTime = 1.0 / 100.0; + public double MaxUpdateTime = 1.0 / 200.0; /// public uint BitmapAlignment = 16; diff --git a/src/UltralightNet/ULPlatform.cs b/src/UltralightNet/ULPlatform.cs index 296e4b45e..183a21952 100755 --- a/src/UltralightNet/ULPlatform.cs +++ b/src/UltralightNet/ULPlatform.cs @@ -19,6 +19,9 @@ public static partial class Methods [DllImport("Ultralight", EntryPoint = "ulPlatformSetFileSystem")] public static extern void ulPlatformSetFileSystem(ULFileSystem file_system); + [DllImport("Ultralight", EntryPoint = "ulPlatformSetFontLoader")] + public static extern void ulPlatformSetFontLoader(ULFontLoader fontLoader); + [DllImport("Ultralight", EntryPoint = "ulPlatformSetGPUDriver")] public static extern void ulPlatformSetGPUDriver(ULGPUDriver gpu_driver); @@ -113,6 +116,11 @@ internal static void Free(in ULFileSystem filesystem) if (filesystemHandles.Remove(filesystem, out List? handles)) foreach (GCHandle handle in handles!) handle.Free(); } + internal static void Free(in ULFontLoader fontLoader) + { + if (fontloaderHandles.Remove(fontLoader, out List? handles)) + foreach (GCHandle handle in handles!) handle.Free(); + } internal static void Free(in ULGPUDriver gpudriver) { if (gpudriverHandles.Remove(gpudriver, out List? handles)) @@ -135,21 +143,24 @@ public static void Free() lock (loggerHandles) lock (clipboardHandles) lock (filesystemHandles) - lock (gpudriverHandles) - lock (surfaceHandles) - { - foreach (List handles in loggerHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); - foreach (List handles in clipboardHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); - foreach (List handles in filesystemHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); - foreach (List handles in gpudriverHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); - foreach (List handles in surfaceHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); - - loggerHandles.Clear(); - clipboardHandles.Clear(); - filesystemHandles.Clear(); - gpudriverHandles.Clear(); - surfaceHandles.Clear(); - } + lock (fontloaderHandles) + lock (gpudriverHandles) + lock (surfaceHandles) + { + foreach (List handles in loggerHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); + foreach (List handles in clipboardHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); + foreach (List handles in filesystemHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); + foreach (List handles in fontloaderHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); + foreach (List handles in gpudriverHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); + foreach (List handles in surfaceHandles.Values) foreach (GCHandle handle in handles) if (handle.IsAllocated) handle.Free(); + + loggerHandles.Clear(); + clipboardHandles.Clear(); + filesystemHandles.Clear(); + fontloaderHandles.Clear(); + gpudriverHandles.Clear(); + surfaceHandles.Clear(); + } } public static bool SetDefaultLogger { get; set; } = true; @@ -166,6 +177,7 @@ public static void Free() private static ULLogger _logger; internal static ULFileSystem _filesystem; + private static ULFontLoader _fontLoader; private static ULGPUDriver _gpudriver; private static ULClipboard _clipboard; @@ -192,6 +204,15 @@ public static ULFileSystem FileSystem Methods.ulPlatformSetFileSystem(value); } } + public static ULFontLoader FontLoader + { + get => _fontLoader; + set + { + _fontLoader = value; + Methods.ulPlatformSetFontLoader(value); + } + } public static ULGPUDriver GPUDriver { get => _gpudriver;