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)
58 => InitializeCore(configPath, autoSaveConfig, logLevel, configurationStore:
null);
72 bool? autoSaveConfig =
null,
73 LogLevel logLevel = LogLevel.Warning)
75 ArgumentNullException.ThrowIfNull(configurationStore);
76 InitializeCore(configPath:
null, autoSaveConfig, logLevel, configurationStore);
79 private void InitializeCore(
118 ArgumentNullException.ThrowIfNull(renderSurfaceHost);
120 _widgetInputRouter?.Dispose();
122 var keyboardPoller =
Engine.Input.KeyboardEventPoller;
123 var mousePoller =
Engine.Input.MouseEventPoller;
124 var touchPoller =
Engine.Input.TouchEventPoller;
126 mousePoller?.StartMonitoringMouse(
127 trackMouseMovement:
true);
135 _widgetInputRouter.Start();
152 EngineLogger.SetLogLevel(logLevel);
264 ??
throw new InvalidOperationException(
265 $
"{nameof(CreateInitialScene)} returned null.");
343 bool? autoSaveConfig)
358 bool? autoSaveConfig,
361 if (configurationStore is
null)
363 Engine.Instance.Initialize(
364 configFileName: configPath,
365 autoSaveConfig: autoSaveConfig);
369 Engine.Instance.InitializeWithConfigurationStore(
371 autoSaveConfig: autoSaveConfig);
373 _engineInitialized =
true;
395 ??
throw new InvalidOperationException(
396 $
"{nameof(Initialize)} must be called on a thread with a current {nameof(SynchronizationContext)}.");
399 _engineStarted =
true;
409 SynchronizationContext syncContext)
411 Engine.Instance.Start(syncContext);
420 return SynchronizationContext.Current;
450 _engineStarted =
false;
466 Engine.Instance.Dispose();
467 _engineInitialized =
false;
494 throw new InvalidOperationException(
495 $
"{GetType().Name} has already been initialized.");
507 ObjectDisposedException.ThrowIf(_disposed,
this);
527 if (_engineInitialized)
532 _widgetInputRouter?.Dispose();
533 _widgetInputRouter =
null;
537 if (_engineInitialized)
544 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.