Skip to content

Commit

Permalink
rename: EntityRelations<> -> EntityRelation<>
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Dec 1, 2024
1 parent e54388b commit bd3b89f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/ECS/Entity/Store/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/ECS/Relations/RelationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
{
Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/ECS/Relations/Test_Relations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Tests/ECS/Relations/Test_Relations_Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/ECS/Relations/Test_Relations_Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bd3b89f

Please sign in to comment.