Revert "Physics (#3452)"

This reverts commit 3e64fd56a1.
This commit is contained in:
Pieter-Jan Briers
2021-02-28 18:49:48 +01:00
parent eddec5fcce
commit 1eb0fbd8d0
211 changed files with 2560 additions and 2600 deletions

View File

@@ -1,11 +1,10 @@
#nullable enable
using System.Diagnostics.CodeAnalysis;
using Content.Shared.GameObjects.Components.Mobs.State;
using Content.Shared.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.Physics;
using Content.Shared.Physics.Pull;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
@@ -16,11 +15,11 @@ using Robust.Shared.Players;
namespace Content.Shared.GameObjects.EntitySystems
{
/// <summary>
/// Handles converting inputs into movement.
/// </summary>
public sealed class SharedMoverSystem : EntitySystem
public abstract class SharedMoverSystem : EntitySystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] protected readonly IPhysicsManager PhysicsManager = default!;
public override void Initialize()
{
base.Initialize();
@@ -46,9 +45,109 @@ namespace Content.Shared.GameObjects.EntitySystems
base.Shutdown();
}
//TODO: reorganize this to make more logical sense
protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, IPhysicsComponent physics)
{
physics.EnsureController<MoverController>();
var weightless = transform.Owner.IsWeightless();
if (weightless)
{
// No gravity: is our entity touching anything?
var touching = IsAroundCollider(transform, mover, physics);
if (!touching)
{
transform.LocalRotation = physics.LinearVelocity.GetDir().ToAngle();
return;
}
}
// TODO: movement check.
var (walkDir, sprintDir) = mover.VelocityDir;
var combined = walkDir + sprintDir;
if (combined.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless)
{
if (physics.TryGetController(out MoverController controller))
{
controller.StopMoving();
}
}
else if (ActionBlockerSystem.CanMove(mover.Owner))
{
if (weightless)
{
if (physics.TryGetController(out MoverController controller))
{
controller.Push(combined, mover.CurrentPushSpeed);
}
transform.LocalRotation = physics.LinearVelocity.GetDir().ToAngle();
return;
}
var total = walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed;
{
if (physics.TryGetController(out MoverController controller))
{
controller.Move(total, 1);
}
}
transform.LocalRotation = total.GetDir().ToAngle();
HandleFootsteps(mover);
}
}
protected virtual void HandleFootsteps(IMoverComponent mover)
{
}
private bool IsAroundCollider(ITransformComponent transform, IMoverComponent mover,
IPhysicsComponent collider)
{
foreach (var entity in _entityManager.GetEntitiesInRange(transform.Owner, mover.GrabRange, true))
{
if (entity == transform.Owner)
{
continue; // Don't try to push off of yourself!
}
if (!entity.TryGetComponent<IPhysicsComponent>(out var otherCollider) ||
!otherCollider.CanCollide ||
(collider.CollisionMask & otherCollider.CollisionLayer) == 0)
{
continue;
}
// Don't count pulled entities
if (otherCollider.HasController<PullController>())
{
continue;
}
// TODO: Item check.
var touching = ((collider.CollisionMask & otherCollider.CollisionLayer) != 0x0
|| (otherCollider.CollisionMask & collider.CollisionLayer) != 0x0) // Ensure collision
&& !entity.HasComponent<IItemComponent>(); // This can't be an item
if (touching)
{
return true;
}
}
return false;
}
private static void HandleDirChange(ICommonSession? session, Direction dir, ushort subTick, bool state)
{
if (!TryGetAttachedComponent<SharedPlayerInputMoverComponent>(session, out var moverComp))
if (!TryGetAttachedComponent<IMoverComponent>(session, out var moverComp))
return;
var owner = session?.AttachedEntity;
@@ -59,15 +158,6 @@ namespace Content.Shared.GameObjects.EntitySystems
{
comp.MoveInputPressed(session);
}
// For stuff like "Moving out of locker" or the likes
if (owner.IsInContainer() &&
(!owner.TryGetComponent(out IMobStateComponent? mobState) ||
mobState.IsAlive()))
{
var relayEntityMoveMessage = new RelayMovementEntityMessage(owner);
owner.Transform.Parent!.Owner.SendMessage(owner.Transform, relayEntityMoveMessage);
}
}
moverComp.SetVelocityDirection(dir, subTick, state);