]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix throwing asserts (#23562)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sat, 6 Jan 2024 02:38:37 +0000 (13:38 +1100)
committerGitHub <noreply@github.com>
Sat, 6 Jan 2024 02:38:37 +0000 (13:38 +1100)
* Fix throwing bad regencontacts call

Throwing needs throwing out the window but this stops it causing problems with anomalies.

* Bandaid throwing

Content.Shared/Throwing/ThrownItemComponent.cs
Content.Shared/Throwing/ThrownItemSystem.cs

index eb23ba0994d65674acb38b2ef090c9c812921130..c6c9c4a44671fbda55dc78e341f71f2a2b4b1794 100644 (file)
@@ -4,48 +4,51 @@ using Robust.Shared.Timing;
 
 namespace Content.Shared.Throwing
 {
-    [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+    [RegisterComponent, NetworkedComponent]
     public sealed partial class ThrownItemComponent : Component
     {
         /// <summary>
         ///     The entity that threw this entity.
         /// </summary>
-        [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
-        public EntityUid? Thrower { get; set; }
+        [DataField, ViewVariables(VVAccess.ReadWrite)]
+        public EntityUid? Thrower;
 
         /// <summary>
         ///     The <see cref="IGameTiming.CurTime"/> timestamp at which this entity was thrown.
         /// </summary>
-        [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
-        public TimeSpan? ThrownTime { get; set; }
+        [DataField, ViewVariables(VVAccess.ReadWrite)]
+        public TimeSpan? ThrownTime;
 
         /// <summary>
         ///     Compared to <see cref="IGameTiming.CurTime"/> to land this entity, if any.
         /// </summary>
-        [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
-        public TimeSpan? LandTime { get; set; }
+        [DataField, ViewVariables(VVAccess.ReadWrite)]
+        public TimeSpan? LandTime;
 
         /// <summary>
         ///     Whether or not this entity was already landed.
         /// </summary>
-        [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
-        public bool Landed { get; set; }
+        [DataField, ViewVariables(VVAccess.ReadWrite)]
+        public bool Landed;
 
         /// <summary>
         ///     Whether or not to play a sound when the entity lands.
         /// </summary>
-        [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
-        public bool PlayLandSound { get; set; }
+        [DataField, ViewVariables(VVAccess.ReadWrite)]
+        public bool PlayLandSound;
     }
 
     [Serializable, NetSerializable]
     public sealed class ThrownItemComponentState : ComponentState
     {
-        public NetEntity? Thrower { get; }
+        public NetEntity? Thrower;
 
-        public ThrownItemComponentState(NetEntity? thrower)
-        {
-            Thrower = thrower;
-        }
+        public TimeSpan? ThrownTime;
+
+        public TimeSpan? LandTime;
+
+        public bool Landed;
+
+        public bool PlayLandSound;
     }
 }
index ec29bf7ee59045aa8a7f8eb4623c91144b708d6b..9b7ba3ebb05abad7f264c51b80768c205938cb8b 100644 (file)
@@ -4,6 +4,7 @@ using Content.Shared.Database;
 using Content.Shared.Gravity;
 using Content.Shared.Physics;
 using Content.Shared.Physics.Pull;
+using Robust.Shared.GameStates;
 using Robust.Shared.Physics;
 using Robust.Shared.Physics.Components;
 using Robust.Shared.Physics.Events;
@@ -35,9 +36,41 @@ namespace Content.Shared.Throwing
             SubscribeLocalEvent<ThrownItemComponent, PreventCollideEvent>(PreventCollision);
             SubscribeLocalEvent<ThrownItemComponent, ThrownEvent>(ThrowItem);
             SubscribeLocalEvent<ThrownItemComponent, EntityUnpausedEvent>(OnThrownUnpaused);
+            SubscribeLocalEvent<ThrownItemComponent, ComponentGetState>(OnThrownGetState);
+            SubscribeLocalEvent<ThrownItemComponent, ComponentHandleState>(OnThrownHandleState);
+
             SubscribeLocalEvent<PullStartedMessage>(HandlePullStarted);
         }
 
+        private void OnThrownGetState(EntityUid uid, ThrownItemComponent component, ref ComponentGetState args)
+        {
+            // TODO: Throwing needs to handle this properly I just want the bad asserts to stop getting in my way.
+            TryGetNetEntity(component.Thrower, out var nent);
+
+            args.State = new ThrownItemComponentState()
+            {
+                ThrownTime = component.ThrownTime,
+                LandTime = component.LandTime,
+                Thrower = nent,
+                Landed = component.Landed,
+                PlayLandSound = component.PlayLandSound,
+            };
+        }
+
+        private void OnThrownHandleState(EntityUid uid, ThrownItemComponent component, ref ComponentHandleState args)
+        {
+            if (args.Current is not ThrownItemComponentState state)
+                return;
+
+            TryGetEntity(state.Thrower, out var thrower);
+
+            component.ThrownTime = state.ThrownTime;
+            component.LandTime = state.LandTime;
+            component.Thrower = thrower;
+            component.Landed = state.Landed;
+            component.PlayLandSound = state.PlayLandSound;
+        }
+
         private void OnMapInit(EntityUid uid, ThrownItemComponent component, MapInitEvent args)
         {
             component.ThrownTime ??= _gameTiming.CurTime;
@@ -86,7 +119,6 @@ namespace Content.Shared.Throwing
 
         private void OnSleep(EntityUid uid, ThrownItemComponent thrownItem, ref PhysicsSleepEvent @event)
         {
-            @event.Cancelled = true;
             StopThrow(uid, thrownItem);
         }
 
@@ -102,7 +134,9 @@ namespace Content.Shared.Throwing
             if (TryComp<PhysicsComponent>(uid, out var physics))
             {
                 _physics.SetBodyStatus(physics, BodyStatus.OnGround);
-                _broadphase.RegenerateContacts(uid, physics);
+
+                if (physics.Awake)
+                    _broadphase.RegenerateContacts(uid, physics);
             }
 
             if (EntityManager.TryGetComponent(uid, out FixturesComponent? manager))