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,15 +0,0 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Content.Shared.GameObjects.Components.Movement
{
public interface IMobMoverComponent : IComponent
{
EntityCoordinates LastPosition { get; set; }
public float StepSoundDistance { get; set; }
float GrabRange { get; set; }
}
}

View File

@@ -19,6 +19,17 @@ namespace Content.Shared.GameObjects.Components.Movement
/// </summary>
float CurrentSprintSpeed { get; }
/// <summary>
/// The movement speed (m/s) of the entity when it pushes off of a solid object in zero gravity.
/// </summary>
float CurrentPushSpeed { get; }
/// <summary>
/// How far an entity can reach (in meters) to grab hold of a solid object in zero gravity.
/// </summary>
float GrabRange { get; }
/// <summary>
/// Is the entity Sprinting (running)?
/// </summary>
@@ -29,6 +40,10 @@ namespace Content.Shared.GameObjects.Components.Movement
/// </summary>
(Vector2 walking, Vector2 sprinting) VelocityDir { get; }
EntityCoordinates LastPosition { get; set; }
float StepSoundDistance { get; set; }
/// <summary>
/// Toggles one of the four cardinal directions. Each of the four directions are
/// composed into a single direction vector, <see cref="SharedPlayerInputMoverComponent.VelocityDir"/>. Enabling
@@ -40,5 +55,6 @@ namespace Content.Shared.GameObjects.Components.Movement
void SetVelocityDirection(Direction direction, ushort subTick, bool enabled);
void SetSprinting(ushort subTick, bool walking);
}
}

View File

@@ -3,89 +3,64 @@ using System;
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Movement
{
public abstract class SharedClimbingComponent : Component, IActionBlocker
public abstract class SharedClimbingComponent : Component, IActionBlocker, ICollideSpecial
{
public sealed override string Name => "Climbing";
public sealed override uint? NetID => ContentNetIDs.CLIMBING;
protected bool IsOnClimbableThisFrame
protected IPhysicsComponent? Body;
protected bool IsOnClimbableThisFrame;
protected bool OwnerIsTransitioning
{
get
{
if (Body == null) return false;
foreach (var entity in Body.GetBodiesIntersecting())
if (Body != null && Body.TryGetController<ClimbController>(out var controller))
{
if ((entity.CollisionLayer & (int) CollisionGroup.VaultImpassable) != 0) return true;
return controller.IsActive;
}
return false;
}
}
public abstract bool IsClimbing { get; set; }
bool IActionBlocker.CanMove() => !OwnerIsTransitioning;
bool IActionBlocker.CanChangeDirection() => !OwnerIsTransitioning;
[ViewVariables]
protected virtual bool OwnerIsTransitioning { get; set; }
[ComponentDependency] protected PhysicsComponent? Body;
protected TimeSpan StartClimbTime = TimeSpan.Zero;
/// <summary>
/// We'll launch the mob onto the table and give them at least this amount of time to be on it.
/// </summary>
protected const float BufferTime = 0.3f;
public virtual bool IsClimbing
bool ICollideSpecial.PreventCollide(IPhysBody collided)
{
get => _isClimbing;
set
if (((CollisionGroup)collided.CollisionLayer).HasFlag(CollisionGroup.VaultImpassable) && collided.Entity.HasComponent<IClimbable>())
{
if (_isClimbing == value) return;
_isClimbing = value;
ToggleVaultPassable(value);
IsOnClimbableThisFrame = true;
return IsClimbing;
}
return false;
}
protected bool _isClimbing;
// TODO: Layers need a re-work
private void ToggleVaultPassable(bool value)
public override void Initialize()
{
// Hope the mob has one fixture
if (Body == null || Body.Deleted) return;
base.Initialize();
foreach (var fixture in Body.Fixtures)
{
if (value)
{
fixture.CollisionMask &= ~(int) CollisionGroup.VaultImpassable;
}
else
{
fixture.CollisionMask |= (int) CollisionGroup.VaultImpassable;
}
}
Owner.TryGetComponent(out Body);
}
[Serializable, NetSerializable]
protected sealed class ClimbModeComponentState : ComponentState
{
public ClimbModeComponentState(bool climbing, bool isTransitioning) : base(ContentNetIDs.CLIMBING)
public ClimbModeComponentState(bool climbing) : base(ContentNetIDs.CLIMBING)
{
Climbing = climbing;
IsTransitioning = isTransitioning;
}
public bool Climbing { get; }
public bool IsTransitioning { get; }
}
}
}

View File

@@ -10,12 +10,14 @@ namespace Content.Shared.GameObjects.Components.Movement
public class SharedDummyInputMoverComponent : Component, IMoverComponent
{
public override string Name => "DummyInputMover";
public bool IgnorePaused => false;
public float CurrentWalkSpeed => 0f;
public float CurrentSprintSpeed => 0f;
public float CurrentPushSpeed => 0f;
public float GrabRange => 0f;
public bool Sprinting => false;
public (Vector2 walking, Vector2 sprinting) VelocityDir => (Vector2.Zero, Vector2.Zero);
public EntityCoordinates LastPosition { get; set; }
public float StepSoundDistance { get; set; }
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled)
{

View File

@@ -5,6 +5,7 @@ using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Players;
@@ -14,9 +15,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Movement
{
[RegisterComponent]
[ComponentReference(typeof(IMoverComponent))]
public class SharedPlayerInputMoverComponent : Component, IMoverComponent
public abstract class SharedPlayerInputMoverComponent : Component, IMoverComponent, ICollideSpecial
{
// This class has to be able to handle server TPS being lower than client FPS.
// While still having perfectly responsive movement client side.
@@ -40,10 +39,8 @@ namespace Content.Shared.GameObjects.Components.Movement
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[ComponentDependency] private readonly MovementSpeedModifierComponent? _movementSpeed = default!;
public override string Name => "PlayerInputMover";
public override uint? NetID => ContentNetIDs.PLAYER_INPUT_MOVER;
public sealed override string Name => "PlayerInputMover";
public sealed override uint? NetID => ContentNetIDs.PLAYER_INPUT_MOVER;
private GameTick _lastInputTick;
private ushort _lastInputSubTick;
@@ -52,19 +49,36 @@ namespace Content.Shared.GameObjects.Components.Movement
private MoveButtons _heldMoveButtons = MoveButtons.None;
// Don't serialize because it probably shouldn't change and it's a waste.
public bool IgnorePaused
public float CurrentWalkSpeed
{
get => _ignorePaused;
set => _ignorePaused = value;
get
{
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component))
{
return component.CurrentWalkSpeed;
}
return MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
}
}
private bool _ignorePaused;
public float CurrentSprintSpeed
{
get
{
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component))
{
return component.CurrentSprintSpeed;
}
public float CurrentWalkSpeed => _movementSpeed?.CurrentWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
public float CurrentSprintSpeed => _movementSpeed?.CurrentSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
return MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
}
}
[ViewVariables(VVAccess.ReadWrite)]
public float CurrentPushSpeed => 5;
[ViewVariables(VVAccess.ReadWrite)]
public float GrabRange => 0.2f;
public bool Sprinting => !HasFlag(_heldMoveButtons, MoveButtons.Walk);
/// <summary>
@@ -117,24 +131,27 @@ namespace Content.Shared.GameObjects.Components.Movement
}
}
public abstract EntityCoordinates LastPosition { get; set; }
public abstract float StepSoundDistance { get; set; }
/// <summary>
/// Whether or not the player can move diagonally.
/// </summary>
[ViewVariables]
public bool DiagonalMovementEnabled => _configurationManager.GetCVar<bool>(CCVars.GameDiagonalMovement);
public override void ExposeData(ObjectSerializer serializer)
/// <inheritdoc />
public override void OnAdd()
{
base.ExposeData(serializer);
serializer.DataField(ref _ignorePaused, "ignorePaused", false);
// This component requires that the entity has a IPhysicsComponent.
if (!Owner.HasComponent<IPhysicsComponent>())
Logger.Error(
$"[ECS] {Owner.Prototype?.Name} - {nameof(SharedPlayerInputMoverComponent)} requires" +
$" {nameof(IPhysicsComponent)}. ");
base.OnAdd();
}
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
Owner.EnsureComponentWarn<PhysicsComponent>();
}
/// <summary>
/// Toggles one of the four cardinal directions. Each of the four directions are
@@ -249,6 +266,12 @@ namespace Content.Shared.GameObjects.Components.Movement
return vec;
}
bool ICollideSpecial.PreventCollide(IPhysBody collidedWith)
{
// Don't collide with other mobs
return collidedWith.Entity.HasComponent<IBody>();
}
[Serializable, NetSerializable]
private sealed class MoverComponentState : ComponentState
{

View File

@@ -1,100 +0,0 @@
#nullable enable
using System;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Mobs;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Movement
{
/// <summary>
/// The basic player mover with footsteps and grabbing
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(IMobMoverComponent))]
public class SharedPlayerMobMoverComponent : Component, IMobMoverComponent, ICollideSpecial
{
public override string Name => "PlayerMobMover";
public override uint? NetID => ContentNetIDs.PLAYER_MOB_MOVER;
private float _stepSoundDistance;
private float _grabRange;
[ViewVariables(VVAccess.ReadWrite)]
public EntityCoordinates LastPosition { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public float StepSoundDistance
{
get => _stepSoundDistance;
set
{
if (MathHelper.CloseTo(_stepSoundDistance, value)) return;
_stepSoundDistance = value;
Dirty();
}
}
[ViewVariables(VVAccess.ReadWrite)]
public float GrabRange
{
get => _grabRange;
set
{
if (MathHelper.CloseTo(_grabRange, value)) return;
_grabRange = value;
Dirty();
}
}
public override void Initialize()
{
base.Initialize();
if (!Owner.HasComponent<IMoverComponent>())
{
Owner.EnsureComponentWarn<SharedPlayerInputMoverComponent>();
}
}
public override ComponentState GetComponentState(ICommonSession session)
{
return new PlayerMobMoverComponentState(StepSoundDistance, GrabRange);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not PlayerMobMoverComponentState playerMoverState) return;
StepSoundDistance = playerMoverState.StepSoundDistance;
GrabRange = playerMoverState.GrabRange;
}
bool ICollideSpecial.PreventCollide(IPhysBody collidedWith)
{
// Don't collide with other mobs
// unless they have combat mode on
return collidedWith.Entity.HasComponent<IBody>(); /* &&
(!Owner.TryGetComponent(out SharedCombatModeComponent? ownerCombat) || !ownerCombat.IsInCombatMode) &&
(!collidedWith.Entity.TryGetComponent(out SharedCombatModeComponent? otherCombat) || !otherCombat.IsInCombatMode);
*/
}
[Serializable, NetSerializable]
private sealed class PlayerMobMoverComponentState : ComponentState
{
public float StepSoundDistance;
public float GrabRange;
public PlayerMobMoverComponentState(float stepSoundDistance, float grabRange) : base(ContentNetIDs.PLAYER_MOB_MOVER)
{
StepSoundDistance = stepSoundDistance;
GrabRange = grabRange;
}
}
}
}

View File

@@ -3,12 +3,10 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.GameObjects.EntitySystems.EffectBlocker;
using Content.Shared.Physics;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -55,12 +53,14 @@ namespace Content.Shared.GameObjects.Components.Movement
[ViewVariables(VVAccess.ReadWrite)]
public virtual bool Slippery { get; set; }
private bool TrySlip(IPhysBody ourBody, IPhysBody otherBody)
private bool TrySlip(IEntity entity)
{
if (!Slippery
|| Owner.IsInContainer()
|| _slipped.Contains(otherBody.Entity.Uid)
|| !otherBody.Entity.TryGetComponent(out SharedStunnableComponent? stun))
|| _slipped.Contains(entity.Uid)
|| !entity.TryGetComponent(out SharedStunnableComponent? stun)
|| !entity.TryGetComponent(out IPhysicsComponent? otherBody)
|| !Owner.TryGetComponent(out IPhysicsComponent? body))
{
return false;
}
@@ -70,22 +70,26 @@ namespace Content.Shared.GameObjects.Components.Movement
return false;
}
var percentage = otherBody.GetWorldAABB().IntersectPercentage(ourBody.GetWorldAABB());
var percentage = otherBody.WorldAABB.IntersectPercentage(body.WorldAABB);
if (percentage < IntersectPercentage)
{
return false;
}
if (!EffectBlockerSystem.CanSlip(otherBody.Entity))
if (!EffectBlockerSystem.CanSlip(entity))
{
return false;
}
otherBody.LinearVelocity *= LaunchForwardsMultiplier;
if (entity.TryGetComponent(out IPhysicsComponent? physics))
{
var controller = physics.EnsureController<SlipController>();
controller.LinearVelocity = physics.LinearVelocity * LaunchForwardsMultiplier;
}
stun.Paralyze(5);
_slipped.Add(otherBody.Entity.Uid);
_slipped.Add(entity.Uid);
OnSlip();
@@ -94,9 +98,9 @@ namespace Content.Shared.GameObjects.Components.Movement
protected virtual void OnSlip() { }
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
public void CollideWith(IEntity collidedWith)
{
TrySlip(ourBody, otherBody);
TrySlip(collidedWith);
}
public void Update()
@@ -110,10 +114,10 @@ namespace Content.Shared.GameObjects.Components.Movement
}
var entity = Owner.EntityManager.GetEntity(uid);
var physics = Owner.GetComponent<IPhysBody>();
var otherPhysics = entity.GetComponent<IPhysBody>();
var physics = Owner.GetComponent<IPhysicsComponent>();
var otherPhysics = entity.GetComponent<IPhysicsComponent>();
if (!physics.GetWorldAABB().Intersects(otherPhysics.GetWorldAABB()))
if (!physics.WorldAABB.Intersects(otherPhysics.WorldAABB))
{
_slipped.Remove(uid);
}
@@ -128,12 +132,12 @@ namespace Content.Shared.GameObjects.Components.Movement
physics.Hard = false;
var fixtures = physics.Fixtures.FirstOrDefault();
var shape = physics.PhysicsShapes.FirstOrDefault();
if (fixtures != null)
if (shape != null)
{
fixtures.CollisionLayer |= (int) CollisionGroup.SmallImpassable;
fixtures.CollisionMask = (int) CollisionGroup.None;
shape.CollisionLayer |= (int) CollisionGroup.SmallImpassable;
shape.CollisionMask = (int) CollisionGroup.None;
}
}

View File

@@ -1,62 +0,0 @@
#nullable enable
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Movement
{
[RegisterComponent]
public class SharedTileFrictionModifier : Component
{
public override string Name => "TileFrictionModifier";
/// <summary>
/// Multiply the tilefriction cvar by this to get the body's actual tilefriction.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float Modifier
{
get => _modifier;
set
{
if (MathHelper.CloseTo(_modifier, value)) return;
_modifier = value;
}
}
private float _modifier;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(this, x => x.Modifier, "modifier", 1.0f);
}
public override ComponentState GetComponentState(ICommonSession session)
{
return new TileFrictionComponentState(_modifier);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not TileFrictionComponentState tileState) return;
_modifier = tileState.Modifier;
}
[NetSerializable, Serializable]
protected class TileFrictionComponentState : ComponentState
{
public float Modifier;
public TileFrictionComponentState(float modifier) : base(ContentNetIDs.TILE_FRICTION)
{
Modifier = modifier;
}
}
}
}