diff --git a/Content.Client/Light/RoofOverlay.cs b/Content.Client/Light/RoofOverlay.cs index 8944630169..6e43466c24 100644 --- a/Content.Client/Light/RoofOverlay.cs +++ b/Content.Client/Light/RoofOverlay.cs @@ -43,7 +43,7 @@ public sealed class RoofOverlay : Overlay protected override void Draw(in OverlayDrawArgs args) { - if (args.Viewport.Eye == null) + if (args.Viewport.Eye == null || !_entManager.HasComponent(args.MapUid)) return; var viewport = args.Viewport; @@ -55,24 +55,42 @@ public sealed class RoofOverlay : Overlay var target = lightoverlay.EnlargedLightTarget; _grids.Clear(); - _mapManager.FindGridsIntersecting(args.MapId, bounds, ref _grids); - - for (var i = _grids.Count - 1; i >= 0; i--) - { - var grid = _grids[i]; - - if (_entManager.HasComponent(grid.Owner)) - continue; - - _grids.RemoveAt(i); - } - - if (_grids.Count == 0) - return; - + _mapManager.FindGridsIntersecting(args.MapId, bounds, ref _grids, approx: true, includeMap: true); var lightScale = viewport.LightRenderTarget.Size / (Vector2) viewport.Size; var scale = viewport.RenderScale / (Vector2.One / lightScale); + worldHandle.RenderInRenderTarget(target, + () => + { + for (var i = 0; i < _grids.Count; i++) + { + var grid = _grids[i]; + + if (!_entManager.TryGetComponent(grid.Owner, out ImplicitRoofComponent? roof)) + continue; + + var invMatrix = target.GetWorldToLocalMatrix(eye, scale); + + var gridMatrix = _xformSystem.GetWorldMatrix(grid.Owner); + var matty = Matrix3x2.Multiply(gridMatrix, invMatrix); + + worldHandle.SetTransform(matty); + + var tileEnumerator = _mapSystem.GetTilesEnumerator(grid.Owner, grid, bounds); + var color = roof.Color; + + while (tileEnumerator.MoveNext(out var tileRef)) + { + var local = _lookup.GetLocalBounds(tileRef, grid.Comp.TileSize); + worldHandle.DrawRect(local, color); + } + + // Don't need it for the next stage. + _grids.RemoveAt(i); + i--; + } + }, null); + worldHandle.RenderInRenderTarget(target, () => { diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.cs index 4eb9669298..4b0e076a4f 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.cs @@ -11,6 +11,7 @@ using Content.Server.Stunnable; using Content.Shared.Buckle.Components; using Content.Shared.Damage; using Content.Shared.GameTicking; +using Content.Shared.Light.Components; using Content.Shared.Inventory; using Content.Shared.Mobs.Systems; using Content.Shared.Movement.Events; @@ -121,7 +122,8 @@ public sealed partial class ShuttleSystem : SharedShuttleSystem if (HasComp(ev.EntityUid)) return; - EntityManager.EnsureComponent(ev.EntityUid); + EnsureComp(ev.EntityUid); + EnsureComp(ev.EntityUid); } private void OnShuttleStartup(EntityUid uid, ShuttleComponent component, ComponentStartup args) diff --git a/Content.Shared/Light/Components/ImplicitRoofComponent.cs b/Content.Shared/Light/Components/ImplicitRoofComponent.cs new file mode 100644 index 0000000000..b457bac3e4 --- /dev/null +++ b/Content.Shared/Light/Components/ImplicitRoofComponent.cs @@ -0,0 +1,13 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Light.Components; + +/// +/// Assumes the entire attached grid is rooved. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class ImplicitRoofComponent : Component +{ + [DataField, AutoNetworkedField] + public Color Color = Color.Black; +}