WiP movement prediction.

This commit is contained in:
Pieter-Jan Briers
2020-06-24 02:21:20 +02:00
parent 822436bb81
commit da45a52325
48 changed files with 1101 additions and 540 deletions

View File

@@ -0,0 +1,43 @@
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Movement;
using Robust.Shared.GameObjects;
#nullable enable
namespace Content.Client.GameObjects.Components.Mobs
{
[RegisterComponent]
[ComponentReference(typeof(SharedStunnableComponent))]
public class StunnableComponent : SharedStunnableComponent
{
private bool _stunned;
private bool _knockedDown;
private bool _slowedDown;
public override bool Stunned => _stunned;
public override bool KnockedDown => _knockedDown;
public override bool SlowedDown => _slowedDown;
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (!(curState is StunnableComponentState state))
{
return;
}
_stunned = state.Stunned;
_knockedDown = state.KnockedDown;
_slowedDown = state.SlowedDown;
WalkModifierOverride = state.WalkModifierOverride;
RunModifierOverride = state.RunModifierOverride;
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
{
movement.RefreshMovementSpeedModifiers();
}
}
}
}

View File

@@ -0,0 +1,26 @@
using Content.Shared.GameObjects.Components.Movement;
using Robust.Client.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
#nullable enable
namespace Content.Client.GameObjects.Components.Movement
{
[RegisterComponent]
[ComponentReference(typeof(IMoverComponent))]
public class PlayerInputMoverComponent : SharedPlayerInputMoverComponent, IMoverComponent
{
public override GridCoordinates LastPosition { get; set; }
public override float StepSoundDistance { get; set; }
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (IoCManager.Resolve<IPlayerManager>().LocalPlayer!.ControlledEntity == Owner)
{
base.HandleComponentState(curState, nextState);
}
}
}
}

View File

@@ -0,0 +1,30 @@
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Nutrition;
using Robust.Shared.GameObjects;
#nullable enable
namespace Content.Client.GameObjects.Components.Nutrition
{
[RegisterComponent]
public class HungerComponent : SharedHungerComponent
{
private HungerThreshold _currentHungerThreshold;
public override HungerThreshold CurrentHungerThreshold => _currentHungerThreshold;
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (!(curState is HungerComponentState hunger))
{
return;
}
_currentHungerThreshold = hunger.CurrentThreshold;
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
{
movement.RefreshMovementSpeedModifiers();
}
}
}
}

View File

@@ -0,0 +1,30 @@
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Nutrition;
using Robust.Shared.GameObjects;
#nullable enable
namespace Content.Client.GameObjects.Components.Nutrition
{
[RegisterComponent]
public class ThirstComponent : SharedThirstComponent
{
private ThirstThreshold _currentThirstThreshold;
public override ThirstThreshold CurrentThirstThreshold => _currentThirstThreshold;
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (!(curState is ThirstComponentState thirst))
{
return;
}
_currentThirstThreshold = thirst.CurrentThreshold;
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
{
movement.RefreshMovementSpeedModifiers();
}
}
}
}

View File

@@ -0,0 +1,53 @@
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Physics;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Physics;
using Robust.Client.Player;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
#nullable enable
namespace Content.Client.GameObjects.EntitySystems
{
[UsedImplicitly]
public class MoverSystem : SharedMoverSystem
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
public override void Initialize()
{
base.Initialize();
UpdatesBefore.Add(typeof(PhysicsSystem));
}
public override void FrameUpdate(float frameTime)
{
var playerEnt = _playerManager.LocalPlayer?.ControlledEntity;
if (playerEnt == null || !playerEnt.TryGetComponent(out IMoverComponent mover))
{
return;
}
var physics = playerEnt.GetComponent<PhysicsComponent>();
playerEnt.TryGetComponent(out CollidableComponent? collidable);
UpdateKinematics(playerEnt.Transform, mover, physics, collidable);
}
public override void Update(float frameTime)
{
FrameUpdate(frameTime);
}
protected override void SetController(SharedPhysicsComponent physics)
{
((PhysicsComponent)physics).SetController<MoverController>();
}
}
}

View File

@@ -444,7 +444,7 @@ namespace Content.Client.GameObjects.EntitySystems
var func = args.Function;
var funcId = _master._inputManager.NetworkBindMap.KeyFunctionID(args.Function);
var message = new FullInputCmdMessage(_master._gameTiming.CurTick, funcId, BoundKeyState.Down,
var message = new FullInputCmdMessage(_master._gameTiming.CurTick, _master._gameTiming.TickFraction, funcId, BoundKeyState.Down,
_entity.Transform.GridPosition,
args.PointerLocation, _entity.Uid);