Replace all T : Component constraints with T : IComponent (#4494)

This commit is contained in:
DrSmugleaf
2023-10-17 19:37:46 -07:00
committed by GitHub
parent f24d18f470
commit 6b6ec844e8
22 changed files with 362 additions and 373 deletions

View File

@@ -35,7 +35,7 @@ END TEMPLATE-->
### Breaking changes
*None yet*
* The Component.OnRemove method has been removed. Use SubscribeLocalEvent<TComp, ComponentRemove>(OnRemove) from an EntitySystem instead.
### New features
@@ -98,7 +98,7 @@ END TEMPLATE-->
### New features
* The YAML validator now checks the default values of ProtoId<T> and EntProtoId data fields.
* The YAML validator now checks the default values of ProtoId<T> and EntProtoId data fields.
### Bugfixes

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Prometheus;
using Robust.Client.GameStates;
using Robust.Client.Player;
@@ -86,7 +85,7 @@ namespace Robust.Client.GameObjects
}
/// <inheritdoc />
public override void Dirty(EntityUid uid, Component component, MetaDataComponent? meta = null)
public override void Dirty(EntityUid uid, IComponent component, MetaDataComponent? meta = null)
{
// Client only dirties during prediction
if (_gameTiming.InPrediction)

View File

@@ -55,7 +55,7 @@ namespace Robust.Client.GameStates
private readonly Dictionary<EntityUid, HashSet<Type>> _pendingReapplyNetStates = new();
private readonly HashSet<NetEntity> _stateEnts = new();
private readonly List<EntityUid> _toDelete = new();
private readonly List<Component> _toRemove = new();
private readonly List<IComponent> _toRemove = new();
private readonly Dictionary<NetEntity, Dictionary<ushort, ComponentState>> _outputData = new();
private readonly List<(EntityUid, TransformComponent)> _queuedBroadphaseUpdates = new();
@@ -499,7 +499,7 @@ namespace Robust.Client.GameStates
var countReset = 0;
var system = _entitySystemManager.GetEntitySystem<ClientDirtySystem>();
var metaQuery = _entityManager.GetEntityQuery<MetaDataComponent>();
RemQueue<Component> toRemove = new();
RemQueue<IComponent> toRemove = new();
foreach (var entity in system.DirtyEntities)
{

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text;
@@ -188,10 +187,10 @@ namespace Robust.Shared.Scripting
}
#region EntityManager proxy methods
public T Comp<T>(EntityUid uid) where T : Component
public T Comp<T>(EntityUid uid) where T : IComponent
=> ent.GetComponent<T>(uid);
public bool TryComp<T>(EntityUid uid, out T? comp) where T : Component
public bool TryComp<T>(EntityUid uid, out T? comp) where T : IComponent
=> ent.TryGetComponent(uid, out comp);
public bool HasComp<T>(EntityUid uid)

View File

@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Robust.Shared.ContentPack;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Players;
using Robust.Shared.Prototypes;
@@ -173,7 +171,7 @@ public static class CompletionHelper
}
}
public static IEnumerable<CompletionOption> Components<T>(string text, IEntityManager? entManager = null) where T : Component
public static IEnumerable<CompletionOption> Components<T>(string text, IEntityManager? entManager = null) where T : IComponent
{
IoCManager.Resolve(ref entManager);

View File

@@ -38,19 +38,6 @@ namespace Robust.Shared.Containers
}
}
/// <inheritdoc />
protected internal override void OnRemove()
{
base.OnRemove();
foreach (var container in Containers.Values)
{
container.Shutdown(_entMan, _netMan);
}
Containers.Clear();
}
/// <inheritdoc />
public T MakeContainer<T>(string id)
where T : BaseContainer

View File

@@ -8,6 +8,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Utility;
@@ -16,6 +17,7 @@ namespace Robust.Shared.Containers
{
public abstract partial class SharedContainerSystem
{
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
@@ -34,6 +36,7 @@ namespace Robust.Shared.Containers
SubscribeLocalEvent<EntParentChangedMessage>(OnParentChanged);
SubscribeLocalEvent<ContainerManagerComponent, ComponentStartup>(OnStartupValidation);
SubscribeLocalEvent<ContainerManagerComponent, ComponentGetState>(OnContainerGetState);
SubscribeLocalEvent<ContainerManagerComponent, ComponentRemove>(OnContainerManagerRemove);
_gridQuery = GetEntityQuery<MapGridComponent>();
_mapQuery = GetEntityQuery<MapComponent>();
@@ -62,6 +65,16 @@ namespace Robust.Shared.Containers
args.State = new ContainerManagerComponent.ContainerManagerComponentState(containerSet);
}
private void OnContainerManagerRemove(EntityUid uid, ContainerManagerComponent component, ComponentRemove args)
{
foreach (var container in component.Containers.Values)
{
container.Shutdown(EntityManager, _net);
}
component.Containers.Clear();
}
// TODO: Make ContainerManagerComponent ECS and make these proxy methods the real deal.
#region Proxy Methods
@@ -242,7 +255,7 @@ namespace Robust.Shared.Containers
EntityQuery<T> entityQuery,
[NotNullWhen(true)] ref T? foundComponent,
MetaDataComponent? meta = null,
TransformComponent? xform = null) where T : Component
TransformComponent? xform = null) where T : IComponent
{
if (!MetaQuery.Resolve(uid, ref meta))
return false;
@@ -270,7 +283,7 @@ namespace Robust.Shared.Containers
EntityQuery<T> entityQuery,
List<T> foundComponents,
MetaDataComponent? meta = null,
TransformComponent? xform = null) where T : Component
TransformComponent? xform = null) where T : IComponent
{
if (!MetaQuery.Resolve(uid, ref meta))
return foundComponents.Any();

View File

@@ -1,5 +1,4 @@
using System;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Reflection;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -8,7 +7,7 @@ using Robust.Shared.ViewVariables;
namespace Robust.Shared.GameObjects
{
/// <inheritdoc />
/// <inheritdoc cref="IComponent"/>
[Reflect(false)]
[ImplicitDataDefinitionForInheritors]
public abstract partial class Component : IComponent
@@ -17,7 +16,8 @@ namespace Robust.Shared.GameObjects
[ViewVariables(VVAccess.ReadWrite)]
private bool _netSync { get; set; } = true;
internal bool Networked = true;
[Obsolete("Do not use from content")]
public bool Networked { get; set; } = true;
/// <inheritdoc />
public bool NetSyncEnabled
@@ -33,19 +33,10 @@ namespace Robust.Shared.GameObjects
/// <inheritdoc />
[ViewVariables]
public ComponentLifeStage LifeStage { get; internal set; } = ComponentLifeStage.PreAdd;
public ComponentLifeStage LifeStage { get; [Obsolete("Do not use from content")] set; } = ComponentLifeStage.PreAdd;
/// <summary>
/// If true, and if this is a networked component, then component data will only be sent to players if their
/// controlled entity is the owner of this component. This is less performance intensive than <see cref="SessionSpecific"/>.
/// </summary>
public virtual bool SendOnlyToOwner => false;
/// <summary>
/// If true, and if this is a networked component, then this component will cause <see
/// cref="ComponentGetStateAttemptEvent"/> events to be raised to check whether a given player should
/// receive this component's state.
/// </summary>
public virtual bool SessionSpecific => false;
/// <inheritdoc />
@@ -62,21 +53,11 @@ namespace Robust.Shared.GameObjects
/// <inheritdoc />
[ViewVariables]
public GameTick CreationTick { get; internal set; }
public GameTick CreationTick { get; [Obsolete("Do not use from content")] set; }
/// <inheritdoc />
[ViewVariables]
public GameTick LastModifiedTick { get; internal set; }
/// <summary>
/// Called when the component is removed from an entity.
/// Shuts down the component.
/// The component has already been marked as deleted in the component manager.
/// </summary>
protected internal virtual void OnRemove()
{
LifeStage = ComponentLifeStage.Deleted;
}
public GameTick LastModifiedTick { get; [Obsolete("Do not use from content")] set; }
/// <inheritdoc />
[Obsolete]
@@ -88,13 +69,15 @@ namespace Robust.Shared.GameObjects
// these two methods clear the LastModifiedTick/CreationTick to mark it as "not different from prototype load".
// This is used as optimization in the game state system to avoid sending redundant component data.
internal virtual void ClearTicks()
[Obsolete("Do not use from content")]
public virtual void ClearTicks()
{
LastModifiedTick = GameTick.Zero;
ClearCreationTick();
}
internal void ClearCreationTick()
[Obsolete("Do not use from content")]
public void ClearCreationTick()
{
CreationTick = GameTick.Zero;
}

View File

@@ -9,7 +9,7 @@ namespace Robust.Shared.GameObjects
/// <summary>
/// Component that this event relates to.
/// </summary>
public Component Component { get; }
public IComponent Component { get; }
/// <summary>
/// EntityUid of the entity this component belongs to.
@@ -21,7 +21,7 @@ namespace Robust.Shared.GameObjects
/// </summary>
/// <param name="component">The relevant component</param>
/// <param name="owner">EntityUid of the entity this component belongs to.</param>
public ComponentEventArgs(Component component, EntityUid owner)
public ComponentEventArgs(IComponent component, EntityUid owner)
{
Component = component;
Owner = owner;

View File

@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
@@ -7,8 +8,6 @@ using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using System;
using System.Collections.Generic;
namespace Robust.Shared.GameObjects
{
@@ -68,7 +67,7 @@ namespace Robust.Shared.GameObjects
/// The components attached to the entity that are currently networked.
/// </summary>
[ViewVariables]
internal readonly Dictionary<ushort, Component> NetComponents = new();
internal readonly Dictionary<ushort, IComponent> NetComponents = new();
/// <summary>
/// Network identifier for this entity.
@@ -199,7 +198,8 @@ namespace Robust.Shared.GameObjects
public bool EntityInitializing => EntityLifeStage == EntityLifeStage.Initializing;
public bool EntityDeleted => EntityLifeStage >= EntityLifeStage.Deleted;
internal override void ClearTicks()
[Obsolete("Do not use from content")]
public override void ClearTicks()
{
// Do not clear modified ticks.
// MetaDataComponent is used in the game state system to carry initial data like prototype ID.

View File

@@ -36,15 +36,15 @@ namespace Robust.Shared.GameObjects
private static readonly ComponentState DefaultComponentState = new();
private readonly Dictionary<Type, Dictionary<EntityUid, Component>> _entTraitDict
private readonly Dictionary<Type, Dictionary<EntityUid, IComponent>> _entTraitDict
= new();
private Dictionary<EntityUid, Component>[] _entTraitArray
= Array.Empty<Dictionary<EntityUid, Component>>();
private Dictionary<EntityUid, IComponent>[] _entTraitArray
= Array.Empty<Dictionary<EntityUid, IComponent>>();
private readonly HashSet<Component> _deleteSet = new(TypeCapacity);
private readonly HashSet<IComponent> _deleteSet = new(TypeCapacity);
private UniqueIndexHkm<EntityUid, Component> _entCompIndex =
private UniqueIndexHkm<EntityUid, IComponent> _entCompIndex =
new(ComponentCollectionCapacity);
/// <inheritdoc />
@@ -78,7 +78,7 @@ namespace Robust.Shared.GameObjects
private void AddComponentRefType(CompIdx type)
{
var dict = new Dictionary<EntityUid, Component>();
var dict = new Dictionary<EntityUid, IComponent>();
_entTraitDict.Add(_componentFactory.IdxToType(type), dict);
CompIdx.AssignArray(ref _entTraitArray, type, dict);
}
@@ -91,7 +91,7 @@ namespace Robust.Shared.GameObjects
#region Component Management
/// <inheritdoc />
public int Count<T>() where T : Component
public int Count<T>() where T : IComponent
{
var dict = _entTraitDict[typeof(T)];
return dict.Count;
@@ -114,7 +114,7 @@ namespace Robust.Shared.GameObjects
metadata.EntityLifeStage = EntityLifeStage.Initializing;
// Initialize() can modify the collection of components. Copy them.
FixedArray32<Component?> compsFixed = default;
FixedArray32<IComponent?> compsFixed = default;
var comps = compsFixed.AsSpan;
CopyComponentsInto(ref comps, uid);
@@ -145,7 +145,7 @@ namespace Robust.Shared.GameObjects
{
// Startup() can modify _components
// This code can only handle additions to the list. Is there a better way? Probably not.
FixedArray32<Component?> compsFixed = default;
FixedArray32<IComponent?> compsFixed = default;
var comps = compsFixed.AsSpan;
CopyComponentsInto(ref comps, uid);
@@ -182,7 +182,7 @@ namespace Robust.Shared.GameObjects
return newComponent;
}
public T AddComponent<T>(EntityUid uid) where T : Component, new()
public T AddComponent<T>(EntityUid uid) where T : IComponent, new()
{
var newComponent = _componentFactory.GetComponent<T>();
#pragma warning disable CS0618 // Type or member is obsolete
@@ -193,7 +193,7 @@ namespace Robust.Shared.GameObjects
}
public readonly struct CompInitializeHandle<T> : IDisposable
where T : Component
where T : IComponent
{
private readonly IEntityManager _entMan;
private readonly EntityUid _owner;
@@ -230,7 +230,7 @@ namespace Robust.Shared.GameObjects
/// <inheritdoc />
[Obsolete]
public CompInitializeHandle<T> AddComponentUninitialized<T>(EntityUid uid) where T : Component, new()
public CompInitializeHandle<T> AddComponentUninitialized<T>(EntityUid uid) where T : IComponent, new()
{
var reg = _componentFactory.GetRegistration<T>();
var newComponent = (T)_componentFactory.GetComponent(reg);
@@ -247,7 +247,7 @@ namespace Robust.Shared.GameObjects
}
/// <inheritdoc />
public void AddComponent<T>(EntityUid uid, T component, bool overwrite = false, MetaDataComponent? metadata = null) where T : Component
public void AddComponent<T>(EntityUid uid, T component, bool overwrite = false, MetaDataComponent? metadata = null) where T : IComponent
{
if (!uid.IsValid() || !EntityExists(uid))
throw new ArgumentException($"Entity {uid} is not valid.", nameof(uid));
@@ -268,14 +268,14 @@ namespace Robust.Shared.GameObjects
AddComponentInternal(uid, component, overwrite, false, metadata);
}
private void AddComponentInternal<T>(EntityUid uid, T component, bool overwrite, bool skipInit, MetaDataComponent? metadata = null) where T : Component
private void AddComponentInternal<T>(EntityUid uid, T component, bool overwrite, bool skipInit, MetaDataComponent? metadata = null) where T : IComponent
{
// get interface aliases for mapping
var reg = _componentFactory.GetRegistration(component);
AddComponentInternal(uid, component, reg, overwrite, skipInit, metadata);
}
private void AddComponentInternal<T>(EntityUid uid, T component, ComponentRegistration reg, bool overwrite, bool skipInit, MetaDataComponent? metadata = null) where T : Component
private void AddComponentInternal<T>(EntityUid uid, T component, ComponentRegistration reg, bool overwrite, bool skipInit, MetaDataComponent? metadata = null) where T : IComponent
{
// We can't use typeof(T) here in case T is just Component
DebugTools.Assert(component is MetaDataComponent ||
@@ -440,7 +440,7 @@ namespace Robust.Shared.GameObjects
RemoveComponentDeferred(component, owner, false);
}
private static IEnumerable<Component> InSafeOrder(IEnumerable<Component> comps, bool forCreation = false)
private static IEnumerable<IComponent> InSafeOrder(IEnumerable<IComponent> comps, bool forCreation = false)
{
static int Sequence(IComponent x)
=> x switch
@@ -527,7 +527,7 @@ namespace Robust.Shared.GameObjects
#endif
}
private void RemoveComponentImmediate(Component component, EntityUid uid, bool terminating,
private void RemoveComponentImmediate(IComponent component, EntityUid uid, bool terminating,
MetaDataComponent? meta)
{
if (component.Deleted)
@@ -602,7 +602,7 @@ namespace Robust.Shared.GameObjects
_deleteSet.Clear();
}
private void DeleteComponent(EntityUid entityUid, Component component, bool terminating, MetaDataComponent? metadata = null)
private void DeleteComponent(EntityUid entityUid, IComponent component, bool terminating, MetaDataComponent? metadata = null)
{
if (!MetaQuery.ResolveInternal(entityUid, ref metadata))
return;
@@ -643,7 +643,7 @@ namespace Robust.Shared.GameObjects
{
var dict = _entTraitArray[CompIdx.ArrayIndex<T>()];
DebugTools.Assert(dict != null, $"Unknown component: {typeof(T).Name}");
return dict!.TryGetValue(uid, out var comp) && !comp.Deleted;
return dict.TryGetValue(uid, out var comp) && !comp.Deleted;
}
/// <inheritdoc />
@@ -699,15 +699,14 @@ namespace Robust.Shared.GameObjects
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T EnsureComponent<T>(EntityUid uid) where T : Component, new()
public T EnsureComponent<T>(EntityUid uid) where T : IComponent, new()
{
if (TryGetComponent<T>(uid, out var component))
{
// Check for deferred component removal.
if (component.LifeStage <= ComponentLifeStage.Running)
return component;
else
RemoveComponent(uid, component);
RemoveComponent(uid, component);
}
return AddComponent<T>(uid);
@@ -715,7 +714,7 @@ namespace Robust.Shared.GameObjects
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool EnsureComponent<T>(EntityUid entity, out T component) where T : Component, new()
public bool EnsureComponent<T>(EntityUid entity, out T component) where T : IComponent, new()
{
if (TryGetComponent<T>(entity, out var comp))
{
@@ -725,8 +724,8 @@ namespace Robust.Shared.GameObjects
component = comp;
return true;
}
else
RemoveComponent(entity, comp);
RemoveComponent(entity, comp);
}
component = AddComponent<T>(entity);
@@ -739,11 +738,11 @@ namespace Robust.Shared.GameObjects
{
var dict = _entTraitArray[CompIdx.ArrayIndex<T>()];
DebugTools.Assert(dict != null, $"Unknown component: {typeof(T).Name}");
if (dict!.TryGetValue(uid, out var comp))
if (dict.TryGetValue(uid, out var comp))
{
if (!comp!.Deleted)
if (!comp.Deleted)
{
return (T)(IComponent) comp;
return (T)comp;
}
}
@@ -802,11 +801,11 @@ namespace Robust.Shared.GameObjects
{
var dict = _entTraitArray[CompIdx.ArrayIndex<T>()];
DebugTools.Assert(dict != null, $"Unknown component: {typeof(T).Name}");
if (dict!.TryGetValue(uid, out var comp))
if (dict.TryGetValue(uid, out var comp))
{
if (!comp.Deleted)
{
component = (T)(IComponent)comp;
component = (T)comp;
return true;
}
}
@@ -922,25 +921,25 @@ namespace Robust.Shared.GameObjects
return TryGetComponent(uid.Value, netId, out component, meta);
}
public EntityQuery<TComp1> GetEntityQuery<TComp1>() where TComp1 : Component
public EntityQuery<TComp1> GetEntityQuery<TComp1>() where TComp1 : IComponent
{
var comps = _entTraitArray[CompIdx.ArrayIndex<TComp1>()];
DebugTools.Assert(comps != null, $"Unknown component: {typeof(TComp1).Name}");
return new EntityQuery<TComp1>(comps!, _resolveSawmill);
return new EntityQuery<TComp1>(comps, _resolveSawmill);
}
public EntityQuery<Component> GetEntityQuery(Type type)
public EntityQuery<IComponent> GetEntityQuery(Type type)
{
var comps = _entTraitArray[CompIdx.ArrayIndex(type)];
DebugTools.Assert(comps != null, $"Unknown component: {type.Name}");
return new EntityQuery<Component>(comps!, _resolveSawmill);
return new EntityQuery<IComponent>(comps, _resolveSawmill);
}
/// <inheritdoc />
public IEnumerable<IComponent> GetComponents(EntityUid uid)
{
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (Component comp in _entCompIndex[uid].ToArray())
foreach (var comp in _entCompIndex[uid].ToArray())
{
if (comp.Deleted) continue;
@@ -957,14 +956,14 @@ namespace Robust.Shared.GameObjects
/// <summary>
/// Copy the components for an entity into the given span,
/// or re-allocate the span as an array if there's not enough space.
/// or re-allocate the span as an array if there's not enough space.º
/// </summary>
private void CopyComponentsInto(ref Span<Component?> comps, EntityUid uid)
private void CopyComponentsInto(ref Span<IComponent?> comps, EntityUid uid)
{
var set = _entCompIndex[uid];
if (set.Count > comps.Length)
{
comps = new Component[set.Count];
comps = new IComponent[set.Count];
}
var i = 0;
@@ -1003,7 +1002,7 @@ namespace Robust.Shared.GameObjects
#region Join Functions
public (EntityUid Uid, T Component)[] AllComponents<T>() where T : Component
public (EntityUid Uid, T Component)[] AllComponents<T>() where T : IComponent
{
var query = AllEntityQueryEnumerator<T>();
var comps = new (EntityUid Uid, T Component)[Count<T>()];
@@ -1018,7 +1017,7 @@ namespace Robust.Shared.GameObjects
return comps;
}
public List<(EntityUid Uid, T Component)> AllComponentsList<T>() where T : Component
public List<(EntityUid Uid, T Component)> AllComponentsList<T>() where T : IComponent
{
var query = AllEntityQueryEnumerator<T>();
var comps = new List<(EntityUid Uid, T Component)>(Count<T>());
@@ -1032,15 +1031,15 @@ namespace Robust.Shared.GameObjects
}
public AllEntityQueryEnumerator<TComp1> AllEntityQueryEnumerator<TComp1>()
where TComp1 : Component
where TComp1 : IComponent
{
var trait1 = _entTraitArray[CompIdx.ArrayIndex<TComp1>()];
return new AllEntityQueryEnumerator<TComp1>(trait1);
}
public AllEntityQueryEnumerator<TComp1, TComp2> AllEntityQueryEnumerator<TComp1, TComp2>()
where TComp1 : Component
where TComp2 : Component
where TComp1 : IComponent
where TComp2 : IComponent
{
var trait1 = _entTraitArray[CompIdx.ArrayIndex<TComp1>()];
var trait2 = _entTraitArray[CompIdx.ArrayIndex<TComp2>()];
@@ -1048,9 +1047,9 @@ namespace Robust.Shared.GameObjects
}
public AllEntityQueryEnumerator<TComp1, TComp2, TComp3> AllEntityQueryEnumerator<TComp1, TComp2, TComp3>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
{
var trait1 = _entTraitArray[CompIdx.ArrayIndex<TComp1>()];
var trait2 = _entTraitArray[CompIdx.ArrayIndex<TComp2>()];
@@ -1059,10 +1058,10 @@ namespace Robust.Shared.GameObjects
}
public AllEntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4> AllEntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp4 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
where TComp4 : IComponent
{
var trait1 = _entTraitArray[CompIdx.ArrayIndex<TComp1>()];
var trait2 = _entTraitArray[CompIdx.ArrayIndex<TComp2>()];
@@ -1072,15 +1071,15 @@ namespace Robust.Shared.GameObjects
}
public EntityQueryEnumerator<TComp1> EntityQueryEnumerator<TComp1>()
where TComp1 : Component
where TComp1 : IComponent
{
var trait1 = _entTraitArray[CompIdx.ArrayIndex<TComp1>()];
return new EntityQueryEnumerator<TComp1>(trait1, MetaQuery);
}
public EntityQueryEnumerator<TComp1, TComp2> EntityQueryEnumerator<TComp1, TComp2>()
where TComp1 : Component
where TComp2 : Component
where TComp1 : IComponent
where TComp2 : IComponent
{
var trait1 = _entTraitArray[CompIdx.ArrayIndex<TComp1>()];
var trait2 = _entTraitArray[CompIdx.ArrayIndex<TComp2>()];
@@ -1088,9 +1087,9 @@ namespace Robust.Shared.GameObjects
}
public EntityQueryEnumerator<TComp1, TComp2, TComp3> EntityQueryEnumerator<TComp1, TComp2, TComp3>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
{
var trait1 = _entTraitArray[CompIdx.ArrayIndex<TComp1>()];
var trait2 = _entTraitArray[CompIdx.ArrayIndex<TComp2>()];
@@ -1099,10 +1098,10 @@ namespace Robust.Shared.GameObjects
}
public EntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4> EntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp4 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
where TComp4 : IComponent
{
var trait1 = _entTraitArray[CompIdx.ArrayIndex<TComp1>()];
var trait2 = _entTraitArray[CompIdx.ArrayIndex<TComp2>()];
@@ -1120,11 +1119,11 @@ namespace Robust.Shared.GameObjects
if (includePaused)
{
foreach (var t1Comp in comps!.Values)
foreach (var t1Comp in comps.Values)
{
if (t1Comp.Deleted) continue;
yield return (T)(object)t1Comp;
yield return (T)t1Comp;
}
}
else
@@ -1135,7 +1134,7 @@ namespace Robust.Shared.GameObjects
if (metaComp.EntityPaused) continue;
yield return (T)(object)t1Comp;
yield return (T)t1Comp;
}
}
}
@@ -1158,8 +1157,8 @@ namespace Robust.Shared.GameObjects
continue;
yield return (
(TComp1)(object)t1Comp,
(TComp2)(object)t2Comp);
(TComp1) t1Comp,
(TComp2) t2Comp);
}
}
else
@@ -1179,8 +1178,8 @@ namespace Robust.Shared.GameObjects
if (meta.EntityPaused) continue;
yield return (
(TComp1)(object)t1Comp,
(TComp2)(object)t2Comp);
(TComp1) t1Comp,
(TComp2) t2Comp);
}
}
}
@@ -1206,9 +1205,9 @@ namespace Robust.Shared.GameObjects
continue;
yield return (
(TComp1)(object)t1Comp,
(TComp2)(object)t2Comp,
(TComp3)(object)t3Comp);
(TComp1) t1Comp,
(TComp2) t2Comp,
(TComp3) t3Comp);
}
}
else
@@ -1231,9 +1230,9 @@ namespace Robust.Shared.GameObjects
if (meta.EntityPaused) continue;
yield return (
(TComp1)(object)t1Comp,
(TComp2)(object)t2Comp,
(TComp3)(object)t3Comp);
(TComp1) t1Comp,
(TComp2) t2Comp,
(TComp3) t3Comp);
}
}
}
@@ -1265,10 +1264,10 @@ namespace Robust.Shared.GameObjects
continue;
yield return (
(TComp1)(object)t1Comp,
(TComp2)(object)t2Comp,
(TComp3)(object)t3Comp,
(TComp4)(object)t4Comp);
(TComp1) t1Comp,
(TComp2) t2Comp,
(TComp3) t3Comp,
(TComp4) t4Comp);
}
}
else
@@ -1294,10 +1293,10 @@ namespace Robust.Shared.GameObjects
if (meta.EntityPaused) continue;
yield return (
(TComp1)(object)t1Comp,
(TComp2)(object)t2Comp,
(TComp3)(object)t3Comp,
(TComp4)(object)t4Comp);
(TComp1) t1Comp,
(TComp2) t2Comp,
(TComp3) t3Comp,
(TComp4) t4Comp);
}
}
}
@@ -1305,7 +1304,7 @@ namespace Robust.Shared.GameObjects
#endregion
/// <inheritdoc />
public IEnumerable<(EntityUid Uid, Component Component)> GetAllComponents(Type type, bool includePaused = false)
public IEnumerable<(EntityUid Uid, IComponent Component)> GetAllComponents(Type type, bool includePaused = false)
{
var comps = _entTraitDict[type];
@@ -1363,23 +1362,23 @@ namespace Robust.Shared.GameObjects
public readonly struct NetComponentEnumerable
{
private readonly Dictionary<ushort, Component> _dictionary;
private readonly Dictionary<ushort, IComponent> _dictionary;
public NetComponentEnumerable(Dictionary<ushort, Component> dictionary) => _dictionary = dictionary;
public NetComponentEnumerable(Dictionary<ushort, IComponent> dictionary) => _dictionary = dictionary;
public NetComponentEnumerator GetEnumerator() => new(_dictionary);
}
public struct NetComponentEnumerator
{
// DO NOT MAKE THIS READONLY
private Dictionary<ushort, Component>.Enumerator _dictEnum;
private Dictionary<ushort, IComponent>.Enumerator _dictEnum;
public NetComponentEnumerator(Dictionary<ushort, Component> dictionary) =>
public NetComponentEnumerator(Dictionary<ushort, IComponent> dictionary) =>
_dictEnum = dictionary.GetEnumerator();
public bool MoveNext() => _dictEnum.MoveNext();
public (ushort netId, Component component) Current
public (ushort netId, IComponent component) Current
{
get
{
@@ -1389,12 +1388,12 @@ namespace Robust.Shared.GameObjects
}
}
public readonly struct EntityQuery<TComp1> where TComp1 : Component
public readonly struct EntityQuery<TComp1> where TComp1 : IComponent
{
private readonly Dictionary<EntityUid, Component> _traitDict;
private readonly Dictionary<EntityUid, IComponent> _traitDict;
private readonly ISawmill _sawmill;
public EntityQuery(Dictionary<EntityUid, Component> traitDict, ISawmill sawmill)
public EntityQuery(Dictionary<EntityUid, IComponent> traitDict, ISawmill sawmill)
{
_traitDict = traitDict;
_sawmill = sawmill;
@@ -1482,7 +1481,7 @@ namespace Robust.Shared.GameObjects
if (TryGetComponent(uid, out var comp))
return comp;
return null;
return default;
}
#region Internal
@@ -1534,7 +1533,7 @@ namespace Robust.Shared.GameObjects
}
/// <summary>
/// Elides the component.Deleted check of <see cref="HasComponent"/>
/// Elides the component.Deleted check of <see cref="HasComponent(EntityUid)"/>
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
@@ -1579,7 +1578,7 @@ namespace Robust.Shared.GameObjects
if (TryGetComponent(uid, out var comp))
return comp;
return null;
return default;
}
#endregion
@@ -1591,13 +1590,13 @@ namespace Robust.Shared.GameObjects
/// Returns all matching unpaused components.
/// </summary>
public struct EntityQueryEnumerator<TComp1> : IDisposable
where TComp1 : Component
where TComp1 : IComponent
{
private Dictionary<EntityUid, Component>.Enumerator _traitDict;
private Dictionary<EntityUid, IComponent>.Enumerator _traitDict;
private readonly EntityQuery<MetaDataComponent> _metaQuery;
public EntityQueryEnumerator(
Dictionary<EntityUid, Component> traitDict,
Dictionary<EntityUid, IComponent> traitDict,
EntityQuery<MetaDataComponent> metaQuery)
{
_traitDict = traitDict.GetEnumerator();
@@ -1611,7 +1610,7 @@ namespace Robust.Shared.GameObjects
if (!_traitDict.MoveNext())
{
uid = default;
comp1 = null;
comp1 = default;
return false;
}
@@ -1649,16 +1648,16 @@ namespace Robust.Shared.GameObjects
/// Returns all matching unpaused components.
/// </summary>
public struct EntityQueryEnumerator<TComp1, TComp2> : IDisposable
where TComp1 : Component
where TComp2 : Component
where TComp1 : IComponent
where TComp2 : IComponent
{
private Dictionary<EntityUid, Component>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, Component> _traitDict2;
private Dictionary<EntityUid, IComponent>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, IComponent> _traitDict2;
private readonly EntityQuery<MetaDataComponent> _metaQuery;
public EntityQueryEnumerator(
Dictionary<EntityUid, Component> traitDict,
Dictionary<EntityUid, Component> traitDict2,
Dictionary<EntityUid, IComponent> traitDict,
Dictionary<EntityUid, IComponent> traitDict2,
EntityQuery<MetaDataComponent> metaQuery)
{
_traitDict = traitDict.GetEnumerator();
@@ -1673,8 +1672,8 @@ namespace Robust.Shared.GameObjects
if (!_traitDict.MoveNext())
{
uid = default;
comp1 = null;
comp2 = null;
comp1 = default;
comp2 = default;
return false;
}
@@ -1718,19 +1717,19 @@ namespace Robust.Shared.GameObjects
/// Returns all matching unpaused components.
/// </summary>
public struct EntityQueryEnumerator<TComp1, TComp2, TComp3> : IDisposable
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
{
private Dictionary<EntityUid, Component>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, Component> _traitDict2;
private readonly Dictionary<EntityUid, Component> _traitDict3;
private Dictionary<EntityUid, IComponent>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, IComponent> _traitDict2;
private readonly Dictionary<EntityUid, IComponent> _traitDict3;
private readonly EntityQuery<MetaDataComponent> _metaQuery;
public EntityQueryEnumerator(
Dictionary<EntityUid, Component> traitDict,
Dictionary<EntityUid, Component> traitDict2,
Dictionary<EntityUid, Component> traitDict3,
Dictionary<EntityUid, IComponent> traitDict,
Dictionary<EntityUid, IComponent> traitDict2,
Dictionary<EntityUid, IComponent> traitDict3,
EntityQuery<MetaDataComponent> metaQuery)
{
_traitDict = traitDict.GetEnumerator();
@@ -1746,9 +1745,9 @@ namespace Robust.Shared.GameObjects
if (!_traitDict.MoveNext())
{
uid = default;
comp1 = null;
comp2 = null;
comp3 = null;
comp1 = default;
comp2 = default;
comp3 = default;
return false;
}
@@ -1801,22 +1800,22 @@ namespace Robust.Shared.GameObjects
/// Returns all matching unpaused components.
/// </summary>
public struct EntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4> : IDisposable
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp4 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
where TComp4 : IComponent
{
private Dictionary<EntityUid, Component>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, Component> _traitDict2;
private readonly Dictionary<EntityUid, Component> _traitDict3;
private readonly Dictionary<EntityUid, Component> _traitDict4;
private Dictionary<EntityUid, IComponent>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, IComponent> _traitDict2;
private readonly Dictionary<EntityUid, IComponent> _traitDict3;
private readonly Dictionary<EntityUid, IComponent> _traitDict4;
private readonly EntityQuery<MetaDataComponent> _metaQuery;
public EntityQueryEnumerator(
Dictionary<EntityUid, Component> traitDict,
Dictionary<EntityUid, Component> traitDict2,
Dictionary<EntityUid, Component> traitDict3,
Dictionary<EntityUid, Component> traitDict4,
Dictionary<EntityUid, IComponent> traitDict,
Dictionary<EntityUid, IComponent> traitDict2,
Dictionary<EntityUid, IComponent> traitDict3,
Dictionary<EntityUid, IComponent> traitDict4,
EntityQuery<MetaDataComponent> metaQuery)
{
_traitDict = traitDict.GetEnumerator();
@@ -1833,10 +1832,10 @@ namespace Robust.Shared.GameObjects
if (!_traitDict.MoveNext())
{
uid = default;
comp1 = null;
comp2 = null;
comp3 = null;
comp4 = null;
comp1 = default;
comp2 = default;
comp3 = default;
comp4 = default;
return false;
}
@@ -1900,12 +1899,12 @@ namespace Robust.Shared.GameObjects
/// Returns all matching components, paused or not.
/// </summary>
public struct AllEntityQueryEnumerator<TComp1> : IDisposable
where TComp1 : Component
where TComp1 : IComponent
{
private Dictionary<EntityUid, Component>.Enumerator _traitDict;
private Dictionary<EntityUid, IComponent>.Enumerator _traitDict;
public AllEntityQueryEnumerator(
Dictionary<EntityUid, Component> traitDict)
Dictionary<EntityUid, IComponent> traitDict)
{
_traitDict = traitDict.GetEnumerator();
}
@@ -1917,7 +1916,7 @@ namespace Robust.Shared.GameObjects
if (!_traitDict.MoveNext())
{
uid = default;
comp1 = null;
comp1 = default;
return false;
}
@@ -1950,15 +1949,15 @@ namespace Robust.Shared.GameObjects
/// Returns all matching components, paused or not.
/// </summary>
public struct AllEntityQueryEnumerator<TComp1, TComp2> : IDisposable
where TComp1 : Component
where TComp2 : Component
where TComp1 : IComponent
where TComp2 : IComponent
{
private Dictionary<EntityUid, Component>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, Component> _traitDict2;
private Dictionary<EntityUid, IComponent>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, IComponent> _traitDict2;
public AllEntityQueryEnumerator(
Dictionary<EntityUid, Component> traitDict,
Dictionary<EntityUid, Component> traitDict2)
Dictionary<EntityUid, IComponent> traitDict,
Dictionary<EntityUid, IComponent> traitDict2)
{
_traitDict = traitDict.GetEnumerator();
_traitDict2 = traitDict2;
@@ -1971,8 +1970,8 @@ namespace Robust.Shared.GameObjects
if (!_traitDict.MoveNext())
{
uid = default;
comp1 = null;
comp2 = null;
comp1 = default;
comp2 = default;
return false;
}
@@ -2011,18 +2010,18 @@ namespace Robust.Shared.GameObjects
/// Returns all matching components, paused or not.
/// </summary>
public struct AllEntityQueryEnumerator<TComp1, TComp2, TComp3> : IDisposable
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
{
private Dictionary<EntityUid, Component>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, Component> _traitDict2;
private readonly Dictionary<EntityUid, Component> _traitDict3;
private Dictionary<EntityUid, IComponent>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, IComponent> _traitDict2;
private readonly Dictionary<EntityUid, IComponent> _traitDict3;
public AllEntityQueryEnumerator(
Dictionary<EntityUid, Component> traitDict,
Dictionary<EntityUid, Component> traitDict2,
Dictionary<EntityUid, Component> traitDict3)
Dictionary<EntityUid, IComponent> traitDict,
Dictionary<EntityUid, IComponent> traitDict2,
Dictionary<EntityUid, IComponent> traitDict3)
{
_traitDict = traitDict.GetEnumerator();
_traitDict2 = traitDict2;
@@ -2036,9 +2035,9 @@ namespace Robust.Shared.GameObjects
if (!_traitDict.MoveNext())
{
uid = default;
comp1 = null;
comp2 = null;
comp3 = null;
comp1 = default;
comp2 = default;
comp3 = default;
return false;
}
@@ -2086,21 +2085,21 @@ namespace Robust.Shared.GameObjects
/// Returns all matching components, paused or not.
/// </summary>
public struct AllEntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4> : IDisposable
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp4 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
where TComp4 : IComponent
{
private Dictionary<EntityUid, Component>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, Component> _traitDict2;
private readonly Dictionary<EntityUid, Component> _traitDict3;
private readonly Dictionary<EntityUid, Component> _traitDict4;
private Dictionary<EntityUid, IComponent>.Enumerator _traitDict;
private readonly Dictionary<EntityUid, IComponent> _traitDict2;
private readonly Dictionary<EntityUid, IComponent> _traitDict3;
private readonly Dictionary<EntityUid, IComponent> _traitDict4;
public AllEntityQueryEnumerator(
Dictionary<EntityUid, Component> traitDict,
Dictionary<EntityUid, Component> traitDict2,
Dictionary<EntityUid, Component> traitDict3,
Dictionary<EntityUid, Component> traitDict4)
Dictionary<EntityUid, IComponent> traitDict,
Dictionary<EntityUid, IComponent> traitDict2,
Dictionary<EntityUid, IComponent> traitDict3,
Dictionary<EntityUid, IComponent> traitDict4)
{
_traitDict = traitDict.GetEnumerator();
_traitDict2 = traitDict2;
@@ -2115,10 +2114,10 @@ namespace Robust.Shared.GameObjects
if (!_traitDict.MoveNext())
{
uid = default;
comp1 = null;
comp2 = null;
comp3 = null;
comp4 = null;
comp1 = default;
comp2 = default;
comp3 = default;
comp4 = default;
return false;
}

View File

@@ -14,7 +14,7 @@ public partial class EntityManager
/// Increases the life stage from <see cref="ComponentLifeStage.PreAdd" /> to <see cref="ComponentLifeStage.Added" />,
/// after raising a <see cref="ComponentAdd"/> event.
/// </summary>
internal void LifeAddToEntity(Component component, CompIdx type)
internal void LifeAddToEntity(IComponent component, CompIdx type)
{
DebugTools.Assert(component.LifeStage == ComponentLifeStage.PreAdd);
@@ -30,7 +30,7 @@ public partial class EntityManager
/// Increases the life stage from <see cref="ComponentLifeStage.Added" /> to <see cref="ComponentLifeStage.Initialized" />,
/// calling <see cref="Initialize" />.
/// </summary>
internal void LifeInitialize(Component component, CompIdx type)
internal void LifeInitialize(IComponent component, CompIdx type)
{
DebugTools.Assert(component.LifeStage == ComponentLifeStage.Added);
@@ -43,7 +43,7 @@ public partial class EntityManager
/// Increases the life stage from <see cref="ComponentLifeStage.Initialized" /> to
/// <see cref="ComponentLifeStage.Running" />, calling <see cref="Startup" />.
/// </summary>
internal void LifeStartup(Component component)
internal void LifeStartup(IComponent component)
{
DebugTools.Assert(component.LifeStage == ComponentLifeStage.Initialized);
@@ -59,7 +59,7 @@ public partial class EntityManager
/// <remarks>
/// Components are allowed to remove themselves in their own Startup function.
/// </remarks>
internal void LifeShutdown(Component component)
internal void LifeShutdown(IComponent component)
{
DebugTools.Assert(component.LifeStage is >= ComponentLifeStage.Initializing and < ComponentLifeStage.Stopping);
@@ -79,21 +79,13 @@ public partial class EntityManager
/// Increases the life stage from <see cref="ComponentLifeStage.Stopped" /> to <see cref="ComponentLifeStage.Deleted" />,
/// calling <see cref="Component.OnRemove" />.
/// </summary>
internal void LifeRemoveFromEntity(Component component)
internal void LifeRemoveFromEntity(IComponent component)
{
// can be called at any time after PreAdd, including inside other life stage events.
DebugTools.Assert(component.LifeStage != ComponentLifeStage.PreAdd);
component.LifeStage = ComponentLifeStage.Removing;
EventBus.RaiseComponentEvent(component, CompRemoveInstance);
component.OnRemove();
#if DEBUG
if (component.LifeStage != ComponentLifeStage.Deleted)
{
DebugTools.Assert($"Component {component.GetType().Name} did not call base {nameof(component.OnRemove)} in derived method.");
}
#endif
component.LifeStage = ComponentLifeStage.Deleted;
}
}

View File

@@ -18,7 +18,7 @@ namespace Robust.Shared.GameObjects
{
public delegate void EntityUidQueryCallback(EntityUid uid);
public delegate void ComponentQueryCallback<T>(EntityUid uid, T component) where T : Component;
public delegate void ComponentQueryCallback<T>(EntityUid uid, T component) where T : IComponent;
/// <inheritdoc />
[Virtual]
@@ -387,13 +387,13 @@ namespace Robust.Shared.GameObjects
/// <inheritdoc />
[Obsolete("use override with an EntityUid")]
public void Dirty(Component component, MetaDataComponent? meta = null)
public void Dirty(IComponent component, MetaDataComponent? meta = null)
{
Dirty(component.Owner, component, meta);
}
/// <inheritdoc />
public virtual void Dirty(EntityUid uid, Component component, MetaDataComponent? meta = null)
public virtual void Dirty(EntityUid uid, IComponent component, MetaDataComponent? meta = null)
{
if (component.LifeStage >= ComponentLifeStage.Removing || !component.NetSyncEnabled)
return;

View File

@@ -3,21 +3,21 @@
public static class EntityManagerExt
{
public static T? GetComponentOrNull<T>(this IEntityManager entityManager, EntityUid entityUid)
where T : class, IComponent
where T : IComponent
{
if (entityManager.TryGetComponent(entityUid, out T? component))
return component;
return null;
return default;
}
public static T? GetComponentOrNull<T>(this IEntityManager entityManager, EntityUid? entityUid)
where T : class, IComponent
where T : IComponent
{
if (entityUid.HasValue && entityManager.TryGetComponent(entityUid.Value, out T? component))
return component;
return null;
return default;
}
}
}

View File

@@ -206,7 +206,7 @@ public partial class EntitySystem
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Obsolete("Use Dirty(EntityUid, Component, MetaDataComponent?")]
protected void Dirty(Component component, MetaDataComponent? meta = null)
protected void Dirty(IComponent component, MetaDataComponent? meta = null)
{
EntityManager.Dirty(component, meta);
}
@@ -215,7 +215,7 @@ public partial class EntitySystem
/// Marks a component as dirty. This also implicitly dirties the entity this component belongs to.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void Dirty(EntityUid uid, Component component, MetaDataComponent? meta = null)
protected void Dirty(EntityUid uid, IComponent component, MetaDataComponent? meta = null)
{
EntityManager.Dirty(uid, component, meta);
}
@@ -433,7 +433,7 @@ public partial class EntitySystem
/// <inheritdoc cref="IEntityManager.GetComponent&lt;T&gt;"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected T Comp<T>(EntityUid uid) where T : Component
protected T Comp<T>(EntityUid uid) where T : IComponent
{
return EntityManager.GetComponent<T>(uid);
}
@@ -442,7 +442,7 @@ public partial class EntitySystem
/// Returns the component of a specific type, or null when it's missing or the entity does not exist.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected T? CompOrNull<T>(EntityUid uid) where T : class, IComponent
protected T? CompOrNull<T>(EntityUid uid) where T : IComponent
{
return EntityManager.GetComponentOrNull<T>(uid);
}
@@ -451,9 +451,9 @@ public partial class EntitySystem
/// Returns the component of a specific type, or null when it's missing or the entity does not exist.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected T? CompOrNull<T>(EntityUid? uid) where T : class, IComponent
protected T? CompOrNull<T>(EntityUid? uid) where T : IComponent
{
return uid.HasValue ? EntityManager.GetComponentOrNull<T>(uid.Value) : null;
return uid.HasValue ? EntityManager.GetComponentOrNull<T>(uid.Value) : default;
}
/// <inheritdoc cref="IEntityManager.TryGetComponent&lt;T&gt;(EntityUid, out T)"/>
@@ -614,14 +614,14 @@ public partial class EntitySystem
/// <inheritdoc cref="IEntityManager.AddComponent&lt;T&gt;(EntityUid, T, bool)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void AddComp<T>(EntityUid uid, T component, bool overwrite = false) where T : Component
protected void AddComp<T>(EntityUid uid, T component, bool overwrite = false) where T : IComponent
{
EntityManager.AddComponent(uid, component, overwrite);
}
/// <inheritdoc cref="IEntityManager.EnsureComponent&lt;T&gt;(EntityUid)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected T EnsureComp<T>(EntityUid uid) where T : Component, new()
protected T EnsureComp<T>(EntityUid uid) where T : IComponent, new()
{
return EntityManager.EnsureComponent<T>(uid);
}
@@ -632,7 +632,7 @@ public partial class EntitySystem
/// <inheritdoc cref="IEntityManager.RemoveComponentDeferred&lt;T&gt;(EntityUid)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected bool RemCompDeferred<T>(EntityUid uid) where T : class, IComponent
protected bool RemCompDeferred<T>(EntityUid uid) where T : IComponent
{
return EntityManager.RemoveComponentDeferred<T>(uid);
}
@@ -663,7 +663,7 @@ public partial class EntitySystem
/// <inheritdoc cref="IEntityManager.Count" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected int Count<T>() where T : Component
protected int Count<T>() where T : IComponent
{
return EntityManager.Count<T>();
}
@@ -681,7 +681,7 @@ public partial class EntitySystem
/// <inheritdoc cref="IEntityManager.RemoveComponent&lt;T&gt;(EntityUid)"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected bool RemComp<T>(EntityUid uid) where T : class, IComponent
protected bool RemComp<T>(EntityUid uid) where T : IComponent
{
return EntityManager.RemoveComponent<T>(uid);
}
@@ -819,34 +819,34 @@ public partial class EntitySystem
#region All Entity Query
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected AllEntityQueryEnumerator<TComp1> AllEntityQuery<TComp1>() where TComp1 : Component
protected AllEntityQueryEnumerator<TComp1> AllEntityQuery<TComp1>() where TComp1 : IComponent
{
return EntityManager.AllEntityQueryEnumerator<TComp1>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected AllEntityQueryEnumerator<TComp1, TComp2> AllEntityQuery<TComp1, TComp2>()
where TComp1 : Component
where TComp2 : Component
where TComp1 : IComponent
where TComp2 : IComponent
{
return EntityManager.AllEntityQueryEnumerator<TComp1, TComp2>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected AllEntityQueryEnumerator<TComp1, TComp2, TComp3> AllEntityQuery<TComp1, TComp2, TComp3>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
{
return EntityManager.AllEntityQueryEnumerator<TComp1, TComp2, TComp3>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected AllEntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4> AllEntityQuery<TComp1, TComp2, TComp3, TComp4>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp4 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
where TComp4 : IComponent
{
return EntityManager.AllEntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4>();
}
@@ -856,34 +856,34 @@ public partial class EntitySystem
#region Get Entity Query
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected EntityQueryEnumerator<TComp1> EntityQueryEnumerator<TComp1>() where TComp1 : Component
protected EntityQueryEnumerator<TComp1> EntityQueryEnumerator<TComp1>() where TComp1 : IComponent
{
return EntityManager.EntityQueryEnumerator<TComp1>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected EntityQueryEnumerator<TComp1, TComp2> EntityQueryEnumerator<TComp1, TComp2>()
where TComp1 : Component
where TComp2 : Component
where TComp1 : IComponent
where TComp2 : IComponent
{
return EntityManager.EntityQueryEnumerator<TComp1, TComp2>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected EntityQueryEnumerator<TComp1, TComp2, TComp3> EntityQueryEnumerator<TComp1, TComp2, TComp3>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
{
return EntityManager.EntityQueryEnumerator<TComp1, TComp2, TComp3>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected EntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4> EntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp4 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
where TComp4 : IComponent
{
return EntityManager.EntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4>();
}
@@ -897,7 +897,7 @@ public partial class EntitySystem
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
protected EntityQuery<T> GetEntityQuery<T>() where T : Component
protected EntityQuery<T> GetEntityQuery<T>() where T : IComponent
{
return EntityManager.GetEntityQuery<T>();
}
@@ -906,7 +906,7 @@ public partial class EntitySystem
/// If you need the EntityUid, use <see cref="EntityQueryEnumerator{TComp1}"/>
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected IEnumerable<TComp1> EntityQuery<TComp1>(bool includePaused = false) where TComp1 : Component
protected IEnumerable<TComp1> EntityQuery<TComp1>(bool includePaused = false) where TComp1 : IComponent
{
return EntityManager.EntityQuery<TComp1>(includePaused);
}
@@ -916,8 +916,8 @@ public partial class EntitySystem
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected IEnumerable<(TComp1, TComp2)> EntityQuery<TComp1, TComp2>(bool includePaused = false)
where TComp1 : Component
where TComp2 : Component
where TComp1 : IComponent
where TComp2 : IComponent
{
return EntityManager.EntityQuery<TComp1, TComp2>(includePaused);
}
@@ -927,9 +927,9 @@ public partial class EntitySystem
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected IEnumerable<(TComp1, TComp2, TComp3)> EntityQuery<TComp1, TComp2, TComp3>(bool includePaused = false)
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
{
return EntityManager.EntityQuery<TComp1, TComp2, TComp3>(includePaused);
}
@@ -939,10 +939,10 @@ public partial class EntitySystem
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected IEnumerable<(TComp1, TComp2, TComp3, TComp4)> EntityQuery<TComp1, TComp2, TComp3, TComp4>(bool includePaused = false)
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp4 : Component
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
where TComp4 : IComponent
{
return EntityManager.EntityQuery<TComp1, TComp2, TComp3, TComp4>(includePaused);
}

View File

@@ -1,5 +1,5 @@
using System;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Timing;
@@ -7,7 +7,6 @@ namespace Robust.Shared.GameObjects
{
/// <remarks>
/// Base component for the ECS system.
/// All discoverable implementations of IComponent must override the <see cref="Name" />.
/// Instances are dynamically instantiated by a <c>ComponentFactory</c>, and will have their IoC Dependencies resolved.
/// </remarks>
[ImplicitDataDefinitionForInheritors]
@@ -17,7 +16,10 @@ namespace Robust.Shared.GameObjects
/// The current lifetime stage of this component. You can use this to check
/// if the component is initialized or being deleted.
/// </summary>
ComponentLifeStage LifeStage { get; }
ComponentLifeStage LifeStage { get; [Obsolete("Do not use from content")] set; }
[Obsolete("Do not use from content")]
bool Networked { get; set; }
/// <summary>
/// Whether this component should be synchronized with clients when modified.
@@ -28,11 +30,24 @@ namespace Robust.Shared.GameObjects
/// </summary>
bool NetSyncEnabled { get; set; }
/// <summary>
/// If true, and if this is a networked component, then component data will only be sent to players if their
/// controlled entity is the owner of this component. This is less performance intensive than <see cref="SessionSpecific"/>.
/// </summary>
bool SendOnlyToOwner { get; }
/// <summary>
/// If true, and if this is a networked component, then this component will cause <see
/// cref="ComponentGetStateAttemptEvent"/> events to be raised to check whether a given player should
/// receive this component's state.
/// </summary>
bool SessionSpecific { get; }
/// <summary>
/// Entity that this component is attached to.
/// </summary>
/// <seealso cref="EntityQueryEnumerator{TComp1}"/>
EntityUid Owner { get; }
EntityUid Owner { get; set; }
/// <summary>
/// Component has been (or is currently being) initialized.
@@ -57,11 +72,17 @@ namespace Robust.Shared.GameObjects
/// <summary>
/// This is the tick the component was created.
/// </summary>
GameTick CreationTick { get; }
GameTick CreationTick { get; [Obsolete("Do not use from content")] set; }
/// <summary>
/// This is the last game tick Dirty() was called.
/// </summary>
GameTick LastModifiedTick { get; }
GameTick LastModifiedTick { get; [Obsolete("Do not use from content")] set; }
[Obsolete("Do not use from content")]
void ClearTicks();
[Obsolete("Do not use from content")]
void ClearCreationTick();
}
}

View File

@@ -31,7 +31,7 @@ namespace Robust.Shared.GameObjects
/// <summary>
/// Gets the number of a specific component.
/// </summary>
public int Count<T>() where T : Component;
public int Count<T>() where T : IComponent;
/// <summary>
/// Gets the number of a specific component.
@@ -44,7 +44,7 @@ namespace Robust.Shared.GameObjects
/// </summary>
/// <typeparam name="T">Concrete component type to add.</typeparam>
/// <returns>The newly added component.</returns>
T AddComponent<T>(EntityUid uid) where T : Component, new();
T AddComponent<T>(EntityUid uid) where T : IComponent, new();
/// <summary>
/// Adds a Component with a given network id to an entity.
@@ -62,7 +62,7 @@ namespace Robust.Shared.GameObjects
/// <param name="uid">Entity being modified.</param>
/// <returns>Component initialization handle. When you are done setting up the component, make sure to dispose this.</returns>
[Obsolete]
EntityManager.CompInitializeHandle<T> AddComponentUninitialized<T>(EntityUid uid) where T : Component, new();
EntityManager.CompInitializeHandle<T> AddComponentUninitialized<T>(EntityUid uid) where T : IComponent, new();
/// <summary>
/// Adds a Component to an entity. If the entity is already Initialized, the component will
@@ -71,7 +71,7 @@ namespace Robust.Shared.GameObjects
/// <param name="uid">Entity being modified.</param>
/// <param name="component">Component to add.</param>
/// <param name="overwrite">Should it overwrite existing components?</param>
void AddComponent<T>(EntityUid uid, T component, bool overwrite = false, MetaDataComponent? metadata = null) where T : Component;
void AddComponent<T>(EntityUid uid, T component, bool overwrite = false, MetaDataComponent? metadata = null) where T : IComponent;
/// <summary>
/// Removes the component with the specified reference type,
@@ -214,7 +214,7 @@ namespace Robust.Shared.GameObjects
/// <param name="uid">Entity to modify.</param>
/// <typeparam name="T">Component to add.</typeparam>
/// <returns>The component in question</returns>
T EnsureComponent<T>(EntityUid uid) where T : Component, new();
T EnsureComponent<T>(EntityUid uid) where T : IComponent, new();
/// <summary>
/// This method will always return a component for a certain entity, adding it if it's not there already.
@@ -223,7 +223,7 @@ namespace Robust.Shared.GameObjects
/// <param name="component">The output component after being ensured.</param>
/// <typeparam name="T">Component to add.</typeparam>
/// <returns>True if the component already existed</returns>
bool EnsureComponent<T>(EntityUid uid, out T component) where T : Component, new();
bool EnsureComponent<T>(EntityUid uid, out T component) where T : IComponent, new();
/// <summary>
/// Returns the component of a specific type.
@@ -334,9 +334,9 @@ namespace Robust.Shared.GameObjects
/// <summary>
/// Returns a cached struct enumerator with the specified component.
/// </summary>
EntityQuery<TComp1> GetEntityQuery<TComp1>() where TComp1 : Component;
EntityQuery<TComp1> GetEntityQuery<TComp1>() where TComp1 : IComponent;
EntityQuery<Component> GetEntityQuery(Type type);
EntityQuery<IComponent> GetEntityQuery(Type type);
/// <summary>
/// Returns ALL component type instances on an entity. A single component instance
@@ -398,49 +398,49 @@ namespace Robust.Shared.GameObjects
/// Returns all instances of a component in an array.
/// Use sparingly.
/// </summary>
(EntityUid Uid, T Component)[] AllComponents<T>() where T : Component;
(EntityUid Uid, T Component)[] AllComponents<T>() where T : IComponent;
/// <summary>
/// Returns all instances of a component in a List.
/// Use sparingly.
/// </summary>
List<(EntityUid Uid, T Component)> AllComponentsList<T>() where T : Component;
List<(EntityUid Uid, T Component)> AllComponentsList<T>() where T : IComponent;
AllEntityQueryEnumerator<TComp1> AllEntityQueryEnumerator<TComp1>()
where TComp1 : Component;
where TComp1 : IComponent;
AllEntityQueryEnumerator<TComp1, TComp2> AllEntityQueryEnumerator<TComp1, TComp2>()
where TComp1 : Component
where TComp2 : Component;
where TComp1 : IComponent
where TComp2 : IComponent;
AllEntityQueryEnumerator<TComp1, TComp2, TComp3> AllEntityQueryEnumerator<TComp1, TComp2, TComp3>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component;
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent;
AllEntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4> AllEntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp4 : Component;
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
where TComp4 : IComponent;
EntityQueryEnumerator<TComp1> EntityQueryEnumerator<TComp1>()
where TComp1 : Component;
where TComp1 : IComponent;
EntityQueryEnumerator<TComp1, TComp2> EntityQueryEnumerator<TComp1, TComp2>()
where TComp1 : Component
where TComp2 : Component;
where TComp1 : IComponent
where TComp2 : IComponent;
EntityQueryEnumerator<TComp1, TComp2, TComp3> EntityQueryEnumerator<TComp1, TComp2, TComp3>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component;
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent;
EntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4> EntityQueryEnumerator<TComp1, TComp2, TComp3, TComp4>()
where TComp1 : Component
where TComp2 : Component
where TComp3 : Component
where TComp4 : Component;
where TComp1 : IComponent
where TComp2 : IComponent
where TComp3 : IComponent
where TComp4 : IComponent;
/// <summary>
/// Returns ALL component instances of a specified type.
@@ -491,7 +491,7 @@ namespace Robust.Shared.GameObjects
/// <param name="type">A trait or component type to check for.</param>
/// <param name="includePaused"></param>
/// <returns>All components that are the specified type.</returns>
IEnumerable<(EntityUid Uid, Component Component)> GetAllComponents(Type type, bool includePaused = false);
IEnumerable<(EntityUid Uid, IComponent Component)> GetAllComponents(Type type, bool includePaused = false);
/// <summary>
/// Culls all components from the collection that are marked as deleted. This needs to be called often.

View File

@@ -83,9 +83,9 @@ namespace Robust.Shared.GameObjects
public void DirtyEntity(EntityUid uid, MetaDataComponent? metadata = null);
public void Dirty(Component component, MetaDataComponent? metadata = null);
public void Dirty(IComponent component, MetaDataComponent? metadata = null);
public void Dirty(EntityUid uid, Component component, MetaDataComponent? meta = null);
public void Dirty(EntityUid uid, IComponent component, MetaDataComponent? meta = null);
public void QueueDeleteEntity(EntityUid? uid);

View File

@@ -2,11 +2,9 @@ using System;
using System.Collections.Generic;
using System.Numerics;
using Robust.Shared.Collections;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Utility;
@@ -21,7 +19,7 @@ public sealed partial class EntityLookupSystem
HashSet<T> intersecting,
Box2 worldAABB,
LookupFlags flags,
EntityQuery<T> query) where T : Component
EntityQuery<T> query) where T : IComponent
{
var lookup = _broadQuery.GetComponent(lookupUid);
var invMatrix = _transform.GetInvWorldMatrix(lookupUid);
@@ -82,7 +80,7 @@ public sealed partial class EntityLookupSystem
Box2 worldAABB,
LookupFlags flags,
EntityQuery<T> query,
EntityUid? ignored = null) where T : Component
EntityUid? ignored = null) where T : IComponent
{
var lookup = _broadQuery.GetComponent(lookupUid);
var invMatrix = _transform.GetInvWorldMatrix(lookupUid);
@@ -153,7 +151,7 @@ public sealed partial class EntityLookupSystem
return state.found;
}
private void RecursiveAdd<T>(EntityUid uid, ref ValueList<T> toAdd, EntityQuery<T> query) where T : Component
private void RecursiveAdd<T>(EntityUid uid, ref ValueList<T> toAdd, EntityQuery<T> query) where T : IComponent
{
var childEnumerator = _xformQuery.GetComponent(uid).ChildEnumerator;
@@ -168,7 +166,7 @@ public sealed partial class EntityLookupSystem
}
}
private void AddContained<T>(HashSet<T> intersecting, LookupFlags flags, EntityQuery<T> query) where T : Component
private void AddContained<T>(HashSet<T> intersecting, LookupFlags flags, EntityQuery<T> query) where T : IComponent
{
if ((flags & LookupFlags.Contained) == 0x0) return;
@@ -209,7 +207,7 @@ public sealed partial class EntityLookupSystem
/// <summary>
/// Should we just iterate every component and check position or do bounds checks.
/// </summary>
private bool UseBoundsQuery<T>(float area) where T : Component
private bool UseBoundsQuery<T>(float area) where T : IComponent
{
// If the component has a low count we'll just do an estimate if it's faster to iterate every comp directly
// Might be useful to have some way to expose this to content?
@@ -224,7 +222,7 @@ public sealed partial class EntityLookupSystem
public bool AnyComponentsIntersecting(Type type, MapId mapId, Box2 worldAABB, EntityUid? ignored = null, LookupFlags flags = DefaultFlags)
{
DebugTools.Assert(typeof(Component).IsAssignableFrom(type));
DebugTools.Assert(typeof(IComponent).IsAssignableFrom(type));
if (mapId == MapId.Nullspace) return false;
if (!UseBoundsQuery(type, worldAABB.Height * worldAABB.Width))
@@ -256,7 +254,7 @@ public sealed partial class EntityLookupSystem
(EntityLookupSystem system,
Box2 worldAABB,
LookupFlags flags,
EntityQuery<Component> query,
EntityQuery<IComponent> query,
EntityUid? ignored,
bool found) tuple) =>
{
@@ -274,13 +272,13 @@ public sealed partial class EntityLookupSystem
return false;
}
public HashSet<Component> GetComponentsIntersecting(Type type, MapId mapId, Box2 worldAABB, LookupFlags flags = DefaultFlags)
public HashSet<IComponent> GetComponentsIntersecting(Type type, MapId mapId, Box2 worldAABB, LookupFlags flags = DefaultFlags)
{
DebugTools.Assert(typeof(Component).IsAssignableFrom(type));
DebugTools.Assert(typeof(IComponent).IsAssignableFrom(type));
if (mapId == MapId.Nullspace)
return new HashSet<Component>();
return new HashSet<IComponent>();
var intersecting = new HashSet<Component>();
var intersecting = new HashSet<IComponent>();
if (!UseBoundsQuery(type, worldAABB.Height * worldAABB.Width))
{
@@ -311,8 +309,8 @@ public sealed partial class EntityLookupSystem
ref (EntityLookupSystem system,
Box2 worldAABB,
LookupFlags flags,
EntityQuery<Component> query,
HashSet<Component> intersecting) tuple) =>
EntityQuery<IComponent> query,
HashSet<IComponent> intersecting) tuple) =>
{
tuple.system.AddComponentsIntersecting(uid, tuple.intersecting, tuple.worldAABB, tuple.flags, tuple.query);
return true;
@@ -327,7 +325,7 @@ public sealed partial class EntityLookupSystem
return intersecting;
}
public HashSet<T> GetComponentsIntersecting<T>(MapId mapId, Box2 worldAABB, LookupFlags flags = DefaultFlags) where T : Component
public HashSet<T> GetComponentsIntersecting<T>(MapId mapId, Box2 worldAABB, LookupFlags flags = DefaultFlags) where T : IComponent
{
if (mapId == MapId.Nullspace) return new HashSet<T>();
@@ -375,7 +373,7 @@ public sealed partial class EntityLookupSystem
#region EntityCoordinates
public HashSet<T> GetComponentsInRange<T>(EntityCoordinates coordinates, float range) where T : Component
public HashSet<T> GetComponentsInRange<T>(EntityCoordinates coordinates, float range) where T : IComponent
{
var mapPos = coordinates.ToMap(EntityManager, _transform);
return GetComponentsInRange<T>(mapPos, range);
@@ -384,13 +382,13 @@ public sealed partial class EntityLookupSystem
#region MapCoordinates
public HashSet<Component> GetComponentsInRange(Type type, MapCoordinates coordinates, float range)
public HashSet<IComponent> GetComponentsInRange(Type type, MapCoordinates coordinates, float range)
{
DebugTools.Assert(typeof(Component).IsAssignableFrom(type));
DebugTools.Assert(typeof(IComponent).IsAssignableFrom(type));
return GetComponentsInRange(type, coordinates.MapId, coordinates.Position, range);
}
public HashSet<T> GetComponentsInRange<T>(MapCoordinates coordinates, float range) where T : Component
public HashSet<T> GetComponentsInRange<T>(MapCoordinates coordinates, float range) where T : IComponent
{
return GetComponentsInRange<T>(coordinates.MapId, coordinates.Position, range);
}
@@ -401,7 +399,7 @@ public sealed partial class EntityLookupSystem
public bool AnyComponentsInRange(Type type, MapId mapId, Vector2 worldPos, float range)
{
DebugTools.Assert(typeof(Component).IsAssignableFrom(type));
DebugTools.Assert(typeof(IComponent).IsAssignableFrom(type));
DebugTools.Assert(range > 0, "Range must be a positive float");
if (mapId == MapId.Nullspace) return false;
@@ -413,12 +411,12 @@ public sealed partial class EntityLookupSystem
return AnyComponentsIntersecting(type, mapId, worldAABB);
}
public HashSet<Component> GetComponentsInRange(Type type, MapId mapId, Vector2 worldPos, float range)
public HashSet<IComponent> GetComponentsInRange(Type type, MapId mapId, Vector2 worldPos, float range)
{
DebugTools.Assert(typeof(Component).IsAssignableFrom(type));
DebugTools.Assert(typeof(IComponent).IsAssignableFrom(type));
DebugTools.Assert(range > 0, "Range must be a positive float");
if (mapId == MapId.Nullspace) return new HashSet<Component>();
if (mapId == MapId.Nullspace) return new HashSet<IComponent>();
// TODO: Actual circles
var rangeVec = new Vector2(range, range);
@@ -427,7 +425,7 @@ public sealed partial class EntityLookupSystem
return GetComponentsIntersecting(type, mapId, worldAABB);
}
public HashSet<T> GetComponentsInRange<T>(MapId mapId, Vector2 worldPos, float range) where T : Component
public HashSet<T> GetComponentsInRange<T>(MapId mapId, Vector2 worldPos, float range) where T : IComponent
{
DebugTools.Assert(range > 0, "Range must be a positive float");

View File

@@ -1,5 +1,5 @@
using Robust.Shared.GameObjects;
using System;
using Robust.Shared.GameObjects;
namespace Robust.Shared.Physics;
@@ -9,7 +9,7 @@ namespace Robust.Shared.Physics;
/// 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 : Component
public readonly struct ComponentTreeEntry<T> : IEquatable<ComponentTreeEntry<T>>, IComparable<ComponentTreeEntry<T>> where T : IComponent
{
public T Component { get; init; }
public TransformComponent Transform { get; init; }

View File

@@ -28,7 +28,7 @@ internal sealed class CompCommand : ToolshedCommand
[CommandImplementation("add")]
public EntityUid Add<T>([PipedArgument] EntityUid input)
where T: Component, new()
where T: IComponent, new()
{
AddComp<T>(input);
return input;
@@ -36,13 +36,13 @@ internal sealed class CompCommand : ToolshedCommand
[CommandImplementation("add")]
public IEnumerable<EntityUid> Add<T>([PipedArgument] IEnumerable<EntityUid> input)
where T : Component, new()
where T : IComponent, new()
=> input.Select(Add<T>);
[CommandImplementation("rm")]
public EntityUid Rm<T>([PipedArgument] EntityUid input)
where T: Component, new()
where T: IComponent, new()
{
RemComp<T>(input);
return input;
@@ -50,12 +50,12 @@ internal sealed class CompCommand : ToolshedCommand
[CommandImplementation("rm")]
public IEnumerable<EntityUid> Rm<T>([PipedArgument] IEnumerable<EntityUid> input)
where T : Component, new()
where T : IComponent, new()
=> input.Select(Rm<T>);
[CommandImplementation("ensure")]
public EntityUid Ensure<T>([PipedArgument] EntityUid input)
where T: Component, new()
where T: IComponent, new()
{
EnsureComp<T>(input);
return input;
@@ -63,7 +63,7 @@ internal sealed class CompCommand : ToolshedCommand
[CommandImplementation("ensure")]
public IEnumerable<EntityUid> Ensure<T>([PipedArgument] IEnumerable<EntityUid> input)
where T : Component, new()
where T : IComponent, new()
=> input.Select(Ensure<T>);
[CommandImplementation("has")]

View File

@@ -126,7 +126,7 @@ public abstract partial class ToolshedCommand
/// </summary>
[PublicAPI, MethodImpl(MethodImplOptions.AggressiveInlining)]
protected T AddComp<T>(EntityUid entity)
where T : Component, new()
where T : IComponent, new()
=> EntityManager.AddComponent<T>(entity);
/// <summary>
@@ -142,7 +142,7 @@ public abstract partial class ToolshedCommand
/// </summary>
[PublicAPI, MethodImpl(MethodImplOptions.AggressiveInlining)]
protected T EnsureComp<T>(EntityUid entity)
where T: Component, new()
where T: IComponent, new()
=> EntityManager.EnsureComponent<T>(entity);
/// <summary>
@@ -159,6 +159,6 @@ public abstract partial class ToolshedCommand
/// </summary>
[PublicAPI, MethodImpl(MethodImplOptions.AggressiveInlining)]
protected EntityQuery<T> GetEntityQuery<T>()
where T : Component
where T : IComponent
=> EntityManager.GetEntityQuery<T>();
}