From bd3b89f52f3e4dc4c8b7132eb7515182e2b11dbf Mon Sep 17 00:00:00 2001 From: Ullrich Praetz <ullrich@praetz.de> Date: Sun, 1 Dec 2024 15:09:05 +0100 Subject: [PATCH] rename: EntityRelations<> -> EntityRelation<> --- src/ECS/Entity/Store/Extension.cs | 2 +- .../{EntityRelations.cs => EntityRelation.cs} | 4 ++-- src/ECS/Relations/RelationExtensions.cs | 12 ++++++------ src/Tests/ECS/Relations/Test_Relations.cs | 2 +- src/Tests/ECS/Relations/Test_Relations_Delete.cs | 8 ++++---- src/Tests/ECS/Relations/Test_Relations_Query.cs | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) rename src/ECS/Relations/{EntityRelations.cs => EntityRelation.cs} (89%) diff --git a/src/ECS/Entity/Store/Extension.cs b/src/ECS/Entity/Store/Extension.cs index f9feab1d..9d5e3156 100644 --- a/src/ECS/Entity/Store/Extension.cs +++ b/src/ECS/Entity/Store/Extension.cs @@ -57,7 +57,7 @@ internal partial struct StoreExtension #endregion #region entity relations - internal AbstractEntityRelations[] relationsMap; // 8 - map & its EntityRelations created on demand + internal AbstractEntityRelations[] relationsMap; // 8 - map & its AbstractEntityRelations created on demand #endregion internal StoreExtension(PidType pidType) diff --git a/src/ECS/Relations/EntityRelations.cs b/src/ECS/Relations/EntityRelation.cs similarity index 89% rename from src/ECS/Relations/EntityRelations.cs rename to src/ECS/Relations/EntityRelation.cs index a131c89c..c4230930 100644 --- a/src/ECS/Relations/EntityRelations.cs +++ b/src/ECS/Relations/EntityRelation.cs @@ -3,12 +3,12 @@ // ReSharper disable once CheckNamespace namespace Friflo.Engine.ECS; -public readonly struct EntityRelations <TRelation> +public readonly struct EntityRelation <TRelation> where TRelation : struct, IRelation { private readonly AbstractEntityRelations relations; - internal EntityRelations(AbstractEntityRelations relations) { + internal EntityRelation(AbstractEntityRelations relations) { this.relations = relations; } diff --git a/src/ECS/Relations/RelationExtensions.cs b/src/ECS/Relations/RelationExtensions.cs index 8e9e2726..ffce148b 100644 --- a/src/ECS/Relations/RelationExtensions.cs +++ b/src/ECS/Relations/RelationExtensions.cs @@ -102,15 +102,15 @@ public static EntityLinks<TRelation> GetIncomingLinks<TRelation>(this Entity tar #endregion #region EntityStore - public static EntityRelations<TRelation> EntityRelations<TRelation>(this EntityStore store) + public static EntityRelation<TRelation> EntityRelation<TRelation>(this EntityStore store) where TRelation : struct, IRelation { var relations = AbstractEntityRelations.GetEntityRelations(store, StructInfo<TRelation>.Index); - return new EntityRelations<TRelation>(relations); + return new EntityRelation<TRelation>(relations); } /// <summary> - /// Obsolete: Use <see cref="EntityRelations{TRelation}.Entities"/><br/> + /// Obsolete: Use <see cref="EntityRelation{TRelation}.Entities"/><br/> /// Returns a collection of entities having one or more relations of the specified <typeparamref name="TRelation"/> type.<br/> /// Executes in O(1). /// </summary> @@ -125,7 +125,7 @@ public static EntityRelations<TRelation> EntityRelations<TRelation>(this EntityS /// </item> /// </list> /// </remarks> - [Obsolete("replace with property: EntityRelations<TRelation>().Entities")] + [Obsolete("replace with property: EntityRelation<TRelation>().Entities")] public static EntityReadOnlyCollection GetAllEntitiesWithRelations<TRelation>(this EntityStore store) where TRelation : struct, IRelation { @@ -134,11 +134,11 @@ public static EntityReadOnlyCollection GetAllEntitiesWithRelations<TRelation>(th } /// <summary> - /// Obsolete: Use <see cref="EntityRelations{TRelation}.For"/><br/> + /// Obsolete: Use <see cref="EntityRelation{TRelation}.For"/><br/> /// Iterates all entity relations of the specified <typeparamref name="TRelation"/> type.<br/> /// Executes in O(N) N: number of all entity relations. /// </summary> - [Obsolete("replace with method: EntityRelations<TRelation>().For()")] + [Obsolete("replace with method: EntityRelation<TRelation>().For()")] public static void ForAllEntityRelations<TRelation>(this EntityStore store, ForEachEntity<TRelation> lambda) where TRelation : struct, IRelation { diff --git a/src/Tests/ECS/Relations/Test_Relations.cs b/src/Tests/ECS/Relations/Test_Relations.cs index a8fd2a02..24815d84 100644 --- a/src/Tests/ECS/Relations/Test_Relations.cs +++ b/src/Tests/ECS/Relations/Test_Relations.cs @@ -227,7 +227,7 @@ public static void Test_Relations_Enumerator() public static void Test_Relations_EntityReadOnlyCollection() { var store = new EntityStore(); - var entities = store.EntityRelations<IntRelation>().Entities; + var entities = store.EntityRelation<IntRelation>().Entities; var entity1 = store.CreateEntity(1); var entity2 = store.CreateEntity(2); diff --git a/src/Tests/ECS/Relations/Test_Relations_Delete.cs b/src/Tests/ECS/Relations/Test_Relations_Delete.cs index 830c12a6..a13dc353 100644 --- a/src/Tests/ECS/Relations/Test_Relations_Delete.cs +++ b/src/Tests/ECS/Relations/Test_Relations_Delete.cs @@ -12,7 +12,7 @@ public static class Test_Relations_Delete public static void Test_Relations_Delete_int_relations() { var store = new EntityStore(); - var allEntities = store.EntityRelations<IntRelation>().Entities; + var allEntities = store.EntityRelation<IntRelation>().Entities; AreEqual("{ }", allEntities.Debug()); var entity1 = store.CreateEntity(1); @@ -29,7 +29,7 @@ public static void Test_Relations_Delete_int_relations() int count = 0; // --- version: iterate all entity relations in O(N) - store.EntityRelations<IntRelation>().For((ref IntRelation relation, Entity entity) => { + store.EntityRelation<IntRelation>().For((ref IntRelation relation, Entity entity) => { switch (count++) { case 0: AreEqual(1, entity.Id); AreEqual(10, relation.value); break; case 1: AreEqual(1, entity.Id); AreEqual(20, relation.value); break; @@ -54,7 +54,7 @@ public static void Test_Relations_Delete_int_relations() public static void Test_Relations_Delete_Entity_relations() { var store = new EntityStore(); - var sourceNodes = store.EntityRelations<AttackRelation>().Entities; + var sourceNodes = store.EntityRelation<AttackRelation>().Entities; AreEqual("{ }", sourceNodes.Debug()); var target10 = store.CreateEntity(10); @@ -76,7 +76,7 @@ public static void Test_Relations_Delete_Entity_relations() int count = 0; // --- version: iterate all entity relations in O(N) - store.EntityRelations<AttackRelation>().For((ref AttackRelation relation, Entity entity) => { + store.EntityRelation<AttackRelation>().For((ref AttackRelation relation, Entity entity) => { switch (count++) { case 0: AreEqual(1, entity.Id); AreEqual(10, relation.target.Id); break; case 1: AreEqual(1, entity.Id); AreEqual(11, relation.target.Id); break; diff --git a/src/Tests/ECS/Relations/Test_Relations_Query.cs b/src/Tests/ECS/Relations/Test_Relations_Query.cs index e6e3d121..7ecffd12 100644 --- a/src/Tests/ECS/Relations/Test_Relations_Query.cs +++ b/src/Tests/ECS/Relations/Test_Relations_Query.cs @@ -197,7 +197,7 @@ public static void Test_Relations_ForAllEntityRelations_Perf() int count = 0; var sw = new Stopwatch(); sw.Start(); - store.EntityRelations<IntRelation>().For((ref IntRelation relation, Entity entity) => { + store.EntityRelation<IntRelation>().For((ref IntRelation relation, Entity entity) => { count++; }); AreEqual(entityCount * relationsPerEntity, count);