Add sprite movement states (#22940)

* Add sprite movement states

Did it for borgs for reference for future implementations.

* Fix

* Fix prediction issue

* review
This commit is contained in:
metalgearsloth
2023-12-25 18:34:21 +11:00
committed by GitHub
parent 721a445bbd
commit 9a40cf81f5
13 changed files with 227 additions and 25 deletions

View File

@@ -1,12 +1,13 @@
using System.Numerics;
using Content.Shared.Movement.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Timing;
namespace Content.Shared.Movement.Components
{
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
[RegisterComponent, NetworkedComponent]
public sealed partial class InputMoverComponent : Component
{
// This class has to be able to handle server TPS being lower than client FPS.
@@ -40,32 +41,30 @@ namespace Content.Shared.Movement.Components
public Vector2 CurTickWalkMovement;
public Vector2 CurTickSprintMovement;
[AutoNetworkedField]
public MoveButtons HeldMoveButtons = MoveButtons.None;
/// <summary>
/// Entity our movement is relative to.
/// </summary>
[AutoNetworkedField]
public EntityUid? RelativeEntity;
/// <summary>
/// Although our movement might be relative to a particular entity we may have an additional relative rotation
/// e.g. if we've snapped to a different cardinal direction
/// </summary>
[ViewVariables, AutoNetworkedField]
[ViewVariables]
public Angle TargetRelativeRotation = Angle.Zero;
/// <summary>
/// The current relative rotation. This will lerp towards the <see cref="TargetRelativeRotation"/>.
/// </summary>
[ViewVariables, AutoNetworkedField]
[ViewVariables]
public Angle RelativeRotation;
/// <summary>
/// If we traverse on / off a grid then set a timer to update our relative inputs.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField]
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan LerpTarget;
@@ -73,7 +72,18 @@ namespace Content.Shared.Movement.Components
public bool Sprinting => (HeldMoveButtons & MoveButtons.Walk) == 0x0;
[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public bool CanMove { get; set; } = true;
[ViewVariables(VVAccess.ReadWrite)]
public bool CanMove = true;
}
[Serializable, NetSerializable]
public sealed class InputMoverComponentState : ComponentState
{
public MoveButtons HeldMoveButtons;
public NetEntity? RelativeEntity;
public Angle TargetRelativeRotation;
public Angle RelativeRotation;
public TimeSpan LerpTarget;
public bool CanMove;
}
}