mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Gets rid of most ComponentManager usages. (#2076)
- Obsoletes more `ComponentManager` fields/properties.
This commit is contained in:
committed by
GitHub
parent
07542ff6eb
commit
fbcdd63988
@@ -58,7 +58,7 @@ namespace Robust.Client.GameObjects
|
||||
/// </summary>
|
||||
public void Play(EntityUid uid, Animation animation, string key)
|
||||
{
|
||||
var component = ComponentManager.EnsureComponent<AnimationPlayerComponent>(EntityManager.GetEntity(uid));
|
||||
var component = EntityManager.EnsureComponent<AnimationPlayerComponent>(EntityManager.GetEntity(uid));
|
||||
Play(component, animation, key);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public bool HasRunningAnimation(EntityUid uid, string key)
|
||||
{
|
||||
return ComponentManager.TryGetComponent(uid, out AnimationPlayerComponent? component) &&
|
||||
return EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? component) &&
|
||||
component.PlayingAnimations.ContainsKey(key);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Robust.Client.GameObjects
|
||||
while (_dirtyEntities.TryDequeue(out var entity))
|
||||
{
|
||||
if (EntityManager.EntityExists(entity)
|
||||
&& ComponentManager.TryGetComponent(entity, out ClientOccluderComponent? occluder)
|
||||
&& EntityManager.TryGetComponent(entity, out ClientOccluderComponent? occluder)
|
||||
&& occluder.UpdateGeneration != _updateGeneration)
|
||||
{
|
||||
occluder.Update();
|
||||
@@ -100,7 +100,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
foreach (var entity in candidates)
|
||||
{
|
||||
if (ComponentManager.HasComponent<ClientOccluderComponent>(entity))
|
||||
if (EntityManager.HasComponent<ClientOccluderComponent>(entity))
|
||||
{
|
||||
_dirtyEntities.Enqueue(entity);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
var gridEnt = _entityManager.GetEntity(grid.GridEntityId);
|
||||
|
||||
if (!_entityManager.ComponentManager.TryGetComponent<PhysicsComponent>(gridEnt.Uid, out var body)) continue;
|
||||
if (!_entityManager.TryGetComponent<PhysicsComponent>(gridEnt.Uid, out var body)) continue;
|
||||
|
||||
var transform = body.GetTransform();
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Robust.Client.GameObjects
|
||||
private void MessageReceived(BoundUIWrapMessage ev)
|
||||
{
|
||||
var uid = ev.Entity;
|
||||
var cmp = ComponentManager.GetComponent<ClientUserInterfaceComponent>(uid);
|
||||
var cmp = EntityManager.GetComponent<ClientUserInterfaceComponent>(uid);
|
||||
|
||||
var message = ev.Message;
|
||||
// This should probably not happen at this point, but better make extra sure!
|
||||
|
||||
@@ -40,7 +40,6 @@ namespace Robust.Client.Graphics.Clyde
|
||||
gridProgram.SetUniform(UniIModUV, new Vector4(0, 0, 1, 1));
|
||||
gridProgram.SetUniform(UniIModulate, Color.White);
|
||||
|
||||
var compMan = _entityManager.ComponentManager;
|
||||
foreach (var mapGrid in _mapManager.FindGridsIntersecting(mapId, worldBounds))
|
||||
{
|
||||
var grid = (IMapGridInternal) mapGrid;
|
||||
@@ -50,7 +49,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
continue;
|
||||
}
|
||||
|
||||
var transform = compMan.GetComponent<ITransformComponent>(grid.GridEntityId);
|
||||
var transform = _entityManager.GetComponent<ITransformComponent>(grid.GridEntityId);
|
||||
gridProgram.SetUniform(UniIModelMatrix, transform.WorldMatrix);
|
||||
|
||||
foreach (var chunk in grid.GetMapChunks(worldBounds))
|
||||
|
||||
@@ -429,7 +429,7 @@ namespace Robust.Client.ViewVariables.Instances
|
||||
{
|
||||
var comp = (Component) componentFactory.GetComponent(registration.Type);
|
||||
comp.Owner = _entity;
|
||||
_entityManager.ComponentManager.AddComponent(_entity, comp);
|
||||
_entityManager.AddComponent(_entity, comp);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -446,7 +446,7 @@ namespace Robust.Client.ViewVariables.Instances
|
||||
{
|
||||
try
|
||||
{
|
||||
_entityManager.ComponentManager.RemoveComponent(_entity.Uid, component);
|
||||
_entityManager.RemoveComponent(_entity.Uid, component);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Robust.Server.GameObjects
|
||||
var uid = entity.Uid;
|
||||
|
||||
// Check if there was a player attached to the entity already...
|
||||
if (ComponentManager.TryGetComponent(uid, out ActorComponent actor))
|
||||
if (EntityManager.TryGetComponent(uid, out ActorComponent actor))
|
||||
{
|
||||
// If we're not forcing the attach, this fails.
|
||||
if (!force)
|
||||
@@ -76,7 +76,7 @@ namespace Robust.Server.GameObjects
|
||||
}
|
||||
|
||||
// We add the actor component.
|
||||
actor = ComponentManager.AddComponent<ActorComponent>(entity);
|
||||
actor = EntityManager.AddComponent<ActorComponent>(entity);
|
||||
actor.PlayerSession = player;
|
||||
player.SetAttachedEntity(entity);
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Robust.Server.GameObjects
|
||||
private void OnActorPlayerDetach(EntityUid uid, ActorComponent component, DetachPlayerEvent args)
|
||||
{
|
||||
// Removing the component will call shutdown, and our subscription will handle the rest of the detach logic.
|
||||
ComponentManager.RemoveComponent<ActorComponent>(uid);
|
||||
EntityManager.RemoveComponent<ActorComponent>(uid);
|
||||
args.Result = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Robust.Server.GameObjects
|
||||
private void OnMessageReceived(BoundUIWrapMessage msg, EntitySessionEventArgs args)
|
||||
{
|
||||
var uid = msg.Entity;
|
||||
if (!ComponentManager.TryGetComponent<ServerUserInterfaceComponent>(uid, out var uiComp))
|
||||
if (!EntityManager.TryGetComponent<ServerUserInterfaceComponent>(uid, out var uiComp))
|
||||
return;
|
||||
|
||||
var message = msg.Message;
|
||||
@@ -122,7 +122,7 @@ namespace Robust.Server.GameObjects
|
||||
|
||||
public bool HasUi(EntityUid uid, object uiKey)
|
||||
{
|
||||
if (!ComponentManager.TryGetComponent<ServerUserInterfaceComponent>(uid, out var ui))
|
||||
if (!EntityManager.TryGetComponent<ServerUserInterfaceComponent>(uid, out var ui))
|
||||
return false;
|
||||
|
||||
return ui.HasBoundUserInterface(uiKey);
|
||||
@@ -130,7 +130,7 @@ namespace Robust.Server.GameObjects
|
||||
|
||||
public BoundUserInterface GetUi(EntityUid uid, object uiKey)
|
||||
{
|
||||
return ComponentManager.GetComponent<ServerUserInterfaceComponent>(uid).GetBoundUserInterface(uiKey);
|
||||
return EntityManager.GetComponent<ServerUserInterfaceComponent>(uid).GetBoundUserInterface(uiKey);
|
||||
}
|
||||
|
||||
public BoundUserInterface? GetUiOrNull(EntityUid uid, object uiKey)
|
||||
@@ -144,7 +144,7 @@ namespace Robust.Server.GameObjects
|
||||
{
|
||||
ui = null;
|
||||
|
||||
return ComponentManager.TryGetComponent(uid, out ServerUserInterfaceComponent uiComp)
|
||||
return EntityManager.TryGetComponent(uid, out ServerUserInterfaceComponent uiComp)
|
||||
&& uiComp.TryGetBoundUserInterface(uiKey, out ui);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Robust.Server.GameObjects
|
||||
/// </summary>
|
||||
public void RemoveViewSubscriber(EntityUid uid, IPlayerSession session)
|
||||
{
|
||||
if(!ComponentManager.TryGetComponent(uid, out ViewSubscriberComponent? viewSubscriber))
|
||||
if(!EntityManager.TryGetComponent(uid, out ViewSubscriberComponent? viewSubscriber))
|
||||
return; // Entity didn't have any subscriptions, do nothing.
|
||||
|
||||
if (!viewSubscriber.SubscribedSessions.Remove(session))
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Robust.Server.GameObjects
|
||||
// As such, we can reset the modified ticks to Zero,
|
||||
// which indicates "not different from client's own deserialization".
|
||||
// So the initial data for the component or even the creation doesn't have to be sent over the wire.
|
||||
foreach (var (netId, component) in ComponentManager.GetNetComponents(entity.Uid))
|
||||
foreach (var (netId, component) in GetNetComponents(entity.Uid))
|
||||
{
|
||||
// Make sure to ONLY get components that are defined in the prototype.
|
||||
// Others could be instantiated directly by AddComponent (e.g. ContainerManager).
|
||||
|
||||
@@ -281,10 +281,9 @@ namespace Robust.Server.GameStates
|
||||
internal static EntityState GetEntityState(IEntityManager entMan, ICommonSession player, EntityUid entityUid, GameTick fromTick)
|
||||
{
|
||||
var bus = entMan.EventBus;
|
||||
var compMan = entMan.ComponentManager;
|
||||
var changed = new List<ComponentChange>();
|
||||
|
||||
foreach (var (netId, component) in compMan.GetNetComponents(entityUid))
|
||||
foreach (var (netId, component) in entMan.GetNetComponents(entityUid))
|
||||
{
|
||||
DebugTools.Assert(component.Initialized);
|
||||
|
||||
@@ -301,7 +300,7 @@ namespace Robust.Server.GameStates
|
||||
{
|
||||
ComponentState? state = null;
|
||||
if (component.NetSyncEnabled && component.LastModifiedTick != GameTick.Zero && component.LastModifiedTick >= fromTick)
|
||||
state = compMan.GetComponentState(bus, component, player);
|
||||
state = entMan.GetComponentState(bus, component, player);
|
||||
|
||||
// Can't be null since it's returned by GetNetComponents
|
||||
// ReSharper disable once PossibleInvalidOperationException
|
||||
@@ -309,7 +308,7 @@ namespace Robust.Server.GameStates
|
||||
}
|
||||
else if (component.NetSyncEnabled && component.LastModifiedTick != GameTick.Zero && component.LastModifiedTick >= fromTick)
|
||||
{
|
||||
changed.Add(ComponentChange.Changed(netId, compMan.GetComponentState(bus, component, player)));
|
||||
changed.Add(ComponentChange.Changed(netId, entMan.GetComponentState(bus, component, player)));
|
||||
}
|
||||
else if (component.Deleted && component.LastModifiedTick >= fromTick)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Robust.Shared.Containers
|
||||
if (!Resolve(uid, ref containerManager))
|
||||
// TODO: I am a Sad Vera. Merge ComponentManager and EntityManager so we don't have to do this. Pretty please?
|
||||
// ps. The to-do above is in effect for this whole file.
|
||||
containerManager = ComponentManager.AddComponent<ContainerManagerComponent>(EntityManager.GetEntity(uid));
|
||||
containerManager = EntityManager.AddComponent<ContainerManagerComponent>(EntityManager.GetEntity(uid));
|
||||
|
||||
return containerManager.MakeContainer<T>(id);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ namespace Robust.Shared.Containers
|
||||
where T : IContainer
|
||||
{
|
||||
if (!Resolve(uid, ref containerManager))
|
||||
containerManager = ComponentManager.AddComponent<ContainerManagerComponent>(EntityManager.GetEntity(uid));
|
||||
containerManager = EntityManager.AddComponent<ContainerManagerComponent>(EntityManager.GetEntity(uid));
|
||||
|
||||
if (TryGetContainer(uid, id, out var container, containerManager))
|
||||
return (T)container;
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
private IEventBus GetBus()
|
||||
{
|
||||
// Apparently components are being created outside of the ComponentManager,
|
||||
// Apparently components are being created outside of the EntityManager,
|
||||
// and the Owner is not being set correctly.
|
||||
// ReSharper disable once RedundantAssertionStatement
|
||||
DebugTools.AssertNotNull(Owner);
|
||||
|
||||
@@ -407,7 +407,7 @@ namespace Robust.Shared.GameObjects
|
||||
// An anchored entity is always parented to the grid.
|
||||
// If Transform.Anchored is true in the prototype but the entity was not spawned with a grid as the parent,
|
||||
// then this will be false.
|
||||
if (Owner.EntityManager.ComponentManager.TryGetComponent<IMapGridComponent>(ParentUid, out var gridComp))
|
||||
if (Owner.EntityManager.TryGetComponent<IMapGridComponent>(ParentUid, out var gridComp))
|
||||
gridComp.UnanchorEntity(this);
|
||||
else
|
||||
SetAnchored(false);
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace Robust.Shared.GameObjects
|
||||
LifeStage = EntityLifeStage.Initializing;
|
||||
|
||||
// Initialize() can modify the collection of components.
|
||||
var components = EntityManager.ComponentManager.GetComponents(Uid)
|
||||
var components = EntityManager.GetComponents(Uid)
|
||||
.OrderBy(x => x switch
|
||||
{
|
||||
ITransformComponent _ => 0,
|
||||
@@ -147,7 +147,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
#if DEBUG
|
||||
// Second integrity check in case of.
|
||||
foreach (var t in EntityManager.ComponentManager.GetComponents(Uid))
|
||||
foreach (var t in EntityManager.GetComponents(Uid))
|
||||
{
|
||||
if (!t.Initialized)
|
||||
{
|
||||
@@ -167,10 +167,8 @@ namespace Robust.Shared.GameObjects
|
||||
public void StartAllComponents()
|
||||
{
|
||||
// Startup() can modify _components
|
||||
var compMan = EntityManager.ComponentManager;
|
||||
|
||||
// This code can only handle additions to the list. Is there a better way? Probably not.
|
||||
var comps = compMan.GetComponents(Uid)
|
||||
var comps = EntityManager.GetComponents(Uid)
|
||||
.OrderBy(x => x switch
|
||||
{
|
||||
ITransformComponent _ => 0,
|
||||
@@ -196,7 +194,7 @@ namespace Robust.Shared.GameObjects
|
||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
||||
public void SendMessage(IComponent? owner, ComponentMessage message)
|
||||
{
|
||||
var components = EntityManager.ComponentManager.GetComponents(Uid);
|
||||
var components = EntityManager.GetComponents(Uid);
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (owner != component)
|
||||
@@ -222,32 +220,32 @@ namespace Robust.Shared.GameObjects
|
||||
/// <param name="component">The component to add.</param>
|
||||
public void AddComponent(Component component)
|
||||
{
|
||||
EntityManager.ComponentManager.AddComponent(this, component);
|
||||
EntityManager.AddComponent(this, component);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public T AddComponent<T>()
|
||||
where T : Component, new()
|
||||
{
|
||||
return EntityManager.ComponentManager.AddComponent<T>(this);
|
||||
return EntityManager.AddComponent<T>(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveComponent<T>()
|
||||
{
|
||||
EntityManager.ComponentManager.RemoveComponent<T>(Uid);
|
||||
EntityManager.RemoveComponent<T>(Uid);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasComponent<T>()
|
||||
{
|
||||
return EntityManager.ComponentManager.HasComponent<T>(Uid);
|
||||
return EntityManager.HasComponent<T>(Uid);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasComponent(Type type)
|
||||
{
|
||||
return EntityManager.ComponentManager.HasComponent(Uid, type);
|
||||
return EntityManager.HasComponent(Uid, type);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -255,7 +253,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity.");
|
||||
|
||||
return (T)EntityManager.ComponentManager.GetComponent(Uid, typeof(T));
|
||||
return (T)EntityManager.GetComponent(Uid, typeof(T));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -263,7 +261,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity.");
|
||||
|
||||
return EntityManager.ComponentManager.GetComponent(Uid, type);
|
||||
return EntityManager.GetComponent(Uid, type);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -271,7 +269,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity.");
|
||||
|
||||
return EntityManager.ComponentManager.TryGetComponent(Uid, out component);
|
||||
return EntityManager.TryGetComponent(Uid, out component);
|
||||
}
|
||||
|
||||
public T? GetComponentOrNull<T>() where T : class
|
||||
@@ -284,7 +282,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
DebugTools.Assert(!Deleted, "Tried to get component on a deleted entity.");
|
||||
|
||||
return EntityManager.ComponentManager.TryGetComponent(Uid, type, out component);
|
||||
return EntityManager.TryGetComponent(Uid, type, out component);
|
||||
}
|
||||
|
||||
public IComponent? GetComponentOrNull(Type type)
|
||||
@@ -307,13 +305,13 @@ namespace Robust.Shared.GameObjects
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IComponent> GetAllComponents()
|
||||
{
|
||||
return EntityManager.ComponentManager.GetComponents(Uid);
|
||||
return EntityManager.GetComponents(Uid);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<T> GetAllComponents<T>()
|
||||
{
|
||||
return EntityManager.ComponentManager.GetComponents<T>(Uid);
|
||||
return EntityManager.GetComponents<T>(Uid);
|
||||
}
|
||||
|
||||
#endregion Components
|
||||
@@ -328,7 +326,7 @@ namespace Robust.Shared.GameObjects
|
||||
LastModifiedTick = EntityManager.CurrentTick;
|
||||
|
||||
if (LifeStage >= EntityLifeStage.Initialized && Transform.Anchored)
|
||||
EntityManager.ComponentManager.GetComponent<IMapGridComponent>(Transform.ParentUid).AnchoredEntityDirty(Transform);
|
||||
EntityManager.GetComponent<IMapGridComponent>(Transform.ParentUid).AnchoredEntityDirty(Transform);
|
||||
}
|
||||
|
||||
#endregion GameState
|
||||
|
||||
@@ -548,12 +548,12 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
public SubscriptionsEnumerator(Type eventType, HashSet<Type>.Enumerator enumerator,
|
||||
IReadOnlyDictionary<Type, Dictionary<Type, DirectedRegistration>> subscriptions, EntityUid uid,
|
||||
IEntityManager componentManager)
|
||||
IEntityManager entityManager)
|
||||
{
|
||||
_eventType = eventType;
|
||||
_enumerator = enumerator;
|
||||
_subscriptions = subscriptions;
|
||||
_entityManager = componentManager;
|
||||
_entityManager = entityManager;
|
||||
_uid = uid;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Robust.Shared.GameObjects
|
||||
IComponentFactory IEntityManager.ComponentFactory => ComponentFactory;
|
||||
|
||||
/// <inheritdoc />
|
||||
[Obsolete("Use EntityManager instead.")]
|
||||
public IComponentManager ComponentManager => this;
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -266,7 +267,7 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
// Dispose all my components, in a safe order so transform is available
|
||||
ComponentManager.DisposeComponents(entity.Uid);
|
||||
DisposeComponents(entity.Uid);
|
||||
|
||||
// map does not have a parent node, everything else needs to be detached
|
||||
if (transform.ParentUid != EntityUid.Invalid)
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Robust.Shared.GameObjects
|
||||
where TComp : IComponent
|
||||
{
|
||||
DebugTools.Assert(component == null || uid == component.Owner.Uid, "Specified Entity is not the component's Owner!");
|
||||
return component != null || ComponentManager.TryGetComponent(uid, out component);
|
||||
return component != null || EntityManager.TryGetComponent(uid, out component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,9 +21,11 @@ namespace Robust.Shared.GameObjects
|
||||
public abstract partial class EntitySystem : IEntitySystem
|
||||
{
|
||||
[Dependency] protected readonly IEntityManager EntityManager = default!;
|
||||
[Dependency] protected readonly IComponentManager ComponentManager = default!;
|
||||
[Dependency] protected readonly IEntitySystemManager EntitySystemManager = default!;
|
||||
|
||||
[Dependency, Obsolete("Use EntityManager instead.")]
|
||||
protected readonly IComponentManager ComponentManager = default!;
|
||||
|
||||
protected internal List<Type> UpdatesAfter { get; } = new();
|
||||
protected internal List<Type> UpdatesBefore { get; } = new();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Robust.Shared.GameObjects
|
||||
void FrameUpdate(float frameTime);
|
||||
|
||||
IComponentFactory ComponentFactory { get; }
|
||||
[Obsolete("Use IEntityManager instead.")]
|
||||
IComponentManager ComponentManager { get; }
|
||||
IEntitySystemManager EntitySysManager { get; }
|
||||
IEntityNetworkManager? EntityNetManager { get; }
|
||||
|
||||
@@ -58,10 +58,10 @@ namespace Robust.Shared.GameObjects
|
||||
// these are called pretty infrequently so I'm fine with this for now.
|
||||
|
||||
// If we just got put into a container don't want to mess with our collision state.
|
||||
if (!ComponentManager.TryGetComponent<PhysicsComponent>(uid, out var body)) return;
|
||||
if (!EntityManager.TryGetComponent<PhysicsComponent>(uid, out var body)) return;
|
||||
|
||||
// If we're attached to the map we'll also just never disable collision due to how grid movement works.
|
||||
body.CanCollide = !component.Enabled || body.Awake || body.Joints.Any() || ComponentManager.GetComponent<TransformComponent>(uid).GridID == GridId.Invalid;
|
||||
body.CanCollide = !component.Enabled || body.Awake || body.Joints.Any() || EntityManager.GetComponent<TransformComponent>(uid).GridID == GridId.Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
private void OnAutoClearChange(bool value)
|
||||
{
|
||||
foreach (var component in ComponentManager.EntityQuery<SharedPhysicsMapComponent>(true))
|
||||
foreach (var component in EntityManager.EntityQuery<SharedPhysicsMapComponent>(true))
|
||||
{
|
||||
component.AutoClearForces = value;
|
||||
}
|
||||
@@ -349,7 +349,7 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var comp in ComponentManager.EntityQuery<SharedPhysicsMapComponent>(true))
|
||||
foreach (var comp in EntityManager.EntityQuery<SharedPhysicsMapComponent>(true))
|
||||
{
|
||||
comp.Step(deltaTime, prediction);
|
||||
}
|
||||
@@ -370,7 +370,7 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
// Go through and run all of the deferred events now
|
||||
foreach (var comp in ComponentManager.EntityQuery<SharedPhysicsMapComponent>(true))
|
||||
foreach (var comp in EntityManager.EntityQuery<SharedPhysicsMapComponent>(true))
|
||||
{
|
||||
comp.ProcessQueue();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
if (!EntityManager.EntityExists(ent)) continue;
|
||||
|
||||
ComponentManager.GetComponent<TransformComponent>(ent).Anchored = false;
|
||||
EntityManager.GetComponent<TransformComponent>(ent).Anchored = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
base.Update(frameTime);
|
||||
// Avoid a collection was modified while enumerating.
|
||||
var timers = ComponentManager.EntityQuery<TimerComponent>().ToList();
|
||||
var timers = EntityManager.EntityQuery<TimerComponent>().ToList();
|
||||
|
||||
foreach (var timer in timers)
|
||||
{
|
||||
@@ -19,7 +19,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
if (!timer.Deleted && !timer.Owner.Deleted && timer.RemoveOnEmpty && timer.TimerCount == 0)
|
||||
{
|
||||
ComponentManager.RemoveComponent<TimerComponent>(timer.Owner.Uid);
|
||||
EntityManager.RemoveComponent<TimerComponent>(timer.Owner.Uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,10 @@ namespace Robust.Shared.Physics.Controllers
|
||||
[MeansImplicitUse]
|
||||
public abstract class VirtualController
|
||||
{
|
||||
[Dependency] protected readonly IComponentManager ComponentManager = default!;
|
||||
[Dependency]
|
||||
[Obsolete("Use EntityManager instead.")]
|
||||
protected readonly IComponentManager ComponentManager = default!;
|
||||
|
||||
[Dependency] protected readonly IEntityManager EntityManager = default!;
|
||||
|
||||
public Histogram.Child BeforeMonitor = default!;
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace Robust.Shared.Physics
|
||||
if (moveBuffer.Count == 0) return;
|
||||
|
||||
// Cache as much broadphase data as we can up front for this map.
|
||||
foreach (var broadphase in ComponentManager.EntityQuery<BroadphaseComponent>(true))
|
||||
foreach (var broadphase in EntityManager.EntityQuery<BroadphaseComponent>(true))
|
||||
{
|
||||
var transform = broadphase.Owner.Transform;
|
||||
|
||||
@@ -882,7 +882,7 @@ namespace Robust.Shared.Physics
|
||||
|
||||
if (mapId == MapId.Nullspace) yield break;
|
||||
|
||||
foreach (var broadphase in ComponentManager.EntityQuery<BroadphaseComponent>(true))
|
||||
foreach (var broadphase in EntityManager.EntityQuery<BroadphaseComponent>(true))
|
||||
{
|
||||
if (broadphase.Owner.Transform.MapID != mapId) continue;
|
||||
|
||||
|
||||
@@ -378,7 +378,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
Assert.That(testThree.TestOne, Is.Null);
|
||||
|
||||
// Let's actually remove the removed components first.
|
||||
dummy.EntityManager.ComponentManager.CullRemovedComponents();
|
||||
dummy.EntityManager.CullRemovedComponents();
|
||||
|
||||
// Re-add test one and two.
|
||||
testOne = dummy.AddComponent<TestOneComponent>();
|
||||
|
||||
@@ -111,10 +111,10 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var compMan = IoCManager.Resolve<IComponentManager>();
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
// Move item into PVS so it gets sent to the client
|
||||
compMan.GetComponent<ITransformComponent>(itemUid).LocalPosition = (0, 0);
|
||||
entMan.GetComponent<ITransformComponent>(itemUid).LocalPosition = (0, 0);
|
||||
});
|
||||
|
||||
await server.WaitRunTicks(1);
|
||||
|
||||
@@ -75,21 +75,20 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
var compRegistration = new Mock<IComponentRegistration>();
|
||||
|
||||
var compManMock = new Mock<IComponentManager>();
|
||||
var compFacMock = new Mock<IComponentFactory>();
|
||||
|
||||
compRegistration.Setup(m => m.References).Returns(new List<Type> {typeof(MetaDataComponent)});
|
||||
compFacMock.Setup(m => m.GetRegistration(typeof(MetaDataComponent))).Returns(compRegistration.Object);
|
||||
compManMock.Setup(m => m.ComponentFactory).Returns(compFacMock.Object);
|
||||
entManMock.Setup(m => m.ComponentFactory).Returns(compFacMock.Object);
|
||||
|
||||
IComponent? outIComponent = compInstance;
|
||||
compManMock.Setup(m => m.TryGetComponent(entUid, typeof(MetaDataComponent), out outIComponent))
|
||||
entManMock.Setup(m => m.TryGetComponent(entUid, typeof(MetaDataComponent), out outIComponent))
|
||||
.Returns(true);
|
||||
|
||||
compManMock.Setup(m => m.GetComponent(entUid, typeof(MetaDataComponent)))
|
||||
entManMock.Setup(m => m.GetComponent(entUid, typeof(MetaDataComponent)))
|
||||
.Returns(compInstance);
|
||||
|
||||
entManMock.Setup(m => m.ComponentManager).Returns(compManMock.Object);
|
||||
entManMock.Setup(m => m.ComponentManager).Returns(entManMock.Object);
|
||||
var bus = new EntityEventBus(entManMock.Object);
|
||||
|
||||
// Subscribe
|
||||
@@ -99,7 +98,7 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
// add a component to the system
|
||||
entManMock.Raise(m => m.EntityAdded += null, entManMock.Object, entUid);
|
||||
compManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(compInstance, entUid));
|
||||
entManMock.Raise(m => m.ComponentAdded += null, new AddedComponentEventArgs(compInstance, entUid));
|
||||
|
||||
// Raise
|
||||
var evntArgs = new TestEvent(5);
|
||||
|
||||
@@ -11,10 +11,9 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
{
|
||||
private static EntityEventBus BusFactory()
|
||||
{
|
||||
var entityMan = new Mock<IEntityManager>();
|
||||
var compMan = new Mock<IComponentManager>();
|
||||
entityMan.Setup(m => m.ComponentManager).Returns(compMan.Object);
|
||||
var bus = new EntityEventBus(entityMan.Object);
|
||||
var entManMock = new Mock<IEntityManager>();
|
||||
entManMock.Setup(m => m.ComponentManager).Returns(entManMock.Object);
|
||||
var bus = new EntityEventBus(entManMock.Object);
|
||||
return bus;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using Robust.UnitTesting.Server;
|
||||
namespace Robust.UnitTesting.Shared.GameObjects
|
||||
{
|
||||
[TestFixture, Parallelizable ,TestOf(typeof(EntityManager))]
|
||||
public class ComponentManager_Tests
|
||||
public class EntityManager_Components_Tests
|
||||
{
|
||||
private static readonly EntityCoordinates DefaultCoords = new(new EntityUid(1), Vector2.Zero);
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = new DummyComponent()
|
||||
{
|
||||
@@ -27,10 +26,10 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
};
|
||||
|
||||
// Act
|
||||
manager.AddComponent(entity, component);
|
||||
entMan.AddComponent(entity, component);
|
||||
|
||||
// Assert
|
||||
var result = manager.GetComponent<DummyComponent>(entity.Uid);
|
||||
var result = entMan.GetComponent<DummyComponent>(entity.Uid);
|
||||
Assert.That(result, Is.EqualTo(component));
|
||||
}
|
||||
|
||||
@@ -40,7 +39,6 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = new DummyComponent()
|
||||
{
|
||||
@@ -48,10 +46,10 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
};
|
||||
|
||||
// Act
|
||||
manager.AddComponent(entity, component, true);
|
||||
entMan.AddComponent(entity, component, true);
|
||||
|
||||
// Assert
|
||||
var result = manager.GetComponent<DummyComponent>(entity.Uid);
|
||||
var result = entMan.GetComponent<DummyComponent>(entity.Uid);
|
||||
Assert.That(result, Is.EqualTo(component));
|
||||
}
|
||||
|
||||
@@ -61,18 +59,17 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var firstComp = new DummyComponent {Owner = entity};
|
||||
manager.AddComponent(entity, firstComp);
|
||||
manager.RemoveComponent<DummyComponent>(entity.Uid);
|
||||
entMan.AddComponent(entity, firstComp);
|
||||
entMan.RemoveComponent<DummyComponent>(entity.Uid);
|
||||
var secondComp = new DummyComponent { Owner = entity };
|
||||
|
||||
// Act
|
||||
manager.AddComponent(entity, secondComp);
|
||||
entMan.AddComponent(entity, secondComp);
|
||||
|
||||
// Assert
|
||||
var result = manager.GetComponent<DummyComponent>(entity.Uid);
|
||||
var result = entMan.GetComponent<DummyComponent>(entity.Uid);
|
||||
Assert.That(result, Is.EqualTo(secondComp));
|
||||
}
|
||||
|
||||
@@ -82,12 +79,11 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
entity.AddComponent<DummyComponent>();
|
||||
|
||||
// Act
|
||||
var result = manager.HasComponent<DummyComponent>(entity.Uid);
|
||||
var result = entMan.HasComponent<DummyComponent>(entity.Uid);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.True);
|
||||
@@ -103,12 +99,11 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var netId = factory.GetRegistration<DummyComponent>().NetID!;
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
entity.AddComponent<DummyComponent>();
|
||||
|
||||
// Act
|
||||
var result = manager.HasComponent(entity.Uid, netId.Value);
|
||||
var result = entMan.HasComponent(entity.Uid, netId.Value);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.True);
|
||||
@@ -124,12 +119,11 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var netId = factory.GetRegistration<DummyComponent>().NetID!;
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entity.AddComponent<DummyComponent>();
|
||||
|
||||
// Act
|
||||
var result = manager.GetComponent(entity.Uid, netId.Value);
|
||||
var result = entMan.GetComponent(entity.Uid, netId.Value);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.EqualTo(component));
|
||||
@@ -141,12 +135,11 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entity.AddComponent<DummyComponent>();
|
||||
|
||||
// Act
|
||||
var result = manager.TryGetComponent<DummyComponent>(entity.Uid, out var comp);
|
||||
var result = entMan.TryGetComponent<DummyComponent>(entity.Uid, out var comp);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.True);
|
||||
@@ -163,12 +156,11 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var netId = factory.GetRegistration<DummyComponent>().NetID!;
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entity.AddComponent<DummyComponent>();
|
||||
|
||||
// Act
|
||||
var result = manager.TryGetComponent(entity.Uid, netId.Value, out var comp);
|
||||
var result = entMan.TryGetComponent(entity.Uid, netId.Value, out var comp);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.True);
|
||||
@@ -181,16 +173,15 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entity.AddComponent<DummyComponent>();
|
||||
|
||||
// Act
|
||||
manager.RemoveComponent<DummyComponent>(entity.Uid);
|
||||
manager.CullRemovedComponents();
|
||||
entMan.RemoveComponent<DummyComponent>(entity.Uid);
|
||||
entMan.CullRemovedComponents();
|
||||
|
||||
// Assert
|
||||
Assert.That(manager.HasComponent(entity.Uid, component.GetType()), Is.False);
|
||||
Assert.That(entMan.HasComponent(entity.Uid, component.GetType()), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -203,16 +194,15 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
var netId = factory.GetRegistration<DummyComponent>().NetID!;
|
||||
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entity.AddComponent<DummyComponent>();
|
||||
|
||||
// Act
|
||||
manager.RemoveComponent(entity.Uid, netId.Value);
|
||||
manager.CullRemovedComponents();
|
||||
entMan.RemoveComponent(entity.Uid, netId.Value);
|
||||
entMan.CullRemovedComponents();
|
||||
|
||||
// Assert
|
||||
Assert.That(manager.HasComponent(entity.Uid, component.GetType()), Is.False);
|
||||
Assert.That(entMan.HasComponent(entity.Uid, component.GetType()), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -221,12 +211,11 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entity.AddComponent<DummyComponent>();
|
||||
|
||||
// Act
|
||||
var result = manager.GetComponents<DummyComponent>(entity.Uid);
|
||||
var result = entMan.GetComponents<DummyComponent>(entity.Uid);
|
||||
|
||||
// Assert
|
||||
var list = result.ToList();
|
||||
@@ -240,12 +229,11 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entity.AddComponent<DummyComponent>();
|
||||
|
||||
// Act
|
||||
var result = manager.EntityQuery<DummyComponent>(true);
|
||||
var result = entMan.EntityQuery<DummyComponent>(true);
|
||||
|
||||
// Assert
|
||||
var list = result.ToList();
|
||||
@@ -259,12 +247,11 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
// Arrange
|
||||
var sim = SimulationFactory();
|
||||
var entMan = sim.Resolve<IEntityManager>();
|
||||
var manager = sim.Resolve<IComponentManager>();
|
||||
var entity = entMan.SpawnEntity(null, DefaultCoords);
|
||||
var component = entity.AddComponent<DummyComponent>();
|
||||
|
||||
// Act
|
||||
var result = manager.GetComponents(entity.Uid);
|
||||
var result = entMan.GetComponents(entity.Uid);
|
||||
|
||||
// Assert
|
||||
var list = result.Where(c=>c.Name == "Dummy").ToList();
|
||||
@@ -28,7 +28,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
var grid = mapManager.CreateGrid(mapId);
|
||||
|
||||
// Should be nothing if grid empty
|
||||
Assert.That(entManager.ComponentManager.TryGetComponent(grid.GridEntityId, out PhysicsComponent gridBody));
|
||||
Assert.That(entManager.TryGetComponent(grid.GridEntityId, out PhysicsComponent gridBody));
|
||||
Assert.That(gridBody.Fixtures.Count, Is.EqualTo(0));
|
||||
Assert.That(gridBody.BodyType, Is.EqualTo(BodyType.Static));
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace Robust.UnitTesting.Shared.Physics
|
||||
var server = StartServer(options);
|
||||
await server.WaitIdleAsync();
|
||||
|
||||
var compManager = server.ResolveDependency<IComponentManager>();
|
||||
var entManager = server.ResolveDependency<IEntityManager>();
|
||||
var mapManager = server.ResolveDependency<IMapManager>();
|
||||
|
||||
@@ -45,7 +44,7 @@ namespace Robust.UnitTesting.Shared.Physics
|
||||
grid = mapManager.CreateGrid(mapId);
|
||||
|
||||
var entity = entManager.SpawnEntity("CollisionWakeTestItem", new MapCoordinates(Vector2.One, mapId));
|
||||
physics = compManager.GetComponent<PhysicsComponent>(entity.Uid);
|
||||
physics = entManager.GetComponent<PhysicsComponent>(entity.Uid);
|
||||
});
|
||||
|
||||
// Should still be collidable
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace Robust.UnitTesting.Shared.Physics
|
||||
var server = StartServer(new ServerIntegrationOptions {ExtraPrototypes = Prototypes});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
var compManager = server.ResolveDependency<IComponentManager>();
|
||||
var entityManager = server.ResolveDependency<IEntityManager>();
|
||||
var mapManager = server.ResolveDependency<IMapManager>();
|
||||
|
||||
@@ -35,7 +34,7 @@ namespace Robust.UnitTesting.Shared.Physics
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGrid(mapId);
|
||||
|
||||
Assert.That(compManager.TryGetComponent<PhysicsComponent>(grid.GridEntityId, out var gridPhysics));
|
||||
Assert.That(entityManager.TryGetComponent<PhysicsComponent>(grid.GridEntityId, out var gridPhysics));
|
||||
|
||||
// TODO: Once grid rotations are a stable thing try it with angular velocity too.
|
||||
// Check that grid even moving first
|
||||
@@ -45,7 +44,7 @@ namespace Robust.UnitTesting.Shared.Physics
|
||||
|
||||
// Check that map velocity is correct for entity
|
||||
var dummy = entityManager.SpawnEntity(DummyEntity, new EntityCoordinates(grid.GridEntityId, Vector2.Zero));
|
||||
Assert.That(compManager.TryGetComponent<PhysicsComponent>(dummy.Uid, out var body));
|
||||
Assert.That(entityManager.TryGetComponent<PhysicsComponent>(dummy.Uid, out var body));
|
||||
Assert.That(body.LinearVelocity, Is.EqualTo(Vector2.Zero));
|
||||
|
||||
Assert.That(body.MapLinearVelocity, Is.EqualTo(Vector2.One));
|
||||
|
||||
Reference in New Issue
Block a user