From 404accb18f1fb87889a5c502325b727a56e4aa19 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Wed, 29 Dec 2021 05:12:28 +1100 Subject: [PATCH] ECS visibility (#5769) --- Content.Server/Ghost/GhostSystem.cs | 13 ++++++++----- .../Pointing/EntitySystems/PointingSystem.cs | 6 ++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs index 8c959bc39a..bf6386f1d9 100644 --- a/Content.Server/Ghost/GhostSystem.cs +++ b/Content.Server/Ghost/GhostSystem.cs @@ -26,6 +26,7 @@ namespace Content.Server.Ghost [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly GameTicker _ticker = default!; + [Dependency] private readonly VisibilitySystem _visibilitySystem = default!; public override void Initialize() { @@ -59,10 +60,11 @@ namespace Content.Server.Ghost private void OnGhostStartup(EntityUid uid, GhostComponent component, ComponentStartup args) { // Allow this entity to be seen by other ghosts. - var visibility = component.Owner.EnsureComponent(); + var visibility = EntityManager.EnsureComponent(component.Owner); - visibility.Layer |= (int) VisibilityFlags.Ghost; - visibility.Layer &= ~(int) VisibilityFlags.Normal; + _visibilitySystem.AddLayer(visibility, (int) VisibilityFlags.Ghost, false); + _visibilitySystem.RemoveLayer(visibility, (int) VisibilityFlags.Normal, false); + _visibilitySystem.RefreshVisibility(visibility); if (EntityManager.TryGetComponent(component.Owner, out EyeComponent? eye)) { @@ -80,8 +82,9 @@ namespace Content.Server.Ghost // Entity can't be seen by ghosts anymore. if (EntityManager.TryGetComponent(component.Owner, out VisibilityComponent? visibility)) { - visibility.Layer &= ~(int) VisibilityFlags.Ghost; - visibility.Layer |= (int) VisibilityFlags.Normal; + _visibilitySystem.RemoveLayer(visibility, (int) VisibilityFlags.Ghost, false); + _visibilitySystem.AddLayer(visibility, (int) VisibilityFlags.Normal, false); + _visibilitySystem.RefreshVisibility(visibility); } // Entity can't see ghosts anymore. diff --git a/Content.Server/Pointing/EntitySystems/PointingSystem.cs b/Content.Server/Pointing/EntitySystems/PointingSystem.cs index 10c524be0e..99de89b2d4 100644 --- a/Content.Server/Pointing/EntitySystems/PointingSystem.cs +++ b/Content.Server/Pointing/EntitySystems/PointingSystem.cs @@ -33,6 +33,7 @@ namespace Content.Server.Pointing.EntitySystems [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!; + [Dependency] private readonly VisibilitySystem _visibilitySystem = default!; private static readonly TimeSpan PointDelay = TimeSpan.FromSeconds(0.5f); @@ -127,8 +128,9 @@ namespace Content.Server.Pointing.EntitySystems var layer = (int) VisibilityFlags.Normal; if (TryComp(player, out VisibilityComponent? playerVisibility)) { - var arrowVisibility = arrow.EnsureComponent(); - layer = arrowVisibility.Layer = playerVisibility.Layer; + var arrowVisibility = EntityManager.EnsureComponent(arrow); + layer = playerVisibility.Layer; + _visibilitySystem.SetLayer(arrowVisibility, layer); } // Get players that are in range and whose visibility layer matches the arrow's.