6using Microsoft.JSInterop;
22 private readonly IJSRuntime _jsRuntime;
23 private DotNetObjectReference<BlazorGameHostBase>? _dotNetRef;
24 private IJSObjectReference? _module;
25 private BlazorLogicalResolutionBinding? _logicalResolution;
47 throw new InvalidOperationException(
"Logical resolution can only be configured after engine initialization.");
48 if (_logicalResolution is not
null)
49 throw new InvalidOperationException(
"Logical resolution is already configured for this host.");
51 _logicalResolution =
new BlazorLogicalResolutionBinding(
55 scale =>
Engine.Configuration.RenderScale = scale);
65 _jsRuntime = jsRuntime ??
throw new ArgumentNullException(nameof(jsRuntime));
93 if (OperatingSystem.IsBrowser())
94 BrowserConsoleLogging.AttachToEngineLogger();
130 ??
throw new InvalidOperationException(
131 $
"{nameof(BindScene)} cannot be called before {nameof(Scene)} has been created.");
139 var syncContext = base.GetSynchronizationContext();
141 if (syncContext is not
null)
144 if (!OperatingSystem.IsBrowser())
147 syncContext =
new SynchronizationContext();
148 SynchronizationContext.SetSynchronizationContext(syncContext);
156 if (OperatingSystem.IsBrowser())
158 Engine.StartTimerDriven(syncContext);
161 _ = StartBrowserRenderLoopAsync();
166 base.StartEngineCore(syncContext);
169 private async Task StartBrowserRenderLoopAsync()
171 var module = await _jsRuntime.InvokeAsync<IJSObjectReference>(
173 "./_content/Gondwana.Blazor/gondwana-blazor.js");
176 _dotNetRef = DotNetObjectReference.Create(
this);
178 await module.InvokeVoidAsync(
"startRenderLoop", _dotNetRef);
192 if (_module is not
null)
193 _ = _module.InvokeVoidAsync(
"stopRenderLoop");
195 base.StopEngineCore();
201 base.OnInputConfigured();
208 _logicalResolution?.Dispose();
209 _logicalResolution =
null;
211 _dotNetRef?.Dispose();
214 if (_module is not
null)
216 _ = _module.DisposeAsync();
BlazorRenderSurfaceComponentBase RenderSurfaceComponent
Gets the concrete Blazor component that supplies DOM input events.
virtual void OnKeyboardAdapterInitialized()
Called after the Blazor keyboard adapter is initialized.
void ConfigureLogicalResolution(int logicalWidth, int logicalHeight)
Establishes a minimum logical game size from the first usable Blazor canvas dimensions.
override void ConfigureGamepads()
Configures the gamepad manager.
virtual void OnMouseAdapterInitialized()
Called after the Blazor mouse adapter is initialized.
override void ConfigureKeyboard()
Configures the keyboard input adapter.
override void ConfigureTouch()
Configures the touch input adapter.
virtual void OnBlazorDisposed()
Runs after Blazor interop resources have been released.
BlazorGameHostBase(IJSRuntime jsRuntime)
Initializes a new instance of BlazorGameHostBase.
void BindSceneCore(Scene scene)
Binds a scene to the concrete typed render-surface host.
override void ConfigureMouse()
Configures the mouse input adapter.
RenderSurfaceHostBase RenderSurfaceHost
Gets the render-surface host used for scene binding and widget input.
override void OnInputConfigured()
Runs after all input devices have been configured.Platform hosts may override this hook to call Initi...
override void ConfigurePlatform()
virtual void OnConfigureGamepads()
Provides a hook for configuring browser gamepad support.
virtual void OnTouchAdapterInitialized()
Called after the Blazor touch adapter is initialized.
override void StopEngineCore()
Performs platform-specific engine shutdown work.
virtual void OnConfigurePlatform()
Provides a hook for configuring additional Blazor platform settings.
override void BindScene()
Binds the current scene to the platform render surface.
virtual bool RenderSurfaceDrivesBrowserFrames
Gets a value indicating whether the render surface itself supplies the browser animation callback tha...
override? SynchronizationContext GetSynchronizationContext()
Gets the synchronization context used to start the engine.The synchronization context,...
void OnAnimationFrame()
Advances the timer-driven bitmap path from Gondwana's browser animation loop.
override void StartEngineCore(SynchronizationContext syncContext)
Starts the engine using the supplied synchronization context.
override void OnDisposed()
Runs after managed resources have been disposed.
Provides the shared DOM input surface used by Gondwana's Blazor bitmap and GPU render components.
Provides a base class for hosting and managing the lifecycle of a Gondwana game application.
Scene? Scene
Gets the current active scene.
void InitializeWidgetInput(RenderSurfaceHostBase renderSurfaceHost)
Initializes widget input routing for the supplied render surface host.
Engine Engine
Gets the singleton instance of the Gondwana engine.
void EnsureNotDisposed()
Ensures that the host has not been disposed.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...