]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix throwing prediction (#37086)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sat, 3 May 2025 15:17:30 +0000 (01:17 +1000)
committerGitHub <noreply@github.com>
Sat, 3 May 2025 15:17:30 +0000 (17:17 +0200)
* Fix throwing prediction

- Disposals is still janky but I think that's disposals in general not being predicted and the disposals throw not being predicted and short-lived.
- Would need to check RMC.
- Couldn't repro the underlying issues however thrown items don't slip anymore so (and we also don't predict their land / stopping anymore so).

* primary constructor

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Shared/Throwing/LandEvent.cs
Content.Shared/Throwing/ThrowingSystem.cs
Content.Shared/Throwing/ThrownItemSystem.cs

index f1326bb9acb2eacee9ab201f5091c5516bc4eddf..aee995b60909034f21443efa52aa24abe15232d1 100644 (file)
@@ -9,8 +9,6 @@ namespace Content.Shared.Throwing
     /// <summary>
     /// Raised when a thrown entity is no longer moving.
     /// </summary>
-    public sealed class StopThrowEvent : EntityEventArgs
-    {
-        public EntityUid? User;
-    }
+    [ByRefEvent]
+    public record struct StopThrowEvent(EntityUid? User);
 }
index 567c969b0fd7a140bf637b95fdc88b330d963f89..2d01810d8bf48707bbcaa4a45a37eac281ac2da0 100644 (file)
@@ -20,11 +20,6 @@ public sealed class ThrowingSystem : EntitySystem
 {
     public const float ThrowAngularImpulse = 5f;
 
-    /// <summary>
-    /// Speed cap on rotation in case of click-spam.
-    /// </summary>
-    public const float ThrowAngularCap = 3f * MathF.PI;
-
     public const float PushbackDefault = 2f;
 
     public const float FlyTimePercentage = 0.8f;
index 236e91aec6f8e3ed8508d930178083165278b584..3e1a4f18ded5d5d6c1fc7078d4c74da2e0c3b01e 100644 (file)
@@ -4,6 +4,7 @@ using Content.Shared.Database;
 using Content.Shared.Gravity;
 using Content.Shared.Physics;
 using Content.Shared.Movement.Pulling.Events;
+using Robust.Shared.Network;
 using Robust.Shared.Physics;
 using Robust.Shared.Physics.Components;
 using Robust.Shared.Physics.Events;
@@ -17,10 +18,11 @@ namespace Content.Shared.Throwing
     /// </summary>
     public sealed class ThrownItemSystem : EntitySystem
     {
-        [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
         [Dependency] private readonly IGameTiming _gameTiming = default!;
-        [Dependency] private readonly SharedBroadphaseSystem _broadphase = default!;
+        [Dependency] private readonly INetManager _netMan = default!;
+        [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
         [Dependency] private readonly FixtureSystem _fixtures = default!;
+        [Dependency] private readonly SharedBroadphaseSystem _broadphase = default!;
         [Dependency] private readonly SharedPhysicsSystem _physics = default!;
         [Dependency] private readonly SharedGravitySystem _gravity = default!;
 
@@ -108,8 +110,9 @@ namespace Content.Shared.Throwing
                 }
             }
 
-            EntityManager.EventBus.RaiseLocalEvent(uid, new StopThrowEvent { User = thrownItemComponent.Thrower }, true);
-            EntityManager.RemoveComponent<ThrownItemComponent>(uid);
+            var ev = new StopThrowEvent(thrownItemComponent.Thrower);
+            RaiseLocalEvent(uid, ref ev);
+            RemComp<ThrownItemComponent>(uid);
         }
 
         public void LandComponent(EntityUid uid, ThrownItemComponent thrownItem, PhysicsComponent physics, bool playSound)
@@ -145,15 +148,13 @@ namespace Content.Shared.Throwing
         {
             base.Update(frameTime);
 
-            // TODO predicted throwing - remove this check
-            // We don't want to predict landing or stopping, since throwing isn't actually predicted.
-            // If we do, the landing/stop will occur prematurely on the client.
-            if (_gameTiming.InPrediction)
-                return;
-
             var query = EntityQueryEnumerator<ThrownItemComponent, PhysicsComponent>();
             while (query.MoveNext(out var uid, out var thrown, out var physics))
             {
+                // If you remove this check verify slipping for other entities is networked properly.
+                if (_netMan.IsClient && !physics.Predict)
+                    continue;
+
                 if (thrown.LandTime <= _gameTiming.CurTime)
                 {
                     LandComponent(uid, thrown, physics, thrown.PlayLandSound);