Skip to content

Commit

Permalink
ECS - Add docs for EntityState and EntityStore.RecycleIds
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Jul 31, 2024
1 parent 55ff515 commit feee72d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ECS/Archetype/Archetype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ internal static int AddEntity(Archetype arch, int id)
}

private static void ResizeGrow (Archetype arch) => Resize(arch, 2 * arch.memory.capacity);
private static void ResizeShrink(Archetype arch) => Resize(arch, 2 * arch.memory.shrinkThreshold);
private static void ResizeShrink(Archetype arch) {
// Resize(arch, 2 * arch.memory.shrinkThreshold);
}

private static void Resize(Archetype arch, int capacity)
{
Expand Down
1 change: 1 addition & 0 deletions src/ECS/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public ref readonly Tags Tags { get {

// ------------------------------------ component properties ----------------------------------
#region component - properties
/// <summary> Returns the entity state used to optimize read / write access to entity components. </summary>
[Browse(Never)] public EntityState State { get {
ref var node = ref store.nodes[Id];
var type = archetype;
Expand Down
14 changes: 14 additions & 0 deletions src/ECS/Entity/EntityState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@
// See LICENSE file in the project root for full license information.

// ReSharper disable once CheckNamespace

using System;

namespace Friflo.Engine.ECS;

/// <summary>
/// An <see cref="EntityState"/> is used to optimize read / write access of entity components.br/>
/// An instance can be returned by <see cref="Entity.State"/>.
/// </summary>
public readonly ref struct EntityState
{
#region entity getter
/// <summary> Returns true is the entity is deleted. </summary>
/// <remarks>Executes in O(1)</remarks>
public bool IsNull => archetype == null;

/// <summary> Return the <see cref="ECS.Tags"/> added to an entity. </summary>
/// <remarks>Executes in O(1)</remarks>
public Tags Tags => archetype.tags;

/// <summary>Return the component of the given type as a reference.</summary>
/// <exception cref="NullReferenceException"> if entity has no component of Type <typeparamref name="T"/></exception>
/// <remarks>Executes in O(1)</remarks>
public ref T Get<T>() where T : struct, IComponent {
return ref ((StructHeap<T>)archetype.heapMap[StructInfo<T>.Index]).components[compIndex];
}
Expand Down
4 changes: 4 additions & 0 deletions src/ECS/EntityStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public sealed partial class EntityStore : EntityStoreBase
/// <summary> Get the number of internally reserved entities. </summary>
[Browse(Never)] public int Capacity => nodes.Length;

/// <summary>
/// If true ids of deleted entities are recycled when creating new entities.<br/>
/// If false every new entity gets its own unique id. As a result the store capacity will always grow over time.
/// </summary>
[Browse(Never)] public bool RecycleIds { get => recycleIds; set => SetRecycleIds(value); }

/// <summary> Return store information used for debugging and optimization. </summary>
Expand Down

0 comments on commit feee72d

Please sign in to comment.