Files
RobustToolbox/Robust.Client/ComponentTrees/LightTreeSystem.cs
2022-12-27 13:33:46 +11:00

39 lines
1.4 KiB
C#

using Robust.Client.GameObjects;
using Robust.Shared.ComponentTrees;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
namespace Robust.Client.ComponentTrees;
public sealed class LightTreeSystem : ComponentTreeSystem<LightTreeComponent, PointLightComponent>
{
#region Component Tree Overrides
protected override bool DoFrameUpdate => true;
protected override bool DoTickUpdate => false;
protected override bool Recursive => true;
protected override int InitialCapacity => 128;
protected override Box2 ExtractAabb(in ComponentTreeEntry<PointLightComponent> entry, Vector2 pos, Angle rot)
{
// Really we should be rotating the light offset by the relative rotation. But I assume the light offset will
// always be relatively small, so fuck it, this is probably faster than having to compute the angle every time.
var radius = entry.Component.Radius + entry.Component.Offset.Length;
return new Box2(pos - radius, pos + radius);
}
protected override Box2 ExtractAabb(in ComponentTreeEntry<PointLightComponent> entry)
{
if (entry.Component.TreeUid == null)
return default;
var pos = XformSystem.GetRelativePosition(
entry.Transform,
entry.Component.TreeUid.Value,
GetEntityQuery<TransformComponent>());
return ExtractAabb(in entry, pos, default);
}
#endregion
}