Skip to content

Commit

Permalink
Engine - ECS: add struct Entities & EntityEnumerator skeletons
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed May 28, 2024
1 parent a62054f commit 772fd49
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 6 deletions.
81 changes: 81 additions & 0 deletions Engine/src/ECS/Archetype/Entities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Ullrich Praetz - https://github.com/friflo. All rights reserved.
// See LICENSE file in the project root for full license information.

using System.Collections;
using System.Collections.Generic;

// ReSharper disable once CheckNamespace
namespace Friflo.Engine.ECS;

public readonly struct Entities : IReadOnlyList<Entity>
{
#region properties
public int Count => count;
#endregion

#region interal fields
internal readonly int[] ids; // 8
internal readonly EntityStore store; // 8
internal readonly int start; // 4
public readonly int count; // 4

Check warning on line 20 in Engine/src/ECS/Archetype/Entities.cs

View workflow job for this annotation

GitHub Actions / build

Identifier 'Entities.count' differing only in case is not CLS-compliant

Check warning on line 20 in Engine/src/ECS/Archetype/Entities.cs

View workflow job for this annotation

GitHub Actions / build

Identifier 'Entities.count' differing only in case is not CLS-compliant

Check warning on line 20 in Engine/src/ECS/Archetype/Entities.cs

View workflow job for this annotation

GitHub Actions / build

Identifier 'Entities.count' differing only in case is not CLS-compliant

Check warning on line 20 in Engine/src/ECS/Archetype/Entities.cs

View workflow job for this annotation

GitHub Actions / build

Identifier 'Entities.count' differing only in case is not CLS-compliant

Check warning on line 20 in Engine/src/ECS/Archetype/Entities.cs

View workflow job for this annotation

GitHub Actions / build

Identifier 'Entities.count' differing only in case is not CLS-compliant

Check warning on line 20 in Engine/src/ECS/Archetype/Entities.cs

View workflow job for this annotation

GitHub Actions / build

Identifier 'Entities.count' differing only in case is not CLS-compliant

Check warning on line 20 in Engine/src/ECS/Archetype/Entities.cs

View workflow job for this annotation

GitHub Actions / build

Identifier 'Entities.count' differing only in case is not CLS-compliant

Check warning on line 20 in Engine/src/ECS/Archetype/Entities.cs

View workflow job for this annotation

GitHub Actions / build

Identifier 'Entities.count' differing only in case is not CLS-compliant
#endregion

#region general
internal Entities(int[] ids, EntityStore store, int start, int count) {
this.ids = ids;
this.store = store;
this.start = start;
this.count = count;
}

public Entity this[int index] => throw new System.NotImplementedException();
#endregion


#region IEnumerator
public EntityEnumerator GetEnumerator() => new EntityEnumerator (this);

// --- IEnumerable
IEnumerator IEnumerable.GetEnumerator() => new EntityEnumerator (this);

// --- IEnumerable<>
IEnumerator<Entity> IEnumerable<Entity>.GetEnumerator() => new EntityEnumerator (this);
#endregion
}


public struct EntityEnumerator : IEnumerator<Entity>
{
private readonly int[] ids; // 8
private readonly EntityStore store; // 8
private readonly int start; // 4
private readonly int last; // 8
private int index; // 4

internal EntityEnumerator(in Entities entities) {
ids = entities.ids;
store = entities.store;
start = entities.start;
last = start + entities.count;
index = start;
}

// --- IEnumerator
public void Reset() => index = start;

readonly object IEnumerator.Current => new Entity(store, ids[index]);

public Entity Current => new Entity(store, ids[index]);

// --- IEnumerator
public bool MoveNext()
{
if (index < last) {
index++;
return true;
}
return false;
}

public readonly void Dispose() { }
}
6 changes: 0 additions & 6 deletions Engine/src/ECS/Entity/Store/Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,3 @@ internal void DeleteEntityEvent(Entity entity)
}
}

/// <summary>
/// Reserved symbol name.
/// If exposing public it needs to store an array of <see cref="Entity"/>'s.<br/>
/// Similar to <see cref="Archetypes"/>.
/// </summary>
internal struct Entities;

0 comments on commit 772fd49

Please sign in to comment.