mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
add readonly pool wrappers
This commit is contained in:
parent
d394ec6b21
commit
fad8c48318
@ -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<T>(IncludeMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||
public static implicit operator EcsPool<T>(ExcludeMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||
public static implicit operator EcsPool<T>(OptionalMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||
@ -383,6 +383,74 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
}
|
||||
|
||||
#if ENABLE_IL2CPP
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
#endif
|
||||
public readonly struct ReadonlyEcsPool<T> : IEcsReadonlyPool //IEnumerable<T> - IntelliSense hack
|
||||
where T : struct, IEcsComponent
|
||||
{
|
||||
private readonly EcsPool<T> _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<T> 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<T>(EcsPool<T> a) { return new ReadonlyEcsPool<T>(a); }
|
||||
public static implicit operator ReadonlyEcsPool<T>(IncludeMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||
public static implicit operator ReadonlyEcsPool<T>(ExcludeMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||
public static implicit operator ReadonlyEcsPool<T>(OptionalMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||
public static implicit operator ReadonlyEcsPool<T>(EcsWorld.GetPoolInstanceMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
public static class EcsPoolExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
@ -26,6 +26,13 @@ namespace DCFApixels.DragonECS.PoolsCore
|
||||
/// <typeparam name="T"> Component type. </typeparam>
|
||||
public interface IEcsPoolImplementation<T> : IEcsPoolImplementation { }
|
||||
|
||||
//TODO
|
||||
//public interface IEcsReadonlyPoolImplementation<TPool> : IEcsReadonlyPool
|
||||
// where TPool : IEcsReadonlyPoolImplementation<TPool>
|
||||
//{
|
||||
// void Init(ref TPool pool);
|
||||
//}
|
||||
|
||||
#region EcsPoolThrowHelper
|
||||
public static class EcsPoolThrowHelper
|
||||
{
|
||||
|
@ -311,7 +311,7 @@ namespace DCFApixels.DragonECS
|
||||
IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); }
|
||||
#endregion
|
||||
|
||||
#region MarkersConverter
|
||||
#region Convertors
|
||||
public static implicit operator EcsTagPool<T>(IncludeMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||
public static implicit operator EcsTagPool<T>(ExcludeMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||
public static implicit operator EcsTagPool<T>(OptionalMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||
@ -330,6 +330,75 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
}
|
||||
|
||||
#if ENABLE_IL2CPP
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
#endif
|
||||
public readonly struct ReadonlyEcsTagPool<T> : IEcsReadonlyPool //IEnumerable<T> - IntelliSense hack
|
||||
where T : struct, IEcsTagComponent
|
||||
{
|
||||
private readonly EcsTagPool<T> _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<T> 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<T>(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<T>(EcsTagPool<T> a) { return new ReadonlyEcsTagPool<T>(a); }
|
||||
public static implicit operator ReadonlyEcsTagPool<T>(IncludeMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||
public static implicit operator ReadonlyEcsTagPool<T>(ExcludeMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||
public static implicit operator ReadonlyEcsTagPool<T>(OptionalMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||
public static implicit operator ReadonlyEcsTagPool<T>(EcsWorld.GetPoolInstanceMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static class EcsTagPoolExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
Loading…
Reference in New Issue
Block a user