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
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(
83 180,
84 255,
85 190,
86 80),
89 centerWorldPx,
90 radiusWorldPx,
91 nickname)
92 {
93 ZOrder = DefaultZOrder,
94 BlendMode = SKBlendMode.Screen,
95 HotspotRadiusRatio = 0.06f,
96 MidpointRadiusRatio = 0.55f,
97 MidpointIntensityRatio = 0.35f
98 };
99
100 _lights.Add(light);
101 LightAdded?.Invoke(light);
102 return light;
103 }
104
110 public bool Remove(DirectRadialLight light)
111 {
112 if (!_lights.Remove(light))
113 return false;
114
115 LightRemoving?.Invoke(light);
116 light.Dispose();
117 return true;
118 }
119
123 public void Clear()
124 {
125 foreach (var light in _lights.ToArray())
126 Remove(light);
127
128 _lights.Clear();
129 }
130
132 public void Dispose()
133 {
134 Clear();
135 LightAdded = null;
136 LightRemoving = null;
137 }
138}
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 ...