* Content side new physics structure

* BroadPhase outline done

* But we need to fix WorldAABB

* Fix static pvs AABB

* Fix import

* Rando fixes

* B is for balloon

* Change human mob hitbox to circle

* Decent movement

* Start adding friction to player controller

I think it's the best way to go about it to keep other objects somewhat consistent for physics.

* This baby can fit so many physics bugs in it.

* Slight mob mover optimisations.

* Player mover kinda works okay.

* Beginnings of testbed

* More testbed

* Circlestack bed

* Namespaces

* BB fixes

* Pull WorldAABB

* Joint pulling

* Semi-decent movement I guess.

* Pulling better

* Bullet controller + old movement

* im too dumb for this shit

* Use kinematic mob controller again

It's probably for the best TBH

* Stashed shitcode

* Remove SlipController

* In which movement code is entirely refactored

* Singularity fix

* Fix ApplyLinearImpulse

* MoveRelay fix

* Fix door collisions

* Disable subfloor collisions

Saves on broadphase a fair bit

* Re-implement ClimbController

* Zumzum's pressure

* Laggy item throwing

* Minor atmos change

* Some caching

* Optimise controllers

* Optimise CollideWith to hell and back

* Re-do throwing and tile friction

* Landing too

* Optimise controllers

* Move CCVars and other stuff swept is beautiful

* Cleanup a bunch of controllers

* Fix shooting and high pressure movement controller

* Flashing improvements

* Stuff and things

* Combat collisions

* Combat mode collisions

* Pulling distance joint again

* Cleanup physics interfaces

* More like scuffedularity

* Shit's fucked

* Haha tests go green

* Bigmoneycrab

* Fix dupe pulling

* Zumzum's based fix

* Don't run tile friction for non-predicted bodies

* Experimental pulling improvement

* Everything's a poly now

* Optimise AI region debugging a bit

Could still be better but should improve default performance a LOT

* Mover no updater

* Crazy kinematic body idea

* Good collisions

* KinematicController

* Fix aghost

* Throwing refactor

* Pushing cleanup

* Fix throwing and footstep sounds

* Frametime in ICollideBehavior

* Fix stuff

* Actually fix weightlessness

* Optimise collision behaviors a lot

* Make open lockers still collide with walls

* powwweeerrrrr

* Merge master proper

* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

* Ch ch ch changesss

* SHIP IT

* Fix #if DEBUG

* Fix vaulting and item locker collision

* Fix throwing

* Editing yaml by hand what can go wrong

* on

* Last yaml fixes

* Okay now it's fixed

* Linter

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
Co-authored-by: Vera Aguilera Puerto <zddm@outlook.es>
This commit is contained in:
metalgearsloth
2021-03-08 04:09:59 +11:00
committed by GitHub
parent 217e8c0ba2
commit 4d064abcd7
237 changed files with 3365 additions and 2880 deletions

View File

@@ -0,0 +1,17 @@
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; }
float PushStrength { get; set; }
}
}

View File

@@ -19,17 +19,6 @@ 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>
@@ -40,10 +29,6 @@ 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
@@ -55,6 +40,5 @@ namespace Content.Shared.GameObjects.Components.Movement
void SetVelocityDirection(Direction direction, ushort subTick, bool enabled);
void SetSprinting(ushort subTick, bool walking);
}
}

View File

@@ -5,62 +5,107 @@ 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, ICollideSpecial
public abstract class SharedClimbingComponent : Component, IActionBlocker
{
public sealed override string Name => "Climbing";
public sealed override uint? NetID => ContentNetIDs.CLIMBING;
protected IPhysicsComponent? Body;
protected bool IsOnClimbableThisFrame;
protected bool OwnerIsTransitioning
protected bool IsOnClimbableThisFrame
{
get
{
if (Body != null && Body.TryGetController<ClimbController>(out var controller))
if (Body == null) return false;
foreach (var entity in Body.GetBodiesIntersecting())
{
return controller.IsActive;
if ((entity.CollisionLayer & (int) CollisionGroup.VaultImpassable) != 0) return true;
}
return false;
}
}
public abstract bool IsClimbing { get; set; }
bool IActionBlocker.CanMove() => !OwnerIsTransitioning;
bool IActionBlocker.CanChangeDirection() => !OwnerIsTransitioning;
bool ICollideSpecial.PreventCollide(IPhysBody collided)
[ViewVariables]
protected virtual bool OwnerIsTransitioning
{
if (((CollisionGroup)collided.CollisionLayer).HasFlag(CollisionGroup.VaultImpassable) && collided.Entity.HasComponent<IClimbable>())
get => _ownerIsTransitioning;
set
{
IsOnClimbableThisFrame = true;
return IsClimbing;
if (_ownerIsTransitioning == value) return;
_ownerIsTransitioning = value;
if (Body == null) return;
if (value)
{
Body.BodyType = BodyType.Dynamic;
}
else
{
Body.BodyType = BodyType.KinematicController;
}
}
return false;
}
public override void Initialize()
{
base.Initialize();
private bool _ownerIsTransitioning = false;
Owner.TryGetComponent(out Body);
[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
{
get => _isClimbing;
set
{
if (_isClimbing == value) return;
_isClimbing = value;
ToggleVaultPassable(value);
}
}
protected bool _isClimbing;
// TODO: Layers need a re-work
private void ToggleVaultPassable(bool value)
{
// Hope the mob has one fixture
if (Body == null || Body.Deleted) return;
foreach (var fixture in Body.Fixtures)
{
if (value)
{
fixture.CollisionMask &= ~(int) CollisionGroup.VaultImpassable;
}
else
{
fixture.CollisionMask |= (int) CollisionGroup.VaultImpassable;
}
}
}
[Serializable, NetSerializable]
protected sealed class ClimbModeComponentState : ComponentState
{
public ClimbModeComponentState(bool climbing) : base(ContentNetIDs.CLIMBING)
public ClimbModeComponentState(bool climbing, bool isTransitioning) : base(ContentNetIDs.CLIMBING)
{
Climbing = climbing;
IsTransitioning = isTransitioning;
}
public bool Climbing { get; }
public bool IsTransitioning { get; }
}
}
}

View File

@@ -10,14 +10,12 @@ 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,7 +5,6 @@ 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;
@@ -15,7 +14,9 @@ using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Movement
{
public abstract class SharedPlayerInputMoverComponent : Component, IMoverComponent, ICollideSpecial
[RegisterComponent]
[ComponentReference(typeof(IMoverComponent))]
public class SharedPlayerInputMoverComponent : Component, IMoverComponent
{
// This class has to be able to handle server TPS being lower than client FPS.
// While still having perfectly responsive movement client side.
@@ -39,8 +40,10 @@ namespace Content.Shared.GameObjects.Components.Movement
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
public sealed override string Name => "PlayerInputMover";
public sealed override uint? NetID => ContentNetIDs.PLAYER_INPUT_MOVER;
[ComponentDependency] private readonly MovementSpeedModifierComponent? _movementSpeed = default!;
public override string Name => "PlayerInputMover";
public override uint? NetID => ContentNetIDs.PLAYER_INPUT_MOVER;
private GameTick _lastInputTick;
private ushort _lastInputSubTick;
@@ -49,36 +52,10 @@ namespace Content.Shared.GameObjects.Components.Movement
private MoveButtons _heldMoveButtons = MoveButtons.None;
public float CurrentWalkSpeed
{
get
{
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component))
{
return component.CurrentWalkSpeed;
}
public float CurrentWalkSpeed => _movementSpeed?.CurrentWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
return MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
}
}
public float CurrentSprintSpeed => _movementSpeed?.CurrentSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
public float CurrentSprintSpeed
{
get
{
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component))
{
return component.CurrentSprintSpeed;
}
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>
@@ -131,9 +108,6 @@ 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>
@@ -141,18 +115,12 @@ namespace Content.Shared.GameObjects.Components.Movement
public bool DiagonalMovementEnabled => _configurationManager.GetCVar<bool>(CCVars.GameDiagonalMovement);
/// <inheritdoc />
public override void OnAdd()
public override void Initialize()
{
// 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();
base.Initialize();
Owner.EnsureComponentWarn<PhysicsComponent>();
}
/// <summary>
/// Toggles one of the four cardinal directions. Each of the four directions are
/// composed into a single direction vector, <see cref="VelocityDir"/>. Enabling
@@ -266,12 +234,6 @@ 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

@@ -0,0 +1,123 @@
#nullable enable
using System;
using Content.Shared.GameObjects.Components.Body;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
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;
[DataField("grabRange")]
private float _grabRange = 0.2f;
[DataField("pushStrength")]
private float _pushStrength = 600.0f;
[ViewVariables(VVAccess.ReadWrite)]
public EntityCoordinates LastPosition { get; set; }
/// <summary>
/// Used to keep track of how far we have moved before playing a step sound
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float StepSoundDistance
{
get => _stepSoundDistance;
set
{
if (MathHelper.CloseTo(_stepSoundDistance, value)) return;
_stepSoundDistance = value;
}
}
[ViewVariables(VVAccess.ReadWrite)]
public float GrabRange
{
get => _grabRange;
set
{
if (MathHelper.CloseTo(_grabRange, value)) return;
_grabRange = value;
Dirty();
}
}
[ViewVariables(VVAccess.ReadWrite)]
public float PushStrength
{
get => _pushStrength;
set
{
if (MathHelper.CloseTo(_pushStrength, value)) return;
_pushStrength = value;
Dirty();
}
}
public override void Initialize()
{
base.Initialize();
if (!Owner.HasComponent<IMoverComponent>())
{
Owner.EnsureComponentWarn<SharedPlayerInputMoverComponent>();
}
if (Owner.TryGetComponent(out IPhysBody? body) && body.BodyType != BodyType.KinematicController)
{
Logger.WarningS("mover", $"Attached {nameof(SharedPlayerMobMoverComponent)} to a mob that's BodyType is not KinematicController!'");
}
}
public override ComponentState GetComponentState(ICommonSession session)
{
return new PlayerMobMoverComponentState(_grabRange, _pushStrength);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not PlayerMobMoverComponentState playerMoverState) return;
GrabRange = playerMoverState.GrabRange;
PushStrength = playerMoverState.PushStrength;
}
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 GrabRange;
public float PushStrength;
public PlayerMobMoverComponentState(float grabRange, float pushStrength) : base(ContentNetIDs.PLAYER_MOB_MOVER)
{
GrabRange = grabRange;
PushStrength = pushStrength;
}
}
}
}

View File

@@ -7,13 +7,15 @@ 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.Physics.Collision;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Movement
{
public abstract class SharedSlipperyComponent : Component, ICollideBehavior
public abstract class SharedSlipperyComponent : Component, IStartCollide
{
public sealed override string Name => "Slippery";
@@ -58,14 +60,12 @@ namespace Content.Shared.GameObjects.Components.Movement
[DataField("slippery")]
public virtual bool Slippery { get; set; } = true;
private bool TrySlip(IEntity entity)
private bool TrySlip(IPhysBody ourBody, IPhysBody otherBody)
{
if (!Slippery
|| Owner.IsInContainer()
|| _slipped.Contains(entity.Uid)
|| !entity.TryGetComponent(out SharedStunnableComponent? stun)
|| !entity.TryGetComponent(out IPhysicsComponent? otherBody)
|| !Owner.TryGetComponent(out IPhysicsComponent? body))
|| _slipped.Contains(otherBody.Entity.Uid)
|| !otherBody.Entity.TryGetComponent(out SharedStunnableComponent? stun))
{
return false;
}
@@ -75,26 +75,22 @@ namespace Content.Shared.GameObjects.Components.Movement
return false;
}
var percentage = otherBody.WorldAABB.IntersectPercentage(body.WorldAABB);
var percentage = otherBody.GetWorldAABB().IntersectPercentage(ourBody.GetWorldAABB());
if (percentage < IntersectPercentage)
{
return false;
}
if (!EffectBlockerSystem.CanSlip(entity))
if (!EffectBlockerSystem.CanSlip(otherBody.Entity))
{
return false;
}
if (entity.TryGetComponent(out IPhysicsComponent? physics))
{
var controller = physics.EnsureController<SlipController>();
controller.LinearVelocity = physics.LinearVelocity * LaunchForwardsMultiplier;
}
otherBody.LinearVelocity *= LaunchForwardsMultiplier;
stun.Paralyze(5);
_slipped.Add(entity.Uid);
_slipped.Add(otherBody.Entity.Uid);
OnSlip();
@@ -103,9 +99,9 @@ namespace Content.Shared.GameObjects.Components.Movement
protected virtual void OnSlip() { }
public void CollideWith(IEntity collidedWith)
void IStartCollide.CollideWith(IPhysBody ourBody, IPhysBody otherBody, in Manifold manifold)
{
TrySlip(collidedWith);
TrySlip(ourBody, otherBody);
}
public void Update()
@@ -119,10 +115,10 @@ namespace Content.Shared.GameObjects.Components.Movement
}
var entity = Owner.EntityManager.GetEntity(uid);
var physics = Owner.GetComponent<IPhysicsComponent>();
var otherPhysics = entity.GetComponent<IPhysicsComponent>();
var physics = Owner.GetComponent<IPhysBody>();
var otherPhysics = entity.GetComponent<IPhysBody>();
if (!physics.WorldAABB.Intersects(otherPhysics.WorldAABB))
if (!physics.GetWorldAABB().Intersects(otherPhysics.GetWorldAABB()))
{
_slipped.Remove(uid);
}
@@ -137,12 +133,12 @@ namespace Content.Shared.GameObjects.Components.Movement
physics.Hard = false;
var shape = physics.PhysicsShapes.FirstOrDefault();
var fixtures = physics.Fixtures.FirstOrDefault();
if (shape != null)
if (fixtures != null)
{
shape.CollisionLayer |= (int) CollisionGroup.SmallImpassable;
shape.CollisionMask = (int) CollisionGroup.None;
fixtures.CollisionLayer |= (int) CollisionGroup.SmallImpassable;
fixtures.CollisionMask = (int) CollisionGroup.None;
}
}
}

View File

@@ -0,0 +1,58 @@
#nullable enable
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
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;
}
}
[DataField("modifier")]
private float _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;
}
}
}
}