Update README.md to include project description, developer documentation links, and license information.
CI / build-test (push) Successful in 1m6s
CI / build-test (push) Successful in 1m6s
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
namespace MrGameEng.Graphics;
|
||||
|
||||
/// <summary>Compact identifier of a render layer. Obtained from <see cref="LayerRegistry.Register"/>.</summary>
|
||||
public readonly record struct LayerId(byte Value)
|
||||
{
|
||||
/// <summary>The default layer (the first one registered).</summary>
|
||||
public static readonly LayerId Default = new(0);
|
||||
}
|
||||
|
||||
/// <summary>Coordinate space a layer is drawn in.</summary>
|
||||
public enum LayerSpace
|
||||
{
|
||||
/// <summary>Drawn through the active camera's transform.</summary>
|
||||
World,
|
||||
|
||||
/// <summary>Drawn in screen coordinates, ignoring the camera (HUD, UI). Never culled.</summary>
|
||||
Screen,
|
||||
}
|
||||
|
||||
/// <summary>How sprites are ordered within a layer.</summary>
|
||||
public enum LayerSortMode
|
||||
{
|
||||
/// <summary>Order by the sprite's <see cref="Sprite.Depth"/> value (smaller = drawn first).</summary>
|
||||
Depth,
|
||||
|
||||
/// <summary>Order by world Y position (top-down games: lower on screen = drawn in front).</summary>
|
||||
YSort,
|
||||
}
|
||||
|
||||
/// <summary>A registered render layer.</summary>
|
||||
public sealed record RenderLayer(LayerId Id, string Name, LayerSpace Space, LayerSortMode SortMode);
|
||||
|
||||
/// <summary>
|
||||
/// Registry of render layers. Layers are registered up front (typically when the renderer is
|
||||
/// created) and drawn in registration order. Maximum 256 layers.
|
||||
/// </summary>
|
||||
public sealed class LayerRegistry
|
||||
{
|
||||
private readonly List<RenderLayer> _layers = [];
|
||||
|
||||
/// <summary>Creates a registry containing the built-in "Default" world layer.</summary>
|
||||
public LayerRegistry() => Register("Default");
|
||||
|
||||
/// <summary>Number of registered layers.</summary>
|
||||
public int Count => _layers.Count;
|
||||
|
||||
/// <summary>Registers a layer drawn after all previously registered ones.</summary>
|
||||
public LayerId Register(string name, LayerSpace space = LayerSpace.World, LayerSortMode sortMode = LayerSortMode.Depth)
|
||||
{
|
||||
if (_layers.Count == 256)
|
||||
{
|
||||
throw new InvalidOperationException("Maximum number of render layers (256) reached.");
|
||||
}
|
||||
|
||||
var id = new LayerId((byte)_layers.Count);
|
||||
_layers.Add(new RenderLayer(id, name, space, sortMode));
|
||||
return id;
|
||||
}
|
||||
|
||||
/// <summary>Returns the layer with the given id.</summary>
|
||||
public RenderLayer this[LayerId id] => _layers[id.Value];
|
||||
}
|
||||
Reference in New Issue
Block a user