mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
These are all essentially just random systems that scaled directly with player count (or were on my list of the top 50 anyways). So just a couple systems that had very inefficient enumerators being swapped out with significantly more efficient ones, plus a few swaps from O(n) to O(m) m << n. A big one was DrainSystem, which was querrying all possible entities, rather than doing so from the "set of all static objects", which is significantly smaller. Puddles are always static objects, so it doesn't make sense to have the drains check for anything other than static. We can also use DirtyField to save on performance costs of Dirty(uid, component) in cases where the Dirty is only networking a single component field. no CL this isn't player facing.
99 lines
3.4 KiB
C#
99 lines
3.4 KiB
C#
using Content.Server.Storage.Components;
|
|
using Content.Shared.Body.Components;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Morgue;
|
|
using Content.Shared.Morgue.Components;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Server.Morgue;
|
|
|
|
public sealed class MorgueSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<MorgueComponent, ExaminedEvent>(OnExamine);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles the examination text for looking at a morgue.
|
|
/// </summary>
|
|
private void OnExamine(EntityUid uid, MorgueComponent component, ExaminedEvent args)
|
|
{
|
|
if (!args.IsInDetailsRange)
|
|
return;
|
|
|
|
_appearance.TryGetData<MorgueContents>(uid, MorgueVisuals.Contents, out var contents);
|
|
|
|
var text = contents switch
|
|
{
|
|
MorgueContents.HasSoul => "morgue-entity-storage-component-on-examine-details-body-has-soul",
|
|
MorgueContents.HasContents => "morgue-entity-storage-component-on-examine-details-has-contents",
|
|
MorgueContents.HasMob => "morgue-entity-storage-component-on-examine-details-body-has-no-soul",
|
|
_ => "morgue-entity-storage-component-on-examine-details-empty"
|
|
};
|
|
|
|
args.PushMarkup(Loc.GetString(text));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates data periodically in case something died/got deleted in the morgue.
|
|
/// </summary>
|
|
private void CheckContents(EntityUid uid, EntityStorageComponent storage, AppearanceComponent app)
|
|
{
|
|
if (storage.Contents.ContainedEntities.Count == 0)
|
|
{
|
|
_appearance.SetData(uid, MorgueVisuals.Contents, MorgueContents.Empty, app);
|
|
return;
|
|
}
|
|
|
|
var hasMob = false;
|
|
|
|
foreach (var ent in storage.Contents.ContainedEntities)
|
|
{
|
|
if (!hasMob && HasComp<BodyComponent>(ent))
|
|
hasMob = true;
|
|
|
|
if (HasComp<ActorComponent>(ent))
|
|
{
|
|
_appearance.SetData(uid, MorgueVisuals.Contents, MorgueContents.HasSoul, app);
|
|
return;
|
|
}
|
|
}
|
|
|
|
_appearance.SetData(uid, MorgueVisuals.Contents, hasMob ? MorgueContents.HasMob : MorgueContents.HasContents, app);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles the periodic beeping that morgues do when a live body is inside.
|
|
/// </summary>
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var query = EntityQueryEnumerator<MorgueComponent>();
|
|
while (query.MoveNext(out var uid, out var comp))
|
|
{
|
|
comp.AccumulatedFrameTime += frameTime;
|
|
if (comp.AccumulatedFrameTime < comp.BeepTime
|
|
|| !TryComp(uid, out EntityStorageComponent? storage)
|
|
|| !TryComp(uid, out AppearanceComponent? appearance))
|
|
continue;
|
|
|
|
CheckContents(uid, storage, appearance);
|
|
|
|
comp.AccumulatedFrameTime -= comp.BeepTime;
|
|
|
|
if (comp.DoSoulBeep && _appearance.TryGetData<MorgueContents>(uid, MorgueVisuals.Contents, out var contents, appearance) && contents == MorgueContents.HasSoul)
|
|
{
|
|
_audio.PlayPvs(comp.OccupantHasSoulAlarmSound, uid);
|
|
}
|
|
}
|
|
}
|
|
}
|