Files
tbd-station-14/Content.Server/Atmos/Monitor/Components/AtmosAlarmableComponent.cs
Pieter-Jan Briers 444180c20d Optimizations from server profile (#38290)
* Properly cache regexes in chat sanitization/accents

Wow I wonder if `new Regex()` has a cost to it *looks at server profile*.

* Avoid lag caused by Tippy command completions

CompletionHelper.PrototypeIDs explicitly says *not* to use it with EntityPrototype. Unsurprisingly, reporting a completion result for every entity prototype in the game is a *bad idea*.

* Add active count metrics to some high-load systems

Mover & NPCs

I suspect the thing that caused the Leviathan round to shit itself on performance is NPC spam in space or something. So let's verify that.

* Enable parallel processing on pow3r again

Originally disabled due to a theory of it causing bugs, it was re-enabled on Vulture, and I'm not aware of it having caused any issues there.

* Replace hashset with bitflags for AtmosMonitor alert types.

Allocating these hashsets was like 20% of the CPU of atmos, somehow.

* Cache HashSet used for space movement collider checks

Turns out this was a ton of server allocations. Huh.
2025-07-26 11:44:34 +02:00

61 lines
2.3 KiB
C#

using Content.Shared.Atmos.Monitor;
using Content.Shared.Tag;
using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
namespace Content.Server.Atmos.Monitor.Components;
// AtmosAlarmables are entities that can be alarmed
// by a linked AtmosMonitor (alarmer?) if a threshold
// is passed in some way. The intended use is to
// do something in case something dangerous happens,
// e.g., activate firelocks in case a temperature
// threshold is reached
//
// It goes:
//
// AtmosMonitor -> AtmosDeviceUpdateEvent
// -> Threshold calculation
// -> AtmosAlarmEvent
// -> Everything linked to that monitor (targetted)
/// <summary>
/// A component to add to device network devices if you want them to be alarmed
/// by an atmospheric alarmer. This will store every single alert received, and
/// calculate the highest alert based on the alerts received. Equally, if you
/// link other alarmables to this, it will store the alerts from them to
/// calculate the highest network alert.
/// </summary>
[RegisterComponent]
public sealed partial class AtmosAlarmableComponent : Component
{
[ViewVariables]
public readonly Dictionary<string, AtmosAlarmType> NetworkAlarmStates = new();
[ViewVariables] public AtmosAlarmType LastAlarmState = AtmosAlarmType.Invalid;
[ViewVariables] public bool IgnoreAlarms { get; set; } = false;
[DataField("alarmSound")]
public SoundSpecifier AlarmSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/alarm.ogg");
[DataField("alarmVolume")]
public float AlarmVolume { get; set; } = -10;
/// <summary>
/// List of tags to check for when synchronizing alarms.
/// </summary>
[DataField("syncWith", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<TagPrototype>))]
public HashSet<string> SyncWithTags { get; private set; } = new();
[DataField("monitorAlertTypes")]
public AtmosMonitorThresholdTypeFlags MonitorAlertTypes { get; private set; }
/// <summary>
/// If this device should receive only. If it can only
/// receive, that means that attempting to sync outwards
/// will result in nothing happening.
/// </summary>
[DataField("receiveOnly")]
public bool ReceiveOnly { get; private set; }
}