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:
@@ -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>
|
||||
|
||||
@@ -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]
|
||||
@@ -66,7 +64,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
var worldBounds = collidable.WorldAABB;
|
||||
var mapGrid = _mapManager.GetGrid(Owner.Transform.GridID);
|
||||
|
||||
|
||||
var tiles = mapGrid.GetTilesIntersecting(worldBounds);
|
||||
var amount = _transferAmount / ReagentUnit.New(tiles.Count());
|
||||
foreach (var tile in tiles)
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user