6using Microsoft.Extensions.Logging;
15 private bool _disposed;
16 private bool _initialized;
17 private bool _engineInitialized;
18 private bool _engineStarted;
55 string? configPath =
null,
56 bool? autoSaveConfig =
null,
57 LogLevel logLevel = LogLevel.Warning)
62 configurationStore:
null);
76 bool? autoSaveConfig =
null,
77 LogLevel logLevel = LogLevel.Warning)
79 ArgumentNullException.ThrowIfNull(configurationStore);
88 private void InitializeCore(
127 ArgumentNullException.ThrowIfNull(renderSurfaceHost);
129 _widgetInputRouter?.Dispose();
131 var keyboardPoller =
Engine.Input.KeyboardEventPoller;
132 var mousePoller =
Engine.Input.MouseEventPoller;
133 var touchPoller =
Engine.Input.TouchEventPoller;
135 mousePoller?.StartMonitoringMouse(
136 trackMouseMovement:
true);
144 _widgetInputRouter.Start();
161 EngineLogger.SetLogLevel(logLevel);
273 ??
throw new InvalidOperationException(
274 $
"{nameof(CreateInitialScene)} returned null.");
352 bool? autoSaveConfig)
367 bool? autoSaveConfig,
370 if (configurationStore is
null)
372 Engine.Instance.Initialize(
373 configFileName: configPath,
374 autoSaveConfig: autoSaveConfig);
378 Engine.Instance.InitializeWithConfigurationStore(
380 autoSaveConfig: autoSaveConfig);
383 _engineInitialized =
true;
405 ??
throw new InvalidOperationException(
406 $
"{nameof(Initialize)} must be called on a thread with a current {nameof(SynchronizationContext)}.");
409 _engineStarted =
true;
419 SynchronizationContext syncContext)
421 Engine.Instance.Start(syncContext);
430 return SynchronizationContext.Current;
460 _engineStarted =
false;
476 Engine.Instance.Dispose();
477 _engineInitialized =
false;
504 throw new InvalidOperationException(
505 $
"{GetType().Name} has already been initialized.");
517 ObjectDisposedException.ThrowIf(_disposed,
this);
537 if (_engineInitialized)
542 _widgetInputRouter?.Dispose();
543 _widgetInputRouter =
null;
547 if (_engineInitialized)
554 GC.SuppressFinalize(
this);
Provides a base class for hosting and managing the lifecycle of a Gondwana game application.
virtual void StopEngineCore()
Performs platform-specific engine shutdown work.
void InitializeEngine(string? configPath, bool? autoSaveConfig)
Initializes the Gondwana engine using the default file-backed configuration store.
virtual void LoadAssets()
Loads textures, sounds, and other game assets.
void ConfigurePlatform()
Configures platform-specific services, adapters, and render infrastructure.
void InitializeEngine(string? configPath, bool? autoSaveConfig, IEngineConfigurationStore? configurationStore)
Initializes the Gondwana engine.
virtual ? SynchronizationContext GetSynchronizationContext()
Gets the synchronization context used to start the engine.
virtual void OnInputConfigured()
Runs after all input devices have been configured.
void InitializeGameContent()
Initializes game-specific content, the scene graph, and scene objects.
void InitializeSceneObjects()
Creates sprites and direct drawings for the current scene.
virtual void ConfigureKeyboard()
Configures the keyboard input adapter.
void LoadContent()
Loads assets, tilesheets, and animation cycles.
virtual void CreateInitialViews()
Creates the initial views and viewports used to render the scene.
virtual void OnInitialized()
Runs after the full host initialization sequence has completed.
virtual void StartEngineCore(SynchronizationContext syncContext)
Starts the engine using the supplied synchronization context.
void DisposeEngine()
Disposes the engine instance.
virtual void OnDisposing()
Runs before managed resources are disposed.
virtual void OnInitializing()
Runs before the host initialization sequence begins.
void EnsureNotInitialized()
Ensures that the host has not already been initialized.
virtual void BindScene()
Binds the current scene to the platform render surface.
virtual void OnEngineInitialized()
Runs after the engine has been initialized but before it has been started.
virtual void OnEngineStarted()
Runs after the engine has been started.
void StopEngine()
Stops the engine during host disposal.
virtual void OnDisposed()
Runs after managed resources have been disposed.
virtual void LoadAnimationCycles()
Loads animation cycle definitions.
virtual void UnhookEvents()
Unhooks custom event handlers during disposal.
virtual void LoadTilesheets()
Loads tilesheet definitions.
virtual void OnSceneBound()
Runs after the current scene has been bound to the render surface host.
virtual void ConfigureGamepads()
Configures the gamepad manager.
virtual void CreateSprites()
Creates sprite objects for the current scene.
void Dispose()
Releases resources owned by the game host.
void CreateSceneGraph()
Creates the initial scene and its views.
Scene? Scene
Gets the current active scene.
virtual Scene CreateInitialScene()
Creates the initial scene for the game.
void Initialize(string? configPath=null, bool? autoSaveConfig=null, LogLevel logLevel=LogLevel.Warning)
Initializes the game host by configuring logging, platform services, input, game content,...
void ConfigureInput()
Configures keyboard, mouse, gamepad, and touch input.
virtual void ConfigureMouse()
Configures the mouse input adapter.
void StartEngine()
Starts the engine using the synchronization context returned by GetSynchronizationContext.
virtual void OnSceneGraphCreated()
Runs after the scene graph has been created but before the scene is bound.
virtual void CreateDirectDrawings()
Creates direct drawings and widgets for the current scene.
void ConfigureLogging(LogLevel logLevel)
Configures the logging level used by Gondwana.
void InitializeWithConfigurationStore(IEngineConfigurationStore configurationStore, bool? autoSaveConfig=null, LogLevel logLevel=LogLevel.Warning)
Initializes the game host using a caller-supplied configuration persistence store.
WidgetInputRouter? WidgetInputRouter
Gets the widget input router, if widget input has been initialized.
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.
virtual void ConfigureTouch()
Configures the touch input adapter.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
Provides a persistence boundary for EngineConfiguration.