mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 09:37:03 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Map.Components;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Shared.ComponentTrees;
|
|
|
|
/// <summary>
|
|
/// This system will recursively raise events to update component tree positions any time any entity moves.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This is used by some client-side systems (e.g., sprites, lights, etc). However this can be quite expensive and if possible should not be used by the server.
|
|
/// </remarks>
|
|
internal sealed partial class RecursiveMoveSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedTransformSystem _transform = default!;
|
|
|
|
public delegate void TreeRecursiveMoveEventHandler(EntityUid uid, TransformComponent xform);
|
|
|
|
public event TreeRecursiveMoveEventHandler? OnTreeRecursiveMove;
|
|
|
|
private EntityQuery<MapComponent> _mapQuery;
|
|
private EntityQuery<MapGridComponent> _gridQuery;
|
|
private EntityQuery<TransformComponent> _xformQuery;
|
|
|
|
private bool _subscribed = false;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
_gridQuery = GetEntityQuery<MapGridComponent>();
|
|
_mapQuery = GetEntityQuery<MapComponent>();
|
|
_xformQuery = GetEntityQuery<TransformComponent>();
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
if (_subscribed)
|
|
_transform.OnBeforeMoveEvent -= AnythingMoved;
|
|
|
|
_subscribed = false;
|
|
}
|
|
|
|
internal void AddSubscription()
|
|
{
|
|
if (_subscribed)
|
|
return;
|
|
|
|
_subscribed = true;
|
|
_transform.OnBeforeMoveEvent += AnythingMoved;
|
|
}
|
|
|
|
private void AnythingMoved(ref MoveEvent args)
|
|
{
|
|
if (args.Component.MapUid == args.Sender || args.Component.GridUid == args.Sender)
|
|
return;
|
|
|
|
DebugTools.Assert(!_mapQuery.HasComp(args.Sender));
|
|
DebugTools.Assert(!_gridQuery.HasComp(args.Sender));
|
|
|
|
AnythingMovedSubHandler(args.Sender, args.Component);
|
|
}
|
|
|
|
private void AnythingMovedSubHandler(
|
|
EntityUid uid,
|
|
TransformComponent xform)
|
|
{
|
|
OnTreeRecursiveMove?.Invoke(uid, xform);
|
|
|
|
// TODO only enumerate over entities in containers if necessary?
|
|
// annoyingly, containers aren't guaranteed to occlude sprites & lights
|
|
// but AFAIK thats currently unused???
|
|
|
|
foreach (var child in xform._children)
|
|
{
|
|
if (_xformQuery.TryGetComponent(child, out var childXform))
|
|
AnythingMovedSubHandler(child, childXform);
|
|
}
|
|
}
|
|
}
|