Mob movement rewrite (#35931)

* Conveyor optimisations

- Optimise movement for moving stuff. Better flags + less resolves + slapped parallelrobustjob on it.
- Sleeping for entities getting conveyed into walls.

* Blocker version

* Finish

* Final

* Fix conveyor power mispredict

* Bagel save

* Revert "Bagel save"

This reverts commit 1b93fda81fb852d89b89b0beae0b80f8a61165f2.

* Conveyor resave

* Fix prediction

* Mob movement rewrite

* Bandaid

* Working version

* Tentatively working

* Friction to fix cornering

* More fixes

* Revert bagel

* Revert this

* a

* Reviewed

* Funky re-save

* Fix velocity

* Table fix

* Review

* a
This commit is contained in:
metalgearsloth
2025-03-28 09:29:02 +11:00
committed by GitHub
parent e98df217e2
commit 948588399c
8 changed files with 360 additions and 131 deletions

View File

@@ -1,7 +1,6 @@
using Content.Server.DeviceLinking.Events;
using Content.Server.DeviceLinking.Systems;
using Content.Server.Materials;
using Content.Server.Power.Components;
using Content.Shared.Conveyor;
using Content.Shared.Destructible;
using Content.Shared.Maps;
@@ -10,7 +9,6 @@ using Content.Shared.Physics.Controllers;
using Content.Shared.Power;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
namespace Content.Server.Physics.Controllers;
@@ -20,7 +18,6 @@ public sealed class ConveyorController : SharedConveyorController
[Dependency] private readonly FixtureSystem _fixtures = default!;
[Dependency] private readonly DeviceLinkSystem _signalSystem = default!;
[Dependency] private readonly MaterialReclaimerSystem _materialReclaimer = default!;
[Dependency] private readonly SharedBroadphaseSystem _broadphase = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
public override void Initialize()
@@ -40,7 +37,7 @@ public sealed class ConveyorController : SharedConveyorController
{
_signalSystem.EnsureSinkPorts(uid, component.ReversePort, component.ForwardPort, component.OffPort);
if (TryComp<PhysicsComponent>(uid, out var physics))
if (PhysicsQuery.TryComp(uid, out var physics))
{
var shape = new PolygonShape();
shape.SetAsBox(0.55f, 0.55f);
@@ -57,7 +54,7 @@ public sealed class ConveyorController : SharedConveyorController
if (MetaData(uid).EntityLifeStage >= EntityLifeStage.Terminating)
return;
if (!TryComp<PhysicsComponent>(uid, out var physics))
if (!PhysicsQuery.TryComp(uid, out var physics))
return;
_fixtures.DestroyFixture(uid, ConveyorFixture, body: physics);
@@ -87,13 +84,11 @@ public sealed class ConveyorController : SharedConveyorController
else if (args.Port == component.ForwardPort)
{
AwakenEntities(uid, component);
SetState(uid, ConveyorState.Forward, component);
}
else if (args.Port == component.ReversePort)
{
AwakenEntities(uid, component);
SetState(uid, ConveyorState.Reverse, component);
}
}
@@ -108,8 +103,10 @@ public sealed class ConveyorController : SharedConveyorController
component.State = state;
if (TryComp<PhysicsComponent>(uid, out var physics))
_broadphase.RegenerateContacts((uid, physics));
if (state != ConveyorState.Off)
{
WakeConveyed(uid);
}
UpdateAppearance(uid, component);
Dirty(uid, component);
@@ -117,29 +114,29 @@ public sealed class ConveyorController : SharedConveyorController
/// <summary>
/// Awakens sleeping entities on the conveyor belt's tile when it's turned on.
/// Fixes an issue where non-hard/sleeping entities refuse to wake up + collide if a belt is turned off and on again.
/// Need this as we might activate under CollisionWake entities and need to forcefully check them.
/// </summary>
private void AwakenEntities(EntityUid uid, ConveyorComponent component)
protected override void AwakenConveyor(Entity<TransformComponent?> ent)
{
var xformQuery = GetEntityQuery<TransformComponent>();
var bodyQuery = GetEntityQuery<PhysicsComponent>();
if (!xformQuery.TryGetComponent(uid, out var xform))
if (!XformQuery.Resolve(ent.Owner, ref ent.Comp))
return;
var xform = ent.Comp;
var beltTileRef = xform.Coordinates.GetTileRef(EntityManager, MapManager);
if (beltTileRef != null)
{
var intersecting = Lookup.GetLocalEntitiesIntersecting(beltTileRef.Value, 0f);
Intersecting.Clear();
Lookup.GetLocalEntitiesIntersecting(beltTileRef.Value.GridUid, beltTileRef.Value.GridIndices, Intersecting, 0f, flags: LookupFlags.Dynamic | LookupFlags.Sundries | LookupFlags.Approximate);
foreach (var entity in intersecting)
foreach (var entity in Intersecting)
{
if (!bodyQuery.TryGetComponent(entity, out var physics))
if (!PhysicsQuery.TryGetComponent(entity, out var physics))
continue;
if (physics.BodyType != BodyType.Static)
Physics.WakeBody(entity, body: physics);
PhysicsSystem.WakeBody(entity, body: physics);
}
}
}