diff --git a/src/Pools/EcsPool.cs b/src/Pools/EcsPool.cs index b88a319..3345981 100644 --- a/src/Pools/EcsPool.cs +++ b/src/Pools/EcsPool.cs @@ -294,7 +294,7 @@ namespace DCFApixels.DragonECS { Add(entityID) = dataRaw == null ? default : (T)dataRaw; } - object IEcsReadonlyPool.GetRaw(int entityID) { return Get(entityID); } + object IEcsReadonlyPool.GetRaw(int entityID) { return Read(entityID); } void IEcsPool.SetRaw(int entityID, object dataRaw) { Get(entityID) = dataRaw == null ? default : (T)dataRaw; @@ -364,7 +364,7 @@ namespace DCFApixels.DragonECS IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); } #endregion - #region MarkersConverter + #region Convertors public static implicit operator EcsPool(IncludeMarker a) { return a.GetInstance>(); } public static implicit operator EcsPool(ExcludeMarker a) { return a.GetInstance>(); } public static implicit operator EcsPool(OptionalMarker a) { return a.GetInstance>(); } @@ -383,6 +383,74 @@ namespace DCFApixels.DragonECS #endregion } +#if ENABLE_IL2CPP + [Il2CppSetOption(Option.NullChecks, false)] +#endif + public readonly struct ReadonlyEcsPool : IEcsReadonlyPool //IEnumerable - IntelliSense hack + where T : struct, IEcsComponent + { + private readonly EcsPool _pool; + + #region Properties + public int ComponentTypeID + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _pool.ComponentTypeID; } + } + public Type ComponentType + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _pool.ComponentType; } + } + public EcsWorld World + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _pool.World; } + } + public int Count + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _pool.Count; } + } + public bool IsReadOnly + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _pool.IsReadOnly; } + } + #endregion + + #region Constructors + internal ReadonlyEcsPool(EcsPool pool) + { + _pool = pool; + } + #endregion + + #region Methods + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Has(int entityID) { return _pool.Has(entityID); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref readonly T Get(int entityID) { return ref _pool.Read(entityID); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref readonly T Read(int entityID) { return ref _pool.Read(entityID); } + object IEcsReadonlyPool.GetRaw(int entityID) { return _pool.Read(entityID); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void AddListener(IEcsPoolEventListener listener) { _pool.AddListener(listener); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void RemoveListener(IEcsPoolEventListener listener) { _pool.AddListener(listener); } + #endregion + + #region Convertors + public static implicit operator ReadonlyEcsPool(EcsPool a) { return new ReadonlyEcsPool(a); } + public static implicit operator ReadonlyEcsPool(IncludeMarker a) { return a.GetInstance>(); } + public static implicit operator ReadonlyEcsPool(ExcludeMarker a) { return a.GetInstance>(); } + public static implicit operator ReadonlyEcsPool(OptionalMarker a) { return a.GetInstance>(); } + public static implicit operator ReadonlyEcsPool(EcsWorld.GetPoolInstanceMarker a) { return a.GetInstance>(); } + #endregion + } + + public static class EcsPoolExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Pools/EcsPoolBase.cs b/src/Pools/EcsPoolBase.cs index ec9e23c..4793eaf 100644 --- a/src/Pools/EcsPoolBase.cs +++ b/src/Pools/EcsPoolBase.cs @@ -26,6 +26,13 @@ namespace DCFApixels.DragonECS.PoolsCore /// Component type. public interface IEcsPoolImplementation : IEcsPoolImplementation { } + //TODO + //public interface IEcsReadonlyPoolImplementation : IEcsReadonlyPool + // where TPool : IEcsReadonlyPoolImplementation + //{ + // void Init(ref TPool pool); + //} + #region EcsPoolThrowHelper public static class EcsPoolThrowHelper { diff --git a/src/Pools/EcsTagPool.cs b/src/Pools/EcsTagPool.cs index 8f1f0b4..bade114 100644 --- a/src/Pools/EcsTagPool.cs +++ b/src/Pools/EcsTagPool.cs @@ -311,7 +311,7 @@ namespace DCFApixels.DragonECS IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); } #endregion - #region MarkersConverter + #region Convertors public static implicit operator EcsTagPool(IncludeMarker a) { return a.GetInstance>(); } public static implicit operator EcsTagPool(ExcludeMarker a) { return a.GetInstance>(); } public static implicit operator EcsTagPool(OptionalMarker a) { return a.GetInstance>(); } @@ -330,6 +330,75 @@ namespace DCFApixels.DragonECS #endregion } +#if ENABLE_IL2CPP + [Il2CppSetOption(Option.NullChecks, false)] +#endif + public readonly struct ReadonlyEcsTagPool : IEcsReadonlyPool //IEnumerable - IntelliSense hack + where T : struct, IEcsTagComponent + { + private readonly EcsTagPool _pool; + + #region Properties + public int ComponentTypeID + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _pool.ComponentTypeID; } + } + public Type ComponentType + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _pool.ComponentType; } + } + public EcsWorld World + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _pool.World; } + } + public int Count + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _pool.Count; } + } + public bool IsReadOnly + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _pool.IsReadOnly; } + } + #endregion + + #region Constructors + internal ReadonlyEcsTagPool(EcsTagPool pool) + { + _pool = pool; + } + #endregion + + #region Methods + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Has(int entityID) { return _pool.Has(entityID); } + object IEcsReadonlyPool.GetRaw(int entityID) + { +#if DEBUG + if (Has(entityID) == false) { EcsPoolThrowHelper.ThrowNotHaveComponent(entityID); } +#endif + return default; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void AddListener(IEcsPoolEventListener listener) { _pool.AddListener(listener); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void RemoveListener(IEcsPoolEventListener listener) { _pool.AddListener(listener); } + #endregion + + #region Convertors + public static implicit operator ReadonlyEcsTagPool(EcsTagPool a) { return new ReadonlyEcsTagPool(a); } + public static implicit operator ReadonlyEcsTagPool(IncludeMarker a) { return a.GetInstance>(); } + public static implicit operator ReadonlyEcsTagPool(ExcludeMarker a) { return a.GetInstance>(); } + public static implicit operator ReadonlyEcsTagPool(OptionalMarker a) { return a.GetInstance>(); } + public static implicit operator ReadonlyEcsTagPool(EcsWorld.GetPoolInstanceMarker a) { return a.GetInstance>(); } + #endregion + } + public static class EcsTagPoolExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)]