Sentry review (#35424)
Co-authored-by: chromiumboy <chromium.boy@gmail.com> Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>
This commit is contained in:
8
Content.Client/Power/EntitySystems/PowerNetSystem.cs
Normal file
8
Content.Client/Power/EntitySystems/PowerNetSystem.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Content.Shared.Power.EntitySystems;
|
||||||
|
|
||||||
|
namespace Content.Client.Power.EntitySystems;
|
||||||
|
|
||||||
|
public sealed class PowerNetSystem : SharedPowerNetSystem
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ using Content.Server.Power.NodeGroups;
|
|||||||
using Content.Server.Power.Pow3r;
|
using Content.Server.Power.Pow3r;
|
||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.Power;
|
using Content.Shared.Power;
|
||||||
|
using Content.Shared.Power.Components;
|
||||||
|
using Content.Shared.Power.EntitySystems;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Configuration;
|
using Robust.Shared.Configuration;
|
||||||
@@ -16,7 +18,7 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
/// Manages power networks, power state, and all power components.
|
/// Manages power networks, power state, and all power components.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class PowerNetSystem : EntitySystem
|
public sealed class PowerNetSystem : SharedPowerNetSystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||||
[Dependency] private readonly PowerNetConnectorSystem _powerNetConnector = default!;
|
[Dependency] private readonly PowerNetConnectorSystem _powerNetConnector = default!;
|
||||||
@@ -28,12 +30,20 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
private readonly HashSet<PowerNet> _powerNetReconnectQueue = new();
|
private readonly HashSet<PowerNet> _powerNetReconnectQueue = new();
|
||||||
private readonly HashSet<ApcNet> _apcNetReconnectQueue = new();
|
private readonly HashSet<ApcNet> _apcNetReconnectQueue = new();
|
||||||
|
|
||||||
|
private EntityQuery<ApcPowerReceiverBatteryComponent> _apcBatteryQuery;
|
||||||
|
private EntityQuery<AppearanceComponent> _appearanceQuery;
|
||||||
|
private EntityQuery<BatteryComponent> _batteryQuery;
|
||||||
|
|
||||||
private BatteryRampPegSolver _solver = new();
|
private BatteryRampPegSolver _solver = new();
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
|
_apcBatteryQuery = GetEntityQuery<ApcPowerReceiverBatteryComponent>();
|
||||||
|
_appearanceQuery = GetEntityQuery<AppearanceComponent>();
|
||||||
|
_batteryQuery = GetEntityQuery<BatteryComponent>();
|
||||||
|
|
||||||
UpdatesAfter.Add(typeof(NodeGroupSystem));
|
UpdatesAfter.Add(typeof(NodeGroupSystem));
|
||||||
_solver = new(_cfg.GetCVar(CCVars.DebugPow3rDisableParallel));
|
_solver = new(_cfg.GetCVar(CCVars.DebugPow3rDisableParallel));
|
||||||
|
|
||||||
@@ -309,10 +319,6 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
|
|
||||||
private void UpdateApcPowerReceiver(float frameTime)
|
private void UpdateApcPowerReceiver(float frameTime)
|
||||||
{
|
{
|
||||||
var appearanceQuery = GetEntityQuery<AppearanceComponent>();
|
|
||||||
var metaQuery = GetEntityQuery<MetaDataComponent>();
|
|
||||||
var apcBatteryQuery = GetEntityQuery<ApcPowerReceiverBatteryComponent>();
|
|
||||||
|
|
||||||
var enumerator = AllEntityQuery<ApcPowerReceiverComponent>();
|
var enumerator = AllEntityQuery<ApcPowerReceiverComponent>();
|
||||||
while (enumerator.MoveNext(out var uid, out var apcReceiver))
|
while (enumerator.MoveNext(out var uid, out var apcReceiver))
|
||||||
{
|
{
|
||||||
@@ -321,8 +327,11 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
|| MathHelper.CloseToPercent(apcReceiver.NetworkLoad.ReceivingPower,
|
|| MathHelper.CloseToPercent(apcReceiver.NetworkLoad.ReceivingPower,
|
||||||
apcReceiver.Load));
|
apcReceiver.Load));
|
||||||
|
|
||||||
|
MetaDataComponent? metadata = null;
|
||||||
|
|
||||||
|
// TODO: If we get archetypes would be better to split this out.
|
||||||
// Check if the entity has an internal battery
|
// Check if the entity has an internal battery
|
||||||
if (apcBatteryQuery.TryComp(uid, out var apcBattery) && TryComp<BatteryComponent>(uid, out var battery))
|
if (_apcBatteryQuery.TryComp(uid, out var apcBattery) && _batteryQuery.TryComp(uid, out var battery))
|
||||||
{
|
{
|
||||||
apcReceiver.Load = apcBattery.IdleLoad;
|
apcReceiver.Load = apcBattery.IdleLoad;
|
||||||
|
|
||||||
@@ -333,7 +342,6 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
{
|
{
|
||||||
_battery.SetCharge(uid, battery.CurrentCharge - apcBattery.IdleLoad * frameTime, battery);
|
_battery.SetCharge(uid, battery.CurrentCharge - apcBattery.IdleLoad * frameTime, battery);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise try to charge the battery
|
// Otherwise try to charge the battery
|
||||||
else if (powered && !_battery.IsFull(uid, battery))
|
else if (powered && !_battery.IsFull(uid, battery))
|
||||||
{
|
{
|
||||||
@@ -347,6 +355,8 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
if (apcBattery.Enabled != enableBattery)
|
if (apcBattery.Enabled != enableBattery)
|
||||||
{
|
{
|
||||||
apcBattery.Enabled = enableBattery;
|
apcBattery.Enabled = enableBattery;
|
||||||
|
metadata = MetaData(uid);
|
||||||
|
Dirty(uid, apcBattery, metadata);
|
||||||
|
|
||||||
var apcBatteryEv = new ApcPowerReceiverBatteryChangedEvent(enableBattery);
|
var apcBatteryEv = new ApcPowerReceiverBatteryChangedEvent(enableBattery);
|
||||||
RaiseLocalEvent(uid, ref apcBatteryEv);
|
RaiseLocalEvent(uid, ref apcBatteryEv);
|
||||||
@@ -361,8 +371,8 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
if (!apcReceiver.Recalculate && apcReceiver.Powered == powered)
|
if (!apcReceiver.Recalculate && apcReceiver.Powered == powered)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var metadata = metaQuery.Comp(uid);
|
metadata ??= MetaData(uid);
|
||||||
if (metadata.EntityPaused)
|
if (Paused(uid, metadata))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
apcReceiver.Recalculate = false;
|
apcReceiver.Recalculate = false;
|
||||||
@@ -372,15 +382,14 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
var ev = new PowerChangedEvent(powered, apcReceiver.NetworkLoad.ReceivingPower);
|
var ev = new PowerChangedEvent(powered, apcReceiver.NetworkLoad.ReceivingPower);
|
||||||
RaiseLocalEvent(uid, ref ev);
|
RaiseLocalEvent(uid, ref ev);
|
||||||
|
|
||||||
if (appearanceQuery.TryComp(uid, out var appearance))
|
if (_appearanceQuery.TryComp(uid, out var appearance))
|
||||||
_appearance.SetData(uid, PowerDeviceVisuals.Powered, powered, appearance);
|
_appearance.SetData(uid, PowerDeviceVisuals.Powered, powered, appearance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdatePowerConsumer()
|
private void UpdatePowerConsumer()
|
||||||
{
|
{
|
||||||
var metaQuery = GetEntityQuery<MetaDataComponent>();
|
var enumerator = EntityQueryEnumerator<PowerConsumerComponent>();
|
||||||
var enumerator = AllEntityQuery<PowerConsumerComponent>();
|
|
||||||
while (enumerator.MoveNext(out var uid, out var consumer))
|
while (enumerator.MoveNext(out var uid, out var consumer))
|
||||||
{
|
{
|
||||||
var newRecv = consumer.NetworkLoad.ReceivingPower;
|
var newRecv = consumer.NetworkLoad.ReceivingPower;
|
||||||
@@ -388,9 +397,6 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
if (MathHelper.CloseToPercent(lastRecv, newRecv))
|
if (MathHelper.CloseToPercent(lastRecv, newRecv))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (metaQuery.GetComponent(uid).EntityPaused)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
lastRecv = newRecv;
|
lastRecv = newRecv;
|
||||||
var msg = new PowerConsumerReceivedChanged(newRecv, consumer.DrawRate);
|
var msg = new PowerConsumerReceivedChanged(newRecv, consumer.DrawRate);
|
||||||
RaiseLocalEvent(uid, ref msg);
|
RaiseLocalEvent(uid, ref msg);
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
using Content.Server.Power.EntitySystems;
|
|
||||||
using Content.Shared.Power.EntitySystems;
|
using Content.Shared.Power.EntitySystems;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
namespace Content.Server.Power.Components;
|
namespace Content.Shared.Power.Components;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attached to APC powered entities that possess a rechargeable internal battery.
|
/// Attached to APC powered entities that possess a rechargeable internal battery.
|
||||||
/// If external power is interrupted, the entity will draw power from this battery instead.
|
/// If external power is interrupted, the entity will draw power from this battery instead.
|
||||||
/// Requires <see cref="ApcPowerReceiverComponent"/> and <see cref="BatteryComponent"/> to function.
|
/// Requires <see cref="Content.Server.Power.Components.ApcPowerReceiverComponent"/> and <see cref="Content.Server.Power.Components.BatteryComponent"/> to function.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||||
[Access([typeof(PowerNetSystem), typeof(SharedPowerReceiverSystem)])]
|
[Access(typeof(SharedPowerNetSystem), typeof(SharedPowerReceiverSystem))]
|
||||||
public sealed partial class ApcPowerReceiverBatteryComponent : Component
|
public sealed partial class ApcPowerReceiverBatteryComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates whether power is currently being drawn from the battery.
|
/// Indicates whether power is currently being drawn from the battery.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField, AutoNetworkedField]
|
||||||
public bool Enabled = false;
|
public bool Enabled = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -24,22 +24,22 @@ public sealed partial class ApcPowerReceiverBatteryComponent : Component
|
|||||||
/// of power is drained from the battery every second.
|
/// of power is drained from the battery every second.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public float IdleLoad { get; set; } = 5f;
|
public float IdleLoad = 5f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines how much battery charge the entity's battery gains
|
/// Determines how much battery charge the entity's battery gains
|
||||||
/// per second when connected to an active APC power network.
|
/// per second when connected to an active APC power network.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public float BatteryRechargeRate { get; set; } = 50f;
|
public float BatteryRechargeRate = 50f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// While the battery is being recharged, the load this entity places on the APC
|
/// While the battery is being recharged, the load this entity places on the APC
|
||||||
/// power network is increased by the <see cref="BatteryRechargeRate"/> multiplied
|
/// power network is increased by the <see cref="BatteryRechargeRate"/> multiplied
|
||||||
/// by this factor.
|
/// by this factor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public float BatteryRechargeEfficiency { get; set; } = 1f;
|
public float BatteryRechargeEfficiency = 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Content.Shared.Power.EntitySystems;
|
||||||
|
|
||||||
|
public abstract class SharedPowerNetSystem : EntitySystem
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user