namespace OECS; /// /// Describes a query over the ECS world. /// Composed of a set of required component types ("with") and /// a set of excluded component types ("without"). /// public class QueryDescriptor { /// /// Component types that must be present on matching entities. /// public IReadOnlySet With { get; } /// /// Component types that must NOT be present on matching entities. /// public IReadOnlySet Without { get; } private readonly int _hashCode; internal QueryDescriptor(HashSet with, HashSet without) { With = with; Without = without; _hashCode = ComputeHashCode(); } /// /// Returns true if this query has no "with" components (matches nothing). /// internal bool IsEmpty => With.Count == 0; public override bool Equals(object? obj) { if (obj is not QueryDescriptor other) return false; if (With.Count != other.With.Count || Without.Count != other.Without.Count) return false; return With.SetEquals(other.With) && Without.SetEquals(other.Without); } public override int GetHashCode() => _hashCode; private int ComputeHashCode() { var hash = new HashCode(); foreach (var t in With.OrderBy(t => t.GUID.ToString())) hash.Add(t); foreach (var t in Without.OrderBy(t => t.GUID.ToString())) hash.Add(t); return hash.ToHashCode(); } }