Optimise mob moverment a little bit (#12136)
This commit is contained in:
@@ -2,7 +2,6 @@ using Content.Shared.CCVar;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
@@ -52,6 +51,7 @@ namespace Content.Shared.Movement.Systems
|
||||
SubscribeLocalEvent<InputMoverComponent, EntParentChangedMessage>(OnInputParentChange);
|
||||
|
||||
_configManager.OnValueChanged(CCVars.CameraRotationLocked, SetCameraRotationLocked, true);
|
||||
_configManager.OnValueChanged(CCVars.GameDiagonalMovement, SetDiagonalMovement, true);
|
||||
}
|
||||
|
||||
private void SetCameraRotationLocked(bool obj)
|
||||
@@ -97,9 +97,12 @@ namespace Content.Shared.Movement.Systems
|
||||
{
|
||||
CommandBinds.Unregister<SharedMoverController>();
|
||||
_configManager.UnsubValueChanged(CCVars.CameraRotationLocked, SetCameraRotationLocked);
|
||||
_configManager.UnsubValueChanged(CCVars.GameDiagonalMovement, SetDiagonalMovement);
|
||||
}
|
||||
|
||||
public bool DiagonalMovementEnabled => _configManager.GetCVar(CCVars.GameDiagonalMovement);
|
||||
public bool DiagonalMovementEnabled { get; private set; }
|
||||
|
||||
private void SetDiagonalMovement(bool value) => DiagonalMovementEnabled = value;
|
||||
|
||||
protected virtual void HandleShuttleInput(EntityUid uid, ShuttleButtons button, ushort subTick, bool state) {}
|
||||
|
||||
@@ -121,6 +124,16 @@ namespace Content.Shared.Movement.Systems
|
||||
Dirty(mover);
|
||||
}
|
||||
|
||||
public Angle GetParentGridAngle(InputMoverComponent mover, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
var rotation = mover.RelativeRotation;
|
||||
|
||||
if (xformQuery.TryGetComponent(mover.RelativeEntity, out var relativeXform))
|
||||
return (_transform.GetWorldRotation(relativeXform, xformQuery) + rotation);
|
||||
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public Angle GetParentGridAngle(InputMoverComponent mover)
|
||||
{
|
||||
var rotation = mover.RelativeRotation;
|
||||
|
||||
@@ -36,8 +36,9 @@ namespace Content.Shared.Movement.Systems
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
[Dependency] private readonly SharedGravitySystem _gravity = default!;
|
||||
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly TagSystem _tags = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly TagSystem _tags = default!;
|
||||
|
||||
private const float StepSoundMoveDistanceRunning = 2;
|
||||
private const float StepSoundMoveDistanceWalking = 1.5f;
|
||||
@@ -231,7 +232,7 @@ namespace Content.Shared.Movement.Systems
|
||||
|
||||
var total = walkDir * walkSpeed + sprintDir * sprintSpeed;
|
||||
|
||||
var parentRotation = GetParentGridAngle(mover);
|
||||
var parentRotation = GetParentGridAngle(mover, xformQuery);
|
||||
var worldTotal = _relativeMovement ? parentRotation.RotateVec(total) : total;
|
||||
|
||||
DebugTools.Assert(MathHelper.CloseToPercent(total.Length, worldTotal.Length));
|
||||
|
||||
Reference in New Issue
Block a user