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, EntityIDs entityIDs) : this() { DBC.ECS.Check.Require(count == 0 || buffer.isValid, "Buffer is found in impossible state"); if (IsUnmanaged) { _nativedBuffer = (NB)buffer; _nativedIndices = entityIDs.nativeIDs; } else { _managedBuffer = (MB)buffer; _managedIndices = entityIDs.managedIDs; } this.count = count; } 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; this.count = count; } public uint count { get; } internal readonly MB _managedBuffer; internal readonly NB _nativedBuffer; internal readonly NativeEntityIDs _nativedIndices; internal readonly ManagedEntityIDs _managedIndices; } public readonly ref struct EntityCollection where T1 : struct, IEntityComponent where T2 : struct, IEntityComponent { internal EntityCollection(in EntityCollection array1, in EntityCollection array2) { buffer1 = array1; buffer2 = array2; } public int count => (int)buffer1.count; internal EntityCollection buffer2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } internal EntityCollection buffer1 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } } 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) { buffer1 = array1; buffer2 = array2; buffer3 = array3; } internal EntityCollection buffer1 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } internal EntityCollection buffer2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } internal EntityCollection buffer3 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } internal int count => (int)buffer1.count; } 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) { buffer1 = array1; buffer2 = array2; buffer3 = array3; buffer4 = array4; } internal EntityCollection buffer1 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } internal EntityCollection buffer2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } internal EntityCollection buffer3 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } internal EntityCollection buffer4 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } internal int count => (int)buffer1.count; } public readonly struct BT { public readonly BufferT1 buffer1; public readonly BufferT2 buffer2; public readonly BufferT3 buffer3; public readonly BufferT4 buffer4; public readonly int count; BT(in (BufferT1 bufferT1, BufferT2 bufferT2, BufferT3 bufferT3, BufferT4 bufferT4, int count) buffer) : this() { buffer1 = buffer.bufferT1; buffer2 = buffer.bufferT2; buffer3 = buffer.bufferT3; buffer4 = buffer.bufferT4; count = buffer.count; } public static implicit operator BT( in (BufferT1 bufferT1, BufferT2 bufferT2, BufferT3 bufferT3, BufferT4 bufferT4, int count) buffer) { return new BT(buffer); } } public readonly struct BT { public readonly BufferT1 buffer1; public readonly BufferT2 buffer2; public readonly BufferT3 buffer3; public readonly int count; BT(in (BufferT1 bufferT1, BufferT2 bufferT2, BufferT3 bufferT3, int count) buffer) : this() { buffer1 = buffer.bufferT1; buffer2 = buffer.bufferT2; buffer3 = buffer.bufferT3; count = buffer.count; } public static implicit operator BT( in (BufferT1 bufferT1, BufferT2 bufferT2, BufferT3 bufferT3, int count) buffer) { return new BT(buffer); } } public readonly struct BT { public readonly BufferT1 buffer; public readonly int count; BT(in (BufferT1 bufferT1, int count) buffer) : this() { this.buffer = buffer.bufferT1; count = buffer.count; } public static implicit operator BT(in (BufferT1 bufferT1, int count) buffer) { return new BT(buffer); } 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; BT(in (BufferT1 bufferT1, BufferT2 bufferT2, int count) buffer) : this() { buffer1 = buffer.bufferT1; buffer2 = buffer.bufferT2; count = buffer.count; } public static implicit operator BT( in (BufferT1 bufferT1, BufferT2 bufferT2, int count) buffer) { return new BT(buffer); } } }