Cache CanMove (#7480)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Shared.Movement.Components
|
||||
@@ -22,6 +22,12 @@ namespace Content.Shared.Movement.Components
|
||||
/// </summary>
|
||||
bool Sprinting { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Can the entity currently move. Avoids having to raise move-attempt events every time a player moves.
|
||||
/// Note that this value will be overridden by the action blocker system, and shouldn't just be set directly.
|
||||
/// </summary>
|
||||
bool CanMove { get; set; }
|
||||
|
||||
Angle LastGridAngle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Content.Shared.Movement.Components
|
||||
public bool IgnorePaused => false;
|
||||
public float CurrentWalkSpeed => 0f;
|
||||
public float CurrentSprintSpeed => 0f;
|
||||
public bool CanMove { get; set; } = true;
|
||||
|
||||
public Angle LastGridAngle { get => Angle.Zero; set {} }
|
||||
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
using System;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Movement.Components
|
||||
{
|
||||
@@ -63,6 +59,9 @@ namespace Content.Shared.Movement.Components
|
||||
|
||||
public bool Sprinting => !HasFlag(_heldMoveButtons, MoveButtons.Walk);
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool CanMove { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Calculated linear velocity direction of the entity.
|
||||
/// </summary>
|
||||
@@ -124,7 +123,7 @@ namespace Content.Shared.Movement.Components
|
||||
{
|
||||
base.Initialize();
|
||||
Owner.EnsureComponentWarn<PhysicsComponent>();
|
||||
LastGridAngle = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Parent?.WorldRotation ?? new Angle(0);
|
||||
LastGridAngle = _entityManager.GetComponent<TransformComponent>(Owner).Parent?.WorldRotation ?? new Angle(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -200,12 +199,13 @@ namespace Content.Shared.Movement.Components
|
||||
_heldMoveButtons = state.Buttons;
|
||||
_lastInputTick = GameTick.Zero;
|
||||
_lastInputSubTick = 0;
|
||||
CanMove = state.CanMove;
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new MoverComponentState(_heldMoveButtons);
|
||||
return new MoverComponentState(_heldMoveButtons, CanMove);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -244,10 +244,12 @@ namespace Content.Shared.Movement.Components
|
||||
private sealed class MoverComponentState : ComponentState
|
||||
{
|
||||
public MoveButtons Buttons { get; }
|
||||
public readonly bool CanMove;
|
||||
|
||||
public MoverComponentState(MoveButtons buttons)
|
||||
public MoverComponentState(MoveButtons buttons, bool canMove)
|
||||
{
|
||||
Buttons = buttons;
|
||||
CanMove = canMove;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Movement
|
||||
{
|
||||
public sealed class MovementAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
public MovementAttemptEvent(EntityUid uid)
|
||||
{
|
||||
Uid = uid;
|
||||
}
|
||||
|
||||
public EntityUid Uid { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Friction;
|
||||
@@ -27,7 +26,6 @@ namespace Content.Shared.Movement
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly TagSystem _tags = default!;
|
||||
@@ -114,7 +112,7 @@ namespace Content.Shared.Movement
|
||||
{
|
||||
DebugTools.Assert(!UsedMobMovement.ContainsKey(mover.Owner));
|
||||
|
||||
if (!UseMobMovement(physicsComponent))
|
||||
if (!UseMobMovement(mover, physicsComponent))
|
||||
{
|
||||
UsedMobMovement[mover.Owner] = false;
|
||||
return;
|
||||
@@ -184,13 +182,13 @@ namespace Content.Shared.Movement
|
||||
return UsedMobMovement.TryGetValue(uid, out var used) && used;
|
||||
}
|
||||
|
||||
protected bool UseMobMovement(PhysicsComponent body)
|
||||
protected bool UseMobMovement(IMoverComponent mover, PhysicsComponent body)
|
||||
{
|
||||
return body.BodyStatus == BodyStatus.OnGround &&
|
||||
EntityManager.HasComponent<MobStateComponent>(body.Owner) &&
|
||||
return mover.CanMove &&
|
||||
body.BodyStatus == BodyStatus.OnGround &&
|
||||
HasComp<MobStateComponent>(body.Owner) &&
|
||||
// If we're being pulled then don't mess with our velocity.
|
||||
(!EntityManager.TryGetComponent(body.Owner, out SharedPullableComponent? pullable) || !pullable.BeingPulled) &&
|
||||
_blocker.CanMove((body).Owner);
|
||||
(!TryComp(body.Owner, out SharedPullableComponent? pullable) || !pullable.BeingPulled);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
17
Content.Shared/Movement/UpdateCanMoveEvent.cs
Normal file
17
Content.Shared/Movement/UpdateCanMoveEvent.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Content.Shared.Movement.Components;
|
||||
|
||||
namespace Content.Shared.Movement;
|
||||
|
||||
/// <summary>
|
||||
/// Raised whenever <see cref="IMoverComponent.CanMove"/> needs to be updated. Cancel this event to prevent a
|
||||
/// mover from moving.
|
||||
/// </summary>
|
||||
public sealed class UpdateCanMoveEvent : CancellableEntityEventArgs
|
||||
{
|
||||
public UpdateCanMoveEvent(EntityUid uid)
|
||||
{
|
||||
Uid = uid;
|
||||
}
|
||||
|
||||
public EntityUid Uid { get; }
|
||||
}
|
||||
Reference in New Issue
Block a user