Static system that tracks all BaseCameraNoise instances, updates them each frame, prunes finished effects, and applies their rotation modifications to a camera Rotation.
namespace Machines.Systems;
/// <summary>
/// Manages active camera noise effects. Call <see cref="Update"/> then <see cref="Apply"/> each frame.
/// </summary>
public static class CameraNoiseSystem
{
private static readonly List<BaseCameraNoise> _all = new();
/// <summary>
/// Register a noise effect. Called automatically by <see cref="BaseCameraNoise"/> constructor.
/// </summary>
public static void Add( BaseCameraNoise noise )
{
_all.Add( noise );
}
/// <summary>
/// Tick all active effects and prune finished ones. Call once per frame before <see cref="Apply"/>.
/// </summary>
public static void Update()
{
foreach ( var effect in _all )
{
effect.Tick();
}
_all.RemoveAll( x => x.IsDone );
}
/// <summary>
/// Apply all active effects to the given camera rotation. Returns the modified rotation.
/// </summary>
public static Rotation Apply( Rotation rotation )
{
foreach ( var effect in _all )
{
rotation = effect.ModifyRotation( rotation );
}
return rotation;
}
}