From 6f50e7818889ef2ac77c9e55dc88ba5e8b50fd15 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 2 Nov 2023 12:15:21 -0700 Subject: [PATCH] add relation count methods --- .../Compatibility/EntityComponentReader.cs | 4 ++++ src/Rev2/World.cs | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Rev2/Compatibility/EntityComponentReader.cs b/src/Rev2/Compatibility/EntityComponentReader.cs index 14c944c..e7bacd9 100644 --- a/src/Rev2/Compatibility/EntityComponentReader.cs +++ b/src/Rev2/Compatibility/EntityComponentReader.cs @@ -25,8 +25,12 @@ public abstract class EntityComponentReader protected ReverseSpanEnumerator OutRelations(in EntityId entity) where T : unmanaged => World.OutRelations(entity); protected EntityId OutRelationSingleton(in EntityId entity) where T : unmanaged => World.OutRelationSingleton(entity); protected bool HasOutRelation(in EntityId entity) where T : unmanaged => World.HasOutRelation(entity); + protected int OutRelationCount(in EntityId entity) where T : unmanaged => World.OutRelationCount(entity); + protected EntityId NthOutRelation(in EntityId entity, int n) where T : unmanaged => World.NthOutRelation(entity, n); protected ReverseSpanEnumerator InRelations(in EntityId entity) where T : unmanaged => World.InRelations(entity); protected EntityId InRelationSingleton(in EntityId entity) where T : unmanaged => World.InRelationSingleton(entity); protected bool HasInRelation(in EntityId entity) where T : unmanaged => World.HasInRelation(entity); + protected int InRelationCount(in EntityId entity) where T : unmanaged => World.InRelationCount(entity); + protected EntityId NthInRelation(in EntityId entity, int n) where T : unmanaged => World.NthInRelation(entity, n); } diff --git a/src/Rev2/World.cs b/src/Rev2/World.cs index 6dbe7e0..e3fbdb1 100644 --- a/src/Rev2/World.cs +++ b/src/Rev2/World.cs @@ -407,6 +407,18 @@ public class World : IDisposable return relationStorage.HasOutRelation(entity); } + public int OutRelationCount(in EntityId entity) where T : unmanaged + { + var relationStorage = GetRelationStorage(); + return relationStorage.OutRelationCount(entity); + } + + public EntityId NthOutRelation(in EntityId entity, int n) where T : unmanaged + { + var relationStorage = GetRelationStorage(); + return relationStorage.OutNth(entity, n); + } + public ReverseSpanEnumerator InRelations(EntityId entity) where T : unmanaged { var relationStorage = GetRelationStorage(); @@ -425,6 +437,18 @@ public class World : IDisposable return relationStorage.HasInRelation(entity); } + public int InRelationCount(in EntityId entity) where T : unmanaged + { + var relationStorage = GetRelationStorage(); + return relationStorage.InRelationCount(entity); + } + + public EntityId NthInRelation(in EntityId entity, int n) where T : unmanaged + { + var relationStorage = GetRelationStorage(); + return relationStorage.InNth(entity, n); + } + // used as a fast path by Archetype.ClearAll and snapshot restore internal void FreeEntity(EntityId entityId) {