6using Microsoft.JSInterop;
22 private readonly IJSRuntime _jsRuntime;
23 private DotNetObjectReference<BlazorGameHostBase>? _dotNetRef;
24 private IJSObjectReference? _module;
33 _jsRuntime = jsRuntime ??
throw new ArgumentNullException(nameof(jsRuntime));
61 if (OperatingSystem.IsBrowser())
62 BrowserConsoleLogging.AttachToEngineLogger();
98 ??
throw new InvalidOperationException(
99 $
"{nameof(BindScene)} cannot be called before {nameof(Scene)} has been created.");
107 var syncContext = base.GetSynchronizationContext();
109 if (syncContext is not
null)
112 if (!OperatingSystem.IsBrowser())
115 syncContext =
new SynchronizationContext();
116 SynchronizationContext.SetSynchronizationContext(syncContext);
124 if (OperatingSystem.IsBrowser())
126 Engine.StartTimerDriven(syncContext);
129 _ = StartBrowserRenderLoopAsync();
134 base.StartEngineCore(syncContext);
137 private async Task StartBrowserRenderLoopAsync()
139 var module = await _jsRuntime.InvokeAsync<IJSObjectReference>(
141 "./_content/Gondwana.Blazor/gondwana-blazor.js");
144 _dotNetRef = DotNetObjectReference.Create(
this);
146 await module.InvokeVoidAsync(
"startRenderLoop", _dotNetRef);
160 if (_module is not
null)
161 _ = _module.InvokeVoidAsync(
"stopRenderLoop");
163 base.StopEngineCore();
169 base.OnInputConfigured();
176 _dotNetRef?.Dispose();
179 if (_module is not
null)
181 _ = _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.
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.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...