Refactor UpdateKinematics() and fix a lot of Content warnings (#1709)

Most warnings were related to EntityQuery and IPhysicsComponent.
Partially fixes #1650 and fixes #1682
This commit is contained in:
Vince
2020-08-16 05:38:35 +02:00
committed by GitHub
parent 8503ab157a
commit b647ad0f42
29 changed files with 65 additions and 151 deletions

View File

@@ -1,25 +1,16 @@
using Content.Client.GameObjects.Components.Mobs;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Client.GameObjects.EntitySystems
{
public sealed class CameraRecoilSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(CameraRecoilComponent));
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
foreach (var entity in RelevantEntities)
foreach (var recoil in EntityManager.ComponentManager.EntityQuery<CameraRecoilComponent>())
{
var recoil = entity.GetComponent<CameraRecoilComponent>();
recoil.FrameUpdate(frameTime);
}
}

View File

@@ -1,6 +1,5 @@
using Content.Client.GameObjects.Components.Instruments;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
@@ -12,12 +11,6 @@ namespace Content.Client.GameObjects.EntitySystems
{
[Dependency] private readonly IGameTiming _gameTiming = default;
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(InstrumentComponent));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
@@ -27,9 +20,9 @@ namespace Content.Client.GameObjects.EntitySystems
return;
}
foreach (var entity in RelevantEntities)
foreach (var instrumentComponent in EntityManager.ComponentManager.EntityQuery<InstrumentComponent>())
{
entity.GetComponent<InstrumentComponent>().Update(frameTime);
instrumentComponent.Update(frameTime);
}
}
}

View File

@@ -1,5 +1,4 @@
using Content.Client.GameObjects.Components.Markers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Client.GameObjects.EntitySystems
@@ -8,13 +7,6 @@ namespace Content.Client.GameObjects.EntitySystems
{
private bool _markersVisible;
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery<MarkerComponent>();
}
public bool MarkersVisible
{
get => _markersVisible;
@@ -27,9 +19,9 @@ namespace Content.Client.GameObjects.EntitySystems
private void UpdateMarkers()
{
foreach (var entity in RelevantEntities)
foreach (var markerComponent in EntityManager.ComponentManager.EntityQuery<MarkerComponent>())
{
entity.GetComponent<MarkerComponent>().UpdateVisibility();
markerComponent.UpdateVisibility();
}
}
}

View File

@@ -1,6 +1,5 @@
using Content.Client.GameObjects.Components.Mobs;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
namespace Content.Client.GameObjects.EntitySystems
@@ -8,20 +7,13 @@ namespace Content.Client.GameObjects.EntitySystems
[UsedImplicitly]
public sealed class MeleeLungeSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
EntityQuery = new TypeEntityQuery<MeleeLungeComponent>();
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
foreach (var entity in RelevantEntities)
foreach (var meleeLungeComponent in EntityManager.ComponentManager.EntityQuery<MeleeLungeComponent>())
{
entity.GetComponent<MeleeLungeComponent>().Update(frameTime);
meleeLungeComponent.Update(frameTime);
}
}
}

View File

@@ -24,16 +24,15 @@ namespace Content.Client.GameObjects.EntitySystems
public override void Initialize()
{
SubscribeNetworkEvent<PlayMeleeWeaponAnimationMessage>(PlayWeaponArc);
EntityQuery = new TypeEntityQuery(typeof(MeleeWeaponArcAnimationComponent));
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
foreach (var entity in RelevantEntities)
foreach (var arcAnimationComponent in EntityManager.ComponentManager.EntityQuery<MeleeWeaponArcAnimationComponent>())
{
entity.GetComponent<MeleeWeaponArcAnimationComponent>().Update(frameTime);
arcAnimationComponent.Update(frameTime);
}
}

View File

@@ -30,11 +30,10 @@ namespace Content.Client.GameObjects.EntitySystems
return;
}
var physics = playerEnt.GetComponent<IPhysicsComponent>();
playerEnt.TryGetComponent(out ICollidableComponent? collidable);
physics.Predict = true;
var collidable = playerEnt.GetComponent<ICollidableComponent>();
collidable.Predict = true;
UpdateKinematics(playerEnt.Transform, mover, physics, collidable);
UpdateKinematics(playerEnt.Transform, mover, collidable);
}
public override void Update(float frameTime)

View File

@@ -1,5 +1,4 @@
using Content.Client.GameObjects.Components.Mobs;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
@@ -12,11 +11,6 @@ namespace Content.Client.GameObjects.EntitySystems
[Dependency] private IGameTiming _gameTiming;
#pragma warning restore 649
public StatusEffectsSystem()
{
EntityQuery = new TypeEntityQuery(typeof(ClientStatusEffectsComponent));
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
@@ -24,9 +18,9 @@ namespace Content.Client.GameObjects.EntitySystems
if (!_gameTiming.IsFirstTimePredicted)
return;
foreach (var entity in RelevantEntities)
foreach (var clientStatusEffectsComponent in EntityManager.ComponentManager.EntityQuery<ClientStatusEffectsComponent>())
{
entity.GetComponent<ClientStatusEffectsComponent>().FrameUpdate(frameTime);
clientStatusEffectsComponent.FrameUpdate(frameTime);
}
}
}

View File

@@ -1,5 +1,4 @@
using Content.Client.Sandbox;
using Robust.Client.Console;
using Robust.Client.Console;
using Robust.Client.Interfaces.Placement;
using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.UserInterface.Controls;
@@ -15,16 +14,12 @@ namespace Content.Client.UserInterface
internal sealed class EscapeMenu : SS14Window
{
private readonly IClientConsole _console;
private readonly ITileDefinitionManager __tileDefinitionManager;
private readonly ITileDefinitionManager _tileDefinitionManager;
private readonly IPlacementManager _placementManager;
private readonly IPrototypeManager _prototypeManager;
private readonly IResourceCache _resourceCache;
private readonly IConfigurationManager _configSystem;
private readonly ILocalizationManager _localizationManager;
#pragma warning disable 649
[Dependency] private readonly ISandboxManager _sandboxManager;
[Dependency] private readonly IClientConGroupController _conGroupController;
#pragma warning restore 649
private BaseButton DisconnectButton;
private BaseButton QuitButton;
@@ -41,7 +36,7 @@ namespace Content.Client.UserInterface
_configSystem = configSystem;
_localizationManager = localizationManager;
_console = console;
__tileDefinitionManager = tileDefinitionManager;
_tileDefinitionManager = tileDefinitionManager;
_placementManager = placementManager;
_prototypeManager = prototypeManager;
_resourceCache = resourceCache;

View File

@@ -28,7 +28,6 @@ namespace Content.Server.GameObjects.Components.Atmos
[RegisterComponent, Serializable]
public class GridAtmosphereComponent : Component, IGridAtmosphereComponent
{
[Robust.Shared.IoC.Dependency] private IGameTiming _gameTiming = default!;
[Robust.Shared.IoC.Dependency] private IMapManager _mapManager = default!;
/// <summary>

View File

@@ -16,9 +16,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
[RegisterComponent]
class VaporComponent : Component, ICollideBehavior
{
#pragma warning disable 649
[Dependency] private readonly IMapManager _mapManager = default!;
#pragma warning enable 649
public override string Name => "Vapor";
[ViewVariables]

View File

@@ -2,8 +2,6 @@
using Content.Shared.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -16,9 +14,6 @@ namespace Content.Server.GameObjects.Components.Construction
[RegisterComponent]
public class ConstructionComponent : Component, IExamine
{
#pragma warning disable 649
[Dependency] private readonly ILocalizationManager _loc;
#pragma warning restore 649
/// <inheritdoc />
public override string Name => "Construction";

View File

@@ -94,7 +94,7 @@ namespace Content.Server.GameObjects.Components.Disposal
collidable.Anchored;
[ViewVariables]
private State State => _pressure >= 1 ? State.Ready : State.Pressurizing;
private PressureState State => _pressure >= 1 ? PressureState.Ready : PressureState.Pressurizing;
[ViewVariables]
private bool Engaged

View File

@@ -668,13 +668,13 @@ namespace Content.Server.GameObjects.Components.GUI
Dirty();
if (!message.Entity.TryGetComponent(out ICollidableComponent physics))
if (!message.Entity.TryGetComponent(out ICollidableComponent collidable))
{
return;
}
// set velocity to zero
physics.Stop();
collidable.Stop();
return;
}
}

View File

@@ -14,7 +14,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
@@ -29,7 +28,6 @@ namespace Content.Server.GameObjects.Components.Items.Storage
public override uint? NetID => ContentNetIDs.ITEM;
#pragma warning disable 649
[Dependency] private readonly IRobustRandom _robustRandom;
[Dependency] private readonly IMapManager _mapManager;
#pragma warning restore 649
@@ -93,7 +91,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
return false;
}
if (Owner.TryGetComponent(out PhysicsComponent physics) &&
if (Owner.TryGetComponent(out CollidableComponent physics) &&
physics.Anchored)
{
return false;

View File

@@ -42,9 +42,9 @@ namespace Content.Server.GameObjects.Components.Movement
{
base.Initialize();
// This component requires a physics component.
if (!Owner.HasComponent<IPhysicsComponent>())
Owner.AddComponent<PhysicsComponent>();
// This component requires a collidable component.
if (!Owner.HasComponent<ICollidableComponent>())
Owner.AddComponent<CollidableComponent>();
}
/// <inheritdoc />

View File

@@ -71,22 +71,15 @@ namespace Content.Server.GameObjects.Components.Movement
_entityManager.TryGetEntity(grid.GridEntityId, out var gridEntity))
{
//TODO: Switch to shuttle component
if (!gridEntity.TryGetComponent(out IPhysicsComponent physComp))
if (!gridEntity.TryGetComponent(out ICollidableComponent collidable))
{
physComp = gridEntity.AddComponent<PhysicsComponent>();
physComp.Mass = 1;
collidable = gridEntity.AddComponent<CollidableComponent>();
collidable.Mass = 1;
collidable.CanCollide = true;
collidable.PhysicsShapes.Add(new PhysShapeGrid(grid));
}
//TODO: Is this always true?
if (!gridEntity.HasComponent<ICollidableComponent>())
{
var collideComp = gridEntity.AddComponent<CollidableComponent>();
collideComp.CanCollide = true;
//collideComp.IsHardCollidable = true;
collideComp.PhysicsShapes.Add(new PhysShapeGrid(grid));
}
var controller = physComp.EnsureController<ShuttleController>();
var controller = collidable.EnsureController<ShuttleController>();
controller.Push(CalcNewVelocity(direction, enabled), CurrentWalkSpeed);
}
}

View File

@@ -92,9 +92,9 @@ namespace Content.Server.GameObjects.Components.Projectiles
}
if (!entity.Deleted && entity.TryGetComponent(out CameraRecoilComponent recoilComponent)
&& Owner.TryGetComponent(out IPhysicsComponent physicsComponent))
&& Owner.TryGetComponent(out ICollidableComponent collidableComponent))
{
var direction = physicsComponent.LinearVelocity.Normalized;
var direction = collidableComponent.LinearVelocity.Normalized;
recoilComponent.Kick(direction);
}
}

View File

@@ -88,7 +88,7 @@ namespace Content.Server.GameObjects.Components.Projectiles
public void StartThrow(Vector2 direction, float speed)
{
var comp = Owner.GetComponent<IPhysicsComponent>();
var comp = Owner.GetComponent<ICollidableComponent>();
comp.Status = BodyStatus.InAir;
var controller = comp.EnsureController<ThrownController>();

View File

@@ -21,9 +21,9 @@ namespace Content.Server.GameObjects.Components.Rotatable
private void TryRotate(IEntity user, Angle angle)
{
if (Owner.TryGetComponent(out IPhysicsComponent physics))
if (Owner.TryGetComponent(out ICollidableComponent collidable))
{
if (physics.Anchored)
if (collidable.Anchored)
{
_notifyManager.PopupMessage(Owner.Transform.GridPosition, user, _localizationManager.GetString("It's stuck."));
return;

View File

@@ -5,7 +5,6 @@ using Content.Server.GameObjects.Components.Damage;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Projectiles;
using Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition;
using Content.Server.Interfaces;
using Content.Shared.Audio;
using Content.Shared.GameObjects.Components.Weapons.Ranged;
using Content.Shared.GameObjects.EntitySystems;
@@ -43,7 +42,6 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
#pragma warning disable 649
[Dependency] private IGameTiming _gameTiming;
[Dependency] private IRobustRandom _robustRandom;
[Dependency] private readonly IServerNotifyManager _notifyManager;
#pragma warning restore 649
public override FireRateSelector FireRateSelector => _fireRateSelector;
@@ -385,15 +383,15 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
projectileAngle = angle;
}
var physicsComponent = projectile.GetComponent<IPhysicsComponent>();
physicsComponent.Status = BodyStatus.InAir;
var collidableComponent = projectile.GetComponent<ICollidableComponent>();
collidableComponent.Status = BodyStatus.InAir;
projectile.Transform.GridPosition = Owner.Transform.GridPosition;
var projectileComponent = projectile.GetComponent<ProjectileComponent>();
projectileComponent.IgnoreEntity(shooter);
projectile
.GetComponent<IPhysicsComponent>()
.GetComponent<ICollidableComponent>()
.EnsureController<BulletController>()
.LinearVelocity = projectileAngle.ToVec() * velocity;

View File

@@ -27,7 +27,6 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
#pragma warning disable 649
[Dependency] private IMapManager _mapManager;
[Dependency] private IEntityManager _entityManager;
[Dependency] private IPauseManager _pauseManager;
#pragma warning restore 649
private PathfindingSystem _pathfindingSystem;

View File

@@ -17,18 +17,14 @@ namespace Content.Server.GameObjects.EntitySystems
[UsedImplicitly]
public class AtmosphereSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPauseManager _pauseManager = default!;
#pragma warning restore 649
public override void Initialize()
{
base.Initialize();
_mapManager.TileChanged += OnTileChanged;
EntityQuery = new MultipleTypeEntityQuery(new List<Type>(){typeof(IGridAtmosphereComponent)});
}
public IGridAtmosphereComponent? GetGridAtmosphere(GridId gridId)
@@ -36,7 +32,7 @@ namespace Content.Server.GameObjects.EntitySystems
// TODO Return space grid atmosphere for invalid grids or grids with no atmos
var grid = _mapManager.GetGrid(gridId);
if (!_entityManager.TryGetEntity(grid.GridEntityId, out var gridEnt)) return null;
if (!EntityManager.TryGetEntity(grid.GridEntityId, out var gridEnt)) return null;
return gridEnt.TryGetComponent(out IGridAtmosphereComponent atmos) ? atmos : null;
}
@@ -45,13 +41,12 @@ namespace Content.Server.GameObjects.EntitySystems
{
base.Update(frameTime);
foreach (var gridEnt in RelevantEntities)
foreach (var (mapGridComponent, gridAtmosphereComponent) in EntityManager.ComponentManager.EntityQuery<IMapGridComponent, IGridAtmosphereComponent>())
{
var grid = gridEnt.GetComponent<IMapGridComponent>();
if (_pauseManager.IsGridPaused(grid.GridIndex))
if (_pauseManager.IsGridPaused(mapGridComponent.GridIndex))
continue;
gridEnt.GetComponent<IGridAtmosphereComponent>().Update(frameTime);
gridAtmosphereComponent.Update(frameTime);
}
}

View File

@@ -58,23 +58,13 @@ namespace Content.Server.GameObjects.EntitySystems
public override void Update(float frameTime)
{
foreach (var entity in RelevantEntities)
foreach (var (moverComponent, collidableComponent) in EntityManager.ComponentManager.EntityQuery<IMoverComponent, ICollidableComponent>())
{
var entity = moverComponent.Owner;
if (_pauseManager.IsEntityPaused(entity))
{
continue;
}
var mover = entity.GetComponent<IMoverComponent>();
var physics = entity.GetComponent<IPhysicsComponent>();
if (entity.TryGetComponent<ICollidableComponent>(out var collider))
{
UpdateKinematics(entity.Transform, mover, physics, collider);
}
else
{
UpdateKinematics(entity.Transform, mover, physics);
}
UpdateKinematics(entity.Transform, moverComponent, collidableComponent);
}
}
@@ -93,7 +83,7 @@ namespace Content.Server.GameObjects.EntitySystems
ev.Entity.RemoveComponent<PlayerInputMoverComponent>();
}
if (ev.Entity.TryGetComponent(out IPhysicsComponent physics) &&
if (ev.Entity.TryGetComponent(out ICollidableComponent physics) &&
physics.TryGetController(out MoverController controller))
{
controller.StopMoving();

View File

@@ -85,7 +85,7 @@ namespace Content.Server.Throw
projComp.StartThrow(angle.ToVec(), spd);
if (throwSourceEnt != null &&
throwSourceEnt.TryGetComponent<IPhysicsComponent>(out var physics) &&
throwSourceEnt.TryGetComponent<ICollidableComponent>(out var physics) &&
physics.TryGetController(out MoverController mover))
{
var physicsMgr = IoCManager.Resolve<IPhysicsManager>();
@@ -136,7 +136,7 @@ namespace Content.Server.Throw
var distance = (targetLoc.ToMapPos(mapManager) - sourceLoc.ToMapPos(mapManager)).Length;
var throwDuration = ThrownItemComponent.DefaultThrowTime;
var mass = 1f;
if (thrownEnt.TryGetComponent(out IPhysicsComponent physicsComponent))
if (thrownEnt.TryGetComponent(out ICollidableComponent physicsComponent))
{
mass = physicsComponent.Mass;
}

View File

@@ -51,7 +51,7 @@ namespace Content.Shared.GameObjects.Components.Disposal
}
[Serializable, NetSerializable]
public enum State
public enum PressureState
{
Ready,
Pressurizing

View File

@@ -142,11 +142,11 @@ namespace Content.Shared.GameObjects.Components.Movement
/// <inheritdoc />
public override void OnAdd()
{
// This component requires that the entity has a PhysicsComponent.
if (!Owner.HasComponent<IPhysicsComponent>())
// This component requires that the entity has a CollidableComponent.
if (!Owner.HasComponent<ICollidableComponent>())
Logger.Error(
$"[ECS] {Owner.Prototype?.Name} - {nameof(SharedPlayerInputMoverComponent)} requires" +
$" {nameof(IPhysicsComponent)}. ");
$" {nameof(ICollidableComponent)}. ");
base.OnAdd();
}

View File

@@ -50,13 +50,12 @@ namespace Content.Shared.GameObjects.Components.Movement
|| _slipped.Contains(entity.Uid)
|| !entity.TryGetComponent(out SharedStunnableComponent stun)
|| !entity.TryGetComponent(out ICollidableComponent otherBody)
|| !entity.TryGetComponent(out IPhysicsComponent otherPhysics)
|| !Owner.TryGetComponent(out ICollidableComponent body))
{
return false;
}
if (otherPhysics.LinearVelocity.Length < RequiredSlipSpeed || stun.KnockedDown)
if (otherBody.LinearVelocity.Length < RequiredSlipSpeed || stun.KnockedDown)
{
return false;
}

View File

@@ -29,8 +29,6 @@ namespace Content.Shared.GameObjects.EntitySystems
{
base.Initialize();
EntityQuery = new TypeEntityQuery(typeof(IMoverComponent));
var moveUpCmdHandler = new MoverDirInputCmdHandler(Direction.North);
var moveLeftCmdHandler = new MoverDirInputCmdHandler(Direction.West);
var moveRightCmdHandler = new MoverDirInputCmdHandler(Direction.East);
@@ -54,18 +52,17 @@ namespace Content.Shared.GameObjects.EntitySystems
base.Shutdown();
}
protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, IPhysicsComponent physics,
ICollidableComponent? collider = null)
protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, ICollidableComponent collidable)
{
physics.EnsureController<MoverController>();
collidable.EnsureController<MoverController>();
var weightless = !transform.Owner.HasComponent<MovementIgnoreGravityComponent>() &&
_physicsManager.IsWeightless(transform.GridPosition);
if (weightless && collider != null)
if (weightless)
{
// No gravity: is our entity touching anything?
var touching = IsAroundCollider(transform, mover, collider);
var touching = IsAroundCollider(transform, mover, collidable);
if (!touching)
{
@@ -78,18 +75,16 @@ namespace Content.Shared.GameObjects.EntitySystems
var combined = walkDir + sprintDir;
if (combined.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless)
{
if (physics.TryGetController(out MoverController controller))
if (collidable.TryGetController(out MoverController controller))
{
controller.StopMoving();
}
}
else
{
//Console.WriteLine($"{IoCManager.Resolve<IGameTiming>().TickStamp}: {combined}");
if (weightless)
{
if (physics.TryGetController(out MoverController controller))
if (collidable.TryGetController(out MoverController controller))
{
controller.Push(combined, mover.CurrentPushSpeed);
}
@@ -99,12 +94,13 @@ namespace Content.Shared.GameObjects.EntitySystems
}
var total = walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed;
//Console.WriteLine($"{walkDir} ({mover.CurrentWalkSpeed}) + {sprintDir} ({mover.CurrentSprintSpeed}): {total}");
{if (physics.TryGetController(out MoverController controller))
{
controller.Move(total, 1);
}}
if (collidable.TryGetController(out MoverController controller))
{
controller.Move(total, 1);
}
}
transform.LocalRotation = total.GetDir().ToAngle();

View File

@@ -18,7 +18,6 @@ namespace Content.Shared.Health.BodySystem.Mechanism
private string _name;
private string _description;
private string _examineMessage;
private string _spritePath;
private string _rsiPath;
private string _rsiState;
private int _durability;