Sloth's subfloor vismask adventure (#35347)
* Add a subfloor vismask Significantly cuts down on sent entity count. * More optimisations * Fix command * Fixes * namespace cleanup * Review * Vismasks * Content update * Bandaid * awewa * Revert these * reh * Update Content.Shared/SubFloor/TrayScannerComponent.cs --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
@@ -1,16 +1,76 @@
|
||||
using Content.Shared.Construction.Components;
|
||||
using Content.Shared.Eye;
|
||||
using Content.Shared.SubFloor;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.SubFloor;
|
||||
|
||||
public sealed class SubFloorHideSystem : SharedSubFloorHideSystem
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly SharedEyeSystem _eye = default!;
|
||||
|
||||
private HashSet<ICommonSession> _showFloors = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SubFloorHideComponent, AnchorAttemptEvent>(OnAnchorAttempt);
|
||||
SubscribeLocalEvent<SubFloorHideComponent, UnanchorAttemptEvent>(OnUnanchorAttempt);
|
||||
SubscribeNetworkEvent<ShowSubfloorRequestEvent>(OnShowSubfloor);
|
||||
SubscribeLocalEvent<GetVisMaskEvent>(OnGetVisibility);
|
||||
|
||||
_player.PlayerStatusChanged += OnPlayerStatus;
|
||||
}
|
||||
|
||||
private void OnPlayerStatus(object? sender, SessionStatusEventArgs e)
|
||||
{
|
||||
if (e.NewStatus == SessionStatus.Connected)
|
||||
return;
|
||||
|
||||
_showFloors.Remove(e.Session);
|
||||
|
||||
if (e.Session.AttachedEntity != null)
|
||||
_eye.RefreshVisibilityMask(e.Session.AttachedEntity.Value);
|
||||
}
|
||||
|
||||
private void OnGetVisibility(ref GetVisMaskEvent ev)
|
||||
{
|
||||
if (!TryComp(ev.Entity, out ActorComponent? actor))
|
||||
return;
|
||||
|
||||
if (_showFloors.Contains(actor.PlayerSession))
|
||||
{
|
||||
ev.VisibilityMask |= (int)VisibilityFlags.Subfloor;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnShowSubfloor(ShowSubfloorRequestEvent ev, EntitySessionEventArgs args)
|
||||
{
|
||||
// TODO: Commands are a bit of an eh? for client-only but checking shared perms
|
||||
var ent = args.SenderSession.AttachedEntity;
|
||||
|
||||
if (!TryComp(ent, out EyeComponent? eyeComp))
|
||||
return;
|
||||
|
||||
if (ev.Value)
|
||||
{
|
||||
_showFloors.Add(args.SenderSession);
|
||||
}
|
||||
else
|
||||
{
|
||||
_showFloors.Remove(args.SenderSession);
|
||||
}
|
||||
|
||||
_eye.RefreshVisibilityMask((ent.Value, eyeComp));
|
||||
|
||||
RaiseNetworkEvent(new ShowSubfloorRequestEvent()
|
||||
{
|
||||
Value = ev.Value,
|
||||
}, args.SenderSession);
|
||||
}
|
||||
|
||||
private void OnAnchorAttempt(EntityUid uid, SubFloorHideComponent component, AnchorAttemptEvent args)
|
||||
|
||||
Reference in New Issue
Block a user