using System.Runtime.CompilerServices; using Svelto.DataStructures; using Svelto.ECS.Internal; namespace Svelto.ECS { public readonly ref struct EntityCollection where T : struct, IEntityComponent { static readonly bool IsUnmanaged = TypeSafeDictionary.isUnmanaged; public EntityCollection(IBuffer buffer, uint count) : this() { DBC.ECS.Check.Require(count == 0 || buffer.isValid, "Buffer is found in impossible state"); if (IsUnmanaged) _nativedBuffer = (NB) buffer; else _managedBuffer = (MB) buffer; _count = count; } public uint count => _count; internal readonly MB _managedBuffer; internal readonly NB _nativedBuffer; readonly uint _count; } public readonly ref struct EntityCollection where T1 : struct, IEntityComponent where T2 : struct, IEntityComponent { internal EntityCollection(in EntityCollection array1, in EntityCollection array2) { _array1 = array1; _array2 = array2; } public uint count => _array1.count; internal EntityCollection buffer2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array2; } internal EntityCollection buffer1 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array1; } readonly EntityCollection _array1; readonly EntityCollection _array2; } public readonly ref struct EntityCollection where T3 : struct, IEntityComponent where T2 : struct, IEntityComponent where T1 : struct, IEntityComponent { internal EntityCollection (in EntityCollection array1, in EntityCollection array2, in EntityCollection array3) { _array1 = array1; _array2 = array2; _array3 = array3; } internal EntityCollection buffer1 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array1; } internal EntityCollection buffer2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array2; } internal EntityCollection buffer3 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array3; } internal uint count => buffer1.count; readonly EntityCollection _array1; readonly EntityCollection _array2; readonly EntityCollection _array3; } public readonly ref struct EntityCollection where T1 : struct, IEntityComponent where T2 : struct, IEntityComponent where T3 : struct, IEntityComponent where T4 : struct, IEntityComponent { internal EntityCollection (in EntityCollection array1, in EntityCollection array2, in EntityCollection array3 , in EntityCollection array4) { _array1 = array1; _array2 = array2; _array3 = array3; _array4 = array4; } internal EntityCollection buffer1 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array1; } internal EntityCollection buffer2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array2; } internal EntityCollection buffer3 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array3; } internal EntityCollection buffer4 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array4; } internal uint count => _array1.count; readonly EntityCollection _array1; readonly EntityCollection _array2; readonly EntityCollection _array3; readonly EntityCollection _array4; } public readonly struct BT { public readonly BufferT1 buffer1; public readonly BufferT2 buffer2; public readonly BufferT3 buffer3; public readonly BufferT4 buffer4; public readonly int count; public BT(BufferT1 bufferT1, BufferT2 bufferT2, BufferT3 bufferT3, BufferT4 bufferT4, uint count) : this() { this.buffer1 = bufferT1; this.buffer2 = bufferT2; this.buffer3 = bufferT3; this.buffer4 = bufferT4; this.count = (int) count; } } public readonly struct BT { public readonly BufferT1 buffer1; public readonly BufferT2 buffer2; public readonly BufferT3 buffer3; public readonly int count; public BT(BufferT1 bufferT1, BufferT2 bufferT2, BufferT3 bufferT3, uint count) : this() { this.buffer1 = bufferT1; this.buffer2 = bufferT2; this.buffer3 = bufferT3; this.count = (int) count; } public void Deconstruct(out BufferT1 bufferT1, out BufferT2 bufferT2, out BufferT3 bufferT3, out int count) { bufferT1 = buffer1; bufferT2 = buffer2; bufferT3 = buffer3; count = this.count; } } public readonly struct BT { public readonly BufferT1 buffer; public readonly int count; public BT(BufferT1 bufferT1, uint count) : this() { this.buffer = bufferT1; this.count = (int) count; } public void Deconstruct(out BufferT1 bufferT1, out int count) { bufferT1 = buffer; count = this.count; } public static implicit operator BufferT1(BT t) => t.buffer; } public readonly struct BT { public readonly BufferT1 buffer1; public readonly BufferT2 buffer2; public readonly int count; public BT(BufferT1 bufferT1, BufferT2 bufferT2, uint count) : this() { this.buffer1 = bufferT1; this.buffer2 = bufferT2; this.count = (int) count; } public void Deconstruct(out BufferT1 bufferT1, out BufferT2 bufferT2, out int count) { bufferT1 = buffer1; bufferT2 = buffer2; count = this.count; } } }