Gondwana Game Engine Development (master) - 2.6.1
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 lock (_lock)
89 snapshot = _snapshot;
90
91 foreach (var plugin in snapshot)
92 {
93 lock (_lock)
94 {
95 if (_disabledPlugins.Contains(plugin))
96 continue;
97 }
98
99 try
100 {
101 callback(plugin);
102 }
103 catch (Exception ex)
104 {
105 lock (_lock)
106 _disabledPlugins.Add(plugin);
107
108 Engine.Logger.LogError(
109 ex,
110 "Engine plugin '{PluginName}' ({PluginVersion}) threw in {Hook} and was disabled.",
111 plugin.Name,
112 plugin.Version,
113 hook);
114 }
115 }
116 }
117}
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,...