From 10f0a1d63c3820f470f41b4bc08c52a77a73fa61 Mon Sep 17 00:00:00 2001 From: metalgearsloth Date: Thu, 23 Nov 2023 11:39:44 +1100 Subject: [PATCH] Update Arch to latest --- Arch/Arch.csproj | 3 ++- .../Arch/ArchComponentAccessBenchmark.cs | 2 +- .../GameObjects/EntityManager.Components.cs | 23 ++++++++++--------- Robust.Shared/GameObjects/EntityManager.cs | 10 +++++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Arch/Arch.csproj b/Arch/Arch.csproj index 6660772ba51..774fde41de1 100644 --- a/Arch/Arch.csproj +++ b/Arch/Arch.csproj @@ -34,9 +34,10 @@ + - + diff --git a/Robust.Benchmarks/Arch/ArchComponentAccessBenchmark.cs b/Robust.Benchmarks/Arch/ArchComponentAccessBenchmark.cs index a249b50dde9..cae65ddfdf9 100644 --- a/Robust.Benchmarks/Arch/ArchComponentAccessBenchmark.cs +++ b/Robust.Benchmarks/Arch/ArchComponentAccessBenchmark.cs @@ -169,7 +169,7 @@ private struct QueryConsumer : IForEach private static readonly Consumer Consumer = new(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Update(in Entity entity) + public void Update(Entity entity) { Consumer.Consume(entity); } diff --git a/Robust.Shared/GameObjects/EntityManager.Components.cs b/Robust.Shared/GameObjects/EntityManager.Components.cs index 580fae9bc1a..b5d97a4fce1 100644 --- a/Robust.Shared/GameObjects/EntityManager.Components.cs +++ b/Robust.Shared/GameObjects/EntityManager.Components.cs @@ -368,7 +368,7 @@ public void RemoveComponents(EntityUid uid, MetaDataComponent? meta = null) // Reverse order for (var i = objComps.Length - 1; i >= 0; i--) { - var comp = (IComponent) objComps[i]; + var comp = (IComponent) objComps[i]!; RemoveComponentImmediate(comp, uid, false, false, meta); } } @@ -381,7 +381,7 @@ public void DisposeComponents(EntityUid uid, MetaDataComponent? meta = null) // Reverse order for (var i = objComps.Length - 1; i >= 0; i--) { - var comp = (IComponent) objComps[i]; + var comp = (IComponent) objComps[i]!; try { @@ -563,7 +563,7 @@ private void DeleteComponent(EntityUid entityUid, IComponent component, bool ter [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool HasComponent(EntityUid uid) where T : IComponent { - if (!IsAlive(uid) || !_world.TryGet(uid, out T comp)) + if (!IsAlive(uid) || !_world.TryGet(uid, out T? comp)) return false; return !comp!.Deleted; @@ -583,7 +583,7 @@ public bool HasComponent(EntityUid uid, Type type) if (!IsAlive(uid) || !_world.TryGet(uid, type, out var comp)) return false; - return !Unsafe.As(comp).Deleted; + return !Unsafe.As(comp!).Deleted; } /// @@ -680,8 +680,8 @@ public bool HasComponent(EntityUid? uid, ushort netId, MetaDataComponent? meta = [MethodImpl(MethodImplOptions.AggressiveInlining)] public T GetComponent(EntityUid uid) where T : IComponent { - if (IsAlive(uid) && _world.TryGet(uid, out T comp)) - return comp; + if (IsAlive(uid) && _world.TryGet(uid, out T? comp)) + return comp!; throw new KeyNotFoundException($"Entity {uid} does not have a component of type {typeof(T)}"); } @@ -761,7 +761,7 @@ public bool TryGetComponent(EntityUid uid, Type type, [NotNullWhen(true)] out IC { if (IsAlive(uid) && _world.TryGet(uid, type, out var comp)) { - component = Unsafe.As(comp); + component = Unsafe.As(comp!); if (!component.Deleted) { return true; @@ -841,7 +841,7 @@ public IEnumerable GetComponents(EntityUid uid) { foreach (var obj in _world.GetAllComponents(uid)) { - var comp = Unsafe.As(obj); + var comp = Unsafe.As(obj!); if (comp.Deleted) continue; @@ -880,9 +880,10 @@ public IEnumerable GetComponents(EntityUid uid) { var comps = _world.GetAllComponents(uid); - foreach (Component comp in comps) + foreach (var comp in comps) { - if (comp.Deleted || comp is not T tComp) continue; + var component = (IComponent)comp!; + if (component.Deleted || component is not T tComp) continue; yield return tComp; } @@ -1349,7 +1350,7 @@ internal bool TryGetComponentInternal(EntityUid uid, [NotNullWhen(true)] out TCo internal bool HasComponentInternal(EntityUid uid) { // TODO fix checking deleted - return _world.TryGet(uid, out TComp1 comp) && !comp.Deleted; + return _world.TryGet(uid, out TComp1? comp) && !comp!.Deleted; } /// diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index a1975dc18d3..f456f84a58a 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -151,8 +151,10 @@ public bool IsDefault(EntityUid uid) if (protoData.Count + 2 != comps.Length) return false; - foreach (IComponent component in comps) + foreach (var comp in comps) { + var component = (IComponent)comp!; + if (component.Deleted) return false; @@ -496,8 +498,10 @@ private void RecursiveDeleteEntity( // Shut down all components. var objComps = _world.GetAllComponents(uid); - foreach (Component component in objComps) + foreach (var comp in objComps) { + var component = (IComponent)comp!; + if (component.Running) { try @@ -565,7 +569,7 @@ public bool IsPaused(EntityUid? uid, MetaDataComponent? metadata = null) public bool Deleted(EntityUid uid) { - return !IsAlive(uid) || !_world.TryGet(uid, out MetaDataComponent comp) || comp.EntityLifeStage > EntityLifeStage.Terminating; + return !IsAlive(uid) || !_world.TryGet(uid, out MetaDataComponent? comp) || comp!.EntityLifeStage > EntityLifeStage.Terminating; } ///