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
DirectLightLayer.cs
1using System.Drawing;
4using SkiaSharp;
5
7
22public sealed class DirectLightLayer : IDisposable
23{
24 private readonly List<DirectRadialLight> _lights = [];
25
29 public event Action<DirectRadialLight>? LightAdded;
30
34 public event Action<DirectRadialLight>? LightRemoving;
35
41 public DirectLightLayer(RenderSurfaceHostBase renderSurfaceHost, SceneLayer sceneLayer)
42 {
43 RenderSurfaceHost = renderSurfaceHost ?? throw new ArgumentNullException(nameof(renderSurfaceHost));
44 SceneLayer = sceneLayer ?? throw new ArgumentNullException(nameof(sceneLayer));
45 }
46
51
55 public SceneLayer SceneLayer { get; }
56
60 public IReadOnlyList<DirectRadialLight> Lights => _lights;
61
65 public int DefaultZOrder { get; set; } = 10_000;
66
76 PointF centerWorldPx,
77 float radiusWorldPx,
78 Color? color = null,
79 string? nickname = null)
80 {
81 var light = new DirectRadialLight(
82 color ?? Color.FromArgb(180, 255, 190, 80),
85 centerWorldPx,
86 radiusWorldPx,
87 nickname)
88 {
89 ZOrder = DefaultZOrder,
90 BlendMode = SKBlendMode.Screen,
91 HotspotRadiusRatio = 0.06f,
92 MidpointRadiusRatio = 0.55f,
93 MidpointIntensityRatio = 0.35f
94 };
95
96 _lights.Add(light);
97 LightAdded?.Invoke(light);
98 return light;
99 }
100
106 public bool Remove(DirectRadialLight light)
107 {
108 if (!_lights.Remove(light))
109 return false;
110
111 LightRemoving?.Invoke(light);
112 light.Dispose();
113 return true;
114 }
115
119 public void Clear()
120 {
121 foreach (var light in _lights.ToArray())
122 Remove(light);
123
124 _lights.Clear();
125 }
126
128 public void Dispose()
129 {
130 Clear();
131 LightAdded = null;
132 LightRemoving = null;
133 }
134}
void Dispose()
Releases all resources used by this DirectDrawingBase instance.
Action< DirectRadialLight >? LightRemoving
Occurs before a light is disposed and removed from this owner.
int DefaultZOrder
Gets or sets the Z-order assigned to newly-created lights.
IReadOnlyList< DirectRadialLight > Lights
Gets the lights owned by this layer.
void Clear()
Disposes every light owned by this layer.
DirectRadialLight AddTorchLight(PointF centerWorldPx, float radiusWorldPx, Color? color=null, string? nickname=null)
Creates a warm, screen-blended torch-style light.
RenderSurfaceHostBase RenderSurfaceHost
Gets the render surface host used by lights created from this owner.
Action< DirectRadialLight >? LightAdded
Occurs after a light has been added to this owner.
bool Remove(DirectRadialLight light)
Removes and disposes a light owned by this layer.
DirectLightLayer(RenderSurfaceHostBase renderSurfaceHost, SceneLayer sceneLayer)
Initializes a new light owner for the given render surface and scene layer.
SceneLayer SceneLayer
Gets the scene layer where lights are drawn.
Draws a bounded, radial light effect as a scene-layer direct drawing.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...