Gondwana Game Engine Development (master) - 2.7.0
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
EnginePluginRegistry.cs
2using Microsoft.Extensions.Logging;
3using SkiaSharp;
4
6
10public static class EnginePluginRegistry
11{
12 private static readonly object _lock = new();
13 private static readonly List<IEnginePlugin> _plugins = [];
14 private static readonly HashSet<IEnginePlugin> _disabledPlugins = [];
15 private static IEnginePlugin[] _snapshot = [];
16
20 public static IReadOnlyList<IEnginePlugin> All
21 {
22 get
23 {
24 lock (_lock)
25 return _snapshot;
26 }
27 }
28
33 public static void Register(IEnginePlugin plugin)
34 {
35 ArgumentNullException.ThrowIfNull(plugin);
36
37 lock (_lock)
38 {
39 if (_plugins.Contains(plugin))
40 return;
41
42 _plugins.Add(plugin);
43 _disabledPlugins.Remove(plugin);
44 _snapshot = [.. _plugins];
45 }
46 }
47
52 public static void Unregister(IEnginePlugin plugin)
53 {
54 ArgumentNullException.ThrowIfNull(plugin);
55
56 lock (_lock)
57 {
58 _plugins.Remove(plugin);
59 _disabledPlugins.Remove(plugin);
60 _snapshot = [.. _plugins];
61 }
62 }
63
64 internal static void InvokeInitialize(Engine engine) =>
65 Invoke(engine, p => p.OnInitialize(engine), "OnInitialize");
66
67 internal static void InvokePreCycle(Engine engine, double deltaSeconds) =>
68 Invoke(engine, p => p.OnPreCycle(engine, deltaSeconds), "OnPreCycle");
69
70 internal static void InvokePreFrameRender(Engine engine, double deltaSeconds) =>
71 Invoke(engine, p => p.OnPreFrameRender(engine, deltaSeconds), "OnPreFrameRender");
72
73 internal static void InvokePostFrameRender(Engine engine, double deltaSeconds) =>
74 Invoke(engine, p => p.OnPostFrameRender(engine, deltaSeconds), "OnPostFrameRender");
75
76 internal static void InvokePostRenderCanvas(Engine engine, RenderSurfaceHostBase host, SKCanvas canvas) =>
77 Invoke(engine, p => p.OnPostRenderCanvas(engine, host, canvas), "OnPostRenderCanvas");
78
79 internal static void InvokePostCycle(Engine engine, double deltaSeconds) =>
80 Invoke(engine, p => p.OnPostCycle(engine, deltaSeconds), "OnPostCycle");
81
82 internal static void InvokeShutdown(Engine engine) =>
83 Invoke(engine, p => p.OnShutdown(engine), "OnShutdown");
84
85 private static void Invoke(Engine engine, Action<IEnginePlugin> callback, string hook)
86 {
87 IEnginePlugin[] snapshot;
88
89 lock (_lock)
90 snapshot = _snapshot;
91
92 foreach (var plugin in snapshot)
93 {
94 lock (_lock)
95 {
96 if (_disabledPlugins.Contains(plugin))
97 continue;
98 }
99
100 try
101 {
102 callback(plugin);
103 }
104 catch (Exception ex)
105 {
106 lock (_lock)
107 _disabledPlugins.Add(plugin);
108
109 Engine.Logger.LogError(
110 ex,
111 "Engine plugin '{PluginName}' ({PluginVersion}) threw in {Hook} and was disabled.",
112 plugin.Name,
113 plugin.Version,
114 hook);
115 }
116 }
117 }
118}
Represents the core game engine singleton responsible for managing the main update loop,...
Definition Engine.cs:36
static ILogger< Engine > Logger
Gets the logger instance used by the engine for diagnostic and informational messages.
Definition Engine.cs:59
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
Defines lifecycle hooks for extending engine startup, simulation, rendering, and shutdown behavior.
string Version
Gets the plugin version string.
string Name
Gets the display name of the plugin.
@ All
Represents all engine state parts combined. This is a convenience value that includes AssetsFiles,...