Adds Logging to Joint Add/Clear/Remove (#3695)

This commit is contained in:
Zoldorf
2023-01-15 06:16:53 -07:00
committed by GitHub
parent 35d4a5c255
commit ca3fdcb294

View File

@@ -10,6 +10,7 @@ using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics.Contacts;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Robust.Shared.Physics.Systems;
@@ -18,6 +19,7 @@ public abstract class SharedJointSystem : EntitySystem
{
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
// To avoid issues with component states we'll queue up all dirty joints and check it every tick to see if
// we can delete the component.
@@ -134,7 +136,7 @@ public abstract class SharedJointSystem : EntitySystem
{
if (existing.BodyBUid != bUid)
{
_sawmill.Error($"While adding joint {joint.ID} to {ToPrettyString(bUid)}, the connected entity {ToPrettyString(aUid)} already had a joint with the same ID connected to another entity {ToPrettyString(existing.BodyBUid)}.");
_sawmill.Error($"While adding joint {joint.ID} to entity {ToPrettyString(bUid)}, the connected entity {ToPrettyString(aUid)} already had a joint with the same ID connected to another entity {ToPrettyString(existing.BodyBUid)}.");
return;
}
@@ -148,17 +150,17 @@ public abstract class SharedJointSystem : EntitySystem
return;
}
_sawmill.Error($"While adding joint {joint.ID} to {ToPrettyString(bUid)}, the joint already existed for the connected entity {ToPrettyString(aUid)}.");
_sawmill.Error($"While adding joint {joint.ID} to entity {ToPrettyString(bUid)}, the joint already existed for the connected entity {ToPrettyString(aUid)}.");
}
else if (!ignoreExisting && jointsB.TryGetValue(joint.ID, out existing))
{
if (existing.BodyAUid != aUid)
{
_sawmill.Error($"While adding joint {joint.ID} to {ToPrettyString(aUid)}, the connected entity {ToPrettyString(bUid)} already had a joint with the same ID connected to another entity {ToPrettyString(existing.BodyAUid)}.");
_sawmill.Error($"While adding joint {joint.ID} to entity {ToPrettyString(aUid)}, the connected entity {ToPrettyString(bUid)} already had a joint with the same ID connected to another entity {ToPrettyString(existing.BodyAUid)}.");
return;
}
_sawmill.Error($"While adding joint {joint.ID} to {ToPrettyString(aUid)}, the joint already existed for the connected entity {ToPrettyString(bUid)}.");
_sawmill.Error($"While adding joint {joint.ID} to entity {ToPrettyString(aUid)}, the joint already existed for the connected entity {ToPrettyString(bUid)}.");
}
jointsA.TryAdd(joint.ID, joint);
@@ -403,6 +405,12 @@ public abstract class SharedJointSystem : EntitySystem
// Need to defer this for prediction reasons, yay!
AddedJoints.Add(joint);
if (_gameTiming.IsFirstTimePredicted)
{
_sawmill.Debug($"Added {joint.JointType} Joint with ID {joint.ID} from {bodyA.BodyType} to {bodyB.BodyType} ");
}
}
public void ClearJoints(EntityUid uid, JointComponent? component = null)
@@ -418,6 +426,11 @@ public abstract class SharedJointSystem : EntitySystem
{
RemoveJoint(a);
}
if(_gameTiming.IsFirstTimePredicted)
{
_sawmill.Debug($"Removed all joints from entity {ToPrettyString(uid)}");
}
}
[Obsolete("Use the other ClearJoints overload")]
@@ -453,8 +466,6 @@ public abstract class SharedJointSystem : EntitySystem
return;
}
_sawmill.Debug($"Removed joint {joint.ID}");
// Wake up connected bodies.
if (EntityManager.TryGetComponent<PhysicsComponent>(bodyAUid, out var bodyA) &&
MetaData(bodyAUid).EntityLifeStage < EntityLifeStage.Terminating &&
@@ -491,11 +502,11 @@ public abstract class SharedJointSystem : EntitySystem
if (bodyA == null)
{
_sawmill.Debug($"Removing joint from entioty {ToPrettyString(bodyAUid)} without a physics component?");
_sawmill.Debug($"Tried to remove joint from entity {ToPrettyString(bodyAUid)} without a physics component");
}
else if (bodyB == null)
{
_sawmill.Debug($"Removing joint from entioty {ToPrettyString(bodyBUid)} without a physics component?");
_sawmill.Debug($"Tried to remove joint from entity {ToPrettyString(bodyBUid)} without a physics component");
}
else
{
@@ -504,6 +515,11 @@ public abstract class SharedJointSystem : EntitySystem
var smug = new JointRemovedEvent(joint, bodyB, bodyA);
EntityManager.EventBus.RaiseLocalEvent(bodyB.Owner, smug, false);
EntityManager.EventBus.RaiseEvent(EventSource.Local, vera);
if (_gameTiming.IsFirstTimePredicted)
{
_sawmill.Debug($"Removed {joint.JointType} joint with ID {joint.ID} from entity {ToPrettyString(bodyAUid)} to entity {ToPrettyString(bodyBUid)}");
}
}
// We can't just check up front due to how prediction works.