Files
RobustToolbox/Robust.Shared/Physics/ComponentTreeEntry.cs
Leon Friedrich 8ae35e12ee Update ComponentTreeSystem (#6211)
* Allow component trees to be disabled

* forgot

* I'm pretty sure this wasn't working as intended

* also outdated

* reduce branches in QueueTreeUpdate

* remove update hashset

* try fix

* Use Entity<T> and add ray overloads

* Move InRangeUnoccluded to engine

* reduce code duplication

* move _initialized check

* release notes
2025-10-09 17:30:00 +13:00

48 lines
1.5 KiB
C#

using System;
using Robust.Shared.GameObjects;
namespace Robust.Shared.Physics;
/// <summary>
/// This is a data struct for use with a <see cref="DynamicTree"/>. This stores both some generic component and the
/// entity's transform component. This is being used in place of a simple tuple so that the IEquatable can be
/// overriden, such that we can remove entries without needing to fetch the transform component of a possible
/// deleted entity.
/// </summary>
public readonly struct ComponentTreeEntry<T> : IEquatable<ComponentTreeEntry<T>>, IComparable<ComponentTreeEntry<T>> where T : IComponent
{
public T Component { get; init; }
public TransformComponent Transform { get; init; }
public EntityUid Uid => Component.Owner;
public int CompareTo(ComponentTreeEntry<T> other)
{
return Uid.CompareTo(other.Uid);
}
public bool Equals(ComponentTreeEntry<T> other)
{
return Uid.Equals(other.Uid);
}
public readonly void Deconstruct(out T component, out TransformComponent xform)
{
component = Component;
xform = Transform;
}
public static implicit operator Entity<T, TransformComponent>(ComponentTreeEntry<T> entry)
{
return new(entry.Uid, entry.Component, entry.Transform);
}
public static implicit operator ComponentTreeEntry<T>((T, TransformComponent) tuple)
{
return new ComponentTreeEntry<T>()
{
Component = tuple.Item1,
Transform = tuple.Item2
};
}
}