forked from space-wizards/RobustToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugLightTreeSystem.cs
More file actions
77 lines (64 loc) · 2.23 KB
/
Copy pathDebugLightTreeSystem.cs
File metadata and controls
77 lines (64 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#if DEBUG
using Robust.Client.ComponentTrees;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Robust.Client.GameObjects
{
internal sealed class DebugLightTreeSystem : EntitySystem
{
private DebugLightOverlay? _lightOverlay;
public bool Enabled
{
get => _enabled;
set
{
if (_enabled == value) return;
_enabled = value;
var overlayManager = IoCManager.Resolve<IOverlayManager>();
if (_enabled)
{
_lightOverlay = new DebugLightOverlay(
EntityManager.System<EntityLookupSystem>(),
EntityManager.System<LightTreeSystem>());
overlayManager.AddOverlay(_lightOverlay);
}
else
{
overlayManager.RemoveOverlay(_lightOverlay!);
_lightOverlay = null;
}
}
}
private bool _enabled;
private sealed class DebugLightOverlay : Overlay
{
private EntityLookupSystem _lookup;
private LightTreeSystem _trees;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
public DebugLightOverlay(EntityLookupSystem lookup, LightTreeSystem trees)
{
_lookup = lookup;
_trees = trees;
}
protected internal override void Draw(in OverlayDrawArgs args)
{
var map = args.MapId;
if (map == MapId.Nullspace) return;
foreach (var (_, treeComp) in _trees.GetIntersectingTrees(map, args.WorldBounds))
{
foreach (var entry in treeComp.Tree)
{
var aabb = _lookup.GetWorldAABB(entry.Uid, entry.Transform);
if (!aabb.Intersects(args.WorldAABB)) continue;
args.WorldHandle.DrawRect(aabb, Color.Green.WithAlpha(0.1f));
}
}
}
}
}
}
#endif