Skip to content

Commit

Permalink
Show ghosts popups etc through walls (#8077)
Browse files Browse the repository at this point in the history
* Show ghosts popups etc through walls

* Stage moment

* crashes
  • Loading branch information
metalgearsloth authored May 12, 2022
1 parent 40361ec commit 6903209
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
5 changes: 4 additions & 1 deletion Content.Client/Chat/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public sealed class ChatSystem : SharedChatSystem
{
[Dependency] private readonly IChatManager _manager = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly ExamineSystem _examineSystem = default!;

public override void FrameUpdate(float frameTime)
{
Expand All @@ -23,6 +24,8 @@ public override void FrameUpdate(float frameTime)
var bubbles = _manager.GetSpeechBubbles();
var playerPos = player != null ? Transform(player.Value).MapPosition : MapCoordinates.Nullspace;

var occluded = player != null && _examineSystem.IsOccluded(player.Value);

foreach (var (ent, bubs) in bubbles)
{
if (ent == player)
Expand All @@ -33,7 +36,7 @@ public override void FrameUpdate(float frameTime)

var otherPos = Transform(ent).MapPosition;

if (!ExamineSystemShared.InRangeUnOccluded(
if (occluded && !ExamineSystemShared.InRangeUnOccluded(
playerPos,
otherPos, 0f,
(ent, player), predicate))
Expand Down
22 changes: 10 additions & 12 deletions Content.Client/DoAfter/DoAfterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.GameStates;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
Expand All @@ -27,19 +28,18 @@ public sealed class DoAfterSystem : EntitySystem
*/
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly ExamineSystemShared _examineSystem = default!;

/// <summary>
/// We'll use an excess time so stuff like finishing effects can show.
/// </summary>
public const float ExcessTime = 0.5f;

private EntityUid? _attachedEntity;

public override void Initialize()
{
base.Initialize();
UpdatesOutsidePrediction = true;
SubscribeLocalEvent<PlayerAttachSysMessage>(HandlePlayerAttached);
SubscribeNetworkEvent<CancelledDoAfterMessage>(OnCancelledDoAfter);
SubscribeLocalEvent<DoAfterComponent, ComponentStartup>(OnDoAfterStartup);
SubscribeLocalEvent<DoAfterComponent, ComponentShutdown>(OnDoAfterShutdown);
Expand Down Expand Up @@ -111,11 +111,6 @@ private void OnCancelledDoAfter(CancelledDoAfterMessage ev)
Cancel(doAfter, ev.ID);
}

private void HandlePlayerAttached(PlayerAttachSysMessage message)
{
_attachedEntity = message.AttachedEntity;
}

/// <summary>
/// For handling PVS so we dispose of controls if they go out of range
/// </summary>
Expand Down Expand Up @@ -196,17 +191,19 @@ public override void Update(float frameTime)
base.Update(frameTime);

var currentTime = _gameTiming.CurTime;
var attached = _player.LocalPlayer?.ControlledEntity;

// Can't see any I guess?
if (_attachedEntity is not {Valid: true} entity || Deleted(entity))
if (attached == null || Deleted(attached))
return;

// ReSharper disable once ConvertToLocalFunction
var predicate = static (EntityUid uid, (EntityUid compOwner, EntityUid? attachedEntity) data)
=> uid == data.compOwner || uid == data.attachedEntity;

var occluded = _examineSystem.IsOccluded(attached.Value);
var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f);
var entXform = Transform(entity);
var entXform = Transform(attached.Value);
var playerPos = entXform.MapPosition;

foreach (var (comp, xform) in EntityManager.EntityQuery<DoAfterComponent, TransformComponent>(true))
Expand All @@ -224,11 +221,12 @@ public override void Update(float frameTime)

var range = (compPos.Position - playerPos.Position).Length + 0.01f;

if (comp.Owner != _attachedEntity &&
if (occluded &&
comp.Owner != attached &&
!ExamineSystemShared.InRangeUnOccluded(
playerPos,
compPos, range,
(comp.Owner, _attachedEntity), predicate))
(comp.Owner, attached), predicate))
{
Disable(comp);
continue;
Expand Down
4 changes: 3 additions & 1 deletion Content.Client/Popups/PopupSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public sealed class PopupSystem : SharedPopupSystem
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly ExamineSystemShared _examineSystem = default!;

private readonly List<PopupLabel> _aliveLabels = new();

Expand Down Expand Up @@ -141,6 +142,7 @@ public override void FrameUpdate(float frameTime)
// ReSharper disable once ConvertToLocalFunction
var predicate = static (EntityUid uid, (EntityUid? compOwner, EntityUid? attachedEntity) data)
=> uid == data.compOwner || uid == data.attachedEntity;
var occluded = player != null && _examineSystem.IsOccluded(player.Value);

for (var i = _aliveLabels.Count - 1; i >= 0; i--)
{
Expand All @@ -161,7 +163,7 @@ public override void FrameUpdate(float frameTime)

var otherPos = label.Entity != null ? Transform(label.Entity.Value).MapPosition : label.InitialPos;

if (!ExamineSystemShared.InRangeUnOccluded(
if (occluded && !ExamineSystemShared.InRangeUnOccluded(
playerPos,
otherPos, 0f,
(label.Entity, player), predicate))
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Examine/ExamineSystemShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ public float GetExaminerRange(EntityUid examiner, MobStateComponent? mobState =
return ExamineRange;
}

/// <summary>
/// True if occluders are drawn for this entity, otherwise false.
/// </summary>
public bool IsOccluded(EntityUid uid)
{
return TryComp<SharedEyeComponent>(uid, out var eye) && eye.DrawFov;
}

public static bool InRangeUnOccluded(MapCoordinates origin, MapCoordinates other, float range, Ignored? predicate, bool ignoreInsideBlocker = true, IEntityManager? entMan = null)
{
// No, rider. This is better.
Expand Down

0 comments on commit 6903209

Please sign in to comment.