Skip to content

Commit

Permalink
rename: AbstractComponentIndex<> -> GenericComponentIndex<>
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Dec 1, 2024
1 parent bd3b89f commit 6489ec2
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/ECS/Index/ComponentIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Friflo.Engine.ECS;
public readonly struct ComponentIndex <TIndexedComponent,TValue>
where TIndexedComponent : struct, IIndexedComponent<TValue>
{
private readonly AbstractComponentIndex<TValue> index;
private readonly GenericComponentIndex<TValue> index;

internal ComponentIndex(AbstractComponentIndex<TValue> index) {
internal ComponentIndex(GenericComponentIndex<TValue> index) {
this.index = index;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ECS/Index/Conditions/HasValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal HasValueCondition(TValue value) {

internal override void AddMatchingEntities(EntityStore store, HashSet<int> idSet)
{
var index = (AbstractComponentIndex<TValue>)StoreIndex.GetIndex(store, StructInfo<TComponent>.Index);
var index = (GenericComponentIndex<TValue>)StoreIndex.GetIndex(store, StructInfo<TComponent>.Index);
var entities = index.GetHasValueEntities(value);
foreach (var id in entities.Ids) {
idSet.Add(id);
Expand Down
2 changes: 1 addition & 1 deletion src/ECS/Index/Conditions/ValueInRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal ValueInRangeCondition(TValue min, TValue max) {

internal override void AddMatchingEntities(EntityStore store, HashSet<int> idSet)
{
var index = (AbstractComponentIndex<TValue>)StoreIndex.GetIndex(store, StructInfo<TComponent>.Index);
var index = (GenericComponentIndex<TValue>)StoreIndex.GetIndex(store, StructInfo<TComponent>.Index);
index.AddValueInRangeEntities(min, max, idSet);
}
}
12 changes: 6 additions & 6 deletions src/ECS/Index/IndexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static EntityLinks<TComponent> GetIncomingLinks<TComponent>(this Entity t
where TComponent: struct, ILinkComponent
{
if (target.IsNull) throw EntityStoreBase.EntityNullException(target);
var index = (AbstractComponentIndex<Entity>)StoreIndex.GetIndex(target.store, StructInfo<TComponent>.Index);
var index = (GenericComponentIndex<Entity>)StoreIndex.GetIndex(target.store, StructInfo<TComponent>.Index);
return new EntityLinks<TComponent>(target, index.GetHasValueEntities(target), null);
}
#endregion
Expand All @@ -37,7 +37,7 @@ public static EntityLinks<TComponent> GetIncomingLinks<TComponent>(this Entity t
public static ComponentIndex<TIndexedComponent,TValue> ComponentIndex<TIndexedComponent, TValue>(this EntityStore store)
where TIndexedComponent: struct, IIndexedComponent<TValue>
{
var index = (AbstractComponentIndex<TValue>)StoreIndex.GetIndex(store, StructInfo<TIndexedComponent>.Index);
var index = (GenericComponentIndex<TValue>)StoreIndex.GetIndex(store, StructInfo<TIndexedComponent>.Index);
return new ComponentIndex<TIndexedComponent, TValue>(index);
}

Expand All @@ -48,7 +48,7 @@ public static ComponentIndex<TIndexedComponent,TValue> ComponentIndex<TIndexedCo
public static LinkComponentIndex<TLinkComponent> LinkComponentIndex<TLinkComponent>(this EntityStore store)
where TLinkComponent: struct, ILinkComponent
{
var index = (AbstractComponentIndex<Entity>)StoreIndex.GetIndex(store, StructInfo<TLinkComponent>.Index);
var index = (GenericComponentIndex<Entity>)StoreIndex.GetIndex(store, StructInfo<TLinkComponent>.Index);
return new LinkComponentIndex<TLinkComponent>(index);
}

Expand All @@ -61,7 +61,7 @@ public static LinkComponentIndex<TLinkComponent> LinkComponentIndex<TLinkCompone
public static Entities GetEntitiesWithComponentValue<TComponent, TValue>(this EntityStore store, TValue value)
where TComponent: struct, IIndexedComponent<TValue>
{
var index = (AbstractComponentIndex<TValue>)StoreIndex.GetIndex(store, StructInfo<TComponent>.Index);
var index = (GenericComponentIndex<TValue>)StoreIndex.GetIndex(store, StructInfo<TComponent>.Index);
return index.GetHasValueEntities(value);
}

Expand All @@ -88,7 +88,7 @@ public static Entities GetEntitiesWithComponentValue<TComponent, TValue>(this En
public static IReadOnlyCollection<TValue> GetAllIndexedComponentValues<TComponent, TValue>(this EntityStore store)
where TComponent: struct, IIndexedComponent<TValue>
{
var index = (AbstractComponentIndex<TValue>)StoreIndex.GetIndex(store, StructInfo<TComponent>.Index);
var index = (GenericComponentIndex<TValue>)StoreIndex.GetIndex(store, StructInfo<TComponent>.Index);
return index.IndexedComponentValues;
}

Expand All @@ -115,7 +115,7 @@ public static IReadOnlyCollection<TValue> GetAllIndexedComponentValues<TCompone
public static IReadOnlyCollection<Entity> GetAllLinkedEntities<TComponent>(this EntityStore store)
where TComponent: struct, ILinkComponent
{
var index = (AbstractComponentIndex<Entity>)StoreIndex.GetIndex(store, StructInfo<TComponent>.Index);
var index = (GenericComponentIndex<Entity>)StoreIndex.GetIndex(store, StructInfo<TComponent>.Index);
return index.IndexedComponentValues;
}
#endregion
Expand Down
4 changes: 2 additions & 2 deletions src/ECS/Index/Indexes/AbstractComponentIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ internal AbstractComponentIndex(EntityStore store, ComponentType componentType)
/// <summary>
/// Generic base class required to implement a custom component index.
/// </summary>
public abstract class AbstractComponentIndex<TValue> : AbstractComponentIndex
public abstract class GenericComponentIndex<TValue> : AbstractComponentIndex
{
internal TValue[] sortBuffer = Array.Empty<TValue>();

internal abstract IReadOnlyCollection<TValue> IndexedComponentValues { get; }
internal abstract Entities GetHasValueEntities (TValue value);
internal virtual void AddValueInRangeEntities(TValue min, TValue max, HashSet<int> idSet) => throw NotSupportedException("ValueInRange()");

internal AbstractComponentIndex(EntityStore store, ComponentType componentType) : base(store, componentType) { }
internal GenericComponentIndex(EntityStore store, ComponentType componentType) : base(store, componentType) { }
}
2 changes: 1 addition & 1 deletion src/ECS/Index/Indexes/EntityIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// ReSharper disable once CheckNamespace
namespace Friflo.Engine.ECS.Index;

internal abstract class EntityIndex : AbstractComponentIndex<Entity>
internal abstract class EntityIndex : GenericComponentIndex<Entity>
{
internal override int Count => entityMap.Count;

Expand Down
2 changes: 1 addition & 1 deletion src/ECS/Index/Indexes/RangeIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Friflo.Engine.ECS.Index;
/// The default index executes in O(1) when adding, removing or updating indexed component values.
/// </summary>
[ExcludeFromCodeCoverage] // not used - kept only for reference
public sealed class RangeIndex<TIndexedComponent,TValue> : AbstractComponentIndex<TValue>
public sealed class RangeIndex<TIndexedComponent,TValue> : GenericComponentIndex<TValue>
where TIndexedComponent : struct, IIndexedComponent<TValue>
{
internal override int Count => entityMap.Count;
Expand Down
2 changes: 1 addition & 1 deletion src/ECS/Index/Indexes/ValueClassIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// ReSharper disable once CheckNamespace
namespace Friflo.Engine.ECS.Index;

internal sealed class ValueClassIndex<TIndexedComponent,TValue> : AbstractComponentIndex<TValue>
internal sealed class ValueClassIndex<TIndexedComponent,TValue> : GenericComponentIndex<TValue>
where TIndexedComponent : struct, IIndexedComponent<TValue>
where TValue : class
{
Expand Down
2 changes: 1 addition & 1 deletion src/ECS/Index/Indexes/ValueStructIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// ReSharper disable once CheckNamespace
namespace Friflo.Engine.ECS.Index;

internal sealed class ValueStructIndex<TIndexedComponent,TValue> : AbstractComponentIndex<TValue>
internal sealed class ValueStructIndex<TIndexedComponent,TValue> : GenericComponentIndex<TValue>
where TIndexedComponent : struct, IIndexedComponent<TValue>
where TValue : struct
{
Expand Down
4 changes: 2 additions & 2 deletions src/ECS/Index/LinkComponentIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace Friflo.Engine.ECS;
public readonly struct LinkComponentIndex <TLinkComponent>
where TLinkComponent: struct, ILinkComponent
{
private readonly AbstractComponentIndex<Entity> index;
private readonly GenericComponentIndex<Entity> index;

internal LinkComponentIndex(AbstractComponentIndex<Entity> index) {
internal LinkComponentIndex(GenericComponentIndex<Entity> index) {
this.index = index;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ECS/Index/Utils/SortUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Friflo.Engine.ECS.Index;

internal static class SortUtils<TValue>
{
internal static void AddValueInRangeEntities(TValue min, TValue max, HashSet<int> idSet, Dictionary<TValue, IdArray> map, AbstractComponentIndex<TValue> componentIndex)
internal static void AddValueInRangeEntities(TValue min, TValue max, HashSet<int> idSet, Dictionary<TValue, IdArray> map, GenericComponentIndex<TValue> componentIndex)
{
int count = map.Count;
var buffer = componentIndex.sortBuffer;
Expand Down

0 comments on commit 6489ec2

Please sign in to comment.