* 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 * Mob collisions * impulses * Collision smoothing * Locked in * 30tps working * r * fixes * Best * Fixes + CVars * CVars in place * Pushies * Opt attempt 1 * Revert "Opt attempt 1" This reverts commit 5ccd72dcbea09261a992aa1f7f05df169a1ce676. * Fix mispredicts * Ready-ish * better * Cleanup * Fix conveyor power mispredict * Forgetting to actually do deltas * Fix buckle pushes * 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 * Bad parity * Working * Fixes * Woops * Doc comments * Pen cap cvar * StandingState cleanup and sub * Fix downed mobs * fish * client * Disable pushing on tests * More variables * Movement mods * Mass diff * 1 more tweak * Cvar
136 lines
5.4 KiB
C#
136 lines
5.4 KiB
C#
using Content.Client.Rotation;
|
|
using Content.Shared.Buckle;
|
|
using Content.Shared.Buckle.Components;
|
|
using Content.Shared.Movement.Systems;
|
|
using Content.Shared.Rotation;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
|
|
namespace Content.Client.Buckle;
|
|
|
|
internal sealed class BuckleSystem : SharedBuckleSystem
|
|
{
|
|
[Dependency] private readonly RotationVisualizerSystem _rotationVisualizerSystem = default!;
|
|
[Dependency] private readonly IEyeManager _eye = default!;
|
|
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<BuckleComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
|
SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapMoveEvent);
|
|
SubscribeLocalEvent<BuckleComponent, BuckledEvent>(OnBuckledEvent);
|
|
SubscribeLocalEvent<BuckleComponent, UnbuckledEvent>(OnUnbuckledEvent);
|
|
SubscribeLocalEvent<BuckleComponent, AttemptMobCollideEvent>(OnMobCollide);
|
|
}
|
|
|
|
private void OnMobCollide(Entity<BuckleComponent> ent, ref AttemptMobCollideEvent args)
|
|
{
|
|
if (ent.Comp.Buckled)
|
|
{
|
|
args.Cancelled = true;
|
|
}
|
|
}
|
|
|
|
private void OnStrapMoveEvent(EntityUid uid, StrapComponent component, ref MoveEvent args)
|
|
{
|
|
// I'm moving this to the client-side system, but for the sake of posterity let's keep this comment:
|
|
// > This is mega cursed. Please somebody save me from Mr Buckle's wild ride
|
|
|
|
// The nice thing is its still true, this is quite cursed, though maybe not omega cursed anymore.
|
|
// This code is garbage, it doesn't work with rotated viewports. I need to finally get around to reworking
|
|
// sprite rendering for entity layers & direction dependent sorting.
|
|
|
|
// Future notes:
|
|
// Right now this doesn't handle: other grids, other grids rotating, the camera rotation changing, and many other fun rotation specific things
|
|
// The entire thing should be a concern of the engine, or something engine helps to implement properly.
|
|
// Give some of the sprite rotations their own drawdepth, maybe as an offset within the rsi, or something like this
|
|
// And we won't ever need to set the draw depth manually
|
|
|
|
if (args.NewRotation == args.OldRotation)
|
|
return;
|
|
|
|
if (!TryComp<SpriteComponent>(uid, out var strapSprite))
|
|
return;
|
|
|
|
var angle = _xformSystem.GetWorldRotation(uid) + _eye.CurrentEye.Rotation; // Get true screen position, or close enough
|
|
|
|
var isNorth = angle.GetCardinalDir() == Direction.North;
|
|
foreach (var buckledEntity in component.BuckledEntities)
|
|
{
|
|
if (!TryComp<BuckleComponent>(buckledEntity, out var buckle))
|
|
continue;
|
|
|
|
if (!TryComp<SpriteComponent>(buckledEntity, out var buckledSprite))
|
|
continue;
|
|
|
|
if (isNorth)
|
|
{
|
|
// This will only assign if empty, it won't get overwritten by new depth on multiple calls, which do happen easily
|
|
buckle.OriginalDrawDepth ??= buckledSprite.DrawDepth;
|
|
buckledSprite.DrawDepth = strapSprite.DrawDepth - 1;
|
|
}
|
|
else if (buckle.OriginalDrawDepth.HasValue)
|
|
{
|
|
buckledSprite.DrawDepth = buckle.OriginalDrawDepth.Value;
|
|
buckle.OriginalDrawDepth = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lower the draw depth of the buckled entity without needing for the strap entity to rotate/move.
|
|
/// Only do so when the entity is facing screen-local north
|
|
/// </summary>
|
|
private void OnBuckledEvent(Entity<BuckleComponent> ent, ref BuckledEvent args)
|
|
{
|
|
if (!TryComp<SpriteComponent>(args.Strap, out var strapSprite))
|
|
return;
|
|
|
|
if (!TryComp<SpriteComponent>(ent.Owner, out var buckledSprite))
|
|
return;
|
|
|
|
var angle = _xformSystem.GetWorldRotation(args.Strap) + _eye.CurrentEye.Rotation; // Get true screen position, or close enough
|
|
|
|
if (angle.GetCardinalDir() != Direction.North)
|
|
return;
|
|
|
|
ent.Comp.OriginalDrawDepth ??= buckledSprite.DrawDepth;
|
|
buckledSprite.DrawDepth = strapSprite.DrawDepth - 1;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Was the draw depth of the buckled entity lowered? Reset it upon unbuckling.
|
|
/// </summary>
|
|
private void OnUnbuckledEvent(Entity<BuckleComponent> ent, ref UnbuckledEvent args)
|
|
{
|
|
if (!TryComp<SpriteComponent>(ent.Owner, out var buckledSprite))
|
|
return;
|
|
|
|
if (!ent.Comp.OriginalDrawDepth.HasValue)
|
|
return;
|
|
|
|
buckledSprite.DrawDepth = ent.Comp.OriginalDrawDepth.Value;
|
|
ent.Comp.OriginalDrawDepth = null;
|
|
}
|
|
|
|
private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args)
|
|
{
|
|
if (!TryComp<RotationVisualsComponent>(uid, out var rotVisuals))
|
|
return;
|
|
|
|
if (!Appearance.TryGetData<bool>(uid, BuckleVisuals.Buckled, out var buckled, args.Component) ||
|
|
!buckled ||
|
|
args.Sprite == null)
|
|
{
|
|
_rotationVisualizerSystem.SetHorizontalAngle((uid, rotVisuals), rotVisuals.DefaultRotation);
|
|
return;
|
|
}
|
|
|
|
// Animate strapping yourself to something at a given angle
|
|
// TODO: Dump this when buckle is better
|
|
_rotationVisualizerSystem.AnimateSpriteRotation(uid, args.Sprite, rotVisuals.HorizontalRotation, 0.125f);
|
|
}
|
|
}
|