From 5d220344b229f9c1bf3f7a37a2650647a5667ee2 Mon Sep 17 00:00:00 2001 From: Kill_Me_I_Noobs <118206719+Vonsant@users.noreply.github.com> Date: Sat, 4 May 2024 00:42:54 +0300 Subject: [PATCH 1/4] Update MoverController.cs --- .../Physics/Controllers/MoverController.cs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Content.Server/Physics/Controllers/MoverController.cs b/Content.Server/Physics/Controllers/MoverController.cs index a5dee13158b..f718f77741c 100644 --- a/Content.Server/Physics/Controllers/MoverController.cs +++ b/Content.Server/Physics/Controllers/MoverController.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; using Content.Server.Shuttles.Components; @@ -146,7 +148,48 @@ private void ResetSubtick(PilotComponent component) component.LastInputTick = Timing.CurTick; component.LastInputSubTick = 0; } + + // Corvax start + public override void UpdateBeforeSolve(bool prediction, float frameTime) + { + base.UpdateBeforeSolve(prediction, frameTime); + UpdatePilots(); + HandleShuttleMovement(frameTime); + } + private void UpdatePilots() + { + var activePilotQuery = EntityQueryEnumerator(); + var shuttleQuery = GetEntityQuery(); + var newPilots = new Dictionary)>(); + + while (activePilotQuery.MoveNext(out var uid, out var pilot, out var mover)) + { + if (!IsPilotActive(pilot)) continue; + + var consoleEnt = pilot.Console; + if (!TryComp(consoleEnt, out var xform)) continue; + + var gridId = xform.GridUid; + if (!shuttleQuery.TryGetComponent(gridId, out var shuttleComponent) || !shuttleComponent.Enabled) continue; + + if (!newPilots.TryGetValue(gridId!.Value, out var pilots)) + pilots = (shuttleComponent, new List<(EntityUid, PilotComponent, InputMoverComponent, TransformComponent)>()); + + pilots.Item2.Add((uid, pilot, mover, xform)); + newPilots[gridId.Value] = pilots; + } + + _shuttlePilots = newPilots; + } + + private bool IsPilotActive(PilotComponent pilot) + { + // Determine if the pilot is currently active based on input. + return pilot.HeldButtons != ShuttleButtons.None; + } + // Corvax end + protected override void HandleShuttleInput(EntityUid uid, ShuttleButtons button, ushort subTick, bool state) { if (!TryComp(uid, out var pilot) || pilot.Console == null) From 8f974460a8e5bde7723132aef4476cd530dc33b2 Mon Sep 17 00:00:00 2001 From: Kill_Me_I_Noobs <118206719+Vonsant@users.noreply.github.com> Date: Sat, 4 May 2024 00:50:13 +0300 Subject: [PATCH 2/4] Update MoverController.cs --- .../Physics/Controllers/MoverController.cs | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Content.Server/Physics/Controllers/MoverController.cs b/Content.Server/Physics/Controllers/MoverController.cs index f718f77741c..931f2ebd41b 100644 --- a/Content.Server/Physics/Controllers/MoverController.cs +++ b/Content.Server/Physics/Controllers/MoverController.cs @@ -63,8 +63,12 @@ public override void UpdateBeforeSolve(bool prediction, float frameTime) { base.UpdateBeforeSolve(prediction, frameTime); - var inputQueryEnumerator = AllEntityQuery(); + // Existing code to update pilots and handle shuttle movement + UpdatePilots(); + HandleShuttleMovement(frameTime); + // Existing code to handle mob movement + var inputQueryEnumerator = AllEntityQuery(); while (inputQueryEnumerator.MoveNext(out var uid, out var mover)) { var physicsUid = uid; @@ -95,17 +99,11 @@ public override void UpdateBeforeSolve(bool prediction, float frameTime) continue; } - HandleMobMovement(uid, - mover, - physicsUid, - body, - xformMover, - frameTime); + HandleMobMovement(uid, mover, physicsUid, body, xformMover, frameTime); } - - HandleShuttleMovement(frameTime); } + public (Vector2 Strafe, float Rotation, float Brakes) GetPilotVelocityInput(PilotComponent component) { if (!Timing.InSimulation) @@ -150,13 +148,6 @@ private void ResetSubtick(PilotComponent component) } // Corvax start - public override void UpdateBeforeSolve(bool prediction, float frameTime) - { - base.UpdateBeforeSolve(prediction, frameTime); - UpdatePilots(); - HandleShuttleMovement(frameTime); - } - private void UpdatePilots() { var activePilotQuery = EntityQueryEnumerator(); From db6b829ecbf3d06407cd42bdc1a1fad99c698ad2 Mon Sep 17 00:00:00 2001 From: Kill_Me_I_Noobs <118206719+Vonsant@users.noreply.github.com> Date: Sat, 4 May 2024 01:17:24 +0300 Subject: [PATCH 3/4] Update MoverController.cs --- .../Physics/Controllers/MoverController.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Content.Server/Physics/Controllers/MoverController.cs b/Content.Server/Physics/Controllers/MoverController.cs index 931f2ebd41b..29d92876dda 100644 --- a/Content.Server/Physics/Controllers/MoverController.cs +++ b/Content.Server/Physics/Controllers/MoverController.cs @@ -21,7 +21,7 @@ public sealed class MoverController : SharedMoverController [Dependency] private readonly ThrusterSystem _thruster = default!; [Dependency] private readonly SharedTransformSystem _xformSystem = default!; - private Dictionary)> _shuttlePilots = new(); + private Dictionary)> _shuttlePilots = new(); public override void Initialize() { @@ -152,7 +152,7 @@ private void UpdatePilots() { var activePilotQuery = EntityQueryEnumerator(); var shuttleQuery = GetEntityQuery(); - var newPilots = new Dictionary)>(); + var newPilots = new Dictionary)>(); while (activePilotQuery.MoveNext(out var uid, out var pilot, out var mover)) { @@ -165,7 +165,7 @@ private void UpdatePilots() if (!shuttleQuery.TryGetComponent(gridId, out var shuttleComponent) || !shuttleComponent.Enabled) continue; if (!newPilots.TryGetValue(gridId!.Value, out var pilots)) - pilots = (shuttleComponent, new List<(EntityUid, PilotComponent, InputMoverComponent, TransformComponent)>()); + pilots = (shuttleComponent, new HashSet<(EntityUid, PilotComponent, InputMoverComponent, TransformComponent)>()); pilots.Item2.Add((uid, pilot, mover, xform)); newPilots[gridId.Value] = pilots; @@ -282,15 +282,15 @@ private Vector2 ObtainMaxVel(Vector2 vel, ShuttleComponent shuttle) var horizIndex = vel.X > 0 ? 1 : 3; // east else west var vertIndex = vel.Y > 0 ? 2 : 0; // north else south - var horizComp = vel.X != 0 ? MathF.Pow(Vector2.Dot(vel, new (shuttle.BaseLinearThrust[horizIndex] / shuttle.LinearThrust[horizIndex], 0f)), 2) : 0; - var vertComp = vel.Y != 0 ? MathF.Pow(Vector2.Dot(vel, new (0f, shuttle.BaseLinearThrust[vertIndex] / shuttle.LinearThrust[vertIndex])), 2) : 0; + var horizComp = vel.X != 0 ? MathF.Pow(Vector2.Dot(vel, new Vector2(shuttle.BaseLinearThrust[horizIndex] / shuttle.LinearThrust[horizIndex], 0f)), 2) : 0; + var vertComp = vel.Y != 0 ? MathF.Pow(Vector2.Dot(vel, new Vector2(0f, shuttle.BaseLinearThrust[vertIndex] / shuttle.LinearThrust[vertIndex])), 2) : 0; return shuttle.BaseMaxLinearVelocity * vel * MathF.ReciprocalSqrtEstimate(horizComp + vertComp); } private void HandleShuttleMovement(float frameTime) { - var newPilots = new Dictionary)>(); + var newPilots = new Dictionary)>(); // We just mark off their movement and the shuttle itself does its own movement var activePilotQuery = EntityQueryEnumerator(); From cfec2f975d73080d4ac58e0617d36885e221fc97 Mon Sep 17 00:00:00 2001 From: Kill_Me_I_Noobs <118206719+Vonsant@users.noreply.github.com> Date: Sat, 4 May 2024 01:25:57 +0300 Subject: [PATCH 4/4] Update MoverController.cs --- Content.Server/Physics/Controllers/MoverController.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Content.Server/Physics/Controllers/MoverController.cs b/Content.Server/Physics/Controllers/MoverController.cs index 29d92876dda..0c3ac07f969 100644 --- a/Content.Server/Physics/Controllers/MoverController.cs +++ b/Content.Server/Physics/Controllers/MoverController.cs @@ -295,6 +295,7 @@ private void HandleShuttleMovement(float frameTime) // We just mark off their movement and the shuttle itself does its own movement var activePilotQuery = EntityQueryEnumerator(); var shuttleQuery = GetEntityQuery(); + while (activePilotQuery.MoveNext(out var uid, out var pilot, out var mover)) { var consoleEnt = pilot.Console; @@ -316,7 +317,7 @@ private void HandleShuttleMovement(float frameTime) if (!newPilots.TryGetValue(gridId!.Value, out var pilots)) { - pilots = (shuttleComponent, new List<(EntityUid, PilotComponent, InputMoverComponent, TransformComponent)>()); + pilots = (shuttleComponent, new HashSet<(EntityUid, PilotComponent, InputMoverComponent, TransformComponent)>()); newPilots[gridId.Value] = pilots; }