Set mover velocity via system (#6288)

This commit is contained in:
metalgearsloth
2022-02-02 17:34:25 +11:00
committed by GitHub
parent 0349a854ac
commit 2e5808085d
12 changed files with 44 additions and 47 deletions

View File

@@ -19,9 +19,9 @@ namespace Content.Client.Physics.Controllers
base.UpdateBeforeSolve(prediction, frameTime); base.UpdateBeforeSolve(prediction, frameTime);
if (_playerManager.LocalPlayer?.ControlledEntity is not {Valid: true} player || if (_playerManager.LocalPlayer?.ControlledEntity is not {Valid: true} player ||
!EntityManager.TryGetComponent(player, out IMoverComponent? mover) || !TryComp(player, out IMoverComponent? mover) ||
!EntityManager.TryGetComponent(player, out PhysicsComponent? body) || !TryComp(player, out PhysicsComponent? body) ||
!EntityManager.TryGetComponent(player, out TransformComponent? xform)) !TryComp(player, out TransformComponent? xform))
{ {
return; return;
} }
@@ -37,7 +37,7 @@ namespace Content.Client.Physics.Controllers
// We set joints to predicted given these can affect how our mob moves. // We set joints to predicted given these can affect how our mob moves.
// I would only recommend disabling this if you make pulling not use joints anymore (someday maybe?) // I would only recommend disabling this if you make pulling not use joints anymore (someday maybe?)
if (EntityManager.TryGetComponent(player, out JointComponent? jointComponent)) if (TryComp(player, out JointComponent? jointComponent))
{ {
foreach (var joint in jointComponent.GetJoints) foreach (var joint in jointComponent.GetJoints)
{ {
@@ -47,9 +47,9 @@ namespace Content.Client.Physics.Controllers
} }
// If we're being pulled then we won't predict anything and will receive server lerps so it looks way smoother. // If we're being pulled then we won't predict anything and will receive server lerps so it looks way smoother.
if (EntityManager.TryGetComponent(player, out SharedPullableComponent? pullableComp)) if (TryComp(player, out SharedPullableComponent? pullableComp))
{ {
if (pullableComp.Puller is {Valid: true} puller && EntityManager.TryGetComponent<PhysicsComponent?>(puller, out var pullerBody)) if (pullableComp.Puller is {Valid: true} puller && TryComp<PhysicsComponent?>(puller, out var pullerBody))
{ {
pullerBody.Predict = false; pullerBody.Predict = false;
body.Predict = false; body.Predict = false;
@@ -57,20 +57,20 @@ namespace Content.Client.Physics.Controllers
} }
// If we're pulling a mob then make sure that isn't predicted so it doesn't fuck our velocity up. // If we're pulling a mob then make sure that isn't predicted so it doesn't fuck our velocity up.
if (EntityManager.TryGetComponent(player, out SharedPullerComponent? pullerComp)) if (TryComp(player, out SharedPullerComponent? pullerComp))
{ {
if (pullerComp.Pulling is {Valid: true} pulling && if (pullerComp.Pulling is {Valid: true} pulling &&
EntityManager.HasComponent<MobStateComponent>(pulling) && HasComp<MobStateComponent>(pulling) &&
EntityManager.TryGetComponent(pulling, out PhysicsComponent? pullingBody)) TryComp(pulling, out PhysicsComponent? pullingBody))
{ {
pullingBody.Predict = false; pullingBody.Predict = false;
} }
} }
// Server-side should just be handled on its own so we'll just do this shizznit // Server-side should just be handled on its own so we'll just do this shizznit
if (EntityManager.TryGetComponent(player, out IMobMoverComponent? mobMover)) if (TryComp(player, out IMobMoverComponent? mobMover))
{ {
HandleMobMovement(mover, body, mobMover); HandleMobMovement(mover, body, mobMover, xform);
return; return;
} }

View File

@@ -19,7 +19,7 @@ namespace Content.Server.Audio
if (!EntityManager.TryGetComponent<AmbientSoundComponent>(uid, out var ambientSound)) return; if (!EntityManager.TryGetComponent<AmbientSoundComponent>(uid, out var ambientSound)) return;
if (ambientSound.Enabled == args.Supply) return; if (ambientSound.Enabled == args.Supply) return;
ambientSound.Enabled = args.Supply; ambientSound.Enabled = args.Supply;
ambientSound.Dirty(); Dirty(ambientSound);
} }
private void HandlePowerChange(EntityUid uid, AmbientOnPoweredComponent component, PowerChangedEvent args) private void HandlePowerChange(EntityUid uid, AmbientOnPoweredComponent component, PowerChangedEvent args)
@@ -27,7 +27,7 @@ namespace Content.Server.Audio
if (!EntityManager.TryGetComponent<AmbientSoundComponent>(uid, out var ambientSound)) return; if (!EntityManager.TryGetComponent<AmbientSoundComponent>(uid, out var ambientSound)) return;
if (ambientSound.Enabled == args.Powered) return; if (ambientSound.Enabled == args.Powered) return;
ambientSound.Enabled = args.Powered; ambientSound.Enabled = args.Powered;
ambientSound.Dirty(); Dirty(ambientSound);
} }
} }
} }

View File

@@ -94,7 +94,7 @@ namespace Content.Server.Buckle.Systems
continue; continue;
} }
buckled.ReAttach(strap); buckled.ReAttach(strap);
buckled.Dirty(); Dirty(buckled);
} }
} }

View File

@@ -223,7 +223,8 @@ namespace Content.Server.Cargo
{ {
if (comp.Database == null || comp.Database.Id != id) if (comp.Database == null || comp.Database.Id != id)
continue; continue;
comp.Dirty();
Dirty(comp);
} }
} }
} }

View File

@@ -20,7 +20,7 @@ namespace Content.Server.Chemistry.EntitySystems
private void OnSolutionChange(EntityUid uid, HyposprayComponent component, SolutionChangedEvent args) private void OnSolutionChange(EntityUid uid, HyposprayComponent component, SolutionChangedEvent args)
{ {
component.Dirty(); Dirty(component);
} }
public void OnAfterInteract(EntityUid uid, HyposprayComponent comp, AfterInteractEvent args) public void OnAfterInteract(EntityUid uid, HyposprayComponent comp, AfterInteractEvent args)

View File

@@ -28,7 +28,7 @@ namespace Content.Server.Chemistry.EntitySystems
private void OnSolutionChange(EntityUid uid, InjectorComponent component, SolutionChangedEvent args) private void OnSolutionChange(EntityUid uid, InjectorComponent component, SolutionChangedEvent args)
{ {
component.Dirty(); Dirty(component);
} }
} }
} }

View File

@@ -122,7 +122,7 @@ namespace Content.Server.Cuffs
{ {
cuffable.CanStillInteract = handCount > cuffable.CuffedHandCount; cuffable.CanStillInteract = handCount > cuffable.CuffedHandCount;
cuffable.CuffedStateChanged(); cuffable.CuffedStateChanged();
cuffable.Dirty(); Dirty(cuffable);
} }
} }
} }

View File

@@ -417,7 +417,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
} }
if (count != component.RecentlyEjected.Count) if (count != component.RecentlyEjected.Count)
component.Dirty(); Dirty(component);
return state == SharedDisposalUnitComponent.PressureState.Ready && component.RecentlyEjected.Count == 0; return state == SharedDisposalUnitComponent.PressureState.Ready && component.RecentlyEjected.Count == 0;
} }
@@ -604,7 +604,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
if (!component.RecentlyEjected.Contains(entity)) if (!component.RecentlyEjected.Contains(entity))
component.RecentlyEjected.Add(entity); component.RecentlyEjected.Add(entity);
component.Dirty(); Dirty(component);
HandleStateChange(component, true); HandleStateChange(component, true);
UpdateVisualState(component); UpdateVisualState(component);
} }

View File

@@ -124,7 +124,7 @@ namespace Content.Server.Flash
{ {
flashable.LastFlash = _gameTiming.CurTime; flashable.LastFlash = _gameTiming.CurTime;
flashable.Duration = flashDuration / 1000f; // TODO: Make this sane... flashable.Duration = flashDuration / 1000f; // TODO: Make this sane...
flashable.Dirty(); Dirty(flashable);
_stunSystem.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), true, _stunSystem.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), true,
slowTo, slowTo); slowTo, slowTo);

View File

@@ -49,10 +49,10 @@ namespace Content.Server.Physics.Controllers
base.UpdateBeforeSolve(prediction, frameTime); base.UpdateBeforeSolve(prediction, frameTime);
_excludedMobs.Clear(); _excludedMobs.Clear();
foreach (var (mobMover, mover, physics) in EntityManager.EntityQuery<IMobMoverComponent, IMoverComponent, PhysicsComponent>()) foreach (var (mobMover, mover, physics, xform) in EntityManager.EntityQuery<IMobMoverComponent, IMoverComponent, PhysicsComponent, TransformComponent>())
{ {
_excludedMobs.Add(mover.Owner); _excludedMobs.Add(mover.Owner);
HandleMobMovement(mover, physics, mobMover); HandleMobMovement(mover, physics, mobMover, xform);
} }
HandleShuttleMovement(frameTime); HandleShuttleMovement(frameTime);

View File

@@ -17,7 +17,7 @@ namespace Content.Server.Weapon.Ranged
// Instead of dirtying on hand-select this component should probably by dirtied whenever it needs to be. // Instead of dirtying on hand-select this component should probably by dirtied whenever it needs to be.
// I take no responsibility for this code. It was like this when I got here. // I take no responsibility for this code. It was like this when I got here.
component.Dirty(); Dirty(component);
} }
} }
} }

View File

@@ -23,11 +23,10 @@ namespace Content.Shared.Movement
/// </summary> /// </summary>
public abstract class SharedMoverController : VirtualController public abstract class SharedMoverController : VirtualController
{ {
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
private ActionBlockerSystem _blocker = default!; [Dependency] private ActionBlockerSystem _blocker = default!;
private SharedPhysicsSystem _broadPhaseSystem = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!;
private bool _relativeMovement; private bool _relativeMovement;
@@ -39,8 +38,6 @@ namespace Content.Shared.Movement
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
_broadPhaseSystem = EntitySystem.Get<SharedPhysicsSystem>();
_blocker = EntitySystem.Get<ActionBlockerSystem>();
var configManager = IoCManager.Resolve<IConfigurationManager>(); var configManager = IoCManager.Resolve<IConfigurationManager>();
configManager.OnValueChanged(CCVars.RelativeMovement, SetRelativeMovement, true); configManager.OnValueChanged(CCVars.RelativeMovement, SetRelativeMovement, true);
UpdatesBefore.Add(typeof(SharedTileFrictionController)); UpdatesBefore.Add(typeof(SharedTileFrictionController));
@@ -91,17 +88,17 @@ namespace Content.Shared.Movement
if (worldTotal != Vector2.Zero) if (worldTotal != Vector2.Zero)
transform.WorldRotation = worldTotal.GetDir().ToAngle(); transform.WorldRotation = worldTotal.GetDir().ToAngle();
physicsComponent.LinearVelocity = worldTotal; _physics.SetLinearVelocity(physicsComponent, worldTotal);
} }
/// <summary> /// <summary>
/// Movement while considering actionblockers, weightlessness, etc. /// Movement while considering actionblockers, weightlessness, etc.
/// </summary> /// </summary>
/// <param name="mover"></param> protected void HandleMobMovement(
/// <param name="physicsComponent"></param> IMoverComponent mover,
/// <param name="mobMover"></param> PhysicsComponent physicsComponent,
protected void HandleMobMovement(IMoverComponent mover, PhysicsComponent physicsComponent, IMobMoverComponent mobMover,
IMobMoverComponent mobMover) TransformComponent xform)
{ {
DebugTools.Assert(!UsedMobMovement.ContainsKey(mover.Owner)); DebugTools.Assert(!UsedMobMovement.ContainsKey(mover.Owner));
@@ -112,22 +109,21 @@ namespace Content.Shared.Movement
} }
UsedMobMovement[mover.Owner] = true; UsedMobMovement[mover.Owner] = true;
var transform = EntityManager.GetComponent<TransformComponent>(mover.Owner); var weightless = mover.Owner.IsWeightless(physicsComponent, mapManager: _mapManager, entityManager: EntityManager);
var weightless = mover.Owner.IsWeightless(physicsComponent, mapManager: _mapManager, entityManager: _entityManager);
var (walkDir, sprintDir) = mover.VelocityDir; var (walkDir, sprintDir) = mover.VelocityDir;
// Handle wall-pushes. // Handle wall-pushes.
if (weightless) if (weightless)
{ {
// No gravity: is our entity touching anything? // No gravity: is our entity touching anything?
var touching = IsAroundCollider(_broadPhaseSystem, transform, mobMover, physicsComponent); var touching = IsAroundCollider(_physics, xform, mobMover, physicsComponent);
if (!touching) if (!touching)
{ {
if (transform.GridID != GridId.Invalid) if (xform.GridID != GridId.Invalid)
mover.LastGridAngle = GetParentGridAngle(transform, mover); mover.LastGridAngle = GetParentGridAngle(xform, mover);
transform.WorldRotation = physicsComponent.LinearVelocity.GetDir().ToAngle(); xform.WorldRotation = physicsComponent.LinearVelocity.GetDir().ToAngle();
return; return;
} }
} }
@@ -137,7 +133,7 @@ namespace Content.Shared.Movement
// This is relative to the map / grid we're on. // This is relative to the map / grid we're on.
var total = walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed; var total = walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed;
var parentRotation = GetParentGridAngle(transform, mover); var parentRotation = GetParentGridAngle(xform, mover);
var worldTotal = _relativeMovement ? parentRotation.RotateVec(total) : total; var worldTotal = _relativeMovement ? parentRotation.RotateVec(total) : total;
@@ -146,19 +142,19 @@ namespace Content.Shared.Movement
if (weightless) if (weightless)
worldTotal *= mobMover.WeightlessStrength; worldTotal *= mobMover.WeightlessStrength;
if (transform.GridID != GridId.Invalid) if (xform.GridID != GridId.Invalid)
mover.LastGridAngle = parentRotation; mover.LastGridAngle = parentRotation;
if (worldTotal != Vector2.Zero) if (worldTotal != Vector2.Zero)
{ {
// This should have its event run during island solver soooo // This should have its event run during island solver soooo
transform.DeferUpdates = true; xform.DeferUpdates = true;
transform.WorldRotation = worldTotal.GetDir().ToAngle(); xform.WorldRotation = worldTotal.GetDir().ToAngle();
transform.DeferUpdates = false; xform.DeferUpdates = false;
HandleFootsteps(mover, mobMover); HandleFootsteps(mover, mobMover);
} }
physicsComponent.LinearVelocity = worldTotal; _physics.SetLinearVelocity(physicsComponent, worldTotal);
} }
public bool UseMobMovement(EntityUid uid) public bool UseMobMovement(EntityUid uid)