diff --git a/Svelto.ECS/QueryGroups.cs b/Svelto.ECS/QueryGroups.cs index a22f4b5..eaa6351 100644 --- a/Svelto.ECS/QueryGroups.cs +++ b/Svelto.ECS/QueryGroups.cs @@ -65,6 +65,49 @@ public QueryResult Except(ExclusiveGroupStruct groupsToIgnore) return new QueryResult(group); } + + public QueryResult WithEntity(EntitiesDB entitiesDB, uint entityId) + where T : struct, IEntityComponent + { + var group = groups.Value.reference; + var groupsCount = group.count; + + var found = false; + for (var i = 0; i < groupsCount; i++) + { + if (found || entitiesDB.Exists(entityId, group[i]) == false) + { + group.UnorderedRemoveAt(i); + i--; + groupsCount--; + } + else + { + found = true; + } + } + + return new QueryResult(group); + } + + public QueryResult WithAny(EntitiesDB entitiesDB) + where T : struct, IEntityComponent + { + var group = groups.Value.reference; + var groupsCount = group.count; + + for (var i = 0; i < groupsCount; i++) + { + if (entitiesDB.Count(group[i]) == 0) + { + group.UnorderedRemoveAt(i); + i--; + groupsCount--; + } + } + + return new QueryResult(group); + } } public readonly ref struct QueryResult