1using System.Runtime.CompilerServices;
4using Microsoft.AspNetCore.Components.Web;
5using Microsoft.Extensions.Logging;
28 private static readonly
int KeyArraySize = Enum.GetValues<
BlazorKey>().Cast<int>().Max() + 1;
31 private readonly
int[] _down;
32 private int _modsBits;
33 private bool _isDisposed;
58 _component = component ??
throw new ArgumentNullException(nameof(component));
59 _down =
new int[KeyArraySize];
61 _component.KeyDown += OnKeyDown;
62 _component.KeyUp += OnKeyUp;
64 Engine.
Logger.LogInformation(
"BlazorKeyboardAdapter initialized.");
68 [MethodImpl(MethodImplOptions.AggressiveInlining)]
71 if ((uint)keyCode >= (uint)_down.Length)
74 return Volatile.Read(ref _down[keyCode]) != 0;
88 Engine.
Logger.LogWarning(
"Invalid Blazor key name: {KeyName}", keyName);
92 private void OnKeyDown(KeyboardEventArgs e)
97 SetDown(e.Code,
true);
101 private void OnKeyUp(KeyboardEventArgs e)
106 SetDown(e.Code,
false);
110 [MethodImpl(MethodImplOptions.AggressiveInlining)]
111 private void SetDown(
string code,
bool down)
116 var index = (int)key;
118 if ((uint)index >= (uint)_down.Length)
121 Volatile.Write(ref _down[index], down ? 1 : 0);
124 [MethodImpl(MethodImplOptions.AggressiveInlining)]
125 private void UpdateMods(KeyboardEventArgs e)
138 Volatile.Write(ref _modsBits, mods);
149 _component.KeyDown -= OnKeyDown;
150 _component.KeyUp -= OnKeyUp;
152 Engine.
Logger.LogInformation(
"BlazorKeyboardAdapter disposed.");
A Blazor component that presents Gondwana game frames on an HTML <canvas> element and forwards keyboa...
Provides the shared DOM input surface used by Gondwana's Blazor bitmap and GPU render components.
Represents the core game engine singleton responsible for managing the main update loop,...
static ILogger< Engine > Logger
Gets the logger instance used by the engine for diagnostic and informational messages.