using System; using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS { public readonly struct EcsField : IEcsMemberCachePool, T> { private readonly EcsFieldPool _pool; private readonly int _poolID; public EcsFieldPool Pool => _pool; public int PoolID => _poolID; private EcsField(int poolID) { _pool = null; _poolID = poolID; } internal EcsField(EcsFieldPool pool) { _pool = pool; _poolID = pool.ID; } [EditorBrowsable(EditorBrowsableState.Never)] public ref T this[int entityID] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => ref _pool[entityID]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool HasValue(int entityID) { return _pool.Has(entityID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T New(int entityID) { return ref _pool.Add(entityID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator EcsField(in int poolID) => new EcsField(poolID); void IEcsMemberCachePool, T>.Inject(out EcsField self, EcsFieldPool pool) { self = new EcsField(pool); } } public readonly struct EcsIncField : IEcsMemberCachePool, T> { private readonly EcsFieldPool _pool; private readonly int _poolID; public EcsFieldPool Pool => _pool; public int PoolID => _poolID; private EcsIncField(int poolID) { _pool = null; _poolID = poolID; } internal EcsIncField(EcsFieldPool pool) { _pool = pool; _poolID = pool.ID; } [EditorBrowsable(EditorBrowsableState.Never)] public ref T this[int entityID] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => ref _pool[entityID]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator EcsIncField(in int poolID) => new EcsIncField(poolID); void IEcsMemberCachePool, T>.Inject(out EcsIncField self, EcsFieldPool pool) { self = new EcsIncField(pool); } } public struct EcsExcField : IEcsTableMember { private readonly int _poolID; public int PoolID => _poolID; private EcsExcField(int poolID) { _poolID = poolID; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator EcsExcField(in int poolID) => new EcsExcField(poolID); } }