mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Revert "Remove PhysicsComponent ref from fixtures (#4374)"
This reverts commit 0624ac36cd.
This commit is contained in:
@@ -28,9 +28,10 @@ public sealed partial class PhysicsSystem
|
||||
|
||||
private void UpdateIsPredicted()
|
||||
{
|
||||
var query = GetEntityQuery<PhysicsComponent>();
|
||||
foreach (var uid in _toUpdate)
|
||||
{
|
||||
if (!PhysicsQuery.TryGetComponent(uid, out var physics))
|
||||
if (!query.TryGetComponent(uid, out var physics))
|
||||
continue;
|
||||
|
||||
var ev = new UpdateIsPredictedEvent(uid);
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Robust.Client.Physics
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly SharedBroadphaseSystem _broadphase = default!;
|
||||
|
||||
public override void Update(float frameTime)
|
||||
|
||||
@@ -152,7 +152,7 @@ namespace Robust.Shared.GameObjects
|
||||
poly,
|
||||
MapGridHelpers.CollisionGroup,
|
||||
MapGridHelpers.CollisionGroup,
|
||||
true);
|
||||
true) { Body = body};
|
||||
#pragma warning restore CS0618
|
||||
|
||||
newFixtures.Add(($"grid_chunk-{bounds.Left}-{bounds.Bottom}", newFixture));
|
||||
|
||||
@@ -50,6 +50,11 @@ namespace Robust.Shared.Physics.Dynamics
|
||||
[DataField("shape")]
|
||||
public IPhysShape Shape { get; private set; } = new PhysShapeAabb();
|
||||
|
||||
[Obsolete("Use other means to obtain the PhysicsComponent for the fixture.")]
|
||||
[ViewVariables]
|
||||
[field:NonSerialized]
|
||||
internal PhysicsComponent Body { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// All of the other fixtures this fixture has a contact with.
|
||||
/// </summary>
|
||||
@@ -176,7 +181,7 @@ namespace Robust.Shared.Physics.Dynamics
|
||||
{
|
||||
if (other == null) return false;
|
||||
|
||||
return Equivalent(other);
|
||||
return Equivalent(other) && other.Body == Body;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
}
|
||||
|
||||
manager.Fixtures.Add(fixtureId, fixture);
|
||||
fixture.Body = body;
|
||||
|
||||
if (body.CanCollide && Resolve(uid, ref xform))
|
||||
{
|
||||
@@ -205,12 +206,16 @@ namespace Robust.Shared.Physics.Systems
|
||||
// hence we'll just make sure its body is set and SharedBroadphaseSystem will deal with it later.
|
||||
if (Resolve(uid, ref body, false))
|
||||
{
|
||||
foreach (var id in component.Fixtures.Keys)
|
||||
foreach (var (id, fixture) in component.Fixtures)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new InvalidOperationException($"Tried to setup fixture on init for {ToPrettyString(uid)} with no ID!");
|
||||
}
|
||||
|
||||
#pragma warning disable CS0618
|
||||
fixture.Body = body;
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
|
||||
// Make sure all the right stuff is set on the body
|
||||
@@ -236,6 +241,15 @@ namespace Robust.Shared.Physics.Systems
|
||||
return;
|
||||
}
|
||||
|
||||
// State handling funnies, someday we'll remove fixture.Body and it won't matter
|
||||
// Alternatively if this is necessary just add it to FixtureSerializer.
|
||||
foreach (var (id, fixture) in component.Fixtures)
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
fixture.Body = physics;
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
|
||||
var toAddFixtures = new ValueList<(string Id, Fixture Fixture)>();
|
||||
var toRemoveFixtures = new ValueList<(string Id, Fixture Fixture)>();
|
||||
var computeProperties = false;
|
||||
@@ -247,6 +261,9 @@ namespace Robust.Shared.Physics.Systems
|
||||
{
|
||||
var newFixture = new Fixture();
|
||||
fixture.CopyTo(newFixture);
|
||||
#pragma warning disable CS0618
|
||||
newFixture.Body = physics;
|
||||
#pragma warning restore CS0618
|
||||
newFixtures.Add(id, newFixture);
|
||||
}
|
||||
|
||||
|
||||
@@ -402,7 +402,7 @@ public partial class SharedPhysicsSystem
|
||||
public void TrySetBodyType(EntityUid uid, BodyType value, FixturesComponent? manager = null, PhysicsComponent? body = null, TransformComponent? xform = null)
|
||||
{
|
||||
if (_fixturesQuery.Resolve(uid, ref manager, false) &&
|
||||
PhysicsQuery.Resolve(uid, ref body, false) &&
|
||||
_physicsQuery.Resolve(uid, ref body, false) &&
|
||||
_xformQuery.Resolve(uid, ref xform, false))
|
||||
{
|
||||
SetBodyType(uid, value, manager, body, xform);
|
||||
|
||||
@@ -121,23 +121,12 @@ public abstract partial class SharedPhysicsSystem
|
||||
|
||||
public bool Return(Contact obj)
|
||||
{
|
||||
SetContact(obj,
|
||||
EntityUid.Invalid, EntityUid.Invalid,
|
||||
string.Empty, string.Empty,
|
||||
null, 0,
|
||||
null, 0,
|
||||
null, null);
|
||||
SetContact(obj, EntityUid.Invalid, EntityUid.Invalid, string.Empty, string.Empty, null, 0, null, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetContact(Contact contact,
|
||||
EntityUid uidA, EntityUid uidB,
|
||||
string fixtureAId, string fixtureBId,
|
||||
Fixture? fixtureA, int indexA,
|
||||
Fixture? fixtureB, int indexB,
|
||||
PhysicsComponent? bodyA,
|
||||
PhysicsComponent? bodyB)
|
||||
private static void SetContact(Contact contact, EntityUid uidA, EntityUid uidB, string fixtureAId, string fixtureBId, Fixture? fixtureA, int indexA, Fixture? fixtureB, int indexB)
|
||||
{
|
||||
contact.Enabled = true;
|
||||
contact.IsTouching = false;
|
||||
@@ -153,8 +142,8 @@ public abstract partial class SharedPhysicsSystem
|
||||
contact.FixtureA = fixtureA;
|
||||
contact.FixtureB = fixtureB;
|
||||
|
||||
contact.BodyA = bodyA;
|
||||
contact.BodyB = bodyB;
|
||||
contact.BodyA = fixtureA?.Body;
|
||||
contact.BodyB = fixtureB?.Body;
|
||||
|
||||
contact.ChildIndexA = indexA;
|
||||
contact.ChildIndexB = indexB;
|
||||
@@ -210,12 +199,7 @@ public abstract partial class SharedPhysicsSystem
|
||||
}
|
||||
}
|
||||
|
||||
private Contact CreateContact(
|
||||
EntityUid uidA, EntityUid uidB,
|
||||
string fixtureAId, string fixtureBId,
|
||||
Fixture fixtureA, int indexA,
|
||||
Fixture fixtureB, int indexB,
|
||||
PhysicsComponent bodyA, PhysicsComponent bodyB)
|
||||
private Contact CreateContact(EntityUid uidA, EntityUid uidB, string fixtureAId, string fixtureBId, Fixture fixtureA, int indexA, Fixture fixtureB, int indexB)
|
||||
{
|
||||
var type1 = fixtureA.Shape.ShapeType;
|
||||
var type2 = fixtureB.Shape.ShapeType;
|
||||
@@ -229,11 +213,11 @@ public abstract partial class SharedPhysicsSystem
|
||||
// Edge+Polygon is non-symmetrical due to the way Erin handles collision type registration.
|
||||
if ((type1 >= type2 || (type1 == ShapeType.Edge && type2 == ShapeType.Polygon)) && !(type2 == ShapeType.Edge && type1 == ShapeType.Polygon))
|
||||
{
|
||||
SetContact(contact, uidA, uidB, fixtureAId, fixtureBId, fixtureA, indexA, fixtureB, indexB, bodyA, bodyB);
|
||||
SetContact(contact, uidA, uidB, fixtureAId, fixtureBId, fixtureA, indexA, fixtureB, indexB);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetContact(contact, uidB, uidA, fixtureBId, fixtureAId, fixtureB, indexB, fixtureA, indexA, bodyB, bodyA);
|
||||
SetContact(contact, uidB, uidA, fixtureBId, fixtureAId, fixtureB, indexB, fixtureA, indexA);
|
||||
}
|
||||
|
||||
contact.Type = _registers[(int)type1, (int)type2];
|
||||
@@ -269,27 +253,27 @@ public abstract partial class SharedPhysicsSystem
|
||||
return;
|
||||
|
||||
// Call the factory.
|
||||
var contact = CreateContact(uidA, uidB, fixtureAId, fixtureBId, fixtureA, indexA, fixtureB, indexB, bodyA, bodyB);
|
||||
var contact = CreateContact(uidA, uidB, fixtureAId, fixtureBId, fixtureA, indexA, fixtureB, indexB);
|
||||
contact.Flags = flags;
|
||||
|
||||
// Contact creation may swap fixtures.
|
||||
var fixA = contact.FixtureA!;
|
||||
var fixB = contact.FixtureB!;
|
||||
var bodA = contact.BodyA!;
|
||||
var bodB = contact.BodyB!;
|
||||
fixtureA = contact.FixtureA!;
|
||||
fixtureB = contact.FixtureB!;
|
||||
bodyA = contact.BodyA!;
|
||||
bodyB = contact.BodyB!;
|
||||
|
||||
// Insert into world
|
||||
_activeContacts.AddLast(contact.MapNode);
|
||||
|
||||
// Connect to body A
|
||||
DebugTools.Assert(!fixA.Contacts.ContainsKey(fixB));
|
||||
fixA.Contacts.Add(fixB, contact);
|
||||
bodA.Contacts.AddLast(contact.BodyANode);
|
||||
DebugTools.Assert(!fixtureA.Contacts.ContainsKey(fixtureB));
|
||||
fixtureA.Contacts.Add(fixtureB, contact);
|
||||
bodyA.Contacts.AddLast(contact.BodyANode);
|
||||
|
||||
// Connect to body B
|
||||
DebugTools.Assert(!fixB.Contacts.ContainsKey(fixA));
|
||||
fixB.Contacts.Add(fixA, contact);
|
||||
bodB.Contacts.AddLast(contact.BodyBNode);
|
||||
DebugTools.Assert(!fixtureB.Contacts.ContainsKey(fixtureA));
|
||||
fixtureB.Contacts.Add(fixtureA, contact);
|
||||
bodyB.Contacts.AddLast(contact.BodyBNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
public bool MetricsEnabled { get; protected set; }
|
||||
|
||||
private EntityQuery<FixturesComponent> _fixturesQuery;
|
||||
protected EntityQuery<PhysicsComponent> PhysicsQuery;
|
||||
private EntityQuery<PhysicsComponent> _physicsQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
public override void Initialize()
|
||||
@@ -71,7 +71,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
base.Initialize();
|
||||
|
||||
_fixturesQuery = GetEntityQuery<FixturesComponent>();
|
||||
PhysicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
SubscribeLocalEvent<GridAddEvent>(OnGridAdd);
|
||||
|
||||
Reference in New Issue
Block a user