diff --git a/Content.Client/Suspicion/SuspicionRoleComponent.cs b/Content.Client/Suspicion/SuspicionRoleComponent.cs index ad7d705459..c0a98512cb 100644 --- a/Content.Client/Suspicion/SuspicionRoleComponent.cs +++ b/Content.Client/Suspicion/SuspicionRoleComponent.cs @@ -68,7 +68,8 @@ namespace Content.Client.Suspicion } _overlayActive = true; - var overlay = new TraitorOverlay(IoCManager.Resolve(), IoCManager.Resolve(), _resourceCache); + var entManager = IoCManager.Resolve(); + var overlay = new TraitorOverlay(entManager, IoCManager.Resolve(), _resourceCache, entManager.System()); _overlayManager.AddOverlay(overlay); } diff --git a/Content.Client/Suspicion/TraitorOverlay.cs b/Content.Client/Suspicion/TraitorOverlay.cs index 88486ba105..84f52b9673 100644 --- a/Content.Client/Suspicion/TraitorOverlay.cs +++ b/Content.Client/Suspicion/TraitorOverlay.cs @@ -17,6 +17,7 @@ namespace Content.Client.Suspicion { private readonly IEntityManager _entityManager; private readonly IPlayerManager _playerManager; + private readonly EntityLookupSystem _lookup; public override OverlaySpace Space => OverlaySpace.ScreenSpace; private readonly Font _font; @@ -26,11 +27,12 @@ namespace Content.Client.Suspicion public TraitorOverlay( IEntityManager entityManager, IPlayerManager playerManager, - IResourceCache resourceCache) + IResourceCache resourceCache, + EntityLookupSystem lookup) { _playerManager = playerManager; - _entityManager = entityManager; + _lookup = lookup; _font = new VectorFont(resourceCache.GetResource("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10); } @@ -77,7 +79,7 @@ namespace Content.Client.Suspicion var (allyWorldPos, allyWorldRot) = allyXform.GetWorldPositionRotation(); - var worldBox = physics.GetWorldAABB(allyWorldPos, allyWorldRot); + var worldBox = _lookup.GetWorldAABB(ally, allyXform); // if not on screen, or too small, continue if (!worldBox.Intersects(in viewport) || worldBox.IsEmpty()) diff --git a/Content.IntegrationTests/Tests/Doors/AirlockTest.cs b/Content.IntegrationTests/Tests/Doors/AirlockTest.cs index 33dc418832..68455ce9ad 100644 --- a/Content.IntegrationTests/Tests/Doors/AirlockTest.cs +++ b/Content.IntegrationTests/Tests/Doors/AirlockTest.cs @@ -6,8 +6,10 @@ using Content.Shared.Doors.Components; using NUnit.Framework; 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.Systems; namespace Content.IntegrationTests.Tests.Doors { @@ -114,6 +116,7 @@ namespace Content.IntegrationTests.Tests.Doors var mapManager = server.ResolveDependency(); var entityManager = server.ResolveDependency(); + var physicsSystem = entityManager.System(); PhysicsComponent physBody = null; EntityUid physicsDummy = default; @@ -140,13 +143,19 @@ namespace Content.IntegrationTests.Tests.Doors await server.WaitIdleAsync(); // Push the human towards the airlock - await server.WaitAssertion(() => Assert.That(physBody != null)); - await server.WaitPost(() => physBody.LinearVelocity = (0.5f, 0)); + await server.WaitAssertion(() => Assert.That(physBody, Is.Not.EqualTo(null))); + await server.WaitPost(() => + { + physicsSystem.SetLinearVelocity(physicsDummy, new Vector2(0.5f, 0f), body: physBody); + }); for (var i = 0; i < 240; i += 10) { // Keep the airlock awake so they collide - await server.WaitPost(() => entityManager.GetComponent(airlock).WakeBody()); + await server.WaitPost(() => + { + physicsSystem.WakeBody(airlock); + }); await server.WaitRunTicks(10); await server.WaitIdleAsync(); diff --git a/Content.IntegrationTests/Tests/ShuttleTest.cs b/Content.IntegrationTests/Tests/ShuttleTest.cs index 72aefd60fe..d999b596d6 100644 --- a/Content.IntegrationTests/Tests/ShuttleTest.cs +++ b/Content.IntegrationTests/Tests/ShuttleTest.cs @@ -6,6 +6,7 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; namespace Content.IntegrationTests.Tests { @@ -20,7 +21,8 @@ namespace Content.IntegrationTests.Tests await server.WaitIdleAsync(); var mapMan = server.ResolveDependency(); - var sEntities = server.ResolveDependency(); + var entManager = server.ResolveDependency(); + var physicsSystem = entManager.System(); EntityUid gridEnt = default; @@ -30,18 +32,18 @@ namespace Content.IntegrationTests.Tests var grid = mapMan.CreateGrid(mapId); gridEnt = grid.Owner; - Assert.That(sEntities.HasComponent(gridEnt)); - Assert.That(sEntities.TryGetComponent(gridEnt, out var physicsComponent)); + Assert.That(entManager.HasComponent(gridEnt)); + Assert.That(entManager.TryGetComponent(gridEnt, out var physicsComponent)); Assert.That(physicsComponent!.BodyType, Is.EqualTo(BodyType.Dynamic)); - Assert.That(sEntities.GetComponent(gridEnt).LocalPosition, Is.EqualTo(Vector2.Zero)); - physicsComponent.ApplyLinearImpulse(Vector2.One); + Assert.That(entManager.GetComponent(gridEnt).LocalPosition, Is.EqualTo(Vector2.Zero)); + physicsSystem.ApplyLinearImpulse(gridEnt, Vector2.One, body: physicsComponent); }); await server.WaitRunTicks(1); await server.WaitAssertion(() => { - Assert.That(sEntities.GetComponent(gridEnt).LocalPosition, Is.Not.EqualTo(Vector2.Zero)); + Assert.That(entManager.GetComponent(gridEnt).LocalPosition, Is.Not.EqualTo(Vector2.Zero)); }); await pairTracker.CleanReturnAsync(); } diff --git a/Content.Server/Administration/Commands/WarpCommand.cs b/Content.Server/Administration/Commands/WarpCommand.cs index be40591490..13945f5ab9 100644 --- a/Content.Server/Administration/Commands/WarpCommand.cs +++ b/Content.Server/Administration/Commands/WarpCommand.cs @@ -9,12 +9,15 @@ using Robust.Shared.Enums; using Robust.Shared.Map; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; namespace Content.Server.Administration.Commands { [AdminCommand(AdminFlags.Admin)] public sealed class WarpCommand : IConsoleCommand { + [Dependency] private readonly IEntityManager _entManager = default!; + public string Command => "warp"; public string Description => "Teleports you to predefined areas on the map."; @@ -37,11 +40,10 @@ namespace Content.Server.Administration.Commands return; } - var entMan = IoCManager.Resolve(); var location = args[0]; if (location == "?") { - var locations = string.Join(", ", GetWarpPointNames(entMan)); + var locations = string.Join(", ", GetWarpPointNames()); shell.WriteLine(locations); } @@ -53,20 +55,19 @@ namespace Content.Server.Administration.Commands return; } - var mapManager = IoCManager.Resolve(); - var currentMap = entMan.GetComponent(playerEntity).MapID; - var currentGrid = entMan.GetComponent(playerEntity).GridUid; + var currentMap = _entManager.GetComponent(playerEntity).MapID; + var currentGrid = _entManager.GetComponent(playerEntity).GridUid; - var found = entMan.EntityQuery(true) + var found = _entManager.EntityQuery(true) .Where(p => p.Location == location) - .Select(p => (entMan.GetComponent(p.Owner).Coordinates, p.Follow)) + .Select(p => (_entManager.GetComponent(p.Owner).Coordinates, p.Follow)) .OrderBy(p => p.Item1, Comparer.Create((a, b) => { // Sort so that warp points on the same grid/map are first. // So if you have two maps loaded with the same warp points, // it will prefer the warp points on the map you're currently on. - var aGrid = a.GetGridUid(entMan); - var bGrid = b.GetGridUid(entMan); + var aGrid = a.GetGridUid(_entManager); + var bGrid = b.GetGridUid(_entManager); if (aGrid == bGrid) { @@ -83,8 +84,8 @@ namespace Content.Server.Administration.Commands return 1; } - var mapA = a.GetMapId(entMan); - var mapB = a.GetMapId(entMan); + var mapA = a.GetMapId(_entManager); + var mapB = a.GetMapId(_entManager); if (mapA == mapB) { @@ -113,25 +114,25 @@ namespace Content.Server.Administration.Commands return; } - if (follow && entMan.HasComponent(playerEntity)) + if (follow && _entManager.HasComponent(playerEntity)) { - entMan.EntitySysManager.GetEntitySystem().StartFollowingEntity(playerEntity, coords.EntityId); + _entManager.System().StartFollowingEntity(playerEntity, coords.EntityId); return; } - var xform = entMan.GetComponent(playerEntity); + var xform = _entManager.GetComponent(playerEntity); xform.Coordinates = coords; xform.AttachToGridOrMap(); - if (entMan.TryGetComponent(playerEntity, out PhysicsComponent? physics)) + if (_entManager.TryGetComponent(playerEntity, out PhysicsComponent? physics)) { - physics.LinearVelocity = Vector2.Zero; + _entManager.System().SetLinearVelocity(playerEntity, Vector2.Zero, body: physics); } } } - private static IEnumerable GetWarpPointNames(IEntityManager entMan) + private IEnumerable GetWarpPointNames() { - return entMan.EntityQuery(true) + return _entManager.EntityQuery(true) .Select(p => p.Location) .Where(p => p != null) .OrderBy(p => p) @@ -142,8 +143,7 @@ namespace Content.Server.Administration.Commands { if (args.Length == 1) { - var ent = IoCManager.Resolve(); - var options = new[] { "?" }.Concat(GetWarpPointNames(ent)); + var options = new[] { "?" }.Concat(GetWarpPointNames()); return CompletionResult.FromHintOptions(options, ""); } diff --git a/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs b/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs index 36971628d1..9d54c15150 100644 --- a/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs +++ b/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs @@ -47,6 +47,7 @@ using Robust.Shared.Map; using Robust.Shared.Map.Components; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; using Robust.Shared.Player; using Robust.Shared.Random; using Timer = Robust.Shared.Timing.Timer; @@ -63,18 +64,20 @@ public sealed partial class AdminVerbSystem [Dependency] private readonly ElectrocutionSystem _electrocutionSystem = default!; [Dependency] private readonly EntityStorageSystem _entityStorageSystem = default!; [Dependency] private readonly ExplosionSystem _explosionSystem = default!; + [Dependency] private readonly FixtureSystem _fixtures = default!; [Dependency] private readonly FlammableSystem _flammableSystem = default!; [Dependency] private readonly GhostKickManager _ghostKickManager = default!; [Dependency] private readonly GodmodeSystem _godmodeSystem = default!; [Dependency] private readonly InventorySystem _inventorySystem = default!; + [Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!; [Dependency] private readonly PolymorphableSystem _polymorphableSystem = default!; [Dependency] private readonly MobStateSystem _mobStateSystem = default!; [Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!; [Dependency] private readonly PopupSystem _popupSystem = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly TabletopSystem _tabletopSystem = default!; [Dependency] private readonly VomitSystem _vomitSystem = default!; [Dependency] private readonly WeldableSystem _weldableSystem = default!; - [Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!; // All smite verbs have names so invokeverb works. private void AddSmiteVerbs(GetVerbsEvent args) @@ -422,20 +425,24 @@ public sealed partial class AdminVerbSystem var xform = Transform(args.Target); var fixtures = Comp(args.Target); xform.Anchored = false; // Just in case. - physics.BodyType = BodyType.Dynamic; - physics.BodyStatus = BodyStatus.InAir; - physics.WakeBody(); - foreach (var (_, fixture) in fixtures.Fixtures) + _physics.SetBodyType(args.Target, BodyType.Dynamic, manager: fixtures, body: physics); + _physics.SetBodyStatus(physics, BodyStatus.InAir); + _physics.WakeBody(args.Target, manager: fixtures, body: physics); + + foreach (var fixture in fixtures.Fixtures.Values) { if (!fixture.Hard) continue; - fixture.Restitution = 1.1f; + + _physics.SetRestitution(args.Target, fixture, 1.1f, false, fixtures); } - physics.LinearVelocity = _random.NextVector2(1.5f, 1.5f); - physics.AngularVelocity = MathF.PI * 12; - physics.LinearDamping = 0.0f; - physics.AngularDamping = 0.0f; + _fixtures.FixtureUpdate(args.Target, manager: fixtures, body: physics); + + _physics.SetLinearVelocity(args.Target, _random.NextVector2(1.5f, 1.5f), manager: fixtures, body: physics); + _physics.SetAngularVelocity(args.Target, MathF.PI * 12, manager: fixtures, body: physics); + _physics.SetLinearDamping(physics, 0f); + _physics.SetAngularDamping(physics, 0f); }, Impact = LogImpact.Extreme, Message = Loc.GetString("admin-smite-pinball-description") @@ -452,18 +459,20 @@ public sealed partial class AdminVerbSystem var xform = Transform(args.Target); var fixtures = Comp(args.Target); xform.Anchored = false; // Just in case. - physics.BodyType = BodyType.Dynamic; - physics.BodyStatus = BodyStatus.InAir; - physics.WakeBody(); - foreach (var (_, fixture) in fixtures.Fixtures) + + _physics.SetBodyType(args.Target, BodyType.Dynamic, body: physics); + _physics.SetBodyStatus(physics, BodyStatus.InAir); + _physics.WakeBody(args.Target, manager: fixtures, body: physics); + + foreach (var fixture in fixtures.Fixtures.Values) { - fixture.Hard = false; + _physics.SetHard(args.Target, fixture, false, manager: fixtures); } - physics.LinearVelocity = _random.NextVector2(8.0f, 8.0f); - physics.AngularVelocity = MathF.PI * 12; - physics.LinearDamping = 0.0f; - physics.AngularDamping = 0.0f; + _physics.SetLinearVelocity(args.Target, _random.NextVector2(8.0f, 8.0f), manager: fixtures, body: physics); + _physics.SetAngularVelocity(args.Target, MathF.PI * 12, manager: fixtures, body: physics); + _physics.SetLinearDamping(physics, 0f); + _physics.SetAngularDamping(physics, 0f); }, Impact = LogImpact.Extreme, Message = Loc.GetString("admin-smite-yeet-description") diff --git a/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs b/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs index 678f5b99b3..0a70180e1a 100644 --- a/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs +++ b/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs @@ -679,8 +679,8 @@ public sealed partial class AdminVerbSystem IconTexture = "/Textures/Interface/AdminActions/halt.png", Act = () => { - physics.LinearVelocity = Vector2.Zero; - physics.AngularVelocity = 0.0f; + _physics.SetLinearVelocity(args.Target, Vector2.Zero, body: physics); + _physics.SetAngularVelocity(args.Target, 0f, body: physics); }, Impact = LogImpact.Medium, Message = Loc.GetString("admin-trick-halt-movement-description"), diff --git a/Content.Server/Atmos/Components/FlammableComponent.cs b/Content.Server/Atmos/Components/FlammableComponent.cs index e7a5fd18ff..c959d5d417 100644 --- a/Content.Server/Atmos/Components/FlammableComponent.cs +++ b/Content.Server/Atmos/Components/FlammableComponent.cs @@ -34,6 +34,6 @@ namespace Content.Server.Atmos.Components /// Used for the fixture created to handle passing firestacks when two flammable objects collide. /// [DataField("flammableCollisionShape")] - public IPhysShape FlammableCollisionShape = new PhysShapeCircle() { Radius = 0.35f }; + public IPhysShape FlammableCollisionShape = new PhysShapeCircle(0.35f); } } diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs index 6396d4b25b..278f8ccd7a 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs @@ -30,15 +30,16 @@ namespace Content.Server.Atmos.EntitySystems foreach (var comp in _activePressures) { + var uid = comp.Owner; MetaDataComponent? metadata = null; - if (Deleted(comp.Owner, metadata)) + if (Deleted(uid, metadata)) { toRemove.Add(comp); continue; } - if (Paused(comp.Owner, metadata)) continue; + if (Paused(uid, metadata)) continue; comp.Accumulator += frameTime; @@ -48,17 +49,17 @@ namespace Content.Server.Atmos.EntitySystems comp.Accumulator = 0f; toRemove.Add(comp); - if (HasComp(comp.Owner) && - TryComp(comp.Owner, out var body)) + if (HasComp(uid) && + TryComp(uid, out var body)) { - body.BodyStatus = BodyStatus.OnGround; + _physics.SetBodyStatus(body, BodyStatus.OnGround); } - if (TryComp(comp.Owner, out var fixtures)) + if (TryComp(uid, out var fixtures)) { - foreach (var (_, fixture) in fixtures.Fixtures) + foreach (var fixture in fixtures.Fixtures.Values) { - _physics.AddCollisionMask(fixtures, fixture, (int) CollisionGroup.TableLayer); + _physics.AddCollisionMask(uid, fixture, (int) CollisionGroup.TableLayer, manager: fixtures); } } } @@ -73,11 +74,11 @@ namespace Content.Server.Atmos.EntitySystems { if (!TryComp(component.Owner, out var fixtures)) return; - body.BodyStatus = BodyStatus.InAir; + _physics.SetBodyStatus(body, BodyStatus.InAir); foreach (var fixture in fixtures.Fixtures.Values) { - _physics.RemoveCollisionMask(fixtures, fixture, (int) CollisionGroup.TableLayer); + _physics.RemoveCollisionMask(body.Owner, fixture, (int) CollisionGroup.TableLayer, manager: fixtures); } // TODO: Make them dynamic type? Ehh but they still want movement so uhh make it non-predicted like weightless? @@ -188,10 +189,12 @@ namespace Content.Server.Atmos.EntitySystems TransformComponent? xform = null, PhysicsComponent? physics = null) { - if (!Resolve(component.Owner, ref physics, false)) + var uid = component.Owner; + + if (!Resolve(uid, ref physics, false)) return; - if (!Resolve(component.Owner, ref xform)) return; + if (!Resolve(uid, ref xform)) return; // TODO ATMOS stuns? @@ -209,7 +212,7 @@ namespace Content.Server.Atmos.EntitySystems && (maxForce >= (component.MoveResist * MovedByPressureComponent.MoveForcePushRatio))) || (physics.BodyType == BodyType.Static && (maxForce >= (component.MoveResist * MovedByPressureComponent.MoveForceForcePushRatio)))) { - if (HasComp(physics.Owner)) + if (HasComp(uid)) { AddMobMovedByPressure(component, physics); } @@ -231,13 +234,12 @@ namespace Content.Server.Atmos.EntitySystems if (throwTarget != EntityCoordinates.Invalid) { var pos = ((throwTarget.ToMap(EntityManager).Position - xform.WorldPosition).Normalized + dirVec).Normalized; - physics.ApplyLinearImpulse(pos * moveForce); + _physics.ApplyLinearImpulse(uid, pos * moveForce, body: physics); } - else { moveForce = MathF.Min(moveForce, SpaceWindMaxPushForce); - physics.ApplyLinearImpulse(dirVec * moveForce); + _physics.ApplyLinearImpulse(uid, dirVec * moveForce, body: physics); } component.LastHighPressureMovementAirCycle = cycle; diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Monstermos.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Monstermos.cs index 6ec036f4e0..ae614574f5 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Monstermos.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Monstermos.cs @@ -484,8 +484,8 @@ namespace Content.Server.Atmos.EntitySystems var gridPhysics = Comp(mapGrid.Owner); // TODO ATMOS: Come up with better values for these. - gridPhysics.ApplyLinearImpulse(direction * totalMolesRemoved * gridPhysics.Mass); - gridPhysics.ApplyAngularImpulse(Vector2.Cross(tile.GridIndices - gridPhysics.LocalCenter, direction) * totalMolesRemoved); + _physics.ApplyLinearImpulse(mapGrid.Owner, direction * totalMolesRemoved * gridPhysics.Mass, body: gridPhysics); + _physics.ApplyAngularImpulse(mapGrid.Owner, Vector2.Cross(tile.GridIndices - gridPhysics.LocalCenter, direction) * totalMolesRemoved, body: gridPhysics); } if(tileCount > 10 && (totalMolesRemoved / tileCount) > 20) diff --git a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs index 3575412b7d..3efaa5b513 100644 --- a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs +++ b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs @@ -33,6 +33,7 @@ namespace Content.Server.Atmos.EntitySystems [Dependency] private readonly AlertsSystem _alertsSystem = default!; [Dependency] private readonly TransformSystem _transformSystem = default!; [Dependency] private readonly FixtureSystem _fixture = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; public const float MinimumFireStacks = -10f; @@ -92,12 +93,8 @@ namespace Content.Server.Atmos.EntitySystems if (!TryComp(uid, out var body)) return; - _fixture.TryCreateFixture(body, new Fixture(body, component.FlammableCollisionShape) - { - Hard = false, - ID = FlammableFixtureID, - CollisionMask = (int) CollisionGroup.FullTileLayer - }); + _fixture.TryCreateFixture(uid, component.FlammableCollisionShape, FlammableFixtureID, hard: false, + collisionMask: (int) CollisionGroup.FullTileLayer, body: body); } private void OnInteractUsing(EntityUid uid, FlammableComponent flammable, InteractUsingEvent args) @@ -274,7 +271,7 @@ namespace Content.Server.Atmos.EntitySystems _timer -= UpdateTime; // TODO: This needs cleanup to take off the crust from TemperatureComponent and shit. - foreach (var (flammable, physics, transform) in EntityManager.EntityQuery()) + foreach (var (flammable, transform) in EntityManager.EntityQuery()) { var uid = flammable.Owner; @@ -327,20 +324,21 @@ namespace Content.Server.Atmos.EntitySystems } - foreach (var otherUid in flammable.Collided.ToArray()) + for (var i = flammable.Collided.Count - 1; i >= 0; i--) { + var otherUid = flammable.Collided[i]; + if (!otherUid.IsValid() || !EntityManager.EntityExists(otherUid)) { - flammable.Collided.Remove(otherUid); + flammable.Collided.RemoveAt(i); continue; } - var otherPhysics = EntityManager.GetComponent(uid); - // TODO: Sloth, please save our souls! - if (!physics.GetWorldAABB().Intersects(otherPhysics.GetWorldAABB())) + // no + if (!_lookup.GetWorldAABB(uid, transform).Intersects(_lookup.GetWorldAABB(otherUid))) { - flammable.Collided.Remove(otherUid); + flammable.Collided.RemoveAt(i); } } } diff --git a/Content.Server/Beam/BeamSystem.cs b/Content.Server/Beam/BeamSystem.cs index bef132adb3..dd2fb798b8 100644 --- a/Content.Server/Beam/BeamSystem.cs +++ b/Content.Server/Beam/BeamSystem.cs @@ -81,17 +81,19 @@ public sealed class BeamSystem : SharedBeamSystem if (TryComp(ent, out var physics) && TryComp(ent, out var beam)) { - var fixture = new Fixture(physics, shape) - { - ID = "BeamBody", - Hard = false, - CollisionMask = (int)CollisionGroup.ItemMask, - CollisionLayer = (int)CollisionGroup.MobLayer - }; + FixturesComponent? manager = null; + _fixture.TryCreateFixture( + ent, + shape, + "BeamBody", + hard: false, + collisionMask: (int)CollisionGroup.ItemMask, + collisionLayer: (int)CollisionGroup.MobLayer, + manager: manager, + body: physics); - _fixture.TryCreateFixture(physics, fixture); - _physics.SetBodyType(physics, BodyType.Dynamic); - _physics.SetCanCollide(physics, true); + _physics.SetBodyType(ent, BodyType.Dynamic, manager: manager, body: physics); + _physics.SetCanCollide(ent, true, manager: manager, body: physics); var beamVisualizerEvent = new BeamVisualizerEvent(ent, distanceLength, userAngle, bodyState, shader); RaiseNetworkEvent(beamVisualizerEvent); diff --git a/Content.Server/Chemistry/EntitySystems/VaporSystem.cs b/Content.Server/Chemistry/EntitySystems/VaporSystem.cs index 7e234e83bd..d4f67de548 100644 --- a/Content.Server/Chemistry/EntitySystems/VaporSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/VaporSystem.cs @@ -13,6 +13,7 @@ using Robust.Shared.Map.Components; using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Dynamics; using Robust.Shared.Physics.Events; +using Robust.Shared.Physics.Systems; using Robust.Shared.Prototypes; namespace Content.Server.Chemistry.EntitySystems @@ -22,6 +23,7 @@ namespace Content.Server.Chemistry.EntitySystems { [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IPrototypeManager _protoManager = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!; [Dependency] private readonly ThrowingSystem _throwing = default!; @@ -37,7 +39,7 @@ namespace Content.Server.Chemistry.EntitySystems { if (!EntityManager.TryGetComponent(uid, out SolutionContainerManagerComponent? contents)) return; - foreach (var (_, value) in contents.Solutions) + foreach (var value in contents.Solutions.Values) { value.DoEntityReaction(args.OtherFixture.Body.Owner, ReactionMethod.Touch); } @@ -58,8 +60,8 @@ namespace Content.Server.Chemistry.EntitySystems // Set Move if (EntityManager.TryGetComponent(vapor.Owner, out PhysicsComponent? physics)) { - physics.LinearDamping = 0f; - physics.AngularDamping = 0f; + _physics.SetLinearDamping(physics, 0f); + _physics.SetAngularDamping(physics, 0f); _throwing.TryThrow(vapor.Owner, dir * speed, user: user, pushbackRatio: 50f); diff --git a/Content.Server/Climbing/ClimbSystem.cs b/Content.Server/Climbing/ClimbSystem.cs index b8b0ac2628..38f7ad8b30 100644 --- a/Content.Server/Climbing/ClimbSystem.cs +++ b/Content.Server/Climbing/ClimbSystem.cs @@ -44,6 +44,7 @@ public sealed class ClimbSystem : SharedClimbSystem [Dependency] private readonly InteractionSystem _interactionSystem = default!; [Dependency] private readonly StunSystem _stunSystem = default!; [Dependency] private readonly AudioSystem _audioSystem = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; private const string ClimbingFixtureName = "climb"; private const int ClimbingCollisionGroup = (int) (CollisionGroup.TableLayer | CollisionGroup.LowImpassable); @@ -162,7 +163,7 @@ public sealed class ClimbSystem : SharedClimbSystem if (!Resolve(uid, ref climbing, ref physics, ref fixtures, false)) return; - if (!ReplaceFixtures(climbing, physics, fixtures)) + if (!ReplaceFixtures(climbing, fixtures)) return; climbing.IsClimbing = true; @@ -202,8 +203,10 @@ public sealed class ClimbSystem : SharedClimbSystem /// Replaces the current fixtures with non-climbing collidable versions so that climb end can be detected /// /// Returns whether adding the new fixtures was successful - private bool ReplaceFixtures(ClimbingComponent climbingComp, PhysicsComponent physicsComp, FixturesComponent fixturesComp) + private bool ReplaceFixtures(ClimbingComponent climbingComp, FixturesComponent fixturesComp) { + var uid = climbingComp.Owner; + // Swap fixtures foreach (var (name, fixture) in fixturesComp.Fixtures) { @@ -213,13 +216,21 @@ public sealed class ClimbSystem : SharedClimbSystem continue; climbingComp.DisabledFixtureMasks.Add(fixture.ID, fixture.CollisionMask & ClimbingCollisionGroup); - fixture.CollisionMask &= ~ClimbingCollisionGroup; + _physics.SetCollisionMask(uid, fixture, fixture.CollisionMask & ~ClimbingCollisionGroup, fixturesComp); } - if (!_fixtureSystem.TryCreateFixture(physicsComp, - new Fixture(new PhysShapeCircle { Radius = 0.35f }, (int) CollisionGroup.None, ClimbingCollisionGroup, false) - {ID = ClimbingFixtureName}, manager: fixturesComp)) + if (!_fixtureSystem.TryCreateFixture( + uid, + new PhysShapeCircle(0.35f), + ClimbingFixtureName, + collisionLayer: (int) CollisionGroup.None, + collisionMask: ClimbingCollisionGroup, + hard: false, + manager: fixturesComp)) + { return false; + } + return true; } @@ -250,8 +261,11 @@ public sealed class ClimbSystem : SharedClimbSystem foreach (var (name, fixtureMask) in climbing.DisabledFixtureMasks) { if (!fixtures.Fixtures.TryGetValue(name, out var fixture)) + { continue; - fixture.CollisionMask |= fixtureMask; + } + + _physics.SetCollisionMask(uid, fixture, fixture.CollisionMask | fixtureMask, fixtures); } climbing.DisabledFixtureMasks.Clear(); @@ -397,16 +411,18 @@ public sealed class ClimbSystem : SharedClimbSystem // Since there are bodies with different masses: // mass * 10 seems enough to move entity // instead of launching cats like rockets against the walls with constant impulse value. - physics.ApplyLinearImpulse((to - from).Normalized * velocity * physics.Mass * 10); - physics.BodyType = BodyType.Dynamic; + _physics.ApplyLinearImpulse(uid, (to - from).Normalized * velocity * physics.Mass * 10, body: physics); + _physics.SetBodyType(uid, BodyType.Dynamic, body: physics); climbing.OwnerIsTransitioning = true; _actionBlockerSystem.UpdateCanMove(uid); // Transition back to KinematicController after BufferTime climbing.Owner.SpawnTimer((int) (ClimbingComponent.BufferTime * 1000), () => { - if (climbing.Deleted) return; - physics.BodyType = BodyType.KinematicController; + if (climbing.Deleted) + return; + + _physics.SetBodyType(uid, BodyType.KinematicController); climbing.OwnerIsTransitioning = false; _actionBlockerSystem.UpdateCanMove(uid); }); @@ -418,10 +434,13 @@ public sealed class ClimbSystem : SharedClimbSystem { if (!TryComp(uid, out var physicsComp) || !TryComp(uid, out var fixturesComp)) + { continue; + } + foreach (var fixture in fixtures) { - _fixtureSystem.DestroyFixture(physicsComp, fixture, true, fixturesComp); + _fixtureSystem.DestroyFixture(uid, fixture, body: physicsComp, manager: fixturesComp); } } diff --git a/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs index 1cfcbe7b6e..5ac8dd0c7b 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs @@ -1,4 +1,3 @@ -using System.Text; using Content.Server.Disposal.Unit.Components; using Content.Server.UserInterface; using Robust.Server.GameObjects; diff --git a/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs b/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs index d6aa84b9b3..aa8b7e5a87 100644 --- a/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs +++ b/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs @@ -5,6 +5,7 @@ using Content.Shared.Item; using Robust.Shared.Containers; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; namespace Content.Server.Disposal.Unit.Components { @@ -85,7 +86,7 @@ namespace Content.Server.Disposal.Unit.Components if (_entMan.TryGetComponent(entity, out PhysicsComponent? physics)) { - physics.CanCollide = false; + _entMan.System().SetCanCollide(entity, false, body: physics); } return true; diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs index 6f6df0c7ff..a0b4f5e826 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs @@ -67,7 +67,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems if (EntityManager.TryGetComponent(entity, out PhysicsComponent? physics)) { - _physicsSystem.WakeBody(entity, physics); + _physicsSystem.WakeBody(entity, body: physics); } } diff --git a/Content.Server/Doors/Systems/DoorSystem.cs b/Content.Server/Doors/Systems/DoorSystem.cs index b47e06f6a1..3b2fbf30f1 100644 --- a/Content.Server/Doors/Systems/DoorSystem.cs +++ b/Content.Server/Doors/Systems/DoorSystem.cs @@ -58,7 +58,9 @@ public sealed class DoorSystem : SharedDoorSystem args.Handled = true; } - protected override void SetCollidable(EntityUid uid, bool collidable, + protected override void SetCollidable( + EntityUid uid, + bool collidable, DoorComponent? door = null, PhysicsComponent? physics = null, OccluderComponent? occluder = null) diff --git a/Content.Server/Explosion/Components/TriggerOnProximityComponent.cs b/Content.Server/Explosion/Components/TriggerOnProximityComponent.cs index 8db3d327b4..97fff3d664 100644 --- a/Content.Server/Explosion/Components/TriggerOnProximityComponent.cs +++ b/Content.Server/Explosion/Components/TriggerOnProximityComponent.cs @@ -14,10 +14,10 @@ namespace Content.Server.Explosion.Components { public const string FixtureID = "trigger-on-proximity-fixture"; - public HashSet Colliding = new(); + public readonly HashSet Colliding = new(); [DataField("shape", required: true)] - public IPhysShape Shape { get; set; } = new PhysShapeCircle {Radius = 2}; + public IPhysShape Shape { get; set; } = new PhysShapeCircle(2f); /// /// How long the the proximity trigger animation plays for. diff --git a/Content.Server/Explosion/EntitySystems/TriggerSystem.Proximity.cs b/Content.Server/Explosion/EntitySystems/TriggerSystem.Proximity.cs index bbdc577d1f..2da099428b 100644 --- a/Content.Server/Explosion/EntitySystems/TriggerSystem.Proximity.cs +++ b/Content.Server/Explosion/EntitySystems/TriggerSystem.Proximity.cs @@ -57,13 +57,16 @@ public sealed partial class TriggerSystem SetProximityAppearance(uid, component); - if (!TryComp(uid, out var body)) return; + if (!TryComp(uid, out var body)) + return; - _fixtures.TryCreateFixture(body, new Fixture(body, component.Shape) - { + _fixtures.TryCreateFixture( + uid, + component.Shape, + TriggerOnProximityComponent.FixtureID, + hard: false, // TODO: Should probably have these settable via datafield but I'm lazy and it's a pain - CollisionLayer = (int) (CollisionGroup.MidImpassable | CollisionGroup.LowImpassable | CollisionGroup.HighImpassable), Hard = false, ID = TriggerOnProximityComponent.FixtureID - }); + collisionLayer: (int) (CollisionGroup.MidImpassable | CollisionGroup.LowImpassable | CollisionGroup.HighImpassable)); } private void OnProximityStartCollide(EntityUid uid, TriggerOnProximityComponent component, ref StartCollideEvent args) diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs index a38b973edf..8d0dbeae2f 100644 --- a/Content.Server/Ghost/GhostSystem.cs +++ b/Content.Server/Ghost/GhostSystem.cs @@ -20,6 +20,7 @@ using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.Console; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; using Robust.Shared.Timing; namespace Content.Server.Ghost @@ -36,6 +37,7 @@ namespace Content.Server.Ghost [Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly FollowerSystem _followerSystem = default!; [Dependency] private readonly MobStateSystem _mobState = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; public override void Initialize() { @@ -226,7 +228,7 @@ namespace Content.Server.Ghost xform.Coordinates = Transform(msg.Target).Coordinates; xform.AttachToGridOrMap(); if (TryComp(attached, out PhysicsComponent? physics)) - physics.LinearVelocity = Vector2.Zero; + _physics.SetLinearVelocity(attached, Vector2.Zero, body: physics); } private void DeleteEntity(EntityUid uid) diff --git a/Content.Server/ImmovableRod/ImmovableRodSystem.cs b/Content.Server/ImmovableRod/ImmovableRodSystem.cs index e684139682..ba41b28de7 100644 --- a/Content.Server/ImmovableRod/ImmovableRodSystem.cs +++ b/Content.Server/ImmovableRod/ImmovableRodSystem.cs @@ -7,6 +7,7 @@ using Robust.Shared.Audio; using Robust.Shared.Map; using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Events; +using Robust.Shared.Physics.Systems; using Robust.Shared.Player; using Robust.Shared.Random; @@ -19,6 +20,7 @@ public sealed class ImmovableRodSystem : EntitySystem [Dependency] private readonly BodySystem _bodySystem = default!; [Dependency] private readonly PopupSystem _popup = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; public override void Update(float frameTime) { @@ -29,6 +31,7 @@ public sealed class ImmovableRodSystem : EntitySystem { if (!rod.DestroyTiles) continue; + if (!_map.TryGetGrid(trans.GridUid, out var grid)) continue; @@ -49,9 +52,9 @@ public sealed class ImmovableRodSystem : EntitySystem { if (EntityManager.TryGetComponent(uid, out PhysicsComponent? phys)) { - phys.LinearDamping = 0f; - phys.Friction = 0f; - phys.BodyStatus = BodyStatus.InAir; + _physics.SetLinearDamping(phys, 0f); + _physics.SetFriction(phys, 0f); + _physics.SetBodyStatus(phys, BodyStatus.InAir); if (!component.RandomizeVelocity) return; @@ -63,7 +66,7 @@ public sealed class ImmovableRodSystem : EntitySystem _ => xform.WorldRotation.RotateVec(component.DirectionOverride.ToVec()) * _random.NextFloat(component.MinSpeed, component.MaxSpeed) }; - phys.ApplyLinearImpulse(vel); + _physics.ApplyLinearImpulse(uid, vel, body: phys); xform.LocalRotation = (vel - xform.WorldPosition).ToWorldAngle() + MathHelper.PiOver2; } } diff --git a/Content.Server/Magic/MagicSystem.cs b/Content.Server/Magic/MagicSystem.cs index 9628c2b6f6..52e8453220 100644 --- a/Content.Server/Magic/MagicSystem.cs +++ b/Content.Server/Magic/MagicSystem.cs @@ -311,7 +311,8 @@ public sealed class MagicSystem : EntitySystem var direction = Transform(ev.Target).MapPosition.Position - Transform(ev.Performer).MapPosition.Position; var impulseVector = direction * 10000; - Comp(ev.Target).ApplyLinearImpulse(impulseVector); + + _physics.ApplyLinearImpulse(ev.Target, impulseVector); if (!TryComp(ev.Target, out var body)) return; diff --git a/Content.Server/Maps/GridDraggingSystem.cs b/Content.Server/Maps/GridDraggingSystem.cs index 55c8fbea46..eef3e56849 100644 --- a/Content.Server/Maps/GridDraggingSystem.cs +++ b/Content.Server/Maps/GridDraggingSystem.cs @@ -4,6 +4,7 @@ using Robust.Server.Player; using Robust.Shared.Players; using Robust.Shared.Utility; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; namespace Content.Server.Maps; @@ -11,6 +12,7 @@ namespace Content.Server.Maps; public sealed class GridDraggingSystem : SharedGridDraggingSystem { [Dependency] private readonly IConGroupController _admin = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; private readonly HashSet _draggers = new(); @@ -54,8 +56,8 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem Deleted(ev.Grid)) return; var gridBody = Comp(ev.Grid); - gridBody.LinearVelocity = ev.LinearVelocity; - gridBody.AngularVelocity = 0f; + _physics.SetLinearVelocity(ev.Grid, ev.LinearVelocity, body: gridBody); + _physics.SetAngularVelocity(ev.Grid, 0f, body: gridBody); } private void OnRequestDrag(GridDragRequestPosition msg, EntitySessionEventArgs args) diff --git a/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs b/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs index 8acb78aed1..f87cc507fd 100644 --- a/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs +++ b/Content.Server/ParticleAccelerator/Components/ParticleProjectileComponent.cs @@ -3,6 +3,7 @@ using Content.Server.Singularity.Components; using Content.Shared.Projectiles; using Content.Shared.Singularity.Components; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; using Robust.Shared.Timing; namespace Content.Server.ParticleAccelerator.Components @@ -18,14 +19,16 @@ namespace Content.Server.ParticleAccelerator.Components { State = state; - if (!_entMan.TryGetComponent(Owner, out var physicsComponent)) + if (!_entMan.TryGetComponent(Owner, out var physicsComponent)) { Logger.Error("ParticleProjectile tried firing, but it was spawned without a CollidableComponent"); return; } - physicsComponent.BodyStatus = BodyStatus.InAir; - if (!_entMan.TryGetComponent(Owner, out var projectileComponent)) + var physics = _entMan.System(); + physics.SetBodyStatus(physicsComponent, BodyStatus.InAir); + + if (!_entMan.TryGetComponent(Owner, out var projectileComponent)) { Logger.Error("ParticleProjectile tried firing, but it was spawned without a ProjectileComponent"); return; @@ -33,7 +36,7 @@ namespace Content.Server.ParticleAccelerator.Components _entMan.EntitySysManager.GetEntitySystem().SetShooter(projectileComponent, firer); - if (!_entMan.TryGetComponent(Owner, out var singuloFoodComponent)) + if (!_entMan.TryGetComponent(Owner, out var singuloFoodComponent)) { Logger.Error("ParticleProjectile tried firing, but it was spawned without a SinguloFoodComponent"); return; @@ -54,7 +57,7 @@ namespace Content.Server.ParticleAccelerator.Components appearance.SetData(ParticleAcceleratorVisuals.VisualState, state); } - physicsComponent.LinearVelocity = angle.ToWorldVec() * 20f; + physics.SetLinearVelocity(Owner, angle.ToWorldVec() * 20f, body: physicsComponent); _entMan.GetComponent(Owner).LocalRotation = angle; Timer.Spawn(3000, () => _entMan.DeleteEntity(Owner)); diff --git a/Content.Server/Physics/Controllers/ConveyorController.cs b/Content.Server/Physics/Controllers/ConveyorController.cs index 71379f6fc7..7b480b2db1 100644 --- a/Content.Server/Physics/Controllers/ConveyorController.cs +++ b/Content.Server/Physics/Controllers/ConveyorController.cs @@ -77,12 +77,9 @@ namespace Content.Server.Physics.Controllers var shape = new PolygonShape(); shape.SetAsBox(0.55f, 0.55f); - _fixtures.TryCreateFixture(body, new Fixture(body, shape) - { - ID = ConveyorFixture, - CollisionLayer = (int) (CollisionGroup.LowImpassable | CollisionGroup.MidImpassable | CollisionGroup.Impassable), - Hard = false, - }); + _fixtures.TryCreateFixture(uid, shape, ConveyorFixture, hard: false, + collisionLayer: (int) (CollisionGroup.LowImpassable | CollisionGroup.MidImpassable | + CollisionGroup.Impassable), body: body); } } @@ -160,7 +157,7 @@ namespace Content.Server.Physics.Controllers continue; if (physics.BodyType != BodyType.Static) - _physics.WakeBody(physics); + _physics.WakeBody(entity, body: physics); } } } @@ -180,7 +177,7 @@ namespace Content.Server.Physics.Controllers if (!TryComp(uid, out var body)) return; - _fixtures.DestroyFixture(body, ConveyorFixture); + _fixtures.DestroyFixture(uid, ConveyorFixture, body: body); } public override void UpdateBeforeSolve(bool prediction, float frameTime) @@ -237,8 +234,9 @@ namespace Content.Server.Physics.Controllers transform.LocalPosition = localPos; // Force it awake for collisionwake reasons. - body.Awake = true; - body.SleepTime = 0f; + // TODO: Just use sleepallowed + _physics.SetAwake(entity, body, true); + _physics.SetSleepTime(body, 0f); } } diff --git a/Content.Server/Physics/Controllers/MoverController.cs b/Content.Server/Physics/Controllers/MoverController.cs index 8e41db304d..6098f8fcf4 100644 --- a/Content.Server/Physics/Controllers/MoverController.cs +++ b/Content.Server/Physics/Controllers/MoverController.cs @@ -8,6 +8,7 @@ using Content.Shared.Shuttles.Systems; using Robust.Server.GameObjects; using Robust.Shared.Map; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; using Robust.Shared.Player; namespace Content.Server.Physics.Controllers @@ -399,7 +400,7 @@ namespace Content.Server.Physics.Controllers impulse.Y = MathF.Max(impulse.Y, -shuttleVelocity.Y); } - PhysicsSystem.SetLinearVelocity(body, body.LinearVelocity + shuttleNorthAngle.RotateVec(impulse)); + PhysicsSystem.SetLinearVelocity(shuttle.Owner, body.LinearVelocity + shuttleNorthAngle.RotateVec(impulse), body: body); } } else @@ -432,7 +433,7 @@ namespace Content.Server.Physics.Controllers else if (body.AngularVelocity > 0f && body.AngularVelocity + accelSpeed < 0f) accelSpeed = -body.AngularVelocity; - PhysicsSystem.SetAngularVelocity(body, body.AngularVelocity + accelSpeed); + PhysicsSystem.SetAngularVelocity(shuttle.Owner, body.AngularVelocity + accelSpeed, body: body); _thruster.SetAngularThrust(shuttle, true); } } @@ -440,19 +441,19 @@ namespace Content.Server.Physics.Controllers if (linearInput.Length.Equals(0f)) { - body.SleepingAllowed = true; + PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, true); if (brakeInput.Equals(0f)) _thruster.DisableLinearThrusters(shuttle); if (body.LinearVelocity.Length < 0.08) { - body.LinearVelocity = Vector2.Zero; + PhysicsSystem.SetLinearVelocity(shuttle.Owner, Vector2.Zero, body: body); } } else { - body.SleepingAllowed = false; + PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, false); var angle = linearInput.ToWorldAngle(); var linearDir = angle.GetDir(); var dockFlag = linearDir.AsFlag(); @@ -519,23 +520,23 @@ namespace Content.Server.Physics.Controllers { var accelSpeed = totalForce.Length * frameTime; accelSpeed = MathF.Min(accelSpeed, addSpeed); - body.ApplyLinearImpulse(shuttleNorthAngle.RotateVec(totalForce.Normalized * accelSpeed)); + PhysicsSystem.ApplyLinearImpulse(shuttle.Owner, shuttleNorthAngle.RotateVec(totalForce.Normalized * accelSpeed), body: body); } } if (MathHelper.CloseTo(angularInput, 0f)) { _thruster.SetAngularThrust(shuttle, false); - body.SleepingAllowed = true; + PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, true); if (Math.Abs(body.AngularVelocity) < 0.01f) { - body.AngularVelocity = 0f; + PhysicsSystem.SetAngularVelocity(shuttle.Owner, 0f, body: body); } } else { - body.SleepingAllowed = false; + PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, false); var impulse = shuttle.AngularThrust * -angularInput; var wishSpeed = MathF.PI; @@ -554,7 +555,7 @@ namespace Content.Server.Physics.Controllers else accelSpeed = MathF.Min(accelSpeed, addSpeed); - PhysicsSystem.SetAngularVelocity(body, body.AngularVelocity + accelSpeed); + PhysicsSystem.SetAngularVelocity(shuttle.Owner, body.AngularVelocity + accelSpeed, body: body); _thruster.SetAngularThrust(shuttle, true); } } diff --git a/Content.Server/Physics/Controllers/PullController.cs b/Content.Server/Physics/Controllers/PullController.cs index 38e922fac5..54c6ad8f31 100644 --- a/Content.Server/Physics/Controllers/PullController.cs +++ b/Content.Server/Physics/Controllers/PullController.cs @@ -73,7 +73,7 @@ namespace Content.Server.Physics.Controllers return; if (TryComp(pullable.Owner, out var physics)) - physics.WakeBody(); + PhysicsSystem.WakeBody(pullable.Owner, body: physics); _pullableSystem.StopMoveTo(pullable); } @@ -164,9 +164,9 @@ namespace Content.Server.Physics.Controllers var diff = movingPosition - ownerPosition; var diffLength = diff.Length; - if ((diffLength < MaximumSettleDistance) && (physics.LinearVelocity.Length < MaximumSettleVelocity)) + if (diffLength < MaximumSettleDistance && (physics.LinearVelocity.Length < MaximumSettleVelocity)) { - physics.LinearVelocity = Vector2.Zero; + PhysicsSystem.SetLinearVelocity(pullable.Owner, Vector2.Zero, body: physics); _pullableSystem.StopMoveTo(pullable); continue; } @@ -183,9 +183,11 @@ namespace Content.Server.Physics.Controllers var scaling = (SettleShutdownDistance - diffLength) / SettleShutdownDistance; accel -= physics.LinearVelocity * SettleShutdownMultiplier * scaling; } - physics.WakeBody(); + + PhysicsSystem.WakeBody(pullable.Owner, body: physics); + var impulse = accel * physics.Mass * frameTime; - physics.ApplyLinearImpulse(impulse); + PhysicsSystem.ApplyLinearImpulse(pullable.Owner, impulse, body: physics); } } } diff --git a/Content.Server/Physics/Controllers/RandomWalkController.cs b/Content.Server/Physics/Controllers/RandomWalkController.cs index 13178805a1..9cd717f811 100644 --- a/Content.Server/Physics/Controllers/RandomWalkController.cs +++ b/Content.Server/Physics/Controllers/RandomWalkController.cs @@ -69,8 +69,8 @@ internal sealed class RandomWalkController : VirtualController var pushAngle = _random.NextAngle(); var pushStrength = _random.NextFloat(randomWalk.MinSpeed, randomWalk.MaxSpeed); - _physics.SetLinearVelocity(physics, physics.LinearVelocity * randomWalk.AccumulatorRatio); - _physics.ApplyLinearImpulse(physics, pushAngle.ToVec() * (pushStrength * physics.Mass)); + _physics.SetLinearVelocity(uid, physics.LinearVelocity * randomWalk.AccumulatorRatio, body: physics); + _physics.ApplyLinearImpulse(uid, pushAngle.ToVec() * (pushStrength * physics.Mass), body: physics); } /// diff --git a/Content.Server/Shuttles/Systems/DockingSystem.cs b/Content.Server/Shuttles/Systems/DockingSystem.cs index 534749e112..ecf3fd0ec5 100644 --- a/Content.Server/Shuttles/Systems/DockingSystem.cs +++ b/Content.Server/Shuttles/Systems/DockingSystem.cs @@ -20,12 +20,13 @@ namespace Content.Server.Shuttles.Systems public sealed partial class DockingSystem : EntitySystem { [Dependency] private readonly IMapManager _mapManager = default!; - [Dependency] private readonly FixtureSystem _fixtureSystem = default!; - [Dependency] private readonly SharedJointSystem _jointSystem = default!; - [Dependency] private readonly SharedTransformSystem _transformSystem = default!; - [Dependency] private readonly ShuttleConsoleSystem _console = default!; [Dependency] private readonly DoorSystem _doorSystem = default!; + [Dependency] private readonly FixtureSystem _fixtureSystem = default!; [Dependency] private readonly PathfindingSystem _pathfinding = default!; + [Dependency] private readonly ShuttleConsoleSystem _console = default!; + [Dependency] private readonly SharedJointSystem _jointSystem = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; + [Dependency] private readonly SharedTransformSystem _transformSystem = default!; private ISawmill _sawmill = default!; private const string DockingFixture = "docking"; @@ -70,10 +71,13 @@ namespace Content.Server.Shuttles.Systems // Assume the docking port itself (and its body) is valid if (!_mapManager.TryGetGrid(dockingXform.GridUid, out var grid) || - !HasComp(grid.Owner)) return null; + !HasComp(grid.Owner)) + { + return null; + } - var transform = body.GetTransform(); - var dockingFixture = _fixtureSystem.GetFixtureOrNull(body, DockingFixture); + var transform = _physics.GetPhysicsTransform(body.Owner, dockingXform); + var dockingFixture = _fixtureSystem.GetFixtureOrNull(body.Owner, DockingFixture); if (dockingFixture == null) return null; @@ -99,13 +103,13 @@ namespace Content.Server.Shuttles.Systems { if (!TryComp(ent, out DockingComponent? otherDocking) || !otherDocking.Enabled || - !TryComp(ent, out PhysicsComponent? otherBody)) + !TryComp(ent, out FixturesComponent? otherBody)) { continue; } - var otherTransform = otherBody.GetTransform(); - var otherDockingFixture = _fixtureSystem.GetFixtureOrNull(otherBody, DockingFixture); + var otherTransform = _physics.GetPhysicsTransform(ent); + var otherDockingFixture = _fixtureSystem.GetFixtureOrNull(ent, DockingFixture, manager: otherBody); if (otherDockingFixture == null) { @@ -251,7 +255,7 @@ namespace Content.Server.Shuttles.Systems return; } - _fixtureSystem.DestroyFixture(physicsComponent, DockingFixture); + _fixtureSystem.DestroyFixture(uid, DockingFixture, body: physicsComponent); } private void EnableDocking(EntityUid uid, DockingComponent component) @@ -264,24 +268,12 @@ namespace Content.Server.Shuttles.Systems component.Enabled = true; - // TODO: WTF IS THIS GARBAGE - var shape = new PhysShapeCircle - { - // Want half of the unit vector - Position = new Vector2(0f, -0.5f), - Radius = DockingRadius - }; + var shape = new PhysShapeCircle(DockingRadius, new Vector2(0f, -0.5f)); // Listen it makes intersection tests easier; you can probably dump this but it requires a bunch more boilerplate - var fixture = new Fixture(physicsComponent, shape) - { - ID = DockingFixture, - Hard = false, - }; - // TODO: I want this to ideally be 2 fixtures to force them to have some level of alignment buuuttt // I also need collisionmanager for that yet again so they get dis. - _fixtureSystem.TryCreateFixture(physicsComponent, fixture); + _fixtureSystem.TryCreateFixture(uid, shape, DockingFixture, hard: false); } /// @@ -407,16 +399,16 @@ namespace Content.Server.Shuttles.Systems return false; } - var fixtureA = _fixtureSystem.GetFixtureOrNull(bodyA, DockingFixture); - var fixtureB = _fixtureSystem.GetFixtureOrNull(bodyB, DockingFixture); + var fixtureA = _fixtureSystem.GetFixtureOrNull(bodyA.Owner, DockingFixture); + var fixtureB = _fixtureSystem.GetFixtureOrNull(bodyB.Owner, DockingFixture); if (fixtureA == null || fixtureB == null) { return false; } - var transformA = bodyA.GetTransform(); - var transformB = bodyB.GetTransform(); + var transformA = _physics.GetPhysicsTransform(dockA.Owner); + var transformB = _physics.GetPhysicsTransform(dockB.Owner); var intersect = false; for (var i = 0; i < fixtureA.Shape.ChildCount; i++) diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs index 7015e39cad..5be20d2238 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs @@ -234,10 +234,10 @@ public sealed partial class ShuttleSystem if (TryComp(comp.Owner, out body)) { - body.LinearVelocity = new Vector2(0f, 20f); - body.AngularVelocity = 0f; - body.LinearDamping = 0f; - body.AngularDamping = 0f; + _physics.SetLinearVelocity(comp.Owner, new Vector2(0f, 20f), body: body); + _physics.SetAngularVelocity(comp.Owner, 0f, body: body); + _physics.SetLinearDamping(body, 0f); + _physics.SetAngularDamping(body, 0f); } if (comp.TravelSound != null) @@ -272,10 +272,10 @@ public sealed partial class ShuttleSystem if (TryComp(comp.Owner, out body)) { - body.LinearVelocity = Vector2.Zero; - body.AngularVelocity = 0f; - body.LinearDamping = ShuttleLinearDamping; - body.AngularDamping = ShuttleAngularDamping; + _physics.SetLinearVelocity(comp.Owner, Vector2.Zero, body: body); + _physics.SetAngularVelocity(comp.Owner, 0f, body: body); + _physics.SetLinearDamping(body, ShuttleLinearDamping); + _physics.SetAngularDamping(body, ShuttleAngularDamping); } TryComp(comp.Owner, out shuttle); @@ -521,8 +521,8 @@ public sealed partial class ShuttleSystem if (TryComp(component.Owner, out var shuttleBody)) { - shuttleBody.LinearVelocity = Vector2.Zero; - shuttleBody.AngularVelocity = 0f; + _physics.SetLinearVelocity(component.Owner, Vector2.Zero, body: shuttleBody); + _physics.SetAngularVelocity(component.Owner, 0f, body: shuttleBody); } xform.Coordinates = new EntityCoordinates(targetXform.MapUid.Value, spawnPos); diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.cs index 080da027c1..1673058bb7 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.cs @@ -85,15 +85,16 @@ namespace Content.Server.Shuttles.Systems // Look this is jank but it's a placeholder until we design it. if (args.NewFixtures.Count == 0) return; - var manager = Comp(args.NewFixtures[0].Body.Owner); + var uid = args.NewFixtures[0].Body.Owner; + var manager = Comp(uid); foreach (var fixture in args.NewFixtures) { - _physics.SetDensity(fixture, TileMassMultiplier, manager, false); - _fixtures.SetRestitution(fixture, 0.1f, manager, false); + _physics.SetDensity(uid, fixture, TileMassMultiplier, false, manager); + _fixtures.SetRestitution(uid, fixture, 0.1f, false, manager); } - _fixtures.FixtureUpdate(manager, args.NewFixtures[0].Body); + _fixtures.FixtureUpdate(uid, manager: manager); } private void OnGridInit(GridInitializeEvent ev) @@ -118,11 +119,11 @@ namespace Content.Server.Shuttles.Systems if (component.Enabled) { - Enable(physicsComponent); + Enable(uid, physicsComponent); } } - public void Toggle(ShuttleComponent component) + public void Toggle(EntityUid uid, ShuttleComponent component) { if (!EntityManager.TryGetComponent(component.Owner, out PhysicsComponent? physicsComponent)) return; @@ -130,28 +131,32 @@ namespace Content.Server.Shuttles.Systems if (component.Enabled) { - Enable(physicsComponent); + Enable(uid, physicsComponent); } else { - Disable(physicsComponent); + Disable(uid, physicsComponent); } } - private void Enable(PhysicsComponent component) + private void Enable(EntityUid uid, PhysicsComponent component) { - component.BodyType = BodyType.Dynamic; - component.BodyStatus = BodyStatus.InAir; - component.FixedRotation = false; - component.LinearDamping = ShuttleLinearDamping; - component.AngularDamping = ShuttleAngularDamping; + FixturesComponent? manager = null; + + _physics.SetBodyType(uid, BodyType.Dynamic, manager: manager, body: component); + _physics.SetBodyStatus(component, BodyStatus.InAir); + _physics.SetFixedRotation(uid, false, manager: manager, body: component); + _physics.SetLinearDamping(component, ShuttleLinearDamping); + _physics.SetAngularDamping(component, ShuttleAngularDamping); } - private void Disable(PhysicsComponent component) + private void Disable(EntityUid uid, PhysicsComponent component) { - component.BodyType = BodyType.Static; - component.BodyStatus = BodyStatus.OnGround; - component.FixedRotation = true; + FixturesComponent? manager = null; + + _physics.SetBodyType(uid, BodyType.Static, manager: manager, body: component); + _physics.SetBodyStatus(component, BodyStatus.OnGround); + _physics.SetFixedRotation(uid, true, manager: manager, body: component); } private void OnShuttleShutdown(EntityUid uid, ShuttleComponent component, ComponentShutdown args) @@ -164,7 +169,7 @@ namespace Content.Server.Shuttles.Systems return; } - Disable(physicsComponent); + Disable(uid, physicsComponent); } } } diff --git a/Content.Server/Shuttles/Systems/ThrusterSystem.cs b/Content.Server/Shuttles/Systems/ThrusterSystem.cs index 5014c97814..109f554f9c 100644 --- a/Content.Server/Shuttles/Systems/ThrusterSystem.cs +++ b/Content.Server/Shuttles/Systems/ThrusterSystem.cs @@ -262,17 +262,8 @@ namespace Content.Server.Shuttles.Systems component.BurnPoly.Count > 0) { var shape = new PolygonShape(); - shape.SetVertices(component.BurnPoly); - - var fixture = new Fixture(physicsComponent, shape) - { - ID = BurnFixture, - Hard = false, - CollisionLayer = (int) CollisionGroup.FullTileMask - }; - - _fixtureSystem.TryCreateFixture(physicsComponent, fixture); + _fixtureSystem.TryCreateFixture(uid, shape, BurnFixture, hard: false, collisionLayer: (int) CollisionGroup.FullTileMask); } break; @@ -352,7 +343,7 @@ namespace Content.Server.Shuttles.Systems if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent)) { - _fixtureSystem.DestroyFixture(physicsComponent, BurnFixture); + _fixtureSystem.DestroyFixture(uid, BurnFixture, body: physicsComponent); } _activeThrusters.Remove(component); diff --git a/Content.Server/Singularity/EntitySystems/GravityWellSystem.cs b/Content.Server/Singularity/EntitySystems/GravityWellSystem.cs index 104ae38abd..55caba994b 100644 --- a/Content.Server/Singularity/EntitySystems/GravityWellSystem.cs +++ b/Content.Server/Singularity/EntitySystems/GravityWellSystem.cs @@ -183,9 +183,11 @@ public sealed class GravityWellSystem : SharedGravityWellSystem var minRange2 = MathF.Max(minRange * minRange, MinGravPulseRange); // Cache square value for speed. Also apply a sane minimum value to the minimum value so that div/0s don't happen. foreach(var entity in _lookup.GetEntitiesInRange(mapPos.MapId, epicenter, maxRange, flags: LookupFlags.Dynamic | LookupFlags.Sundries)) { - if(!TryComp(entity, out var physics) - || physics.BodyType == BodyType.Static) + if (!TryComp(entity, out var physics) + || physics.BodyType == BodyType.Static) + { continue; + } if(!CanGravPulseAffect(entity)) continue; @@ -196,7 +198,7 @@ public sealed class GravityWellSystem : SharedGravityWellSystem continue; var scaling = (1f / distance2) * physics.Mass; // TODO: Variable falloff gradiants. - _physics.ApplyLinearImpulse(physics, (displacement * baseMatrixDeltaV) * scaling); + _physics.ApplyLinearImpulse(entity, (displacement * baseMatrixDeltaV) * scaling, body: physics); } } diff --git a/Content.Server/StationEvents/Events/MeteorSwarm.cs b/Content.Server/StationEvents/Events/MeteorSwarm.cs index 042b32991f..aabc9ba2bc 100644 --- a/Content.Server/StationEvents/Events/MeteorSwarm.cs +++ b/Content.Server/StationEvents/Events/MeteorSwarm.cs @@ -2,11 +2,14 @@ using Content.Server.GameTicking; using Content.Shared.Spawners.Components; using Robust.Shared.Map; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; namespace Content.Server.StationEvents.Events { public sealed class MeteorSwarm : StationEventSystem { + [Dependency] private readonly SharedPhysicsSystem _physics = default!; + public override string Prototype => "MeteorSwarm"; private float _cooldown; @@ -70,12 +73,7 @@ namespace Content.Server.StationEvents.Events foreach (var grid in MapManager.GetAllMapGrids(mapId)) { - if (!TryComp(grid.Owner, out var gridBody)) - { - continue; - } - - var aabb = gridBody.GetWorldAABB(); + var aabb = _physics.GetWorldAABB(grid.Owner); playableArea = playableArea?.Union(aabb) ?? aabb; } @@ -97,15 +95,15 @@ namespace Content.Server.StationEvents.Events var spawnPosition = new MapCoordinates(center + offset, mapId); var meteor = EntityManager.SpawnEntity("MeteorLarge", spawnPosition); var physics = EntityManager.GetComponent(meteor); - physics.BodyStatus = BodyStatus.InAir; - physics.LinearDamping = 0f; - physics.AngularDamping = 0f; - physics.ApplyLinearImpulse(-offset.Normalized * MeteorVelocity * physics.Mass); - physics.ApplyAngularImpulse( - // Get a random angular velocity. - physics.Mass * ((MaxAngularVelocity - MinAngularVelocity) * RobustRandom.NextFloat() + - MinAngularVelocity)); - // TODO: God this disgusts me but projectile needs a refactor. + _physics.SetBodyStatus(physics, BodyStatus.InAir); + _physics.SetLinearDamping(physics, 0f); + _physics.SetAngularDamping(physics, 0f); + _physics.ApplyLinearImpulse(meteor, -offset.Normalized * MeteorVelocity * physics.Mass, body: physics); + _physics.ApplyAngularImpulse( + meteor, + physics.Mass * ((MaxAngularVelocity - MinAngularVelocity) * RobustRandom.NextFloat() + MinAngularVelocity), + body: physics); + EnsureComp(meteor).Lifetime = 120f; } } diff --git a/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs b/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs index dc24f7ea35..7deb015cc9 100644 --- a/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs @@ -19,6 +19,7 @@ using Robust.Shared.Containers; using Robust.Shared.Map; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; using Robust.Shared.Player; namespace Content.Server.Storage.EntitySystems; @@ -34,6 +35,7 @@ public sealed class EntityStorageSystem : EntitySystem [Dependency] private readonly PlaceableSurfaceSystem _placeableSurface = default!; [Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly AtmosphereSystem _atmos = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly IMapManager _map = default!; public const string ContainerName = "entity_storage"; @@ -323,7 +325,9 @@ public sealed class EntityStorageSystem : EntitySystem if (TryComp(toAdd, out var phys)) { - if (component.MaxSize < phys.GetWorldAABB().Size.X || component.MaxSize < phys.GetWorldAABB().Size.Y) + var aabb = _physics.GetWorldAABB(toAdd, body: phys); + + if (component.MaxSize < aabb.Size.X || component.MaxSize < aabb.Size.Y) return false; } @@ -387,11 +391,11 @@ public sealed class EntityStorageSystem : EntitySystem if (component.Open) { component.RemovedMasks = fixture.CollisionLayer & component.MasksToRemove; - fixture.CollisionLayer &= ~component.MasksToRemove; + _physics.SetCollisionLayer(uid, fixture, fixture.CollisionLayer & ~component.MasksToRemove, manager: fixtures); } else { - fixture.CollisionLayer |= component.RemovedMasks; + _physics.SetCollisionLayer(uid, fixture, fixture.CollisionLayer | component.RemovedMasks, manager: fixtures); component.RemovedMasks = 0; } } diff --git a/Content.Server/Temperature/Components/TemperatureComponent.cs b/Content.Server/Temperature/Components/TemperatureComponent.cs index df81387d08..60c6b8bacf 100644 --- a/Content.Server/Temperature/Components/TemperatureComponent.cs +++ b/Content.Server/Temperature/Components/TemperatureComponent.cs @@ -52,7 +52,7 @@ namespace Content.Server.Temperature.Components { get { - if (IoCManager.Resolve().TryGetComponent(Owner, out var physics) && physics.FixturesMass != 0) + if (IoCManager.Resolve().TryGetComponent(Owner, out var physics) && physics.FixturesMass != 0) { return SpecificHeat * physics.FixturesMass; } diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs index 2c61065ba7..c6d1cc41cb 100644 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs @@ -243,12 +243,12 @@ public sealed partial class GunSystem : SharedGunSystem public void ShootProjectile(EntityUid uid, Vector2 direction, Vector2 gunVelocity, EntityUid? user = null, float speed = 20f) { var physics = EnsureComp(uid); - physics.BodyStatus = BodyStatus.InAir; + Physics.SetBodyStatus(physics, BodyStatus.InAir); var targetMapVelocity = gunVelocity + direction.Normalized * speed; var currentMapVelocity = Physics.GetMapLinearVelocity(uid, physics); var finalLinear = physics.LinearVelocity + targetMapVelocity - currentMapVelocity; - Physics.SetLinearVelocity(physics, finalLinear); + Physics.SetLinearVelocity(uid, finalLinear, body: physics); if (user != null) { diff --git a/Content.Server/Weapons/Ranged/Systems/TetherGunSystem.cs b/Content.Server/Weapons/Ranged/Systems/TetherGunSystem.cs index 5b9b73fdca..d81f571a32 100644 --- a/Content.Server/Weapons/Ranged/Systems/TetherGunSystem.cs +++ b/Content.Server/Weapons/Ranged/Systems/TetherGunSystem.cs @@ -111,12 +111,12 @@ public sealed class TetherGunSystem : SharedTetherGunSystem if (TryComp(msg.Entity, out var body)) { - body.BodyStatus = BodyStatus.InAir; + _physics.SetBodyStatus(body, BodyStatus.InAir); } - _physics.WakeBody(bodyA); - _physics.WakeBody(bodyB); - var joint = _joints.CreateMouseJoint(bodyA.Owner, bodyB.Owner, id: JointId); + _physics.WakeBody(tether, body: bodyA); + _physics.WakeBody(msg.Entity, body: bodyB); + var joint = _joints.CreateMouseJoint(tether, msg.Entity, id: JointId); SharedJointSystem.LinearStiffness(5f, 0.7f, bodyA.Mass, bodyB.Mass, out var stiffness, out var damping); joint.Stiffness = stiffness; @@ -147,8 +147,9 @@ public sealed class TetherGunSystem : SharedTetherGunSystem { Timer.Spawn(1000, () => { - if (Deleted(body.Owner)) return; - body.BodyStatus = BodyStatus.OnGround; + if (Deleted(weh.Entity)) return; + + _physics.SetBodyStatus(body, BodyStatus.OnGround); }); } @@ -186,7 +187,7 @@ public sealed class TetherGunSystem : SharedTetherGunSystem // Force it awake, always if (bodyQuery.TryGetComponent(entity.Entity, out var body)) { - _physics.WakeBody(body); + _physics.WakeBody(entity.Entity, body: body); } } diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/PhasingArtifactSystem.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/PhasingArtifactSystem.cs index 4615b3fb85..d07da6aa8f 100644 --- a/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/PhasingArtifactSystem.cs +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/PhasingArtifactSystem.cs @@ -25,12 +25,12 @@ public sealed class PhasingArtifactSystem : EntitySystem private void OnActivate(EntityUid uid, PhasingArtifactComponent component, ArtifactActivatedEvent args) { - if (!TryComp(uid, out var fixtures) || !TryComp(uid, out var phys)) + if (!TryComp(uid, out var fixtures)) return; - foreach (var (_, fixture) in fixtures.Fixtures) + foreach (var fixture in fixtures.Fixtures.Values) { - _physics.SetHard(fixture, false, fixtures); + _physics.SetHard(uid, fixture, false, fixtures); } } } diff --git a/Content.Shared/Blocking/BlockingSystem.cs b/Content.Shared/Blocking/BlockingSystem.cs index 923c75e02d..1e09524883 100644 --- a/Content.Shared/Blocking/BlockingSystem.cs +++ b/Content.Shared/Blocking/BlockingSystem.cs @@ -186,14 +186,12 @@ public sealed partial class BlockingSystem : EntitySystem if (TryComp(user, out var physicsComponent)) { - var fixture = new Fixture(physicsComponent, component.Shape) - { - ID = BlockingComponent.BlockFixtureID, - Hard = true, - CollisionLayer = (int) CollisionGroup.WallLayer - }; - - _fixtureSystem.TryCreateFixture(physicsComponent, fixture); + _fixtureSystem.TryCreateFixture(user, + component.Shape, + BlockingComponent.BlockFixtureID, + hard: true, + collisionLayer: (int) CollisionGroup.WallLayer, + body: physicsComponent); } component.IsBlocking = true; @@ -243,8 +241,8 @@ public sealed partial class BlockingSystem : EntitySystem _transformSystem.Unanchor(xform); _actionsSystem.SetToggled(component.BlockingToggleAction, false); - _fixtureSystem.DestroyFixture(physicsComponent, BlockingComponent.BlockFixtureID); - _physics.SetBodyType(physicsComponent, blockingUserComponent.OriginalBodyType); + _fixtureSystem.DestroyFixture(user, BlockingComponent.BlockFixtureID, body: physicsComponent); + _physics.SetBodyType(user, blockingUserComponent.OriginalBodyType, body: physicsComponent); _popupSystem.PopupEntity(msgUser, user, user); _popupSystem.PopupEntity(msgOther, user, Filter.PvsExcept(user), true); } diff --git a/Content.Shared/Blocking/Components/BlockingComponent.cs b/Content.Shared/Blocking/Components/BlockingComponent.cs index fc2d4e3923..2468becf84 100644 --- a/Content.Shared/Blocking/Components/BlockingComponent.cs +++ b/Content.Shared/Blocking/Components/BlockingComponent.cs @@ -31,9 +31,8 @@ public sealed class BlockingComponent : Component /// /// The shape of the blocking fixture that will be dynamically spawned /// - [ViewVariables(VVAccess.ReadWrite)] - [DataField("shape")] - public IPhysShape Shape = new PhysShapeCircle {Radius = 0.5F}; + [ViewVariables(VVAccess.ReadWrite)] [DataField("shape")] + public IPhysShape Shape = new PhysShapeCircle(0.5f); /// /// The damage modifer to use while passively blocking diff --git a/Content.Shared/Doors/Systems/SharedDoorSystem.cs b/Content.Shared/Doors/Systems/SharedDoorSystem.cs index 51eb160e20..c8db06b792 100644 --- a/Content.Shared/Doors/Systems/SharedDoorSystem.cs +++ b/Content.Shared/Doors/Systems/SharedDoorSystem.cs @@ -381,7 +381,10 @@ public abstract class SharedDoorSystem : EntitySystem #endregion #region Collisions - protected virtual void SetCollidable(EntityUid uid, bool collidable, + + protected virtual void SetCollidable( + EntityUid uid, + bool collidable, DoorComponent? door = null, PhysicsComponent? physics = null, OccluderComponent? occluder = null) @@ -390,13 +393,13 @@ public abstract class SharedDoorSystem : EntitySystem return; if (Resolve(uid, ref physics, false)) - PhysicsSystem.SetCanCollide(physics, collidable); + PhysicsSystem.SetCanCollide(uid, collidable, body: physics); if (!collidable) door.CurrentlyCrushing.Clear(); if (door.Occludes) - _occluder.SetEnabled(uid, collidable); + _occluder.SetEnabled(uid, collidable, occluder); } /// diff --git a/Content.Shared/Explosion/SharedTriggerOnProximityComponent.cs b/Content.Shared/Explosion/SharedTriggerOnProximityComponent.cs index f3af003bf7..72c17e8936 100644 --- a/Content.Shared/Explosion/SharedTriggerOnProximityComponent.cs +++ b/Content.Shared/Explosion/SharedTriggerOnProximityComponent.cs @@ -1,5 +1,8 @@ +using Robust.Shared.GameStates; + namespace Content.Shared.Explosion; +[NetworkedComponent] public abstract class SharedTriggerOnProximityComponent : Component { diff --git a/Content.Shared/Friction/TileFrictionController.cs b/Content.Shared/Friction/TileFrictionController.cs index 9b82e12fc6..f3f760f0a0 100644 --- a/Content.Shared/Friction/TileFrictionController.cs +++ b/Content.Shared/Friction/TileFrictionController.cs @@ -78,6 +78,8 @@ namespace Content.Shared.Friction foreach (var body in mapComponent.AwakeBodies) { + var uid = body.Owner; + // Only apply friction when it's not a mob (or the mob doesn't have control) if (prediction && !body.Predict || body.BodyStatus == BodyStatus.InAir || @@ -86,46 +88,45 @@ namespace Content.Shared.Friction continue; } - if (body.LinearVelocity.Equals(Vector2.Zero) && body.AngularVelocity.Equals(0f)) continue; + if (body.LinearVelocity.Equals(Vector2.Zero) && body.AngularVelocity.Equals(0f)) + continue; - DebugTools.Assert(!Deleted(body.Owner)); - - if (!xformQuery.TryGetComponent(body.Owner, out var xform)) + if (!xformQuery.TryGetComponent(uid, out var xform)) { Logger.ErrorS("physics", $"Unable to get transform for {ToPrettyString(body.Owner)} in tilefrictioncontroller"); continue; } - var surfaceFriction = GetTileFriction(body, xform); + var surfaceFriction = GetTileFriction(uid, body, xform); var bodyModifier = 1f; - if (frictionQuery.TryGetComponent(body.Owner, out var frictionComp)) + if (frictionQuery.TryGetComponent(uid, out var frictionComp)) { bodyModifier = frictionComp.Modifier; } var ev = new TileFrictionEvent(bodyModifier); - RaiseLocalEvent(body.Owner, ref ev); + RaiseLocalEvent(uid, ref ev); bodyModifier = ev.Modifier; // If we're sandwiched between 2 pullers reduce friction // Might be better to make this dynamic and check how many are in the pull chain? // Either way should be much faster for now. - if (pullerQuery.TryGetComponent(body.Owner, out var puller) && puller.Pulling != null && - pullableQuery.TryGetComponent(body.Owner, out var pullable) && pullable.BeingPulled) + if (pullerQuery.TryGetComponent(uid, out var puller) && puller.Pulling != null && + pullableQuery.TryGetComponent(uid, out var pullable) && pullable.BeingPulled) { bodyModifier *= 0.2f; } var friction = _frictionModifier * surfaceFriction * bodyModifier; - ReduceLinearVelocity(prediction, body, friction, frameTime); - ReduceAngularVelocity(prediction, body, friction, frameTime); + ReduceLinearVelocity(uid, prediction, body, friction, frameTime); + ReduceAngularVelocity(uid, prediction, body, friction, frameTime); } } - private void ReduceLinearVelocity(bool prediction, PhysicsComponent body, float friction, float frameTime) + private void ReduceLinearVelocity(EntityUid uid, bool prediction, PhysicsComponent body, float friction, float frameTime) { var speed = body.LinearVelocity.Length; @@ -153,10 +154,10 @@ namespace Content.Shared.Friction var newSpeed = MathF.Max(0.0f, speed - drop); newSpeed /= speed; - _physics.SetLinearVelocity(body, body.LinearVelocity * newSpeed); + _physics.SetLinearVelocity(uid, body.LinearVelocity * newSpeed, body: body); } - private void ReduceAngularVelocity(bool prediction, PhysicsComponent body, float friction, float frameTime) + private void ReduceAngularVelocity(EntityUid uid, bool prediction, PhysicsComponent body, float friction, float frameTime) { var speed = MathF.Abs(body.AngularVelocity); @@ -184,14 +185,14 @@ namespace Content.Shared.Friction var newSpeed = MathF.Max(0.0f, speed - drop); newSpeed /= speed; - _physics.SetAngularVelocity(body, body.AngularVelocity * newSpeed); + _physics.SetAngularVelocity(uid, body.AngularVelocity * newSpeed, body: body); } [Pure] - private float GetTileFriction(PhysicsComponent body, TransformComponent xform) + private float GetTileFriction(EntityUid uid, PhysicsComponent body, TransformComponent xform) { // TODO: Make IsWeightless event-based; we already have grid traversals tracked so just raise events - if (_gravity.IsWeightless(body.Owner, body, xform)) + if (_gravity.IsWeightless(uid, body, xform)) return 0.0f; if (!xform.Coordinates.IsValid(EntityManager)) return 0.0f; @@ -201,7 +202,8 @@ namespace Content.Shared.Friction var tile = grid.GetTileRef(xform.Coordinates); // If it's a map but on an empty tile then just assume it has gravity. - if (tile.Tile.IsEmpty && HasComp(xform.GridUid) && + if (tile.Tile.IsEmpty && + HasComp(xform.GridUid) && (!TryComp(xform.GridUid, out var gravity) || gravity.Enabled)) { return DefaultFriction; diff --git a/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs b/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs index a403b3e4be..82b183e519 100644 --- a/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs +++ b/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs @@ -42,21 +42,20 @@ public partial class MobStateSystem private void OnStateExitSubscribers(EntityUid target, MobStateComponent component, MobState state) { - var uid = component.Owner; switch (state) { case MobState.Alive: //unused break; case MobState.Critical: - _standing.Stand(uid); + _standing.Stand(target); break; case MobState.Dead: - RemComp(uid); - _standing.Stand(uid); - if (!_standing.IsDown(uid) && TryComp(uid, out var physics)) + RemComp(target); + _standing.Stand(target); + if (!_standing.IsDown(target) && TryComp(target, out var physics)) { - _physics.SetCanCollide(physics, true); + _physics.SetCanCollide(target, true, body: physics); } break; @@ -70,28 +69,27 @@ public partial class MobStateSystem private void OnStateEnteredSubscribers(EntityUid target, MobStateComponent component, MobState state) { - var uid = component.Owner; - _blocker.UpdateCanMove(uid); //update movement anytime a state changes + _blocker.UpdateCanMove(target); //update movement anytime a state changes switch (state) { case MobState.Alive: - _standing.Stand(uid); - _appearance.SetData(uid, MobStateVisuals.State, MobState.Alive); + _standing.Stand(target); + _appearance.SetData(target, MobStateVisuals.State, MobState.Alive); break; case MobState.Critical: - _standing.Down(uid); - _appearance.SetData(uid, MobStateVisuals.State, MobState.Critical); + _standing.Down(target); + _appearance.SetData(target, MobStateVisuals.State, MobState.Critical); break; case MobState.Dead: - EnsureComp(uid); - _standing.Down(uid); + EnsureComp(target); + _standing.Down(target); - if (_standing.IsDown(uid) && TryComp(uid, out var physics)) + if (_standing.IsDown(target) && TryComp(target, out var physics)) { - _physics.SetCanCollide(physics, false); + _physics.SetCanCollide(target, false, body: physics); } - _appearance.SetData(uid, MobStateVisuals.State, MobState.Dead); + _appearance.SetData(target, MobStateVisuals.State, MobState.Dead); break; case MobState.Invalid: //unused; diff --git a/Content.Shared/Movement/Systems/SharedMoverController.cs b/Content.Shared/Movement/Systems/SharedMoverController.cs index e79a67ea34..f8c99543da 100644 --- a/Content.Shared/Movement/Systems/SharedMoverController.cs +++ b/Content.Shared/Movement/Systems/SharedMoverController.cs @@ -34,6 +34,7 @@ namespace Content.Shared.Movement.Systems [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly InventorySystem _inventory = default!; [Dependency] private readonly SharedContainerSystem _container = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly SharedGravitySystem _gravity = default!; [Dependency] private readonly MobStateSystem _mobState = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; @@ -304,10 +305,10 @@ namespace Content.Shared.Movement.Systems if (!weightless || touching) Accelerate(ref velocity, in worldTotal, accel, frameTime); - PhysicsSystem.SetLinearVelocity(physicsComponent, velocity); + PhysicsSystem.SetLinearVelocity(physicsComponent.Owner, velocity, body: physicsComponent); // Ensures that players do not spiiiiiiin - PhysicsSystem.SetAngularVelocity(physicsComponent, 0); + PhysicsSystem.SetAngularVelocity(physicsComponent.Owner, 0, body: physicsComponent); } private void Friction(float minimumFrictionSpeed, float frameTime, float friction, ref Vector2 velocity) @@ -364,7 +365,7 @@ namespace Content.Shared.Movement.Systems /// private bool IsAroundCollider(SharedPhysicsSystem broadPhaseSystem, TransformComponent transform, MobMoverComponent mover, PhysicsComponent collider) { - var enlargedAABB = collider.GetWorldAABB().Enlarged(mover.GrabRangeVV); + var enlargedAABB = _lookup.GetWorldAABB(collider.Owner, transform).Enlarged(mover.GrabRangeVV); foreach (var otherCollider in broadPhaseSystem.GetCollidingEntities(transform.MapID, enlargedAABB)) { diff --git a/Content.Shared/Pulling/Events/PullMessage.cs b/Content.Shared/Pulling/Events/PullMessage.cs index 24a8cdae56..b11de7c170 100644 --- a/Content.Shared/Pulling/Events/PullMessage.cs +++ b/Content.Shared/Pulling/Events/PullMessage.cs @@ -1,5 +1,4 @@ -using Robust.Shared.Physics; -using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Components; namespace Content.Shared.Physics.Pull { diff --git a/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs b/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs index 93e8223b5d..409a1f75a0 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingStateManagementSystem.cs @@ -146,7 +146,7 @@ namespace Content.Shared.Pulling if (!_timing.ApplyingState) { // Joint startup - var union = _physics.GetHardAABB(pullerPhysics).Union(_physics.GetHardAABB(pullablePhysics)); + var union = _physics.GetHardAABB(puller.Owner).Union(_physics.GetHardAABB(pullable.Owner, body: pullablePhysics)); var length = Math.Max(union.Size.X, union.Size.Y) * 0.75f; var joint = _jointSystem.CreateDistanceJoint(pullablePhysics.Owner, pullerPhysics.Owner, id: pullable.PullJointId); diff --git a/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs b/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs index 6f624cb7a0..9fbd04382b 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs @@ -11,15 +11,17 @@ using Robust.Shared.Containers; using Robust.Shared.Map; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; namespace Content.Shared.Pulling { - public abstract partial class SharedPullingSystem : EntitySystem + public abstract partial class SharedPullingSystem { [Dependency] private readonly ActionBlockerSystem _blocker = default!; [Dependency] private readonly SharedContainerSystem _containerSystem = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; [Dependency] private readonly SharedInteractionSystem _interaction = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; public bool CanPull(EntityUid puller, EntityUid pulled) @@ -102,7 +104,7 @@ namespace Content.Shared.Pulling if (TryComp(pullable.Owner, out var pullablePhysics)) { - pullablePhysics.FixedRotation = pullable.PrevFixedRotation; + _physics.SetFixedRotation(pullable.Owner, pullable.PrevFixedRotation, body: pullablePhysics); } _pullSm.ForceRelationship(null, pullable); @@ -198,7 +200,7 @@ namespace Content.Shared.Pulling _pullSm.ForceRelationship(puller, pullable); pullable.PrevFixedRotation = pullablePhysics.FixedRotation; - pullablePhysics.FixedRotation = pullable.FixedRotationOnPull; + _physics.SetFixedRotation(pullable.Owner, pullable.FixedRotationOnPull, body: pullablePhysics); _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(puller.Owner):user} started pulling {ToPrettyString(pullable.Owner):target}"); return true; diff --git a/Content.Shared/Revenant/EntitySystems/SharedCorporealSystem.cs b/Content.Shared/Revenant/EntitySystems/SharedCorporealSystem.cs index 293504523a..70b3820796 100644 --- a/Content.Shared/Revenant/EntitySystems/SharedCorporealSystem.cs +++ b/Content.Shared/Revenant/EntitySystems/SharedCorporealSystem.cs @@ -40,8 +40,8 @@ public abstract class SharedCorporealSystem : EntitySystem { var fixture = fixtures.Fixtures.Values.First(); - _physics.SetCollisionMask(fixture, (int) (CollisionGroup.SmallMobMask | CollisionGroup.GhostImpassable)); - _physics.SetCollisionLayer(fixture, (int) CollisionGroup.SmallMobLayer); + _physics.SetCollisionMask(uid, fixture, (int) (CollisionGroup.SmallMobMask | CollisionGroup.GhostImpassable), fixtures); + _physics.SetCollisionLayer(uid, fixture, (int) CollisionGroup.SmallMobLayer, fixtures); } _movement.RefreshMovementSpeedModifiers(uid); } @@ -54,8 +54,8 @@ public abstract class SharedCorporealSystem : EntitySystem { var fixture = fixtures.Fixtures.Values.First(); - _physics.SetCollisionMask(fixture, (int) CollisionGroup.GhostImpassable); - _physics.SetCollisionLayer(fixture, 0); + _physics.SetCollisionMask(uid, fixture, (int) CollisionGroup.GhostImpassable, fixtures); + _physics.SetCollisionLayer(uid, fixture, 0, fixtures); } component.MovementSpeedDebuff = 1; //just so we can avoid annoying code elsewhere _movement.RefreshMovementSpeedModifiers(uid); diff --git a/Content.Shared/Singularity/EntitySystems/SharedEventHorizonSystem.cs b/Content.Shared/Singularity/EntitySystems/SharedEventHorizonSystem.cs index 3cf3c5d67c..2defe27a19 100644 --- a/Content.Shared/Singularity/EntitySystems/SharedEventHorizonSystem.cs +++ b/Content.Shared/Singularity/EntitySystems/SharedEventHorizonSystem.cs @@ -6,6 +6,7 @@ using Robust.Shared.Physics.Systems; using Content.Shared.Ghost; using Content.Shared.Singularity.Components; +using Robust.Shared.Physics; namespace Content.Shared.Singularity.EntitySystems; @@ -14,10 +15,11 @@ namespace Content.Shared.Singularity.EntitySystems; /// public abstract class SharedEventHorizonSystem : EntitySystem { -#region Dependencies + [Dependency] private readonly FixtureSystem _fixtures = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] protected readonly IViewVariablesManager Vvm = default!; -#endregion Dependencies + public override void Initialize() { base.Initialize(); @@ -62,7 +64,7 @@ public abstract class SharedEventHorizonSystem : EntitySystem return; eventHorizon.Radius = value; - EntityManager.Dirty(eventHorizon); + Dirty(eventHorizon); if (updateFixture) UpdateEventHorizonFixture(uid, eventHorizon: eventHorizon); } @@ -85,7 +87,7 @@ public abstract class SharedEventHorizonSystem : EntitySystem return; eventHorizon.CanBreachContainment = value; - EntityManager.Dirty(eventHorizon); + Dirty(eventHorizon); if (updateFixture) UpdateEventHorizonFixture(uid, eventHorizon: eventHorizon); } @@ -108,7 +110,7 @@ public abstract class SharedEventHorizonSystem : EntitySystem return; eventHorizon.HorizonFixtureId = value; - EntityManager.Dirty(eventHorizon); + Dirty(eventHorizon); if (updateFixture) UpdateEventHorizonFixture(uid, eventHorizon: eventHorizon); } @@ -117,25 +119,26 @@ public abstract class SharedEventHorizonSystem : EntitySystem /// Updates the state of the fixture associated with the event horizon. /// /// The uid of the event horizon associated with the fixture to update. - /// The physics component containing the fixture to update. + /// The physics component containing the fixture to update. /// The state of the event horizon associated with the fixture to update. - public void UpdateEventHorizonFixture(EntityUid uid, PhysicsComponent? fixtures = null, EventHorizonComponent? eventHorizon = null) + public void UpdateEventHorizonFixture(EntityUid uid, PhysicsComponent? physics = null, EventHorizonComponent? eventHorizon = null) { if(!Resolve(uid, ref eventHorizon)) return; var fixtureId = eventHorizon.HorizonFixtureId; - if (fixtureId == null || !Resolve(eventHorizon.Owner, ref fixtures, logMissing: false)) + FixturesComponent? manager = null; + + if (fixtureId == null || !Resolve(uid, ref manager, ref physics, logMissing: false)) return; - var fixture = _fixtures.GetFixtureOrNull(fixtures, fixtureId); + var fixture = _fixtures.GetFixtureOrNull(uid, fixtureId, manager); if (fixture == null) return; var shape = (PhysShapeCircle)fixture.Shape; - shape.Radius = eventHorizon.Radius; - fixture.Hard = !eventHorizon.CanBreachContainment; - EntityManager.Dirty(fixtures); + _physics.SetRadius(uid, fixture, shape, eventHorizon.Radius, manager: manager, body: physics); + _physics.SetHard(uid, fixture, true, manager); } #endregion Getters/Setters @@ -181,8 +184,8 @@ public abstract class SharedEventHorizonSystem : EntitySystem var otherUid = args.BodyB.Owner; // For prediction reasons always want the client to ignore these. - if (EntityManager.HasComponent(otherUid) || - EntityManager.HasComponent(otherUid)) + if (HasComp(otherUid) || + HasComp(otherUid)) { args.Cancelled = true; return true; @@ -190,8 +193,8 @@ public abstract class SharedEventHorizonSystem : EntitySystem // If we can, breach containment // otherwise, check if it's containment and just keep the collision - if (EntityManager.HasComponent(otherUid) || - EntityManager.HasComponent(otherUid)) + if (HasComp(otherUid) || + HasComp(otherUid)) { if (comp.CanBreachContainment) args.Cancelled = true; diff --git a/Content.Shared/Singularity/EntitySystems/SharedSingularitySystem.cs b/Content.Shared/Singularity/EntitySystems/SharedSingularitySystem.cs index e5890676c4..1dca848773 100644 --- a/Content.Shared/Singularity/EntitySystems/SharedSingularitySystem.cs +++ b/Content.Shared/Singularity/EntitySystems/SharedSingularitySystem.cs @@ -355,7 +355,7 @@ public abstract class SharedSingularitySystem : EntitySystem { _physics.SetBodyStatus(comp, (args.NewValue > 1) ? BodyStatus.InAir : BodyStatus.OnGround); if (args.NewValue <= 1 && args.OldValue > 1) // Apparently keeps singularities from getting stuck in the corners of containment fields. - _physics.SetLinearVelocity(comp, Vector2.Zero); // No idea how stopping the singularities movement keeps it from getting stuck though. + _physics.SetLinearVelocity(uid, Vector2.Zero, body: comp); // No idea how stopping the singularities movement keeps it from getting stuck though. } /// diff --git a/Content.Shared/Slippery/SlipperySystem.cs b/Content.Shared/Slippery/SlipperySystem.cs index a5ea35207b..276f797299 100644 --- a/Content.Shared/Slippery/SlipperySystem.cs +++ b/Content.Shared/Slippery/SlipperySystem.cs @@ -85,7 +85,7 @@ namespace Content.Shared.Slippery return; if (TryComp(other, out PhysicsComponent? physics)) - _physics.SetLinearVelocity(physics, physics.LinearVelocity * component.LaunchForwardsMultiplier); + _physics.SetLinearVelocity(other, physics.LinearVelocity * component.LaunchForwardsMultiplier, body: physics); var playSound = !_statusEffectsSystem.HasStatusEffect(other, "KnockedDown"); diff --git a/Content.Shared/Standing/StandingStateSystem.cs b/Content.Shared/Standing/StandingStateSystem.cs index 9c1116d537..7d10036fb0 100644 --- a/Content.Shared/Standing/StandingStateSystem.cs +++ b/Content.Shared/Standing/StandingStateSystem.cs @@ -96,7 +96,7 @@ namespace Content.Shared.Standing continue; standingState.ChangedFixtures.Add(key); - _physics.SetCollisionMask(fixture, fixture.CollisionMask & ~StandingCollisionLayer); + _physics.SetCollisionMask(uid, fixture, fixture.CollisionMask & ~StandingCollisionLayer, manager: fixtureComponent); } } @@ -148,7 +148,7 @@ namespace Content.Shared.Standing foreach (var key in standingState.ChangedFixtures) { if (fixtureComponent.Fixtures.TryGetValue(key, out var fixture)) - _physics.SetCollisionMask(fixture, fixture.CollisionMask | StandingCollisionLayer); + _physics.SetCollisionMask(uid, fixture, fixture.CollisionMask | StandingCollisionLayer, fixtureComponent); } } standingState.ChangedFixtures.Clear(); diff --git a/Content.Shared/Throwing/ThrowingSystem.cs b/Content.Shared/Throwing/ThrowingSystem.cs index e84b392507..53d6341aff 100644 --- a/Content.Shared/Throwing/ThrowingSystem.cs +++ b/Content.Shared/Throwing/ThrowingSystem.cs @@ -60,7 +60,7 @@ public sealed class ThrowingSystem : EntitySystem comp.Thrower = user; // Give it a l'il spin. if (!_tagSystem.HasTag(uid, "NoSpinOnThrow")) - _physics.ApplyAngularImpulse(physics, ThrowAngularImpulse); + _physics.ApplyAngularImpulse(uid, ThrowAngularImpulse, body: physics); else { if (transform == null) @@ -75,7 +75,7 @@ public sealed class ThrowingSystem : EntitySystem _interactionSystem.ThrownInteraction(user.Value, uid); var impulseVector = direction.Normalized * strength * physics.Mass; - _physics.ApplyLinearImpulse(physics, impulseVector); + _physics.ApplyLinearImpulse(uid, impulseVector, body: physics); // Estimate time to arrival so we can apply OnGround status and slow it much faster. var time = (direction / strength).Length; @@ -109,7 +109,7 @@ public sealed class ThrowingSystem : EntitySystem RaiseLocalEvent(physics.Owner, msg); if (!msg.Cancelled) - _physics.ApplyLinearImpulse(userPhysics, -impulseVector * pushbackRatio); + _physics.ApplyLinearImpulse(user.Value, -impulseVector * pushbackRatio, body: userPhysics); } } } diff --git a/Content.Shared/Throwing/ThrownItemSystem.cs b/Content.Shared/Throwing/ThrownItemSystem.cs index caf290084c..fa29a03e45 100644 --- a/Content.Shared/Throwing/ThrownItemSystem.cs +++ b/Content.Shared/Throwing/ThrownItemSystem.cs @@ -55,19 +55,16 @@ namespace Content.Shared.Throwing private void ThrowItem(EntityUid uid, ThrownItemComponent component, ThrownEvent args) { - if (!EntityManager.TryGetComponent(component.Owner, out FixturesComponent? fixturesComponent) || - fixturesComponent.Fixtures.Count != 1) return; - if (!EntityManager.TryGetComponent(component.Owner, out PhysicsComponent? physicsComponent)) return; - - if (fixturesComponent.Fixtures.ContainsKey(ThrowingFixture)) + if (!EntityManager.TryGetComponent(uid, out FixturesComponent? fixturesComponent) || + fixturesComponent.Fixtures.Count != 1 || + !TryComp(uid, out var body)) { - Logger.Error($"Found existing throwing fixture on {component.Owner}"); return; } + var fixture = fixturesComponent.Fixtures.Values.First(); var shape = fixture.Shape; - var throwingFixture = new Fixture(physicsComponent, shape) { CollisionMask = (int) CollisionGroup.ThrownItem, Hard = false, ID = ThrowingFixture }; - _fixtures.TryCreateFixture(physicsComponent, throwingFixture, manager: fixturesComponent); + _fixtures.TryCreateFixture(uid, shape, ThrowingFixture, hard: false, collisionMask: (int) CollisionGroup.ThrownItem, manager: fixturesComponent, body: body); } private void HandleCollision(EntityUid uid, ThrownItemComponent component, ref StartCollideEvent args) @@ -104,13 +101,13 @@ namespace Content.Shared.Throwing private void StopThrow(EntityUid uid, ThrownItemComponent thrownItemComponent) { - if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent)) + if (EntityManager.TryGetComponent(uid, out FixturesComponent? manager)) { - var fixture = _fixtures.GetFixtureOrNull(physicsComponent, ThrowingFixture); + var fixture = _fixtures.GetFixtureOrNull(uid, ThrowingFixture, manager: manager); if (fixture != null) { - _fixtures.DestroyFixture(physicsComponent, fixture); + _fixtures.DestroyFixture(uid, fixture, manager: manager); } } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedFlyBySoundSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedFlyBySoundSystem.cs index 40e67656b1..c2fd397e42 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedFlyBySoundSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedFlyBySoundSystem.cs @@ -28,21 +28,12 @@ public abstract class SharedFlyBySoundSystem : EntitySystem private void OnStartup(EntityUid uid, FlyBySoundComponent component, ComponentStartup args) { - if (!TryComp(uid, out var body)) return; + if (!TryComp(uid, out var body)) + return; - var shape = new PhysShapeCircle() - { - Radius = component.Range, - }; + var shape = new PhysShapeCircle(component.Range); - var fixture = new Fixture(body, shape) - { - Hard = false, - ID = FlyByFixture, - CollisionLayer = (int) CollisionGroup.MobMask, - }; - - _fixtures.TryCreateFixture(body, fixture); + _fixtures.TryCreateFixture(uid, shape, FlyByFixture, collisionLayer: (int) CollisionGroup.MobMask, hard: false, body: body); } private void OnShutdown(EntityUid uid, FlyBySoundComponent component, ComponentShutdown args) @@ -53,7 +44,7 @@ public abstract class SharedFlyBySoundSystem : EntitySystem return; } - _fixtures.DestroyFixture(body, FlyByFixture); + _fixtures.DestroyFixture(uid, FlyByFixture, body: body); } private void OnHandleState(EntityUid uid, FlyBySoundComponent component, ref ComponentHandleState args) diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs index f1e7ea8f39..736fa6ee74 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs @@ -383,7 +383,7 @@ public abstract partial class SharedGunSystem : EntitySystem const float impulseStrength = 85.0f; //The bullet impulse strength, TODO: In the future we might want to make it more projectile dependent var impulseVector = shotDirection * impulseStrength; - Physics.ApplyLinearImpulse(userPhysics, -impulseVector); + Physics.ApplyLinearImpulse(userPhysics.Owner, -impulseVector, body: userPhysics); } protected abstract void CreateEffect(EntityUid uid, MuzzleFlashEvent message, EntityUid? user = null); diff --git a/Resources/Prototypes/Entities/Mobs/Player/observer.yml b/Resources/Prototypes/Entities/Mobs/Player/observer.yml index e70aa85dab..8ef363de41 100644 --- a/Resources/Prototypes/Entities/Mobs/Player/observer.yml +++ b/Resources/Prototypes/Entities/Mobs/Player/observer.yml @@ -11,7 +11,6 @@ - type: Physics bodyType: KinematicController fixedRotation: true - status: OnGround - type: Fixtures fixtures: - shape: diff --git a/Resources/Prototypes/Entities/Structures/Power/Generation/ame.yml b/Resources/Prototypes/Entities/Structures/Power/Generation/ame.yml index 9522565ee1..8b64240549 100644 --- a/Resources/Prototypes/Entities/Structures/Power/Generation/ame.yml +++ b/Resources/Prototypes/Entities/Structures/Power/Generation/ame.yml @@ -102,6 +102,7 @@ fixtures: - shape: !type:PhysShapeAabb + bounds: "-0.5,-0.5,0.5,0.5" density: 190 mask: - FullTileMask