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:
@@ -51,7 +51,7 @@ namespace Content.Shared.GameObjects.Components.Disposal
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum State
|
||||
public enum PressureState
|
||||
{
|
||||
Ready,
|
||||
Pressurizing
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user