Converted everything to use collision and physics component interfaces.

This commit is contained in:
Acruid
2020-07-19 00:33:02 -07:00
parent ea94f4a182
commit c9374992a6
29 changed files with 75 additions and 75 deletions

View File

@@ -31,8 +31,8 @@ namespace Content.Client.GameObjects.EntitySystems
return;
}
var physics = playerEnt.GetComponent<PhysicsComponent>();
playerEnt.TryGetComponent(out CollidableComponent? collidable);
var physics = playerEnt.GetComponent<IPhysicsComponent>();
playerEnt.TryGetComponent(out ICollidableComponent? collidable);
physics.Predict = true;
UpdateKinematics(playerEnt.Transform, mover, physics, collidable);
@@ -43,7 +43,7 @@ namespace Content.Client.GameObjects.EntitySystems
FrameUpdate(frameTime);
}
protected override void SetController(PhysicsComponent physics)
protected override void SetController(IPhysicsComponent physics)
{
physics.SetController<MoverController>();
}

View File

@@ -19,7 +19,7 @@ namespace Content.Server.GameObjects.Components
public bool InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!Owner.TryGetComponent(out PhysicsComponent physics)
if (!Owner.TryGetComponent(out IPhysicsComponent physics)
|| !eventArgs.Using.TryGetComponent(out ToolComponent tool))
return false;

View File

@@ -36,7 +36,7 @@ namespace Content.Server.GameObjects
protected const float AutoCloseDelay = 5;
protected float CloseSpeed = AutoCloseDelay;
private CollidableComponent collidableComponent;
private ICollidableComponent _collidableComponent;
private AppearanceComponent _appearance;
private CancellationTokenSource _cancellationTokenSource;
@@ -64,7 +64,7 @@ namespace Content.Server.GameObjects
{
base.Initialize();
collidableComponent = Owner.GetComponent<CollidableComponent>();
_collidableComponent = Owner.GetComponent<ICollidableComponent>();
_appearance = Owner.GetComponent<AppearanceComponent>();
_cancellationTokenSource = new CancellationTokenSource();
}
@@ -72,7 +72,7 @@ namespace Content.Server.GameObjects
public override void OnRemove()
{
_cancellationTokenSource.Cancel();
collidableComponent = null;
_collidableComponent = null;
_appearance = null;
base.OnRemove();
@@ -164,7 +164,7 @@ namespace Content.Server.GameObjects
Timer.Spawn(OpenTimeOne, async () =>
{
collidableComponent.Hard = false;
_collidableComponent.Hard = false;
await Timer.Delay(OpenTimeTwo, _cancellationTokenSource.Token);
@@ -203,7 +203,7 @@ namespace Content.Server.GameObjects
private void CheckCrush()
{
// Check if collides with something
var collidesWith = collidableComponent.GetCollidingEntities(Vector2.Zero, false);
var collidesWith = _collidableComponent.GetCollidingEntities(Vector2.Zero, false);
if (collidesWith.Count() != 0)
{
// Crush
@@ -236,7 +236,7 @@ namespace Content.Server.GameObjects
public bool Close()
{
bool shouldCheckCrush = false;
if (collidableComponent.IsColliding(Vector2.Zero, false))
if (_collidableComponent.IsColliding(Vector2.Zero, false))
{
if (Safety)
return false;
@@ -260,7 +260,7 @@ namespace Content.Server.GameObjects
CheckCrush();
}
collidableComponent.Hard = true;
_collidableComponent.Hard = true;
await Timer.Delay(CloseTimeTwo, _cancellationTokenSource.Token);

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -393,7 +393,7 @@ namespace Content.Server.GameObjects.Components.Fluids
foreach (var entity in _snapGrid.GetInDir(direction))
{
if (entity.TryGetComponent(out CollidableComponent collidable) &&
if (entity.TryGetComponent(out ICollidableComponent collidable) &&
(collidable.CollisionLayer & (int) CollisionGroup.Impassable) != 0)
{
puddle = default;

View File

@@ -568,7 +568,7 @@ namespace Content.Server.GameObjects
Dirty();
if (!message.Entity.TryGetComponent(out PhysicsComponent physics))
if (!message.Entity.TryGetComponent(out IPhysicsComponent physics))
{
return;
}

View File

@@ -136,7 +136,7 @@ namespace Content.Server.GameObjects.Components
public void Fumble()
{
if (Owner.TryGetComponent<PhysicsComponent>(out var physicsComponent))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physicsComponent))
{
physicsComponent.LinearVelocity += RandomOffset();
}

View File

@@ -187,7 +187,7 @@ namespace Content.Server.GameObjects
StandingStateHelper.Down(entity);
if (entity.TryGetComponent(out CollidableComponent collidable))
if (entity.TryGetComponent(out ICollidableComponent collidable))
{
collidable.CanCollide = false;
}
@@ -197,7 +197,7 @@ namespace Content.Server.GameObjects
{
StandingStateHelper.Standing(entity);
if (entity.TryGetComponent(out CollidableComponent collidable))
if (entity.TryGetComponent(out ICollidableComponent collidable))
{
collidable.CanCollide = true;
}

View File

@@ -43,7 +43,7 @@ namespace Content.Server.GameObjects.Components.Movement
base.Initialize();
// This component requires a physics component.
if (!Owner.HasComponent<PhysicsComponent>())
if (!Owner.HasComponent<IPhysicsComponent>())
Owner.AddComponent<PhysicsComponent>();
}

View File

@@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Movement
{
// This will blow up an entity it's attached to
base.OnAdd();
if (Owner.TryGetComponent<CollidableComponent>(out var collide))
if (Owner.TryGetComponent<ICollidableComponent>(out var collide))
{
//collide.IsHardCollidable = false;
}

View File

@@ -114,7 +114,7 @@ namespace Content.Server.GameObjects.Components.Movement
{
// Added this component to avoid stacking portals and causing shenanigans
// TODO: Doesn't do a great job of stopping stacking portals for directed
if (entity.HasComponent<CollidableComponent>() || entity.HasComponent<ServerTeleporterComponent>())
if (entity.HasComponent<ICollidableComponent>() || entity.HasComponent<ServerTeleporterComponent>())
{
return;
}
@@ -159,7 +159,7 @@ namespace Content.Server.GameObjects.Components.Movement
// TODO: Check the user's spot? Upside is no stacking TPs but downside is they can't unstuck themselves from walls.
foreach (var entity in _serverEntityManager.GetEntitiesIntersecting(user.Transform.MapID, target))
{
if (entity.HasComponent<CollidableComponent>() || entity.HasComponent<ServerPortalComponent>())
if (entity.HasComponent<ICollidableComponent>() || entity.HasComponent<ServerPortalComponent>())
{
return false;
}

View File

@@ -55,7 +55,7 @@ namespace Content.Server.GameObjects.Components.Movement
if (_mapManager.TryGetGrid(gridId, out var grid) && _entityManager.TryGetEntity(grid.GridEntityId, out var gridEntity))
{
//TODO: Switch to shuttle component
if (!gridEntity.TryGetComponent(out PhysicsComponent physComp))
if (!gridEntity.TryGetComponent(out IPhysicsComponent physComp))
{
physComp = gridEntity.AddComponent<PhysicsComponent>();
physComp.Mass = 1;

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Timers;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.Throw;
@@ -79,7 +79,7 @@ namespace Content.Server.GameObjects.Components.Movement
|| _slipped.Contains(collidedWith.Uid)
|| !collidedWith.TryGetComponent(out StunnableComponent stun)
|| !collidedWith.TryGetComponent(out ICollidableComponent otherBody)
|| !collidedWith.TryGetComponent(out PhysicsComponent otherPhysics)
|| !collidedWith.TryGetComponent(out IPhysicsComponent otherPhysics)
|| !Owner.TryGetComponent(out ICollidableComponent body))
return;

View File

@@ -38,7 +38,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
/// </summary>
private bool Connectable => !_deleting && Anchored;
private bool Anchored => !Owner.TryGetComponent<PhysicsComponent>(out var physics) || physics.Anchored;
private bool Anchored => !Owner.TryGetComponent<IPhysicsComponent>(out var physics) || physics.Anchored;
/// <summary>
/// Prevents a node from being used by other nodes while midway through removal.
@@ -60,7 +60,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
{
TryAssignGroupIfNeeded();
CombineGroupWithReachable();
if (Owner.TryGetComponent<PhysicsComponent>(out var physics))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
AnchorUpdate();
physics.AnchoredChanged += AnchorUpdate;
@@ -70,9 +70,9 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
public void OnContainerRemove()
{
_deleting = true;
if (Owner.TryGetComponent<PhysicsComponent>(out var physics))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
physics.AnchoredChanged -= AnchorUpdate;
((IPhysicsComponent) physics).AnchoredChanged -= AnchorUpdate;
}
NodeGroup.RemoveNode(this);
}

View File

@@ -45,7 +45,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
/// </summary>
public bool Connectable => Anchored;
private bool Anchored => !Owner.TryGetComponent<PhysicsComponent>(out var physics) || physics.Anchored;
private bool Anchored => !Owner.TryGetComponent<IPhysicsComponent>(out var physics) || physics.Anchored;
[ViewVariables]
public bool NeedsProvider { get; private set; } = true;
@@ -86,18 +86,18 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
{
TryFindAndSetProvider();
}
if (Owner.TryGetComponent<PhysicsComponent>(out var physics))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
AnchorUpdate();
physics.AnchoredChanged += AnchorUpdate;
((IPhysicsComponent) physics).AnchoredChanged += AnchorUpdate;
}
}
public override void OnRemove()
{
if (Owner.TryGetComponent<PhysicsComponent>(out var physics))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
physics.AnchoredChanged -= AnchorUpdate;
((IPhysicsComponent) physics).AnchoredChanged -= AnchorUpdate;
}
_provider.RemoveReceiver(this);
base.OnRemove();

View File

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

View File

@@ -40,7 +40,7 @@ namespace Content.Server.GameObjects.Components
// after impacting the first object.
// For realism this should actually be changed when the velocity of the object is less than a threshold.
// This would allow ricochets off walls, and weird gravity effects from slowing the object.
if (Owner.TryGetComponent(out CollidableComponent body) && body.PhysicsShapes.Count >= 1)
if (Owner.TryGetComponent(out ICollidableComponent body) && body.PhysicsShapes.Count >= 1)
{
_shouldCollide = false;
}
@@ -53,11 +53,11 @@ namespace Content.Server.GameObjects.Components
return;
}
if (Owner.TryGetComponent(out CollidableComponent body) && body.PhysicsShapes.Count >= 1)
if (Owner.TryGetComponent(out ICollidableComponent body) && body.PhysicsShapes.Count >= 1)
{
body.PhysicsShapes[0].CollisionMask &= (int) ~CollisionGroup.ThrownItem;
var physics = Owner.GetComponent<PhysicsComponent>();
var physics = Owner.GetComponent<IPhysicsComponent>();
physics.LinearVelocity = Vector2.Zero;
physics.Status = BodyStatus.OnGround;
body.Status = BodyStatus.OnGround;
@@ -76,7 +76,7 @@ namespace Content.Server.GameObjects.Components
public void StartThrow(Vector2 initialImpulse)
{
var comp = Owner.GetComponent<PhysicsComponent>();
var comp = Owner.GetComponent<IPhysicsComponent>();
comp.Status = BodyStatus.InAir;
comp.Momentum = initialImpulse;
StartStopTimer();

View File

@@ -21,7 +21,7 @@ namespace Content.Server.GameObjects.Components
private void TryRotate(IEntity user, Angle angle)
{
if (Owner.TryGetComponent(out PhysicsComponent physics))
if (Owner.TryGetComponent(out IPhysicsComponent physics))
{
if (physics.Anchored)
{

View File

@@ -347,13 +347,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
projectileAngle = angle;
}
var physicsComponent = projectile.GetComponent<PhysicsComponent>();
var physicsComponent = projectile.GetComponent<IPhysicsComponent>();
physicsComponent.Status = BodyStatus.InAir;
projectile.Transform.GridPosition = Owner.Transform.GridPosition;
var projectileComponent = projectile.GetComponent<ProjectileComponent>();
projectileComponent.IgnoreEntity(shooter);
projectile.GetComponent<PhysicsComponent>().LinearVelocity = projectileAngle.ToVec() * velocity;
projectile.GetComponent<IPhysicsComponent>().LinearVelocity = projectileAngle.ToVec() * velocity;
projectile.Transform.LocalRotation = projectileAngle.Theta;
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Pathfinders;
@@ -148,7 +148,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
var targetNode = _pathfindingSystem.GetNode(targetTile);
var collisionMask = 0;
if (entity.TryGetComponent(out CollidableComponent collidableComponent))
if (entity.TryGetComponent(out ICollidableComponent collidableComponent))
{
collisionMask = collidableComponent.CollisionMask;
}

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.Components.Movement;
using Robust.Shared.GameObjects.Components;
@@ -27,7 +27,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
public static ReachableArgs GetArgs(IEntity entity)
{
var collisionMask = 0;
if (entity.TryGetComponent(out CollidableComponent collidableComponent))
if (entity.TryGetComponent(out ICollidableComponent collidableComponent))
{
collisionMask = collidableComponent.CollisionMask;
}
@@ -38,4 +38,4 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
return new ReachableArgs(visionRadius, access, collisionMask);
}
}
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Access;
@@ -266,10 +266,10 @@ namespace Content.Server.GameObjects.EntitySystems.Pathfinding
return;
}
if (entity.TryGetComponent(out CollidableComponent collidableComponent) &&
if (entity.TryGetComponent(out ICollidableComponent collidableComponent) &&
(PathfindingSystem.TrackedCollisionLayers & collidableComponent.CollisionLayer) != 0)
{
if (entity.TryGetComponent(out PhysicsComponent physicsComponent) && !physicsComponent.Anchored)
if (entity.TryGetComponent(out IPhysicsComponent physicsComponent) && !physicsComponent.Anchored)
{
_physicsLayers.Add(entity.Uid, collidableComponent.CollisionLayer);
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading;
using Content.Server.GameObjects.Components.Access;
@@ -358,7 +358,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
public bool CanTraverse(IEntity entity, PathfindingNode node)
{
if (entity.TryGetComponent(out CollidableComponent collidableComponent) &&
if (entity.TryGetComponent(out ICollidableComponent collidableComponent) &&
(collidableComponent.CollisionMask & node.BlockedCollisionMask) != 0)
{
return false;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -397,7 +397,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
var startTile = gridManager.GetTileRef(entity.Transform.GridPosition);
var endTile = gridManager.GetTileRef(steeringRequest.TargetGrid);
var collisionMask = 0;
if (entity.TryGetComponent(out CollidableComponent collidableComponent))
if (entity.TryGetComponent(out ICollidableComponent collidableComponent))
{
collisionMask = collidableComponent.CollisionMask;
}
@@ -581,7 +581,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
return Vector2.Zero;
}
if (target.TryGetComponent(out PhysicsComponent physicsComponent))
if (target.TryGetComponent(out IPhysicsComponent physicsComponent))
{
var targetDistance = (targetPos.Position - entityPos.Position);
targetPos = targetPos.Offset(physicsComponent.LinearVelocity * targetDistance);
@@ -599,7 +599,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
/// <returns></returns>
private Vector2 CollisionAvoidance(IEntity entity, Vector2 direction, ICollection<EntityUid> ignoredTargets)
{
if (direction == Vector2.Zero || !entity.TryGetComponent(out CollidableComponent collidableComponent))
if (direction == Vector2.Zero || !entity.TryGetComponent(out ICollidableComponent collidableComponent))
{
return Vector2.Zero;
}
@@ -637,7 +637,7 @@ 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 (collisionEntity.TryGetComponent(out PhysicsComponent physicsComponent) &&
if (collisionEntity.TryGetComponent(out IPhysicsComponent physicsComponent) &&
Vector2.Dot(physicsComponent.LinearVelocity, direction) > 0)
{
continue;

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using Content.Server.GameObjects;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Items.Storage;
@@ -66,8 +66,8 @@ namespace Content.Server.GameObjects.EntitySystems
}
var mover = entity.GetComponent<IMoverComponent>();
var physics = entity.GetComponent<PhysicsComponent>();
if (entity.TryGetComponent<CollidableComponent>(out var collider))
var physics = entity.GetComponent<IPhysicsComponent>();
if (entity.TryGetComponent<ICollidableComponent>(out var collider))
{
UpdateKinematics(entity.Transform, mover, physics, collider);
}
@@ -78,7 +78,7 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
protected override void SetController(PhysicsComponent physics)
protected override void SetController(IPhysicsComponent physics)
{
physics.SetController<MoverController>();
}
@@ -98,7 +98,7 @@ namespace Content.Server.GameObjects.EntitySystems
ev.Entity.RemoveComponent<PlayerInputMoverComponent>();
}
if (ev.Entity.TryGetComponent(out PhysicsComponent physics))
if (ev.Entity.TryGetComponent(out IPhysicsComponent physics))
{
(physics.Controller as MoverController)?.StopMoving();
}

View File

@@ -41,7 +41,7 @@ namespace Content.Server.Throw
/// </param>
public static void Throw(IEntity thrownEnt, float throwForce, GridCoordinates targetLoc, GridCoordinates sourceLoc, bool spread = false, IEntity throwSourceEnt = null)
{
if (!thrownEnt.TryGetComponent(out CollidableComponent colComp))
if (!thrownEnt.TryGetComponent(out ICollidableComponent colComp))
return;
var mapManager = IoCManager.Resolve<IMapManager>();
@@ -75,7 +75,7 @@ namespace Content.Server.Throw
throwSourceEnt.Transform.LocalRotation = angle.GetCardinalDir().ToAngle();
}
if (!thrownEnt.TryGetComponent(out PhysicsComponent physComp))
if (!thrownEnt.TryGetComponent(out IPhysicsComponent physComp))
physComp = thrownEnt.AddComponent<PhysicsComponent>();
var timing = IoCManager.Resolve<IGameTiming>();
@@ -85,7 +85,7 @@ namespace Content.Server.Throw
projComp.StartThrow(angle.ToVec() * spd);
if (throwSourceEnt != null && throwSourceEnt.TryGetComponent<PhysicsComponent>(out var physics)
if (throwSourceEnt != null && throwSourceEnt.TryGetComponent<IPhysicsComponent>(out var physics)
&& physics.Controller is 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 PhysicsComponent physicsComponent))
if (thrownEnt.TryGetComponent(out IPhysicsComponent physicsComponent))
{
mass = physicsComponent.Mass;
}

View File

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

View File

@@ -54,8 +54,8 @@ namespace Content.Shared.GameObjects.EntitySystems
base.Shutdown();
}
protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, PhysicsComponent physics,
CollidableComponent? collider = null)
protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, IPhysicsComponent physics,
ICollidableComponent? collider = null)
{
if (physics.Controller == null)
{
@@ -110,10 +110,10 @@ namespace Content.Shared.GameObjects.EntitySystems
}
protected abstract void SetController(PhysicsComponent physics);
protected abstract void SetController(IPhysicsComponent physics);
private bool IsAroundCollider(ITransformComponent transform, IMoverComponent mover,
CollidableComponent collider)
ICollidableComponent collider)
{
foreach (var entity in _entityManager.GetEntitiesInRange(transform.Owner, mover.GrabRange, true))
{
@@ -122,7 +122,7 @@ namespace Content.Shared.GameObjects.EntitySystems
continue; // Don't try to push off of yourself!
}
if (!entity.TryGetComponent<CollidableComponent>(out var otherCollider))
if (!entity.TryGetComponent<ICollidableComponent>(out var otherCollider))
{
continue;
}

View File

@@ -10,7 +10,7 @@ namespace Content.Shared.Physics
public class MoverController : VirtualController
{
private Vector2 _velocity;
private PhysicsComponent _component = null;
private IPhysicsComponent _component = null;
public Vector2 Velocity
{
@@ -18,7 +18,7 @@ namespace Content.Shared.Physics
set => _velocity = value;
}
public override PhysicsComponent ControlledComponent
public override IPhysicsComponent ControlledComponent
{
set => _component = value;
}