Mob Movement Major Refactor (#36847)
* 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 * Init Commit * windows yelling at me to update commit * working commit, need prediciton and more dehardcoding * Project 0 warnings * Working Commit (Near Final) * ryder got confused commit * I love Merge Conflicts :) * Working commit, no prediction * Forgot the yaml changes * Comments and typos * Apparently while the reduced launch mult of lube was initialized it was never used so I revered back to default * Fixed an incorrect divisor * bit of cleanup * Prediciton fixed, and puddles now affect all entities * FORGOT TO RENAME A VERY IMPORTANT VARIABLE OOPS * Really big I forgor moment * Even bigger I forgor moment * four more merge conflicts to fix four more oopsies * fixed actual divide by zero moment and also im very dumb * Even bigger I forgor moment * four more merge conflicts to fix four more oopsies * fixed actual divide by zero moment and also im very dumb * Fix all test fails * code cleanup * Webedit whitespace * Code cleaup * whitespace webedit * whitespace webedit * whitespace webedit * whitespace removal * Comments and cleanup * Re-Added 20 warnings as per Ork's request * Cleanups * Spacing fix * bugfixes and cleanup * Small bugfix * Fix prediction * Mob movement rewrite * Bandaid * Working version * Tentatively working * Friction to fix cornering * More fixes * Refactor mob movement Trying to cleanup relay ordering / tryupdaterelative being cooked, purge ToParent, and fix all the eye rotation shenanigans. * Building * Re-implement jetpacks * Reorganise weightless movement * More work * Fix camera * reh * Revert bagel * Revert this * Revert held move buttons * Puddles work but are unpredicted and unoptimized * Fixes * Puddle code... * Actually dirty the slipComp for real * Sliding component done plus an extra suggestion from ArtisticRoomba * Atomized Commit * Added Friction field to Reagent Prototype per design discussion * Cleaned up Working Commit * a * Delete stinkers * Fix this code smell * Reviewed * Funky re-save * Our conveyance * Better conveyor sleeping * Remove this * Revert "Better conveyor sleeping" This reverts commit f5281f64bbae95b7b9feb56295c5cf931f9fb2e1. * Revert that Way too janky * Also this * a * Working Commit - Still a lot to do * Acceleration refactor * Minor jetpack cleanup * frictionnomovement no longer nullable * Shared Mover Feels 99% done * OffGrid/Weightless/Throwing Friction saved * Fix merge conflicts * Fix a debug assert * Final Commit for today * Some fixes * Actually use those CCVars Properly * Need to fix throwing * Second to last Commit for real * Jetpack bug fixed * Jetpack bug fixed * Test fail patch * Small patch * Skates Component cleanup + Bring Accel back to 5 (oops) * Fix test fail oops * yaml cleanup make dragons not fat --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1fbc845126
commit
36030ef154
@@ -1,6 +1,7 @@
|
||||
using System.Numerics;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Gravity;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Movement.Pulling.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
@@ -8,6 +9,7 @@ using JetBrains.Annotations;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Controllers;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
@@ -21,7 +23,6 @@ namespace Content.Shared.Friction
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly SharedGravitySystem _gravity = default!;
|
||||
[Dependency] private readonly SharedMoverController _mover = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly SharedMapSystem _map = default!;
|
||||
|
||||
private EntityQuery<TileFrictionModifierComponent> _frictionQuery;
|
||||
@@ -30,16 +31,19 @@ namespace Content.Shared.Friction
|
||||
private EntityQuery<PullableComponent> _pullableQuery;
|
||||
private EntityQuery<MapGridComponent> _gridQuery;
|
||||
|
||||
private float _stopSpeed;
|
||||
private float _frictionModifier;
|
||||
public const float DefaultFriction = 0.3f;
|
||||
private float _minDamping;
|
||||
private float _airDamping;
|
||||
private float _offGridDamping;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Subs.CVar(_configManager, CCVars.TileFrictionModifier, value => _frictionModifier = value, true);
|
||||
Subs.CVar(_configManager, CCVars.StopSpeed, value => _stopSpeed = value, true);
|
||||
Subs.CVar(_configManager, CCVars.MinFriction, value => _minDamping = value, true);
|
||||
Subs.CVar(_configManager, CCVars.AirFriction, value => _airDamping = value, true);
|
||||
Subs.CVar(_configManager, CCVars.OffgridFriction, value => _offGridDamping = value, true);
|
||||
_frictionQuery = GetEntityQuery<TileFrictionModifierComponent>();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
_pullerQuery = GetEntityQuery<PullerComponent>();
|
||||
@@ -56,12 +60,9 @@ namespace Content.Shared.Friction
|
||||
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 ||
|
||||
_mover.UseMobMovement(uid))
|
||||
{
|
||||
// We may want to instead only apply friction to dynamic entities and not mobs ever.
|
||||
if (prediction && !body.Predict || _mover.UseMobMovement(uid))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (body.LinearVelocity.Equals(Vector2.Zero) && body.AngularVelocity.Equals(0f))
|
||||
continue;
|
||||
@@ -72,7 +73,15 @@ namespace Content.Shared.Friction
|
||||
continue;
|
||||
}
|
||||
|
||||
var surfaceFriction = GetTileFriction(uid, body, xform);
|
||||
float friction;
|
||||
|
||||
// If we're not touching the ground, don't use tileFriction.
|
||||
// TODO: Make IsWeightless event-based; we already have grid traversals tracked so just raise events
|
||||
if (body.BodyStatus == BodyStatus.InAir || _gravity.IsWeightless(uid, body, xform) || !xform.Coordinates.IsValid(EntityManager))
|
||||
friction = xform.GridUid == null || !_gridQuery.HasComp(xform.GridUid) ? _offGridDamping : _airDamping;
|
||||
else
|
||||
friction = _frictionModifier * GetTileFriction(uid, body, xform);
|
||||
|
||||
var bodyModifier = 1f;
|
||||
|
||||
if (_frictionQuery.TryGetComponent(uid, out var frictionComp))
|
||||
@@ -94,96 +103,39 @@ namespace Content.Shared.Friction
|
||||
bodyModifier *= 0.2f;
|
||||
}
|
||||
|
||||
var friction = _frictionModifier * surfaceFriction * bodyModifier;
|
||||
friction *= bodyModifier;
|
||||
|
||||
ReduceLinearVelocity(uid, prediction, body, friction, frameTime);
|
||||
ReduceAngularVelocity(uid, prediction, body, friction, frameTime);
|
||||
friction = Math.Max(_minDamping, friction);
|
||||
|
||||
PhysicsSystem.SetLinearDamping(uid, body, friction);
|
||||
PhysicsSystem.SetAngularDamping(uid, body, friction);
|
||||
|
||||
if (body.BodyType != BodyType.KinematicController)
|
||||
return;
|
||||
|
||||
// Physics engine doesn't apply damping to Kinematic Controllers so we have to do it here.
|
||||
// BEWARE YE TRAVELLER:
|
||||
// You may think you can just pass the body.LinearVelocity to the Friction function and edit it there!
|
||||
// But doing so is unpredicted! And you will doom yourself to 1000 years of rubber banding!
|
||||
var velocity = body.LinearVelocity;
|
||||
_mover.Friction(0f, frameTime, friction, ref velocity);
|
||||
PhysicsSystem.SetLinearVelocity(uid, velocity, body: body);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReduceLinearVelocity(EntityUid uid, bool prediction, PhysicsComponent body, float friction, float frameTime)
|
||||
{
|
||||
var speed = body.LinearVelocity.Length();
|
||||
|
||||
if (speed <= 0.0f)
|
||||
return;
|
||||
|
||||
// This is the *actual* amount that speed will drop by, we just do some multiplication around it to be easier.
|
||||
var drop = 0.0f;
|
||||
float control;
|
||||
|
||||
if (friction > 0.0f)
|
||||
{
|
||||
// TBH I can't really tell if this makes a difference.
|
||||
if (!prediction)
|
||||
{
|
||||
control = speed < _stopSpeed ? _stopSpeed : speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
control = speed;
|
||||
}
|
||||
|
||||
drop += control * friction * frameTime;
|
||||
}
|
||||
|
||||
var newSpeed = MathF.Max(0.0f, speed - drop);
|
||||
|
||||
newSpeed /= speed;
|
||||
_physics.SetLinearVelocity(uid, body.LinearVelocity * newSpeed, body: body);
|
||||
}
|
||||
|
||||
private void ReduceAngularVelocity(EntityUid uid, bool prediction, PhysicsComponent body, float friction, float frameTime)
|
||||
{
|
||||
var speed = MathF.Abs(body.AngularVelocity);
|
||||
|
||||
if (speed <= 0.0f)
|
||||
return;
|
||||
|
||||
// This is the *actual* amount that speed will drop by, we just do some multiplication around it to be easier.
|
||||
var drop = 0.0f;
|
||||
float control;
|
||||
|
||||
if (friction > 0.0f)
|
||||
{
|
||||
// TBH I can't really tell if this makes a difference.
|
||||
if (!prediction)
|
||||
{
|
||||
control = speed < _stopSpeed ? _stopSpeed : speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
control = speed;
|
||||
}
|
||||
|
||||
drop += control * friction * frameTime;
|
||||
}
|
||||
|
||||
var newSpeed = MathF.Max(0.0f, speed - drop);
|
||||
|
||||
newSpeed /= speed;
|
||||
_physics.SetAngularVelocity(uid, body.AngularVelocity * newSpeed, body: body);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
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(uid, body, xform))
|
||||
return 0.0f;
|
||||
|
||||
if (!xform.Coordinates.IsValid(EntityManager))
|
||||
return 0.0f;
|
||||
|
||||
// If not on a grid then return the map's friction.
|
||||
var tileModifier = 1f;
|
||||
// If not on a grid and not in the air then return the map's friction.
|
||||
if (!_gridQuery.TryGetComponent(xform.GridUid, out var grid))
|
||||
{
|
||||
return _frictionQuery.TryGetComponent(xform.MapUid, out var friction)
|
||||
? friction.Modifier
|
||||
: DefaultFriction;
|
||||
: tileModifier;
|
||||
}
|
||||
|
||||
var tile = _map.GetTileRef(xform.GridUid.Value, grid, xform.Coordinates);
|
||||
@@ -192,21 +144,18 @@ namespace Content.Shared.Friction
|
||||
if (tile.Tile.IsEmpty &&
|
||||
HasComp<MapComponent>(xform.GridUid) &&
|
||||
(!TryComp<GravityComponent>(xform.GridUid, out var gravity) || gravity.Enabled))
|
||||
{
|
||||
return DefaultFriction;
|
||||
}
|
||||
|
||||
// If there's an anchored ent that modifies friction then fallback to that instead.
|
||||
var anc = grid.GetAnchoredEntitiesEnumerator(tile.GridIndices);
|
||||
return tileModifier;
|
||||
|
||||
// Check for anchored ents that modify friction
|
||||
var anc = _map.GetAnchoredEntitiesEnumerator(xform.GridUid.Value, grid, tile.GridIndices);
|
||||
while (anc.MoveNext(out var tileEnt))
|
||||
{
|
||||
if (_frictionQuery.TryGetComponent(tileEnt, out var friction))
|
||||
return friction.Modifier;
|
||||
tileModifier *= friction.Modifier;
|
||||
}
|
||||
|
||||
var tileDef = _tileDefinitionManager[tile.Tile.TypeId];
|
||||
return tileDef.Friction;
|
||||
return tileDef.Friction * tileModifier;
|
||||
}
|
||||
|
||||
public void SetModifier(EntityUid entityUid, float value, TileFrictionModifierComponent? friction = null)
|
||||
|
||||
Reference in New Issue
Block a user