Server EntitySystem cleanup (#1617)

* Server EntitySystem cleanup

I went after low-hanging fruit systems.

* Add / change to internal access modifiers to systems
* Use EntityQuery to get components instead
* Add sealed modifier to systems
* Remove unused imports
* Add jetbrains annotation for unused classes
* Removed some pragmas for dependencies

This should also fix a decent chunk of the server build warnings, at least the ones that matter.

* Also disposals

* Update Content.Server/GameObjects/EntitySystems/GravitySystem.cs

* Fix build

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
metalgearsloth
2020-08-13 22:17:12 +10:00
committed by GitHub
parent f4bf71edfe
commit 619386a04a
36 changed files with 172 additions and 424 deletions

View File

@@ -33,9 +33,6 @@ namespace Content.Server.GameObjects.EntitySystems.AI
{
base.Initialize();
// register entity query
EntityQuery = new TypeEntityQuery(typeof(AiControllerComponent));
var processors = _reflectionManager.GetAllChildren<AiLogicProcessor>();
foreach (var processor in processors)
{
@@ -49,18 +46,16 @@ namespace Content.Server.GameObjects.EntitySystems.AI
/// <inheritdoc />
public override void Update(float frameTime)
{
var entities = EntityManager.GetEntities(EntityQuery);
foreach (var entity in entities)
foreach (var comp in ComponentManager.EntityQuery<AiControllerComponent>())
{
if (_pauseManager.IsEntityPaused(entity))
if (_pauseManager.IsEntityPaused(comp.Owner))
{
continue;
}
var aiComp = entity.GetComponent<AiControllerComponent>();
ProcessorInitialize(aiComp);
ProcessorInitialize(comp);
var processor = aiComp.Processor;
var processor = comp.Processor;
processor.Update(frameTime);
}

View File

@@ -581,7 +581,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
return Vector2.Zero;
}
if (target.TryGetComponent(out IPhysicsComponent physicsComponent))
if (target.TryGetComponent(out ICollidableComponent physicsComponent))
{
var targetDistance = (targetPos.Position - entityPos.Position);
targetPos = targetPos.Offset(physicsComponent.LinearVelocity * targetDistance);
@@ -640,11 +640,12 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
// if we're moving in the same direction then ignore
// So if 2 entities are moving towards each other and both detect a collision they'll both move in the same direction
// i.e. towards the right
if (physicsEntity.TryGetComponent(out IPhysicsComponent physicsComponent) &&
if (physicsEntity.TryGetComponent(out ICollidableComponent physicsComponent) &&
Vector2.Dot(physicsComponent.LinearVelocity, direction) > 0)
{
continue;
}
var centerGrid = physicsEntity.Transform.GridPosition;
// Check how close we are to center of tile and get the inverse; if we're closer this is stronger
var additionalVector = (centerGrid.Position - entityGridCoords.Position);

View File

@@ -1,23 +1,17 @@
using Content.Server.GameObjects.Components.Power.Chargers;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
[UsedImplicitly]
internal class BaseChargerSystem : EntitySystem
internal sealed class BaseChargerSystem : EntitySystem
{
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(BaseCharger));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<BaseCharger>())
{
entity.GetComponent<BaseCharger>().OnUpdate(frameTime);
comp.OnUpdate(frameTime);
}
}
}

View File

@@ -1,31 +1,26 @@
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using JetBrains.Annotations;
using Robust.Server.Interfaces.Timing;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems
{
internal class BatteryDischargerSystem : EntitySystem
[UsedImplicitly]
internal sealed class BatteryDischargerSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IPauseManager _pauseManager;
#pragma warning restore 649
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(BatteryDischargerComponent));
}
[Dependency] private readonly IPauseManager _pauseManager = default!;
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<BatteryDischargerComponent>())
{
if (_pauseManager.IsEntityPaused(entity))
if (_pauseManager.IsEntityPaused(comp.Owner))
{
continue;
}
entity.GetComponent<BatteryDischargerComponent>().Update(frameTime);
comp.Update(frameTime);
}
}
}

View File

@@ -1,31 +1,26 @@
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using JetBrains.Annotations;
using Robust.Server.Interfaces.Timing;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems
{
internal class BatteryStorageSystem : EntitySystem
[UsedImplicitly]
internal sealed class BatteryStorageSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IPauseManager _pauseManager;
#pragma warning restore 649
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(BatteryStorageComponent));
}
[Dependency] private readonly IPauseManager _pauseManager = default!;
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<BatteryStorageComponent>())
{
if (_pauseManager.IsEntityPaused(entity))
if (_pauseManager.IsEntityPaused(comp.Owner))
{
continue;
}
entity.GetComponent<BatteryStorageComponent>().Update(frameTime);
comp.Update(frameTime);
}
}
}

View File

@@ -1,21 +1,16 @@
using Content.Server.GameObjects.Components.Metabolism;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
/// <summary>
/// Triggers metabolism updates for <see cref="BloodstreamComponent"/>
/// Triggers metabolism updates for <see cref="BloodstreamComponent"/>
/// </summary>
[UsedImplicitly]
public class BloodstreamSystem : EntitySystem
internal sealed class BloodstreamSystem : EntitySystem
{
private float _accumulatedFrameTime;
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(BloodstreamComponent));
}
public override void Update(float frameTime)
{
@@ -23,12 +18,11 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
_accumulatedFrameTime += frameTime;
if (_accumulatedFrameTime > 1.0f)
{
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<BloodstreamComponent>())
{
var comp = entity.GetComponent<BloodstreamComponent>();
comp.OnUpdate(_accumulatedFrameTime);
component.OnUpdate(_accumulatedFrameTime);
}
_accumulatedFrameTime = 0.0f;
_accumulatedFrameTime -= 1.0f;
}
}
}

View File

@@ -2,36 +2,25 @@
using Content.Server.GameObjects.EntitySystems.Click;
using JetBrains.Annotations;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class BuckleSystem : EntitySystem
internal sealed class BuckleSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(BuckleComponent));
UpdatesAfter.Add(typeof(InteractionSystem));
UpdatesAfter.Add(typeof(InputSystem));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var buckle in ComponentManager.EntityQuery<BuckleComponent>())
{
if (!entity.TryGetComponent(out BuckleComponent buckle))
{
continue;
}
buckle.Update();
}
}

View File

@@ -1,33 +1,19 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Conveyor;
using Content.Shared.GameObjects.Components.Conveyor;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class ConveyorSystem : EntitySystem
internal sealed class ConveyorSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(ConveyorComponent));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<ConveyorComponent>())
{
if (!entity.TryGetComponent(out ConveyorComponent conveyor))
{
continue;
}
conveyor.Update(frameTime);
comp.Update(frameTime);
}
}
}

View File

@@ -1,25 +1,18 @@
using Content.Server.GameObjects.Components.Disposal;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class DisposableSystem : EntitySystem
internal sealed class DisposableSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(DisposalHolderComponent));
}
public override void Update(float frameTime)
{
foreach (var disposable in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<DisposalHolderComponent>())
{
disposable.GetComponent<DisposalHolderComponent>().Update(frameTime);
comp.Update(frameTime);
}
}
}

View File

@@ -1,25 +1,17 @@
using Content.Server.GameObjects.Components.Disposal;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class DisposalUnitSystem : EntitySystem
internal sealed class DisposalUnitSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(DisposalUnitComponent));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<DisposalUnitComponent>())
{
entity.GetComponent<DisposalUnitComponent>().Update(frameTime);
comp.Update(frameTime);
}
}
}

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Gravity;
@@ -6,9 +5,7 @@ using Content.Server.GameObjects.Components.Mobs;
using JetBrains.Annotations;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
@@ -19,42 +16,34 @@ using Robust.Shared.Random;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
[UsedImplicitly]
public class GravitySystem: EntitySystem
internal sealed class GravitySystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IMapManager _mapManager;
[Dependency] private readonly IPlayerManager _playerManager;
[Dependency] private readonly IRobustRandom _random;
#pragma warning restore 649
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
private const float GravityKick = 100.0f;
private const uint ShakeTimes = 10;
private Dictionary<GridId, uint> _gridsToShake;
private Dictionary<GridId, uint> _gridsToShake = new Dictionary<GridId, uint>();
private float internalTimer = 0.0f;
public override void Initialize()
{
EntityQuery = new TypeEntityQuery<GravityGeneratorComponent>();
_gridsToShake = new Dictionary<GridId, uint>();
}
private float _internalTimer = 0.0f;
public override void Update(float frameTime)
{
internalTimer += frameTime;
_internalTimer += frameTime;
var gridsWithGravity = new List<GridId>();
foreach (var entity in RelevantEntities)
foreach (var generator in ComponentManager.EntityQuery<GravityGeneratorComponent>())
{
var generator = entity.GetComponent<GravityGeneratorComponent>();
if (generator.NeedsUpdate)
{
generator.UpdateState();
}
if (generator.Status == GravityGeneratorStatus.On)
{
gridsWithGravity.Add(entity.Transform.GridID);
gridsWithGravity.Add(generator.Owner.Transform.GridID);
}
}
@@ -71,10 +60,10 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
}
}
if (internalTimer > 0.2f)
if (_internalTimer > 0.2f)
{
ShakeGrids();
internalTimer = 0.0f;
_internalTimer = 0.0f;
}
}

View File

@@ -1,21 +1,16 @@
using Content.Server.GameObjects.Components.Interactable;
using Robust.Shared.GameObjects;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
public class HandHeldLightSystem : EntitySystem
[UsedImplicitly]
internal sealed class HandHeldLightSystem : EntitySystem
{
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(HandheldLightComponent));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<HandheldLightComponent>())
{
var comp = entity.GetComponent<HandheldLightComponent>();
comp.OnUpdate(frameTime);
}
}

View File

@@ -1,30 +1,24 @@
using Content.Server.GameObjects.Components.Nutrition;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
[UsedImplicitly]
public class HungerSystem : EntitySystem
internal sealed class HungerSystem : EntitySystem
{
private float _accumulatedFrameTime;
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(HungerComponent));
}
public override void Update(float frameTime)
{
_accumulatedFrameTime += frameTime;
if (_accumulatedFrameTime > 1.0f)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<HungerComponent>())
{
var comp = entity.GetComponent<HungerComponent>();
comp.OnUpdate(_accumulatedFrameTime);
}
_accumulatedFrameTime = 0.0f;
_accumulatedFrameTime -= 1.0f;
}
}
}

View File

@@ -1,24 +1,19 @@
using Content.Server.GameObjects.Components.Instruments;
using Robust.Shared.GameObjects;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
public class InstrumentSystem : EntitySystem
[UsedImplicitly]
internal sealed class InstrumentSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(InstrumentComponent));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<InstrumentComponent>())
{
entity.GetComponent<InstrumentComponent>().Update(frameTime);
component.Update(frameTime);
}
}
}

View File

@@ -1,21 +1,16 @@
using Content.Server.GameObjects.Components.Research;
using Robust.Shared.GameObjects;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
public class LatheSystem : EntitySystem
[UsedImplicitly]
internal sealed class LatheSystem : EntitySystem
{
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(LatheComponent));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<LatheComponent>())
{
var comp = entity.GetComponent<LatheComponent>();
if (comp.Producing == false && comp.Queue.Count > 0)
{
comp.Produce(comp.Queue.Dequeue());

View File

@@ -1,37 +1,23 @@
using Content.Server.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using System;
using System.Collections.Generic;
using System.Text;
namespace Content.Server.GameObjects.EntitySystems
{
class ListeningSystem : EntitySystem
internal sealed class ListeningSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IMapManager _mapManager;
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(ListeningComponent));
}
[Dependency] private readonly IMapManager _mapManager = default!;
public void PingListeners(IEntity source, GridCoordinates sourcePos, string message)
{
foreach (var listener in RelevantEntities)
foreach (var listener in ComponentManager.EntityQuery<ListeningComponent>())
{
var dist = sourcePos.Distance(_mapManager, listener.Transform.GridPosition);
var dist = sourcePos.Distance(_mapManager, listener.Owner.Transform.GridPosition);
listener.GetComponent<ListeningComponent>()
.PassSpeechData(message, source, dist);
listener.PassSpeechData(message, source, dist);
}
}
}

View File

@@ -1,21 +1,16 @@
using Content.Server.GameObjects.Components.Medical;
using Robust.Shared.GameObjects;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
public class MedicalScannerSystem : EntitySystem
[UsedImplicitly]
internal sealed class MedicalScannerSystem : EntitySystem
{
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(MedicalScannerComponent));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<MedicalScannerComponent>())
{
var comp = entity.GetComponent<MedicalScannerComponent>();
comp.Update(frameTime);
}
}

View File

@@ -1,23 +1,17 @@
using Content.Server.GameObjects.Components.Kitchen;
using Robust.Shared.GameObjects;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
public class MicrowaveSystem : EntitySystem
[UsedImplicitly]
internal sealed class MicrowaveSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(MicrowaveComponent));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<MicrowaveComponent>())
{
var comp = entity.GetComponent<MicrowaveComponent>();
comp.OnUpdate();
}
}

View File

@@ -24,14 +24,12 @@ using Robust.Shared.Players;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class PointingSystem : EntitySystem
internal sealed class PointingSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
#pragma warning restore 649
private static readonly TimeSpan PointDelay = TimeSpan.FromSeconds(0.5f);
@@ -156,8 +154,6 @@ namespace Content.Server.GameObjects.EntitySystems
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
EntityQuery = new TypeEntityQuery(typeof(PointingArrowComponent));
CommandBinds.Builder
.Bind(ContentKeyFunctions.Point, new PointerInputCmdHandler(TryPoint))
.Register<PointingSystem>();
@@ -173,9 +169,9 @@ namespace Content.Server.GameObjects.EntitySystems
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<PointingArrowComponent>())
{
entity.GetComponent<PointingArrowComponent>().Update(frameTime);
component.Update(frameTime);
}
}
}

View File

@@ -1,23 +1,17 @@
using Content.Server.GameObjects.Components.Movement;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
[UsedImplicitly]
public class PortalSystem : EntitySystem
internal sealed class PortalSystem : EntitySystem
{
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(ServerPortalComponent));
}
// TODO: Someone refactor portals
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<ServerPortalComponent>())
{
var comp = entity.GetComponent<ServerPortalComponent>();
comp.OnUpdate();
}
}

View File

@@ -1,37 +1,32 @@
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using System.Collections.Generic;
using JetBrains.Annotations;
using Robust.Shared.IoC;
using Robust.Server.Interfaces.Timing;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
public sealed class ApcSystem : EntitySystem
[UsedImplicitly]
internal sealed class PowerApcSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IPauseManager _pauseManager;
#pragma warning restore 649
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(ApcComponent));
}
[Dependency] private readonly IPauseManager _pauseManager = default!;
public override void Update(float frameTime)
{
var uniqueApcNets = new HashSet<IApcNet>(); //could be improved by maintaining set instead of getting collection every frame
foreach (var entity in RelevantEntities)
foreach (var apc in ComponentManager.EntityQuery<ApcComponent>())
{
if (_pauseManager.IsEntityPaused(entity))
if (_pauseManager.IsEntityPaused(apc.Owner))
{
continue;
}
var apc = entity.GetComponent<ApcComponent>();
uniqueApcNets.Add(apc.Net);
entity.GetComponent<ApcComponent>().Update();
apc.Update();
}
foreach (var apcNet in uniqueApcNets)
{
apcNet.Update(frameTime);

View File

@@ -1,21 +1,18 @@
using Content.Server.GameObjects.Components.Power;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
[UsedImplicitly]
internal class PowerSmesSystem : EntitySystem
{
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(SmesComponent));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<SmesComponent>())
{
entity.GetComponent<SmesComponent>().OnUpdate();
comp.OnUpdate();
}
}
}

View File

@@ -1,16 +1,6 @@
using Content.Server.GameObjects.Components.Power;
using JetBrains.Annotations;
using Content.Shared.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Physics;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.Physics;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using System;
namespace Content.Server.GameObjects.EntitySystems
{
@@ -18,27 +8,22 @@ namespace Content.Server.GameObjects.EntitySystems
/// Responsible for updating solar control consoles.
/// </summary>
[UsedImplicitly]
public class PowerSolarControlConsoleSystem : EntitySystem
internal sealed class PowerSolarControlConsoleSystem : EntitySystem
{
/// <summary>
/// Timer used to avoid updating the UI state every frame (which would be overkill)
/// </summary>
private float UpdateTimer = 0f;
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(SolarControlConsoleComponent));
}
private float _updateTimer;
public override void Update(float frameTime)
{
UpdateTimer += frameTime;
if (UpdateTimer >= 1)
_updateTimer += frameTime;
if (_updateTimer >= 1)
{
UpdateTimer = 0;
foreach (var entity in RelevantEntities)
_updateTimer -= 1;
foreach (var component in ComponentManager.EntityQuery<SolarControlConsoleComponent>())
{
entity.GetComponent<SolarControlConsoleComponent>().UpdateUIState();
component.UpdateUIState();
}
}
}

View File

@@ -1,13 +1,11 @@
using Content.Server.GameObjects.Components.Power;
using JetBrains.Annotations;
using Content.Shared.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Physics;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.Physics;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using System;
@@ -19,12 +17,10 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
/// Responsible for maintaining the solar-panel sun angle and updating <see cref='SolarPanelComponent'/> coverage.
/// </summary>
[UsedImplicitly]
public class PowerSolarSystem : EntitySystem
internal sealed class PowerSolarSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private IGameTiming _gameTiming;
[Dependency] private IRobustRandom _robustRandom;
#pragma warning restore 649
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
/// <summary>
/// The current sun angle.
@@ -75,7 +71,6 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(SolarPanelComponent));
// Initialize the sun to something random
TowardsSun = MathHelper.TwoPi * _robustRandom.NextDouble();
SunAngularVelocity = Angle.FromDegrees(0.1 + ((_robustRandom.NextDouble() - 0.5) * 0.05));
@@ -91,12 +86,11 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
TotalPanelPower = 0;
foreach (var entity in RelevantEntities)
foreach (var panel in ComponentManager.EntityQuery<SolarPanelComponent>())
{
// There's supposed to be rotational logic here, but that implies putting it somewhere.
entity.Transform.WorldRotation = TargetPanelRotation;
panel.Owner.Transform.WorldRotation = TargetPanelRotation;
var panel = entity.GetComponent<SolarPanelComponent>();
if (panel.TimeOfNextCoverageUpdate < _gameTiming.CurTime)
{
// Setup the next coverage check.

View File

@@ -1,6 +1,5 @@
using Content.Server.GameObjects.Components.Projectiles;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
@@ -8,25 +7,17 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
[UsedImplicitly]
internal sealed class ProjectileSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(ProjectileComponent));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<ProjectileComponent>())
{
var component = entity.GetComponent<ProjectileComponent>();
component.TimeLeft -= frameTime;
if (component.TimeLeft <= 0)
{
entity.Delete();
component.Owner.Delete();
}
}
}

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components.Fluids;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems;
@@ -8,12 +9,12 @@ using Robust.Shared.Map;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
public class PuddleSystem : EntitySystem
[UsedImplicitly]
internal sealed class PuddleSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(PuddleComponent));
var mapManager = IoCManager.Resolve<IMapManager>();
mapManager.TileChanged += HandleTileChanged;
}
@@ -28,17 +29,14 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
private void HandleTileChanged(object sender, TileChangedEventArgs eventArgs)
{
// If this gets hammered you could probably queue up all the tile changes every tick but I doubt that would ever happen.
var entities = EntityManager.GetEntities(EntityQuery);
foreach (var entity in entities)
foreach (var (puddle, snapGrid) in ComponentManager.EntityQuery<PuddleComponent, SnapGridComponent>())
{
// If the tile becomes space then delete it (potentially change by design)
if (eventArgs.NewTile.GridIndex == entity.Transform.GridID &&
entity.TryGetComponent(out SnapGridComponent snapGridComponent) &&
snapGridComponent.Position == eventArgs.NewTile.GridIndices &&
if (eventArgs.NewTile.GridIndex == puddle.Owner.Transform.GridID &&
snapGrid.Position == eventArgs.NewTile.GridIndices &&
eventArgs.NewTile.Tile.IsEmpty)
{
entity.Delete();
puddle.Owner.Delete();
break; // Currently it's one puddle per tile, if that changes remove this
}
}

View File

@@ -1,27 +1,13 @@
using Content.Server.GameObjects.Components.Interactable;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Content.Server.GameObjects.EntitySystems
{
class RadioSystem : EntitySystem
internal sealed class RadioSystem : EntitySystem
{
private List<string> _messages;
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(RadioComponent));
_messages = new List<string>();
}
private readonly List<string> _messages = new List<string>();
public void SpreadMessage(IEntity source, string message)
{
@@ -32,10 +18,9 @@ namespace Content.Server.GameObjects.EntitySystems
_messages.Add(message);
foreach (var radioEntity in RelevantEntities)
foreach (var radio in ComponentManager.EntityQuery<RadioComponent>())
{
var radio = radioEntity.GetComponent<RadioComponent>();
if (radioEntity == source || !radio.RadioOn)
if (radio.Owner == source || !radio.RadioOn)
{
continue;
}

View File

@@ -1,25 +1,17 @@
using Content.Server.GameObjects.Components.Recycling;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class RecyclerSystem : EntitySystem
internal sealed class RecyclerSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(RecyclerComponent));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<RecyclerComponent>())
{
entity.GetComponent<RecyclerComponent>().Update(frameTime);
component.Update(frameTime);
}
}
}

View File

@@ -1,25 +1,17 @@
using Content.Server.GameObjects.Components.Pointing;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class RoguePointingSystem : EntitySystem
internal sealed class RoguePointingSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(RoguePointingArrowComponent));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<RoguePointingArrowComponent>())
{
entity.GetComponent<RoguePointingArrowComponent>().Update(frameTime);
component.Update(frameTime);
}
}
}

View File

@@ -1,21 +1,16 @@
using Content.Server.GameObjects.Components.Nutrition;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
/// <summary>
/// Triggers digestion updates on <see cref="StomachComponent"/>
/// Triggers digestion updates on <see cref="StomachComponent"/>
/// </summary>
[UsedImplicitly]
public class StomachSystem : EntitySystem
internal sealed class StomachSystem : EntitySystem
{
private float _accumulatedFrameTime;
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(StomachComponent));
}
public override void Update(float frameTime)
{
@@ -23,12 +18,11 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
_accumulatedFrameTime += frameTime;
if (_accumulatedFrameTime > 1.0f)
{
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<StomachComponent>())
{
var comp = entity.GetComponent<StomachComponent>();
comp.OnUpdate(_accumulatedFrameTime);
component.OnUpdate(_accumulatedFrameTime);
}
_accumulatedFrameTime = 0.0f;
_accumulatedFrameTime -= 1.0f;
}
}
}

View File

@@ -1,16 +1,15 @@
using System.Collections.Generic;
using Content.Server.GameObjects;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.EntitySystems.Click;
using JetBrains.Annotations;
using Robust.Server.GameObjects.EntitySystemMessages;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
class StorageSystem : EntitySystem
[UsedImplicitly]
internal sealed class StorageSystem : EntitySystem
{
private readonly List<IPlayerSession> _sessionCache = new List<IPlayerSession>();
@@ -19,16 +18,14 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
SubscribeLocalEvent<EntRemovedFromContainerMessage>(HandleEntityRemovedFromContainer);
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleEntityInsertedIntoContainer);
EntityQuery = new TypeEntityQuery(typeof(ServerStorageComponent));
}
/// <inheritdoc />
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<ServerStorageComponent>())
{
CheckSubscribedEntities(entity);
CheckSubscribedEntities(component);
}
}
@@ -52,9 +49,8 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
}
}
private void CheckSubscribedEntities(IEntity entity)
private void CheckSubscribedEntities(ServerStorageComponent storageComp)
{
var storageComp = entity.GetComponent<ServerStorageComponent>();
// We have to cache the set of sessions because Unsubscribe modifies the original.
_sessionCache.Clear();
@@ -63,8 +59,8 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
if (_sessionCache.Count == 0)
return;
var storagePos = entity.Transform.WorldPosition;
var storageMap = entity.Transform.MapID;
var storagePos = storageComp.Owner.Transform.WorldPosition;
var storageMap = storageComp.Owner.Transform.MapID;
foreach (var session in _sessionCache)
{

View File

@@ -1,30 +1,21 @@
using System;
using Content.Server.GameObjects.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Maths;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class StressTestMovementSystem : EntitySystem
internal sealed class StressTestMovementSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery<StressTestMovementComponent>();
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var entity in RelevantEntities)
foreach (var stressTest in ComponentManager.EntityQuery<StressTestMovementComponent>())
{
var stressTest = entity.GetComponent<StressTestMovementComponent>();
var transform = entity.Transform;
var transform = stressTest.Owner.Transform;
stressTest.Progress += frameTime;

View File

@@ -1,27 +1,19 @@
using Content.Server.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Mobs;
using Robust.Shared.GameObjects;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
public class StunSystem : EntitySystem
[UsedImplicitly]
internal sealed class StunSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(StunnableComponent));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<StunnableComponent>())
{
entity.GetComponent<StunnableComponent>().Update(frameTime);
component.Update(frameTime);
}
}
}

View File

@@ -1,21 +1,16 @@
using Content.Server.GameObjects;
using Robust.Shared.GameObjects;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
class TemperatureSystem : EntitySystem
[UsedImplicitly]
internal sealed class TemperatureSystem : EntitySystem
{
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(TemperatureComponent));
}
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var comp in ComponentManager.EntityQuery<TemperatureComponent>())
{
var comp = entity.GetComponent<TemperatureComponent>();
comp.OnUpdate(frameTime);
}
}

View File

@@ -1,30 +1,24 @@
using Content.Server.GameObjects.Components.Nutrition;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{
[UsedImplicitly]
public class ThirstSystem : EntitySystem
internal sealed class ThirstSystem : EntitySystem
{
private float _accumulatedFrameTime;
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(ThirstComponent));
}
public override void Update(float frameTime)
{
_accumulatedFrameTime += frameTime;
if (_accumulatedFrameTime > 1.0f)
{
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<ThirstComponent>())
{
var comp = entity.GetComponent<ThirstComponent>();
comp.OnUpdate(_accumulatedFrameTime);
component.OnUpdate(_accumulatedFrameTime);
}
_accumulatedFrameTime = 0.0f;
_accumulatedFrameTime -= 1.0f;
}
}
}

View File

@@ -1,7 +1,6 @@
using Content.Server.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Mobs;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
@@ -9,33 +8,24 @@ using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class TimedOverlayRemovalSystem : EntitySystem
internal sealed class TimedOverlayRemovalSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IGameTiming _gameTiming;
#pragma warning restore 649
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(ServerOverlayEffectsComponent));
}
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var entity in RelevantEntities)
foreach (var component in ComponentManager.EntityQuery<ServerOverlayEffectsComponent>())
{
var effectsComponent = entity.GetComponent<ServerOverlayEffectsComponent>();
foreach (var overlay in effectsComponent.ActiveOverlays.ToArray())
foreach (var overlay in component.ActiveOverlays.ToArray())
{
if (overlay.TryGetOverlayParameter<TimedOverlayParameter>(out var parameter))
{
if (parameter.StartedAt + parameter.Length <= _gameTiming.CurTime.TotalMilliseconds)
{
effectsComponent.RemoveOverlay(overlay);
component.RemoveOverlay(overlay);
}
}
}