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)
return false;
72 return Volatile.Read(ref _down[keyCode]) != 0;
86 Engine.
Logger.LogWarning(
"Invalid Blazor key name: {KeyName}", keyName);
90 private void OnKeyDown(KeyboardEventArgs e)
92 if (_isDisposed)
return;
93 SetDown(e.Code,
true);
97 private void OnKeyUp(KeyboardEventArgs e)
99 if (_isDisposed)
return;
100 SetDown(e.Code,
false);
104 [MethodImpl(MethodImplOptions.AggressiveInlining)]
105 private void SetDown(
string code,
bool down)
107 if (!Enum.TryParse<
BlazorKey>(code,
false, out var key) || key ==
BlazorKey.None)
return;
108 var index = (int)key;
109 if ((uint)index >= (uint)_down.Length)
return;
110 Volatile.Write(ref _down[index], down ? 1 : 0);
113 [MethodImpl(MethodImplOptions.AggressiveInlining)]
114 private void UpdateMods(KeyboardEventArgs e)
120 Volatile.Write(ref _modsBits, mods);
126 if (_isDisposed)
return;
129 _component.KeyDown -= OnKeyDown;
130 _component.KeyUp -= OnKeyUp;
132 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.