Raise collision events by-ref (#3201)

This commit is contained in:
metalgearsloth
2022-09-14 17:23:35 +10:00
committed by GitHub
parent c9aa2c61bd
commit de01b9d8cb
88 changed files with 292 additions and 185 deletions

View File

@@ -16,6 +16,7 @@ using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;

View File

@@ -57,9 +57,11 @@ using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Dynamics.Contacts;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Physics.Systems;
namespace Robust.Client.Debugging
{

View File

@@ -1,6 +1,7 @@
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics.Components;
using Robust.Shared.Reflection;
namespace Robust.Client.GameObjects

View File

@@ -11,6 +11,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Timing;

View File

@@ -5,6 +5,7 @@ using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
namespace Robust.Client.GameObjects
{

View File

@@ -1,4 +1,5 @@
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
namespace Robust.Client.Physics
{

View File

@@ -4,6 +4,7 @@ using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Physics.Systems;
namespace Robust.Client.Physics
{

View File

@@ -4,6 +4,7 @@ using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
namespace Robust.Client.Physics

View File

@@ -2,6 +2,7 @@ using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Timing;
namespace Robust.Client.Physics

View File

@@ -8,6 +8,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Utility;
namespace Robust.Client.Placement

View File

@@ -6,6 +6,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Systems;
namespace Robust.Server.Console.Commands;

View File

@@ -2,6 +2,7 @@ using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
namespace Robust.Server.Console.Commands;

View File

@@ -30,8 +30,10 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Timing;
namespace Robust.Server.Console.Commands

View File

@@ -6,6 +6,8 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
namespace Robust.Server.GameObjects
{

View File

@@ -1,6 +1,7 @@
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics.Components;
using Robust.Shared.Reflection;
namespace Robust.Server.GameObjects

View File

@@ -17,6 +17,7 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Network.Messages;
using Robust.Shared.Physics.Components;
using Robust.Shared.Players;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -226,7 +227,7 @@ internal sealed partial class PVSSystem : EntitySystem
// we just discard it.
_visSetPool.Return(overflowEnts);
}
if (sessionData.SentEntities.TryGetValue(ackedTick, out var ackedData))
ProcessAckedTick(sessionData, ackedData, ackedTick, lastAckedTick);
}
@@ -691,7 +692,7 @@ internal sealed partial class PVSSystem : EntitySystem
if (visibleEnts.Count != 0)
throw new Exception("Encountered non-empty object inside of _visSetPool. Was the same object returned to the pool more than once?");
var deletions = _entityPvsCollection.GetDeletedIndices(fromTick);
foreach (var i in chunkIndices)
@@ -754,7 +755,7 @@ internal sealed partial class PVSSystem : EntitySystem
var entFromTick = entered ? lastSeen.GetValueOrDefault(uid) : fromTick;
var state = GetEntityState(session, uid, entFromTick, mQuery.GetComponent(uid));
if (entered || !state.Empty)
if (entered || !state.Empty)
entityStates.Add(state);
}
@@ -808,7 +809,7 @@ internal sealed partial class PVSSystem : EntitySystem
foreach (var uid in lastSent.Keys)
{
if (!visibleEnts.ContainsKey(uid))
leftView.Add(uid);
leftView.Add(uid);
}
return leftView.Count > 0 ? leftView : null;
@@ -901,7 +902,7 @@ internal sealed partial class PVSSystem : EntitySystem
// the budget. Chances are the packet will arrive in a nice and orderly fashion, and the client will stick to
// their requested budget. However this can cause issues if a packet gets dropped, because a player may create
// 2x or more times the normal entity creation budget.
//
//
// The fix for that would be to just also give the PVS budget a client-side aspect that controls entity creation
// rate.
if (enteredSinceLastSent)

View File

@@ -15,7 +15,9 @@ using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager;

View File

@@ -1,5 +1,6 @@
using Robust.Server.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
namespace Robust.Server.Physics
{

View File

@@ -12,6 +12,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Players;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

View File

@@ -3,6 +3,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Physics.Systems;
namespace Robust.Server.Physics
{

View File

@@ -3,6 +3,8 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;

View File

@@ -2,7 +2,7 @@ using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.Physics.Components;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Robust.Shared.Containers

View File

@@ -9,6 +9,7 @@ using Robust.Shared.Utility;
using System.Runtime.CompilerServices;
using Robust.Shared.Log;
using System.Diagnostics;
using Robust.Shared.Physics.Components;
#if EXCEPTION_TOLERANCE
using Robust.Shared.Exceptions;
#endif

View File

@@ -1,3 +1,5 @@
using Robust.Shared.Physics.Components;
namespace Robust.Shared.GameObjects
{
public sealed class CollideOnAnchorSystem : EntitySystem

View File

@@ -2,6 +2,8 @@ using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
namespace Robust.Shared.GameObjects
{

View File

@@ -8,7 +8,9 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
namespace Robust.Shared.GameObjects
{

View File

@@ -7,6 +7,7 @@ using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

View File

@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
namespace Robust.Shared.Map
{

View File

@@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
namespace Robust.Shared.Map

View File

@@ -5,6 +5,7 @@ using System.Linq;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;

View File

@@ -6,6 +6,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Utility;
namespace Robust.Shared.Map;

View File

@@ -2,7 +2,7 @@ using System.Collections.Generic;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Dynamics;
namespace Robust.Shared.Physics.Broadphase
namespace Robust.Shared.Physics.BroadPhase
{
public sealed class DynamicTreeBroadPhase : IBroadPhase
{

View File

@@ -1,10 +1,9 @@
using System;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Serialization;
namespace Robust.Shared.GameObjects
namespace Robust.Shared.Physics.Components
{
// TODO: Move to content
[Serializable, NetSerializable]
public enum BodyStatus: byte
{

View File

@@ -24,19 +24,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Dynamics.Contacts;
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Robust.Shared.GameObjects
namespace Robust.Shared.Physics.Components
{
[ComponentReference(typeof(ILookupWorldBox2Component))]
[ComponentReference(typeof(IPhysBody))]
@@ -808,85 +809,10 @@ namespace Robust.Shared.GameObjects
}
/// <summary>
/// Used to prevent bodies from colliding; may lie depending on joints.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
internal bool ShouldCollide(PhysicsComponent other)
{
if ((_bodyType & (BodyType.Kinematic | BodyType.Static)) != 0 &&
(other._bodyType & (BodyType.Kinematic | BodyType.Static)) != 0)
{
return false;
}
// Does a joint prevent collision?
// if one of them doesn't have jointcomp then they can't share a common joint.
// otherwise, only need to iterate over the joints of one component as they both store the same joint.
if (_entMan.TryGetComponent(Owner, out JointComponent? jointComponentA) &&
_entMan.TryGetComponent(other.Owner, out JointComponent? jointComponentB))
{
var aUid = jointComponentA.Owner;
var bUid = jointComponentB.Owner;
foreach (var (_, joint) in jointComponentA.Joints)
{
// Check if either: the joint even allows collisions OR the other body on the joint is actually the other body we're checking.
if (!joint.CollideConnected &&
((aUid == joint.BodyAUid &&
bUid == joint.BodyBUid) ||
(bUid == joint.BodyAUid &&
aUid == joint.BodyBUid))) return false;
}
}
var preventCollideMessage = new PreventCollideEvent(this, other);
_entMan.EventBus.RaiseLocalEvent(Owner, preventCollideMessage, true);
if (preventCollideMessage.Cancelled) return false;
preventCollideMessage = new PreventCollideEvent(other, this);
_entMan.EventBus.RaiseLocalEvent(other.Owner, preventCollideMessage, true);
if (preventCollideMessage.Cancelled) return false;
return true;
}
// View variables conveniences properties.
[ViewVariables]
private Vector2 _mapLinearVelocity => _entMan.EntitySysManager.GetEntitySystem<SharedPhysicsSystem>().GetMapLinearVelocity(Owner, this);
[ViewVariables]
private float _mapAngularVelocity => _entMan.EntitySysManager.GetEntitySystem<SharedPhysicsSystem>().GetMapAngularVelocity(Owner, this);
}
/// <summary>
/// Directed event raised when an entity's physics BodyType changes.
/// </summary>
[ByRefEvent]
public readonly struct PhysicsBodyTypeChangedEvent
{
public readonly EntityUid Entity;
/// <summary>
/// New BodyType of the entity.
/// </summary>
public readonly BodyType New;
/// <summary>
/// Old BodyType of the entity.
/// </summary>
public readonly BodyType Old;
public readonly PhysicsComponent Component;
public PhysicsBodyTypeChangedEvent(EntityUid entity, BodyType newType, BodyType oldType, PhysicsComponent component)
{
Entity = entity;
New = newType;
Old = oldType;
Component = component;
}
}
}

View File

@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Serialization;
namespace Robust.Shared.GameObjects
namespace Robust.Shared.Physics.Components
{
[Serializable, NetSerializable]
public sealed class PhysicsComponentState : ComponentState

View File

@@ -5,6 +5,7 @@ using Prometheus;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Timing;
namespace Robust.Shared.Physics.Controllers

View File

@@ -39,7 +39,10 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Collision;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics.Contacts;
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Utility;
namespace Robust.Shared.Physics.Dynamics
@@ -48,6 +51,7 @@ namespace Robust.Shared.Physics.Dynamics
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPhysicsManager _physicsManager = default!;
private SharedPhysicsSystem _physics = default!;
private SharedTransformSystem _transform = default!;
internal MapId MapId { get; set; }
@@ -159,7 +163,8 @@ namespace Robust.Shared.Physics.Dynamics
public void Initialize()
{
IoCManager.InjectDependencies(this);
_transform = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SharedTransformSystem>();
_physics = _entityManager.EntitySysManager.GetEntitySystem<SharedPhysicsSystem>();
_transform = _entityManager.EntitySysManager.GetEntitySystem<SharedTransformSystem>();
var configManager = IoCManager.Resolve<IConfigurationManager>();
configManager.OnValueChanged(CVars.ContactMultithreadThreshold, OnContactMultithreadThreshold, true);
configManager.OnValueChanged(CVars.ContactMinimumThreads, OnContactMinimumThreads, true);
@@ -243,7 +248,7 @@ namespace Robust.Shared.Physics.Dynamics
DebugTools.Assert(!fixtureB.Contacts.ContainsKey(fixtureA));
// Does a joint override collision? Is at least one body dynamic?
if (!bodyB.ShouldCollide(bodyA))
if (!_physics.ShouldCollide(bodyB, bodyA))
return;
// Call the factory.
@@ -293,8 +298,10 @@ namespace Robust.Shared.Physics.Dynamics
if (contact.IsTouching)
{
_entityManager.EventBus.RaiseLocalEvent(bodyA.Owner, new EndCollideEvent(fixtureA, fixtureB), true);
_entityManager.EventBus.RaiseLocalEvent(bodyB.Owner, new EndCollideEvent(fixtureB, fixtureA), true);
var ev1 = new EndCollideEvent(fixtureA, fixtureB);
var ev2 = new EndCollideEvent(fixtureB, fixtureA);
_entityManager.EventBus.RaiseLocalEvent(bodyA.Owner, ref ev1);
_entityManager.EventBus.RaiseLocalEvent(bodyB.Owner, ref ev2);
}
if (contact.Manifold.PointCount > 0 && contact.FixtureA?.Hard == true && contact.FixtureB?.Hard == true)
@@ -364,7 +371,7 @@ namespace Robust.Shared.Physics.Dynamics
if ((contact.Flags & ContactFlags.Filter) != 0x0)
{
// Should these bodies collide?
if (bodyB.ShouldCollide(bodyA) == false)
if (_physics.ShouldCollide(bodyB, bodyA) == false)
{
node = node.Next;
Destroy(contact);
@@ -497,8 +504,11 @@ namespace Robust.Shared.Physics.Dynamics
var bodyB = fixtureB.Body;
var worldPoint = Transform.Mul(_physicsManager.EnsureTransform(bodyA), contact.Manifold.LocalPoint);
_entityManager.EventBus.RaiseLocalEvent(bodyA.Owner, new StartCollideEvent(fixtureA, fixtureB, worldPoint), true);
_entityManager.EventBus.RaiseLocalEvent(bodyB.Owner, new StartCollideEvent(fixtureB, fixtureA, worldPoint), true);
var ev1 = new StartCollideEvent(fixtureA, fixtureB, worldPoint);
var ev2 = new StartCollideEvent(fixtureB, fixtureA, worldPoint);
_entityManager.EventBus.RaiseLocalEvent(bodyA.Owner, ref ev1, true);
_entityManager.EventBus.RaiseLocalEvent(bodyB.Owner, ref ev2, true);
break;
}
case ContactStatus.Touching:
@@ -515,8 +525,11 @@ namespace Robust.Shared.Physics.Dynamics
var bodyA = fixtureA.Body;
var bodyB = fixtureB.Body;
_entityManager.EventBus.RaiseLocalEvent(bodyA.Owner, new EndCollideEvent(fixtureA, fixtureB), true);
_entityManager.EventBus.RaiseLocalEvent(bodyB.Owner, new EndCollideEvent(fixtureB, fixtureA), true);
var ev1 = new EndCollideEvent(fixtureA, fixtureB);
var ev2 = new EndCollideEvent(fixtureB, fixtureA);
_entityManager.EventBus.RaiseLocalEvent(bodyA.Owner, ref ev1);
_entityManager.EventBus.RaiseLocalEvent(bodyB.Owner, ref ev2);
break;
}
case ContactStatus.NoContact:
@@ -606,60 +619,8 @@ namespace Robust.Shared.Physics.Dynamics
}
}
}
public void PostSolve()
{
}
}
#region Collide Events Classes
public abstract class CollideEvent : EntityEventArgs
{
public Fixture OurFixture { get; }
public Fixture OtherFixture { get; }
public CollideEvent(Fixture ourFixture, Fixture otherFixture)
{
OurFixture = ourFixture;
OtherFixture = otherFixture;
}
}
public sealed class StartCollideEvent : CollideEvent
{
public Vector2 WorldPoint;
public StartCollideEvent(Fixture ourFixture, Fixture otherFixture, Vector2 worldPoint)
: base(ourFixture, otherFixture)
{
WorldPoint = worldPoint;
}
}
public sealed class EndCollideEvent : CollideEvent
{
public EndCollideEvent(Fixture ourFixture, Fixture otherFixture)
: base(ourFixture, otherFixture)
{
}
}
public sealed class PreventCollideEvent : CancellableEntityEventArgs
{
public IPhysBody BodyA;
public IPhysBody BodyB;
public PreventCollideEvent(IPhysBody ourBody, IPhysBody otherBody)
{
BodyA = ourBody;
BodyB = otherBody;
}
}
#endregion
internal enum ContactStatus : byte
{
NoContact = 0,

View File

@@ -34,6 +34,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Collision;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
namespace Robust.Shared.Physics.Dynamics.Contacts
{

View File

@@ -26,6 +26,7 @@ using System.Threading.Tasks;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Collision;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Utility;
namespace Robust.Shared.Physics.Dynamics.Contacts

View File

@@ -26,7 +26,9 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics.Contacts;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

View File

@@ -29,6 +29,7 @@ using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;

View File

@@ -25,6 +25,7 @@ using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;

View File

@@ -26,6 +26,8 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;

View File

@@ -21,6 +21,7 @@
*/
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Components;
namespace Robust.Shared.Physics.Dynamics.Joints
{

View File

@@ -24,6 +24,7 @@ using System;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;

View File

@@ -25,6 +25,7 @@ using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;

View File

@@ -24,6 +24,7 @@ using System;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;

View File

@@ -2,6 +2,7 @@ using System;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;

View File

@@ -27,6 +27,7 @@ using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics.Contacts;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Utility;

View File

@@ -28,8 +28,9 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Dynamics.Contacts;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Utility;
using PhysicsComponent = Robust.Shared.GameObjects.PhysicsComponent;
using PhysicsComponent = Robust.Shared.Physics.Components.PhysicsComponent;
namespace Robust.Shared.Physics.Dynamics
{
@@ -344,8 +345,6 @@ namespace Robust.Shared.Physics.Dynamics
SolveIslands(frameTime, dtRatio, invDt, prediction);
Cleanup(frameTime);
ContactManager.PostSolve();
}
protected virtual void Cleanup(float frameTime)

View File

@@ -1,4 +1,7 @@
namespace Robust.Shared.GameObjects
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Components;
namespace Robust.Shared.Physics.Events
{
[ByRefEvent]
public readonly struct CollisionChangeEvent

View File

@@ -0,0 +1,17 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Dynamics;
namespace Robust.Shared.Physics.Events;
[ByRefEvent]
public readonly struct EndCollideEvent
{
public readonly Fixture OurFixture;
public readonly Fixture OtherFixture;
public EndCollideEvent(Fixture ourFixture, Fixture otherFixture)
{
OurFixture = ourFixture;
OtherFixture = otherFixture;
}
}

View File

@@ -0,0 +1,33 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Components;
namespace Robust.Shared.Physics.Events;
/// <summary>
/// Directed event raised when an entity's physics BodyType changes.
/// </summary>
[ByRefEvent]
public readonly struct PhysicsBodyTypeChangedEvent
{
public readonly EntityUid Entity;
/// <summary>
/// New BodyType of the entity.
/// </summary>
public readonly BodyType New;
/// <summary>
/// Old BodyType of the entity.
/// </summary>
public readonly BodyType Old;
public readonly PhysicsComponent Component;
public PhysicsBodyTypeChangedEvent(EntityUid entity, BodyType newType, BodyType oldType, PhysicsComponent component)
{
Entity = entity;
New = newType;
Old = oldType;
Component = component;
}
}

View File

@@ -0,0 +1,18 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Components;
namespace Robust.Shared.Physics.Events;
[ByRefEvent]
public struct PreventCollideEvent
{
public PhysicsComponent BodyA;
public PhysicsComponent BodyB;
public bool Cancelled = false;
public PreventCollideEvent(PhysicsComponent ourBody, PhysicsComponent otherBody)
{
BodyA = ourBody;
BodyB = otherBody;
}
}

View File

@@ -0,0 +1,18 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Dynamics;
namespace Robust.Shared.Physics.Events;
[ByRefEvent]
public readonly struct StartCollideEvent
{
public readonly Fixture OurFixture;
public readonly Fixture OtherFixture;
public StartCollideEvent(Fixture ourFixture, Fixture otherFixture, Vector2 worldPoint)
{
OurFixture = ourFixture;
OtherFixture = otherFixture;
}
}

View File

@@ -4,6 +4,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;

View File

@@ -2,7 +2,7 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Dynamics.Contacts;

View File

@@ -1,6 +1,7 @@
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
namespace Robust.Shared.Physics
{

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics.Components;
namespace Robust.Shared.Physics
{

View File

@@ -1,4 +1,5 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Components;
namespace Robust.Shared.Physics
{

View File

@@ -4,7 +4,7 @@ using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Utility;
namespace Robust.Shared.Physics
namespace Robust.Shared.Physics.Systems
{
public partial class FixtureSystem
{

View File

@@ -7,11 +7,12 @@ using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Robust.Shared.Physics
namespace Robust.Shared.Physics.Systems
{
/// <summary>
/// Manages physics fixtures.

View File

@@ -1,20 +1,19 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Robust.Shared.Configuration;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Physics.BroadPhase;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Dynamics.Contacts;
using Robust.Shared.Physics.Events;
using Robust.Shared.Utility;
namespace Robust.Shared.Physics
namespace Robust.Shared.Physics.Systems
{
public abstract class SharedBroadphaseSystem : EntitySystem
{

View File

@@ -1,21 +1,18 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using Robust.Shared.Configuration;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
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
namespace Robust.Shared.Physics.Systems
{
// These exist as a means to defer joint additions / removals so we can use HandleComponentState gracefully without
// exploding for modifying components.

View File

@@ -1,14 +1,16 @@
using System;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Events;
using Robust.Shared.Utility;
namespace Robust.Shared.GameObjects;
namespace Robust.Shared.Physics.Systems;
public partial class SharedPhysicsSystem
{

View File

@@ -0,0 +1,54 @@
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Events;
namespace Robust.Shared.Physics.Systems;
public abstract partial class SharedPhysicsSystem
{
/// <summary>
/// Used to prevent bodies from colliding; may lie depending on joints.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
internal bool ShouldCollide(PhysicsComponent body, PhysicsComponent other)
{
if ((body.BodyType & (BodyType.Kinematic | BodyType.Static)) != 0 &&
(other.BodyType & (BodyType.Kinematic | BodyType.Static)) != 0)
{
return false;
}
// Does a joint prevent collision?
// if one of them doesn't have jointcomp then they can't share a common joint.
// otherwise, only need to iterate over the joints of one component as they both store the same joint.
if (TryComp(body.Owner, out JointComponent? jointComponentA) &&
TryComp(other.Owner, out JointComponent? jointComponentB))
{
var aUid = jointComponentA.Owner;
var bUid = jointComponentB.Owner;
foreach (var (_, joint) in jointComponentA.Joints)
{
// Check if either: the joint even allows collisions OR the other body on the joint is actually the other body we're checking.
if (!joint.CollideConnected &&
((aUid == joint.BodyAUid &&
bUid == joint.BodyBUid) ||
(bUid == joint.BodyAUid &&
aUid == joint.BodyBUid))) return false;
}
}
var preventCollideMessage = new PreventCollideEvent(body, other);
RaiseLocalEvent(body.Owner, ref preventCollideMessage);
if (preventCollideMessage.Cancelled) return false;
preventCollideMessage = new PreventCollideEvent(other, body);
RaiseLocalEvent(other.Owner, ref preventCollideMessage);
if (preventCollideMessage.Cancelled) return false;
return true;
}
}

View File

@@ -1,9 +1,9 @@
using Robust.Shared.IoC;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Utility;
namespace Robust.Shared.GameObjects;
namespace Robust.Shared.Physics.Systems;
public abstract partial class SharedPhysicsSystem
{

View File

@@ -1,14 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.Debugging;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Debugging;
namespace Robust.Shared.GameObjects
namespace Robust.Shared.Physics.Systems
{
/*
* Handles all of the public query methods for physics.
@@ -84,7 +84,7 @@ namespace Robust.Shared.GameObjects
{
if (other.Fixture.Body.Deleted || other.Fixture.Body == body) return true;
if ((proxy.Fixture.CollisionMask & other.Fixture.CollisionLayer) == 0x0) return true;
if (!body.ShouldCollide(other.Fixture.Body)) return true;
if (!ShouldCollide(body, other.Fixture.Body)) return true;
state.entities.Add(other.Fixture.Body);
return true;

View File

@@ -1,10 +1,11 @@
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
namespace Robust.Shared.GameObjects;
namespace Robust.Shared.Physics.Systems;
public abstract partial class SharedPhysicsSystem
{

View File

@@ -3,17 +3,19 @@ using System.Collections.Generic;
using Prometheus;
using Robust.Shared.Configuration;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Events;
using Robust.Shared.Utility;
using DependencyAttribute = Robust.Shared.IoC.DependencyAttribute;
namespace Robust.Shared.GameObjects
namespace Robust.Shared.Physics.Systems
{
public abstract partial class SharedPhysicsSystem : EntitySystem
{

View File

@@ -10,7 +10,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Timing;

View File

@@ -26,6 +26,8 @@ using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Profiling;
using Robust.Shared.Prototypes;
using Robust.Shared.Reflection;

View File

@@ -6,6 +6,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.UnitTesting.Server;
// ReSharper disable AccessToStaticMemberViaDerivedType

View File

@@ -5,6 +5,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
namespace Robust.UnitTesting.Shared.Map
{

View File

@@ -5,6 +5,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
namespace Robust.UnitTesting.Shared.Map
{

View File

@@ -4,6 +4,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.UnitTesting.Server;
namespace Robust.UnitTesting.Shared.Physics;

View File

@@ -4,6 +4,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Components;
namespace Robust.UnitTesting.Shared.Physics
{

View File

@@ -26,6 +26,7 @@ using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Systems;
namespace Robust.UnitTesting.Shared.Physics;

View File

@@ -3,6 +3,7 @@ using NUnit.Framework;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Systems;
namespace Robust.UnitTesting.Shared.Physics
{

View File

@@ -4,6 +4,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
namespace Robust.UnitTesting.Shared.Physics;

View File

@@ -5,7 +5,9 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Systems;
namespace Robust.UnitTesting.Shared.Physics;

View File

@@ -5,7 +5,9 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Physics.Systems;
namespace Robust.UnitTesting.Shared.Physics;

View File

@@ -8,8 +8,10 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Reflection;
using Robust.UnitTesting.Server;

View File

@@ -5,6 +5,8 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
namespace Robust.UnitTesting.Shared.Physics
{

View File

@@ -7,7 +7,9 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Systems;
namespace Robust.UnitTesting.Shared.Physics
{

View File

@@ -4,6 +4,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.UnitTesting.Server;

View File

@@ -33,7 +33,9 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Systems;
namespace Robust.UnitTesting.Shared.Physics
{