Class Light2DManager
Manages 2D lights in the scene.
public class Light2DManager : ILightManager, ISerialization, IGraphicsResource
- Inheritance
-
Light2DManager
- Implements
- Inherited Members
Constructors
Light2DManager()
Initializes a new instance of the Light2DManager class.
public Light2DManager()
Properties
ChunkSize
Gets or sets the size, in characters, of each chunk used during processing.
public float ChunkSize { get; set; }
Property Value
Remarks
Adjust this value to control the maximum number of characters included in a single chunk. Larger chunk sizes may improve performance but can increase memory usage.
Chunks
The dictionary of light chunks, where the key is a tuple of chunk coordinates (x, y).
public Dictionary<(int, int), Light2DChunk> Chunks { get; set; }
Property Value
- Dictionary<(int, int), Light2DChunk>
DirectionalLight
The directional light in the scene.
public DirectionalLight2D DirectionalLight { get; set; }
Property Value
IsInitialized
Gets a value indicating whether the object has been initialized.
public bool IsInitialized { get; }
Property Value
LightSSBO
The shader storage buffer object (SSBO) for the lights.
public int LightSSBO { get; set; }
Property Value
Methods
AddPointLight(PointLight2D)
Adds a directional light to the scene.
public void AddPointLight(PointLight2D light)
Parameters
lightPointLight2D
BindLights(Viewport, IRenderDevice, Camera)
Binds the lights to the shader program for rendering.
public void BindLights(Viewport viewport, IRenderDevice renderer, Camera camera)
Parameters
viewportViewportrendererIRenderDevicecameraCamera
ClearLights()
Removes all lights from the scene, including the directional light and any additional light sources.
public void ClearLights()
Remarks
After calling this method, the scene will contain no active lights. Use this method to reset the lighting configuration before adding new lights or reconfiguring the scene's illumination.
ContainsLight(Light)
Determines whether the specified light is contained within this collection.
public bool ContainsLight(Light light)
Parameters
lightLightThe light to locate in the collection. Can be a directional or point light.
Returns
- bool
true if the specified light is present in the collection; otherwise, false.
Remarks
This method checks for both directional and point lights. For directional lights, it compares with the collection's directional light. For point lights, it searches all chunks in the collection.
CullChunkLights(Camera, float)
Gets the lights in the nearby chunks based on the given coordinates and chunk size.
public IEnumerable<Point2DLightData> CullChunkLights(Camera camera, float chunkSize)
Parameters
Returns
CullLights(Viewport, IRenderDevice, Camera)
Culls the lights based on the camera's view and the viewport.
public void CullLights(Viewport viewport, IRenderDevice renderer, Camera camera)
Parameters
viewportViewportrendererIRenderDevicecameraCamera
Deserialize(JObject, SerializationContext, Func<JObject, bool>)
Populates the current object with values from the specified JSON object.
public void Deserialize(JObject obj, SerializationContext serializationContext, Func<JObject, bool> callback = null)
Parameters
objJObjectserializationContextSerializationContextcallbackFunc<JObject, bool>
Dispose(IRenderDevice)
Disposes of the light manager and releases any resources.
public void Dispose(IRenderDevice renderDevice)
Parameters
renderDeviceIRenderDevice
DisposeLights(IRenderDevice)
Releases all light resources associated with the current instance using the specified render device.
public void DisposeLights(IRenderDevice renderDevice)
Parameters
renderDeviceIRenderDeviceThe render device to use when disposing of light resources. Cannot be null.
Remarks
Call this method to ensure that all light resources are properly released before disposing of the parent object or when lights are no longer needed. After calling this method, the collection of lights will be cleared.
FindNearbyChunks(float, float, float)
Finds nearby chunks based on the given coordinates and chunk size.
public IEnumerable<(int, int)> FindNearbyChunks(float x, float y, float chunkSize)
Parameters
Returns
- IEnumerable<(int, int)>
ForEachLight(Action<Light>)
Performs an action on each light in the scene, regardless of type.
public void ForEachLight(Action<Light> action)
Parameters
ForEachLight<T>(Action<T>)
Performs an action on each light of the specified type in the scene.
public void ForEachLight<T>(Action<T> action) where T : Light
Parameters
actionAction<T>
Type Parameters
T
Exceptions
FreeCPUResources()
Frees any CPU resources used by the light manager.
public void FreeCPUResources()
GetChunk(float, float, float)
Gets the chunk coordinates based on the given x and y coordinates and chunk size.
public (int, int) GetChunk(float x, float y, float chunkSize)
Parameters
Returns
GetLightCount<T>()
Gets the light count of the specified type.
public int GetLightCount<T>() where T : Light
Returns
Type Parameters
T
Exceptions
GetLight<T>()
Gets the total light count across all types.
public T GetLight<T>() where T : Light
Returns
- T
Type Parameters
T
Exceptions
Init(IRenderDevice)
Initializes the light manager with the given render device.
public void Init(IRenderDevice renderDevice)
Parameters
renderDeviceIRenderDevice
RemovePointLight(PointLight2D)
Removes a point light from the scene.
public void RemovePointLight(PointLight2D light)
Parameters
lightPointLight2D
Serialize(JsonWriter, SerializationContext, Action<JsonWriter>)
Serializes the current object to a new JSON object representation.
public void Serialize(JsonWriter writer, SerializationContext serializationContext, Action<JsonWriter> callback = null)
Parameters
writerJsonWriterserializationContextSerializationContextcallbackAction<JsonWriter>
SetLightSpaceMatrix(Matrix4)
Sets the light view matrix for the light manager, which is used to transform the light's perspective in the scene. Note: This method is not implemented for 2D lights as they do not have a light space matrix like 3D lights.
public void SetLightSpaceMatrix(Matrix4 lightViewMatrix)
Parameters
lightViewMatrixMatrix4