Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: genaray/Arch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: space-wizards/Arch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
Loading
2 changes: 1 addition & 1 deletion src/Arch/Arch.csproj
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
<TargetFrameworks>net7.0; net6.0; netstandard2.1</TargetFrameworks>
<TargetFramework>net7.0</TargetFramework>

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
23 changes: 7 additions & 16 deletions src/Arch/CommandBuffer/CommandBuffer.cs
Original file line number Diff line number Diff line change
@@ -137,7 +137,6 @@ public CommandBuffer(World world, int initialCapacity = 128)
/// </summary>
/// <param name="entity">The <see cref="Entity"/> to register.</param>
/// <param name="info">Its <see cref="BufferedEntityInfo"/> which stores indexes used for <see cref="CommandBuffer"/> operations.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void Register(in Entity entity, out BufferedEntityInfo info)
{
var setIndex = Sets.Create(in entity);
@@ -151,15 +150,14 @@ internal void Register(in Entity entity, out BufferedEntityInfo info)
Size++;
}

/// TODO : Probably just run this if the wrapped entity is negative? To save some overhead?
/// TODO : Probably just run this if the wrapped entity is negative? To save some overhead?
/// <summary>
/// Resolves an <see cref="Entity"/> originally either from a <see cref="StructuralSparseArray"/> or <see cref="SparseArray"/> to its real <see cref="Entity"/>.
/// This is required since we can also create new entities via this buffer and buffer operations for it. So sometimes there negative entities stored in the arrays and those must then be resolved to its newly created real entity.
/// This is required since we can also create new entities via this buffer and buffer operations for it. So sometimes there negative entities stored in the arrays and those must then be resolved to its newly created real entity.
/// <remarks>Probably hard to understand, blame genaray for this.</remarks>
/// </summary>
/// <param name="entity">The <see cref="Entity"/> with a negative or positive id to resolve.</param>
/// <returns>Its real <see cref="Entity"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal Entity Resolve(Entity entity)
{
var entityIndex = BufferedEntityInfo[entity.Id].Index;
@@ -172,7 +170,6 @@ internal Entity Resolve(Entity entity)
/// </summary>
/// <param name="types">The <see cref="Entity"/>'s component structure/<see cref="Archetype"/>.</param>
/// <returns>The buffered <see cref="Entity"/> with an index of <c>-1</c>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Entity Create(ComponentType[] types)
{
lock (this)
@@ -192,7 +189,6 @@ public Entity Create(ComponentType[] types)
/// Will be destroyed during <see cref="Playback"/>.
/// </summary>
/// <param name="entity">The <see cref="Entity"/> to destroy.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Destroy(in Entity entity)
{
lock (this)
@@ -214,7 +210,6 @@ public void Destroy(in Entity entity)
/// <typeparam name="T">The component type.</typeparam>
/// <param name="entity">The <see cref="Entity"/>.</param>
/// <param name="component">The component value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set<T>(in Entity entity, in T? component = default)
{
BufferedEntityInfo info;
@@ -237,7 +232,6 @@ public void Set<T>(in Entity entity, in T? component = default)
/// <typeparam name="T">The component type.</typeparam>
/// <param name="entity">The <see cref="Entity"/>.</param>
/// <param name="component">The component value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add<T>(in Entity entity, in T? component = default)
{
BufferedEntityInfo info;
@@ -259,7 +253,6 @@ public void Add<T>(in Entity entity, in T? component = default)
/// </summary>
/// <typeparam name="T">The component type.</typeparam>
/// <param name="entity">The <see cref="Entity"/>.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Remove<T>(in Entity entity)
{
BufferedEntityInfo info;
@@ -281,7 +274,6 @@ public void Remove<T>(in Entity entity)
/// <param name="entity">The <see cref="Entity"/>.</param>
/// <param name="components">A <see cref="IList{T}"/> of <see cref="ComponentType"/>'s, those are added to the <see cref="Entity"/>.</param>
[SkipLocalsInit]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void AddRange(World world, Entity entity, IList<ComponentType> components)
{
var oldArchetype = world.EntityInfo.GetArchetype(entity.Id);
@@ -306,14 +298,13 @@ internal static void AddRange(World world, Entity entity, IList<ComponentType> c

world.Move(entity, oldArchetype, newArchetype, out _);
}

/// <summary>
/// Plays back all recorded commands, modifying the world.
/// </summary>
/// <remarks>
/// This operation should only happen on the main thread.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Playback()
{
// Create recorded entities.
@@ -344,8 +335,8 @@ public void Playback()
{
continue;
}
// Resolves the entity to get the real one (e.g. for newly created negative entities and stuff).

// Resolves the entity to get the real one (e.g. for newly created negative entities and stuff).
var entity = Resolve(wrappedEntity.Entity);
Debug.Assert(World.IsAlive(entity), $"CommandBuffer can not to add components to the dead {wrappedEntity.Entity}");

@@ -360,7 +351,7 @@ public void Playback()
var wrappedEntity = Sets.Entities[index];
var entity = Resolve(wrappedEntity.Entity);
var id = wrappedEntity.Index;

Debug.Assert(World.IsAlive(entity), $"CommandBuffer can not to set components to the dead {wrappedEntity.Entity}");

// Get entity chunk
@@ -417,7 +408,7 @@ public void Playback()
{
continue;
}

var entity = Resolve(wrappedEntity.Entity);
Debug.Assert(World.IsAlive(entity), $"CommandBuffer can not to remove components from the dead {wrappedEntity.Entity}");

15 changes: 1 addition & 14 deletions src/Arch/CommandBuffer/SparseSet.cs
Original file line number Diff line number Diff line change
@@ -74,12 +74,11 @@ public SparseArray(ComponentType type, int capacity = 64)
/// Gets an array of components contained by the <see cref="SparseArray"/>.
/// </summary>
public Array Components { get; private set; }

/// <summary>
/// Adds an item to the array.
/// </summary>
/// <param name="index">Its index in the array.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(int index)
{
lock (this)
@@ -114,7 +113,6 @@ public void Add(int index)
/// </summary>
/// <param name="index">The index in the array.</param>
/// <returns>True if an component exists there, otherwhise false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Contains(int index)
{
return index < Entities.Length && Entities[index] != -1;
@@ -126,7 +124,6 @@ public bool Contains(int index)
/// </summary>
/// <typeparam name="T">The component type.</typeparam>
/// <returns>The array instance if it exists.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private T[] GetArray<T>()
{
return Unsafe.As<T[]>(Components);
@@ -237,7 +234,6 @@ public SparseSet(int capacity = 64)
/// <remarks>Does not ensure the capacity in terms of how many operations or components are recorded.</remarks>
/// </summary>
/// <param name="capacity">The new capacity, the id of the component which will be ensured to fit into the arrays.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void EnsureTypeCapacity(int capacity)
{
// Allocate new `SparseArray` for new component type.
@@ -252,7 +248,6 @@ private void EnsureTypeCapacity(int capacity)
/// Ensures the capacity for the <see cref="Used"/> array.
/// </summary>
/// <param name="capacity">The new capacity.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void EnsureUsedCapacity(int capacity)
{
// Resize UsedSize array.
@@ -268,7 +263,6 @@ private void EnsureUsedCapacity(int capacity)
/// </summary>
/// <param name="entity">The <see cref="Entity"/>.</param>
/// <returns>The index in the <see cref="SparseSet"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Create(in Entity entity)
{
lock (_createLock)
@@ -286,7 +280,6 @@ public int Create(in Entity entity)
/// Adds an <see cref="SparseArray"/> to the <see cref="Components"/> list and updates the <see cref="Used"/> properly.
/// </summary>
/// <param name="type">The <see cref="ComponentType"/> of the <see cref="SparseArray"/>.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void AddSparseArray(ComponentType type)
{
Components[type.Id] = new SparseArray(type, type.Id);
@@ -300,7 +293,6 @@ private void AddSparseArray(ComponentType type)
/// </summary>
/// <param name="type">The <see cref="ComponentType"/> to check.</param>
/// <returns>True if it does, false if not.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool HasSparseArray(ComponentType type)
{
return Components[type.Id] != null;
@@ -311,7 +303,6 @@ private bool HasSparseArray(ComponentType type)
/// </summary>
/// <param name="type">The <see cref="ComponentType"/>.</param>
/// <returns>The existing <see cref="StructuralSparseArray"/> instance.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private SparseArray GetSparseArray(ComponentType type)
{
return Components[type.Id];
@@ -324,7 +315,6 @@ private SparseArray GetSparseArray(ComponentType type)
/// <typeparam name="T">The component type.</typeparam>
/// <param name="index">The index.</param>
/// <param name="component">The component instance.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set<T>(int index, in T component)
{
var componentType = Component<T>.ComponentType;
@@ -358,7 +348,6 @@ public void Set<T>(int index, in T component)
/// </summary>
/// <param name="index">The index in the array.</param>
/// <returns>True if an component exists there, otherwhise false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Contains<T>(int index)
{
var id = Component<T>.ComponentType.Id;
@@ -375,7 +364,6 @@ public bool Contains<T>(int index)
/// <typeparam name="T">The component type.</typeparam>
/// <param name="index">The index.</param>
/// <returns>A reference to the component.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T Get<T>(int index)
{
var id = Component<T>.ComponentType.Id;
@@ -387,7 +375,6 @@ public ref T Get<T>(int index)
/// <summary>
/// Clears the <see cref="SparseSet"/>.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear()
{
Count = 0;
11 changes: 0 additions & 11 deletions src/Arch/CommandBuffer/StructuralSparseSet.cs
Original file line number Diff line number Diff line change
@@ -68,7 +68,6 @@ public StructuralSparseArray(ComponentType type, int capacity = 64)
/// Adds an item to the array.
/// </summary>
/// <param name="index">Its index in the array.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(int index)
{
lock (this)
@@ -92,7 +91,6 @@ public void Add(int index)
/// </summary>
/// <param name="index">The index in the array.</param>
/// <returns>True if an component exists there, otherwhise false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Contains(int index)
{
return index < Entities.Length && Entities[index] != -1;
@@ -171,7 +169,6 @@ public StructuralSparseSet(int capacity = 64)
/// <remarks>Does not ensure the capacity in terms of how many operations or components are recorded.</remarks>
/// </summary>
/// <param name="capacity">The new capacity, the id of the component which will be ensured to fit into the arrays.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void EnsureTypeCapacity(int capacity)
{
// Resize arrays
@@ -185,7 +182,6 @@ private void EnsureTypeCapacity(int capacity)
/// Ensures the capacity for the <see cref="Used"/> array.
/// </summary>
/// <param name="capacity">The new capacity.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void EnsureUsedCapacity(int capacity)
{
// Resize UsedSize array.
@@ -200,7 +196,6 @@ private void EnsureUsedCapacity(int capacity)
/// Adds an <see cref="StructuralSparseArray"/> to the <see cref="Components"/> list and updates the <see cref="Used"/> properly.
/// </summary>
/// <param name="type">The <see cref="ComponentType"/> of the <see cref="StructuralSparseArray"/>.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void AddStructuralSparseArray(ComponentType type)
{
Components[type.Id] = new StructuralSparseArray(type, Capacity);
@@ -214,7 +209,6 @@ private void AddStructuralSparseArray(ComponentType type)
/// </summary>
/// <param name="type">The <see cref="ComponentType"/> to check.</param>
/// <returns>True if it does, false if not.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool HasStructuralSparseArray(ComponentType type)
{
return Components[type.Id] != null;
@@ -225,7 +219,6 @@ private bool HasStructuralSparseArray(ComponentType type)
/// </summary>
/// <param name="type">The <see cref="ComponentType"/>.</param>
/// <returns>The existing <see cref="StructuralSparseArray"/> instance.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private StructuralSparseArray GetStructuralSparseArray(ComponentType type)
{
return Components[type.Id];
@@ -236,7 +229,6 @@ private StructuralSparseArray GetStructuralSparseArray(ComponentType type)
/// </summary>
/// <param name="entity">The <see cref="Entity"/>.</param>
/// <returns>Its index in this <see cref="StructuralSparseSet"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Create(in Entity entity)
{
lock (_createLock)
@@ -255,7 +247,6 @@ public int Create(in Entity entity)
/// </summary>
/// <typeparam name="T">The component type.</typeparam>
/// <param name="index">The index.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set<T>(int index)
{
var componentType = Component<T>.ComponentType;
@@ -287,7 +278,6 @@ public void Set<T>(int index)
/// </summary>
/// <param name="index">The index in the array.</param>
/// <returns>True if an component exists there, otherwhise false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Contains<T>(int index)
{
var id = Component<T>.ComponentType.Id;
@@ -299,7 +289,6 @@ public bool Contains<T>(int index)
/// <summary>
/// Clears the <see cref="StructuralSparseSet"/>.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear()
{
Count = 0;
Loading