Skip to content

Commit

Permalink
Update Arch to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth committed Nov 23, 2023
1 parent 3028a81 commit 10f0a1d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Arch/Arch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Arch.LowLevel" Version="1.1.0" />
<PackageReference Include="Collections.Pooled" Version="2.0.0-preview.27" />
<PackageReference Include="CommunityToolkit.HighPerformance" Version="7.1.2" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="ZeroAllocJobScheduler" Version="1.0.2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Robust.Benchmarks/Arch/ArchComponentAccessBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
23 changes: 12 additions & 11 deletions Robust.Shared/GameObjects/EntityManager.Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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
{
Expand Down Expand Up @@ -563,7 +563,7 @@ private void DeleteComponent(EntityUid entityUid, IComponent component, bool ter
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool HasComponent<T>(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;
Expand All @@ -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<IComponent>(comp).Deleted;
return !Unsafe.As<IComponent>(comp!).Deleted;
}

/// <inheritdoc />
Expand Down Expand Up @@ -680,8 +680,8 @@ public bool HasComponent(EntityUid? uid, ushort netId, MetaDataComponent? meta =
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T GetComponent<T>(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)}");
}
Expand Down Expand Up @@ -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<IComponent>(comp);
component = Unsafe.As<IComponent>(comp!);
if (!component.Deleted)
{
return true;
Expand Down Expand Up @@ -841,7 +841,7 @@ public IEnumerable<IComponent> GetComponents(EntityUid uid)
{
foreach (var obj in _world.GetAllComponents(uid))
{
var comp = Unsafe.As<IComponent>(obj);
var comp = Unsafe.As<IComponent>(obj!);

if (comp.Deleted) continue;

Expand Down Expand Up @@ -880,9 +880,10 @@ public IEnumerable<T> GetComponents<T>(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;
}
Expand Down Expand Up @@ -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;
}

/// <summary>
Expand Down
10 changes: 7 additions & 3 deletions Robust.Shared/GameObjects/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/// <summary>
Expand Down

0 comments on commit 10f0a1d

Please sign in to comment.