Increase MoverController performance (#4448)
Should be a decent amount; rest will come from removing IActionBlocker.
This commit is contained in:
15
Content.Client/Friction/TileFrictionController.cs
Normal file
15
Content.Client/Friction/TileFrictionController.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Content.Client.Physics.Controllers;
|
||||||
|
using Content.Shared.Friction;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Client.Friction
|
||||||
|
{
|
||||||
|
public sealed class TileFrictionController : SharedTileFrictionController
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
Mover = EntitySystem.Get<SharedPhysicsSystem>().GetController<MoverController>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Content.Server/Friction/TileFrictionController.cs
Normal file
15
Content.Server/Friction/TileFrictionController.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Content.Server.Physics.Controllers;
|
||||||
|
using Content.Shared.Friction;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Server.Friction
|
||||||
|
{
|
||||||
|
public sealed class TileFrictionController : SharedTileFrictionController
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
Mover = EntitySystem.Get<SharedPhysicsSystem>().GetController<MoverController>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,35 +7,43 @@ using Robust.Shared.Configuration;
|
|||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Physics;
|
|
||||||
using Robust.Shared.Physics.Controllers;
|
using Robust.Shared.Physics.Controllers;
|
||||||
using Robust.Shared.Physics.Dynamics;
|
using Robust.Shared.Physics.Dynamics;
|
||||||
|
|
||||||
|
|
||||||
namespace Content.Shared.Friction
|
namespace Content.Shared.Friction
|
||||||
{
|
{
|
||||||
public sealed class SharedTileFrictionController : VirtualController
|
public abstract class SharedTileFrictionController : VirtualController
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||||
|
|
||||||
private SharedBroadphaseSystem _broadPhaseSystem = default!;
|
protected SharedMoverController Mover = default!;
|
||||||
|
|
||||||
private float _stopSpeed;
|
private float _stopSpeed;
|
||||||
|
|
||||||
private float _frictionModifier;
|
private float _frictionModifier;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
_broadPhaseSystem = EntitySystem.Get<SharedBroadphaseSystem>();
|
|
||||||
|
|
||||||
_frictionModifier = _configManager.GetCVar(CCVars.TileFrictionModifier);
|
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
||||||
_configManager.OnValueChanged(CCVars.TileFrictionModifier, value => _frictionModifier = value);
|
|
||||||
|
|
||||||
_stopSpeed = _configManager.GetCVar(CCVars.StopSpeed);
|
configManager.OnValueChanged(CCVars.TileFrictionModifier, SetFrictionModifier, true);
|
||||||
_configManager.OnValueChanged(CCVars.StopSpeed, value => _stopSpeed = value);
|
configManager.OnValueChanged(CCVars.StopSpeed, SetStopSpeed, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetStopSpeed(float value) => _stopSpeed = value;
|
||||||
|
|
||||||
|
private void SetFrictionModifier(float value) => _frictionModifier = value;
|
||||||
|
|
||||||
|
public override void Shutdown()
|
||||||
|
{
|
||||||
|
base.Shutdown();
|
||||||
|
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
||||||
|
|
||||||
|
configManager.UnsubValueChanged(CCVars.TileFrictionModifier, SetFrictionModifier);
|
||||||
|
configManager.UnsubValueChanged(CCVars.StopSpeed, SetStopSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateBeforeMapSolve(bool prediction, PhysicsMap map, float frameTime)
|
public override void UpdateBeforeMapSolve(bool prediction, PhysicsMap map, float frameTime)
|
||||||
@@ -47,7 +55,7 @@ namespace Content.Shared.Friction
|
|||||||
// Only apply friction when it's not a mob (or the mob doesn't have control)
|
// Only apply friction when it's not a mob (or the mob doesn't have control)
|
||||||
if (prediction && !body.Predict ||
|
if (prediction && !body.Predict ||
|
||||||
body.BodyStatus == BodyStatus.InAir ||
|
body.BodyStatus == BodyStatus.InAir ||
|
||||||
SharedMoverController.UseMobMovement(_broadPhaseSystem, body, _mapManager)) continue;
|
Mover.UseMobMovement(body.Owner.Uid)) continue;
|
||||||
|
|
||||||
var surfaceFriction = GetTileFriction(body);
|
var surfaceFriction = GetTileFriction(body);
|
||||||
var bodyModifier = body.Owner.GetComponentOrNull<SharedTileFrictionModifier>()?.Modifier ?? 1.0f;
|
var bodyModifier = body.Owner.GetComponentOrNull<SharedTileFrictionModifier>()?.Modifier ?? 1.0f;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using Content.Shared.ActionBlocker;
|
using Content.Shared.ActionBlocker;
|
||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
|
using Content.Shared.Friction;
|
||||||
using Content.Shared.MobState;
|
using Content.Shared.MobState;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
using Content.Shared.Pulling.Components;
|
using Content.Shared.Pulling.Components;
|
||||||
@@ -9,7 +11,6 @@ using Robust.Shared.IoC;
|
|||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Physics.Broadphase;
|
|
||||||
using Robust.Shared.Physics.Controllers;
|
using Robust.Shared.Physics.Controllers;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
@@ -23,16 +24,39 @@ namespace Content.Shared.Movement
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
|
|
||||||
|
private ActionBlockerSystem _blocker = default!;
|
||||||
private SharedBroadphaseSystem _broadPhaseSystem = default!;
|
private SharedBroadphaseSystem _broadPhaseSystem = default!;
|
||||||
|
|
||||||
private bool _relativeMovement;
|
private bool _relativeMovement;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cache the mob movement calculation to re-use elsewhere.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<EntityUid, bool> UsedMobMovement = new();
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
_broadPhaseSystem = EntitySystem.Get<SharedBroadphaseSystem>();
|
_broadPhaseSystem = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||||
|
_blocker = EntitySystem.Get<ActionBlockerSystem>();
|
||||||
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
||||||
configManager.OnValueChanged(CCVars.RelativeMovement, value => _relativeMovement = value, true);
|
configManager.OnValueChanged(CCVars.RelativeMovement, SetRelativeMovement, true);
|
||||||
|
UpdatesBefore.Add(typeof(SharedTileFrictionController));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetRelativeMovement(bool value) => _relativeMovement = value;
|
||||||
|
|
||||||
|
public override void Shutdown()
|
||||||
|
{
|
||||||
|
base.Shutdown();
|
||||||
|
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
||||||
|
configManager.UnsubValueChanged(CCVars.RelativeMovement, SetRelativeMovement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateAfterSolve(bool prediction, float frameTime)
|
||||||
|
{
|
||||||
|
base.UpdateAfterSolve(prediction, frameTime);
|
||||||
|
UsedMobMovement.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -65,17 +89,19 @@ namespace Content.Shared.Movement
|
|||||||
protected void HandleMobMovement(IMoverComponent mover, PhysicsComponent physicsComponent,
|
protected void HandleMobMovement(IMoverComponent mover, PhysicsComponent physicsComponent,
|
||||||
IMobMoverComponent mobMover)
|
IMobMoverComponent mobMover)
|
||||||
{
|
{
|
||||||
// TODO: Look at https://gameworksdocs.nvidia.com/PhysX/4.1/documentation/physxguide/Manual/CharacterControllers.html?highlight=controller as it has some adviceo n kinematic controllersx
|
DebugTools.Assert(!UsedMobMovement.ContainsKey(mover.Owner.Uid));
|
||||||
if (!UseMobMovement(_broadPhaseSystem, physicsComponent, _mapManager))
|
|
||||||
|
if (!UseMobMovement(physicsComponent))
|
||||||
{
|
{
|
||||||
|
UsedMobMovement[mover.Owner.Uid] = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UsedMobMovement[mover.Owner.Uid] = true;
|
||||||
var transform = mover.Owner.Transform;
|
var transform = mover.Owner.Transform;
|
||||||
|
var weightless = mover.Owner.IsWeightless(physicsComponent, mapManager: _mapManager);
|
||||||
var (walkDir, sprintDir) = mover.VelocityDir;
|
var (walkDir, sprintDir) = mover.VelocityDir;
|
||||||
|
|
||||||
var weightless = transform.Owner.IsWeightless(physicsComponent, mapManager: _mapManager);
|
|
||||||
|
|
||||||
// Handle wall-pushes.
|
// Handle wall-pushes.
|
||||||
if (weightless)
|
if (weightless)
|
||||||
{
|
{
|
||||||
@@ -117,14 +143,16 @@ namespace Content.Shared.Movement
|
|||||||
physicsComponent.LinearVelocity = worldTotal;
|
physicsComponent.LinearVelocity = worldTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool UseMobMovement(SharedBroadphaseSystem broadPhaseSystem, PhysicsComponent body, IMapManager mapManager)
|
public bool UseMobMovement(EntityUid uid)
|
||||||
{
|
{
|
||||||
return (body.BodyStatus == BodyStatus.OnGround) &
|
return UsedMobMovement.TryGetValue(uid, out var used) && used;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected bool UseMobMovement(PhysicsComponent body)
|
||||||
|
{
|
||||||
|
return body.BodyStatus == BodyStatus.OnGround &&
|
||||||
body.Owner.HasComponent<IMobStateComponent>() &&
|
body.Owner.HasComponent<IMobStateComponent>() &&
|
||||||
EntitySystem.Get<ActionBlockerSystem>().CanMove(body.Owner) &&
|
_blocker.CanMove(body.Owner);
|
||||||
(!body.Owner.IsWeightless(body, mapManager: mapManager) ||
|
|
||||||
body.Owner.TryGetComponent(out SharedPlayerMobMoverComponent? mover) &&
|
|
||||||
IsAroundCollider(broadPhaseSystem, body.Owner.Transform, mover, body));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user