mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 17:34:36 +08:00
update pools
This commit is contained in:
parent
d107d29482
commit
450e98f0cd
@ -113,9 +113,6 @@ namespace DCFApixels.DragonECS
|
||||
private EcsWorld _world;
|
||||
private EcsStaticMask.Builder _maskBuilder;
|
||||
|
||||
//private IEcsPool[] _poolsBuffer = new IEcsPool[8];
|
||||
//private int _poolsBufferCount;
|
||||
|
||||
#region Properties
|
||||
public IncludeMarker Inc
|
||||
{
|
||||
@ -219,11 +216,6 @@ namespace DCFApixels.DragonECS
|
||||
private TPool CachePool<TPool>() where TPool : IEcsPoolImplementation, new()
|
||||
{
|
||||
var pool = _world.GetPoolInstance<TPool>();
|
||||
//if (_poolsBufferCount >= _poolsBuffer.Length)
|
||||
//{
|
||||
// Array.Resize(ref _poolsBuffer, _poolsBuffer.Length << 1);
|
||||
//}
|
||||
//_poolsBuffer[_poolsBufferCount++] = pool;
|
||||
return pool;
|
||||
}
|
||||
private void IncludeImplicit(Type type)
|
||||
@ -374,25 +366,25 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region EcsAspectExtensions
|
||||
//public static class EcsAspectExtensions
|
||||
//{
|
||||
// public static EcsAspect.Builder Inc<TPool>(this EcsAspect.Builder self, ref TPool pool) where TPool : IEcsPoolImplementation, new()
|
||||
// {
|
||||
// pool = self.IncludePool<TPool>();
|
||||
// return self;
|
||||
// }
|
||||
// public static EcsAspect.Builder Exc<TPool>(this EcsAspect.Builder self, ref TPool pool) where TPool : IEcsPoolImplementation, new()
|
||||
// {
|
||||
// pool = self.ExcludePool<TPool>();
|
||||
// return self;
|
||||
// }
|
||||
// public static EcsAspect.Builder Opt<TPool>(this EcsAspect.Builder self, ref TPool pool) where TPool : IEcsPoolImplementation, new()
|
||||
// {
|
||||
// pool = self.OptionalPool<TPool>();
|
||||
// return self;
|
||||
// }
|
||||
//}
|
||||
#region EcsAspect.Builder.Extensions
|
||||
public static class EcsAspectBuilderExtensions
|
||||
{
|
||||
public static EcsAspect.Builder Inc<TPool>(this EcsAspect.Builder self, ref TPool pool) where TPool : IEcsPoolImplementation, new()
|
||||
{
|
||||
pool = self.IncludePool<TPool>();
|
||||
return self;
|
||||
}
|
||||
public static EcsAspect.Builder Exc<TPool>(this EcsAspect.Builder self, ref TPool pool) where TPool : IEcsPoolImplementation, new()
|
||||
{
|
||||
pool = self.ExcludePool<TPool>();
|
||||
return self;
|
||||
}
|
||||
public static EcsAspect.Builder Opt<TPool>(this EcsAspect.Builder self, ref TPool pool) where TPool : IEcsPoolImplementation, new()
|
||||
{
|
||||
pool = self.OptionalPool<TPool>();
|
||||
return self;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constraint Markers
|
||||
|
@ -374,40 +374,38 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
ref var slot = ref _poolSlots[componentTypeID];
|
||||
if (slot.locked == false)
|
||||
if (slot.lockedCounter == 0)
|
||||
{
|
||||
slot.locked = true;
|
||||
if (_lockedPoolCount == 0)
|
||||
{
|
||||
ReleaseDelEntityBufferAll();
|
||||
}
|
||||
//очистка буффера, чтобы она рандомно не сработала в блоке блоикровки пула
|
||||
ReleaseDelEntityBufferAll();
|
||||
_lockedPoolCount++;
|
||||
_pools[componentTypeID].OnLockedChanged_Debug(true);
|
||||
}
|
||||
slot.lockedCounter++;
|
||||
_pools[componentTypeID].OnLockedChanged_Debug(true);
|
||||
#endif
|
||||
}
|
||||
public void UnlockPool_Debug(int componentTypeID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
ref var slot = ref _poolSlots[componentTypeID];
|
||||
if (slot.locked == true)
|
||||
slot.lockedCounter--;
|
||||
if (slot.lockedCounter <= 0)
|
||||
{
|
||||
slot.locked = false;
|
||||
_lockedPoolCount--;
|
||||
|
||||
if (_lockedPoolCount < 0)
|
||||
if (_lockedPoolCount < 0 || slot.lockedCounter < 0)
|
||||
{
|
||||
_lockedPoolCount = 0;
|
||||
slot.lockedCounter = 0;
|
||||
Throw.OpeningClosingMethodsBalanceError();
|
||||
}
|
||||
_pools[componentTypeID].OnLockedChanged_Debug(false);
|
||||
}
|
||||
_pools[componentTypeID].OnLockedChanged_Debug(false);
|
||||
#endif
|
||||
}
|
||||
public bool CheckPoolLocked_Debug(int componentTypeID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
return _poolSlots[componentTypeID].locked;
|
||||
return _poolSlots[componentTypeID].lockedCounter != 0;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
@ -417,10 +415,10 @@ namespace DCFApixels.DragonECS
|
||||
#region Utils
|
||||
internal struct PoolSlot
|
||||
{
|
||||
public int count;
|
||||
public long version;
|
||||
public int count;
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
public bool locked;
|
||||
public int lockedCounter;
|
||||
#endif
|
||||
}
|
||||
public readonly ref struct GetPoolInstanceMarker
|
||||
|
@ -3,6 +3,7 @@ using DCFApixels.DragonECS.PoolsCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
#if ENABLE_IL2CPP
|
||||
@ -46,7 +47,7 @@ namespace DCFApixels.DragonECS
|
||||
private bool _isHasComponentCopyHandler = EcsComponentCopyHandler<T>.isHasHandler;
|
||||
|
||||
#if !DISABLE_POOLS_EVENTS
|
||||
private readonly List<IEcsPoolEventListener> _listeners = new List<IEcsPoolEventListener>();
|
||||
private readonly StructList<IEcsPoolEventListener> _listeners = new StructList<IEcsPoolEventListener>(2);
|
||||
private int _listenersCachedCount = 0;
|
||||
#endif
|
||||
private bool _isLocked;
|
||||
@ -102,11 +103,12 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
}
|
||||
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
||||
EnableComponent(ref _items[itemIndex]);
|
||||
ref T result = ref _items[itemIndex];
|
||||
EnableComponent(ref result);
|
||||
#if !DISABLE_POOLS_EVENTS
|
||||
_listeners.InvokeOnAddAndGet(entityID, _listenersCachedCount);
|
||||
#endif
|
||||
return ref _items[itemIndex];
|
||||
return ref result;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ref T Get(int entityID)
|
||||
@ -284,7 +286,7 @@ namespace DCFApixels.DragonECS
|
||||
public void RemoveListener(IEcsPoolEventListener listener)
|
||||
{
|
||||
if (listener == null) { EcsPoolThrowHelper.ThrowNullListener(); }
|
||||
if (_listeners.Remove(listener))
|
||||
if (_listeners.RemoveWithOrder(listener))
|
||||
{
|
||||
_listenersCachedCount--;
|
||||
}
|
||||
@ -343,7 +345,8 @@ namespace DCFApixels.DragonECS
|
||||
public static implicit operator EcsPool<T>(EcsWorld.GetPoolInstanceMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||
#endregion
|
||||
}
|
||||
public static class EcsPoolExt
|
||||
|
||||
public static class EcsPoolExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsPool<TComponent> GetPool<TComponent>(this EcsWorld self) where TComponent : struct, IEcsComponent
|
||||
@ -356,20 +359,44 @@ namespace DCFApixels.DragonECS
|
||||
return self.GetPoolInstanceUnchecked<EcsPool<TComponent>>();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsPool<TComponent> Inc<TComponent>(this EcsAspect.Builder self) where TComponent : struct, IEcsComponent
|
||||
{
|
||||
return self.IncludePool<EcsPool<TComponent>>();
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsPool<TComponent> Exc<TComponent>(this EcsAspect.Builder self) where TComponent : struct, IEcsComponent
|
||||
{
|
||||
return self.ExcludePool<EcsPool<TComponent>>();
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsPool<TComponent> Opt<TComponent>(this EcsAspect.Builder self) where TComponent : struct, IEcsComponent
|
||||
{
|
||||
return self.OptionalPool<EcsPool<TComponent>>();
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Inc) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsPool<TComponent> Include<TComponent>(this EcsAspect.Builder self) where TComponent : struct, IEcsComponent
|
||||
{
|
||||
return self.IncludePool<EcsPool<TComponent>>();
|
||||
}
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Exc) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsPool<TComponent> Exclude<TComponent>(this EcsAspect.Builder self) where TComponent : struct, IEcsComponent
|
||||
{
|
||||
return self.ExcludePool<EcsPool<TComponent>>();
|
||||
}
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Opt) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsPool<TComponent> Optional<TComponent>(this EcsAspect.Builder self) where TComponent : struct, IEcsComponent
|
||||
{
|
||||
return self.OptionalPool<EcsPool<TComponent>>();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -295,6 +295,34 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
for (int i = 0; i < cachedCount; i++) self[i].OnDel(entityID);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void InvokeOnAdd(this StructList<IEcsPoolEventListener> self, int entityID, int cachedCount)
|
||||
{
|
||||
for (int i = 0; i < cachedCount; i++) self[i].OnAdd(entityID);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void InvokeOnAddAndGet(this StructList<IEcsPoolEventListener> self, int entityID, int cachedCount)
|
||||
{
|
||||
for (int i = 0; i < cachedCount; i++)
|
||||
{
|
||||
self[i].OnAdd(entityID);
|
||||
self[i].OnGet(entityID);
|
||||
}
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void InvokeOnGet(this StructList<IEcsPoolEventListener> self, int entityID, int cachedCount)
|
||||
{
|
||||
for (int i = 1; i < cachedCount; i++) self[i].OnGet(entityID);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void InvokeOnDel(this StructList<IEcsPoolEventListener> self, int entityID, int cachedCount)
|
||||
{
|
||||
for (int i = 0; i < cachedCount; i++) self[i].OnDel(entityID);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
@ -4,7 +4,8 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Diagnostics;
|
||||
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using System.ComponentModel;
|
||||
#if (DEBUG && !DISABLE_DEBUG)
|
||||
using System.Reflection;
|
||||
#endif
|
||||
@ -41,7 +42,7 @@ namespace DCFApixels.DragonECS
|
||||
private int _count = 0;
|
||||
|
||||
#if !DISABLE_POOLS_EVENTS
|
||||
private List<IEcsPoolEventListener> _listeners = new List<IEcsPoolEventListener>();
|
||||
private StructList<IEcsPoolEventListener> _listeners = new StructList<IEcsPoolEventListener>(2);
|
||||
private int _listenersCachedCount = 0;
|
||||
#endif
|
||||
private bool _isLocked;
|
||||
@ -274,7 +275,7 @@ namespace DCFApixels.DragonECS
|
||||
public void RemoveListener(IEcsPoolEventListener listener)
|
||||
{
|
||||
if (listener == null) { EcsPoolThrowHelper.ThrowNullListener(); }
|
||||
if (_listeners.Remove(listener))
|
||||
if (_listeners.RemoveWithOrder(listener))
|
||||
{
|
||||
_listenersCachedCount--;
|
||||
}
|
||||
@ -294,7 +295,8 @@ namespace DCFApixels.DragonECS
|
||||
public static implicit operator EcsTagPool<T>(EcsWorld.GetPoolInstanceMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||
#endregion
|
||||
}
|
||||
public static class EcsTagPoolExt
|
||||
|
||||
public static class EcsTagPoolExtensions
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> GetPool<TTagComponent>(this EcsWorld self) where TTagComponent : struct, IEcsTagComponent
|
||||
@ -307,16 +309,39 @@ namespace DCFApixels.DragonECS
|
||||
return self.GetPoolInstanceUnchecked<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> Inc<TTagComponent>(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.IncludePool<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> Exc<TTagComponent>(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.ExcludePool<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> Opt<TTagComponent>(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.OptionalPool<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Inc) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> Include<TTagComponent>(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.IncludePool<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Exc) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> Exclude<TTagComponent>(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.ExcludePool<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Opt) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> Optional<TTagComponent>(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
@ -325,31 +350,42 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(GetPool) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> GetTagPool<TTagComponent>(this EcsWorld self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.GetPoolInstance<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(GetPoolUnchecked) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> GetTagPoolUnchecked<TTagComponent>(this EcsWorld self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.GetPoolInstanceUnchecked<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Inc) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> IncludeTag<TTagComponent>(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.IncludePool<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Exc) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> ExcludeTag<TTagComponent>(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.ExcludePool<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
[Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Opt) + "<T>()")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static EcsTagPool<TTagComponent> OptionalTag<TTagComponent>(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.OptionalPool<EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user