mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
add DISABLE_POOLS_EVENTS define
This commit is contained in:
parent
22304f56c0
commit
935127219f
@ -23,6 +23,12 @@
|
|||||||
|
|
||||||
/// defs
|
/// defs
|
||||||
|
|
||||||
|
public const bool DISABLE_POOLS_EVENTS =
|
||||||
|
#if DISABLE_POOLS_EVENTS
|
||||||
|
true;
|
||||||
|
#else
|
||||||
|
false;
|
||||||
|
#endif
|
||||||
public const bool ENABLE_DRAGONECS_DEBUGGER =
|
public const bool ENABLE_DRAGONECS_DEBUGGER =
|
||||||
#if ENABLE_DRAGONECS_DEBUGGER
|
#if ENABLE_DRAGONECS_DEBUGGER
|
||||||
true;
|
true;
|
||||||
|
@ -37,8 +37,10 @@ namespace DCFApixels.DragonECS
|
|||||||
private IEcsComponentCopy<T> _componentCopyHandler = EcsComponentCopyHandler<T>.instance;
|
private IEcsComponentCopy<T> _componentCopyHandler = EcsComponentCopyHandler<T>.instance;
|
||||||
private bool _isHasComponentCopyHandler = EcsComponentCopyHandler<T>.isHasHandler;
|
private bool _isHasComponentCopyHandler = EcsComponentCopyHandler<T>.isHasHandler;
|
||||||
|
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
private List<IEcsPoolEventListener> _listeners = new List<IEcsPoolEventListener>();
|
private List<IEcsPoolEventListener> _listeners = new List<IEcsPoolEventListener>();
|
||||||
private int _listenersCachedCount = 0;
|
private int _listenersCachedCount = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
private EcsWorld.PoolsMediator _mediator;
|
private EcsWorld.PoolsMediator _mediator;
|
||||||
|
|
||||||
@ -91,7 +93,9 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
EnableComponent(ref _items[itemIndex]);
|
EnableComponent(ref _items[itemIndex]);
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnAddAndGet(entityID, _listenersCachedCount);
|
_listeners.InvokeOnAddAndGet(entityID, _listenersCachedCount);
|
||||||
|
#endif
|
||||||
return ref _items[itemIndex];
|
return ref _items[itemIndex];
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -100,7 +104,9 @@ namespace DCFApixels.DragonECS
|
|||||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
if (!Has(entityID)) { EcsPoolThrowHalper.ThrowNotHaveComponent<T>(entityID); }
|
if (!Has(entityID)) { EcsPoolThrowHalper.ThrowNotHaveComponent<T>(entityID); }
|
||||||
#endif
|
#endif
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnGet(entityID, _listenersCachedCount);
|
_listeners.InvokeOnGet(entityID, _listenersCachedCount);
|
||||||
|
#endif
|
||||||
return ref _items[_mapping[entityID]];
|
return ref _items[_mapping[entityID]];
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -131,9 +137,13 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
EnableComponent(ref _items[itemIndex]);
|
EnableComponent(ref _items[itemIndex]);
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnAdd(entityID, _listenersCachedCount);
|
_listeners.InvokeOnAdd(entityID, _listenersCachedCount);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnGet(entityID, _listenersCachedCount);
|
_listeners.InvokeOnGet(entityID, _listenersCachedCount);
|
||||||
|
#endif
|
||||||
return ref _items[itemIndex];
|
return ref _items[itemIndex];
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -156,7 +166,9 @@ namespace DCFApixels.DragonECS
|
|||||||
itemIndex = 0;
|
itemIndex = 0;
|
||||||
_itemsCount--;
|
_itemsCount--;
|
||||||
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
|
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
public void TryDel(int entityID)
|
public void TryDel(int entityID)
|
||||||
{
|
{
|
||||||
@ -191,7 +203,9 @@ namespace DCFApixels.DragonECS
|
|||||||
DisableComponent(ref _items[itemIndex]);
|
DisableComponent(ref _items[itemIndex]);
|
||||||
itemIndex = 0;
|
itemIndex = 0;
|
||||||
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
|
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -239,6 +253,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Listeners
|
#region Listeners
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
public void AddListener(IEcsPoolEventListener listener)
|
public void AddListener(IEcsPoolEventListener listener)
|
||||||
{
|
{
|
||||||
if (listener == null) { EcsPoolThrowHalper.ThrowNullListener(); }
|
if (listener == null) { EcsPoolThrowHalper.ThrowNullListener(); }
|
||||||
@ -253,6 +268,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_listenersCachedCount--;
|
_listenersCachedCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Enable/Disable/Copy
|
#region Enable/Disable/Copy
|
||||||
|
@ -156,10 +156,12 @@ namespace DCFApixels.DragonECS
|
|||||||
void Copy(int fromEntityID, EcsWorld toWorld, int toEntityID);
|
void Copy(int fromEntityID, EcsWorld toWorld, int toEntityID);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
#region Add/Remove Listeners
|
#region Add/Remove Listeners
|
||||||
void AddListener(IEcsPoolEventListener listener);
|
void AddListener(IEcsPoolEventListener listener);
|
||||||
void RemoveListener(IEcsPoolEventListener listener);
|
void RemoveListener(IEcsPoolEventListener listener);
|
||||||
#endregion
|
#endregion
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
public interface IEcsPool : IEcsReadonlyPool
|
public interface IEcsPool : IEcsReadonlyPool
|
||||||
{
|
{
|
||||||
@ -218,6 +220,7 @@ namespace DCFApixels.DragonECS
|
|||||||
/// <summary>Called after deleting an entity from the pool</summary>
|
/// <summary>Called after deleting an entity from the pool</summary>
|
||||||
void OnDel(int entityID);
|
void OnDel(int entityID);
|
||||||
}
|
}
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
public static class PoolEventListExtensions
|
public static class PoolEventListExtensions
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -268,5 +271,6 @@ namespace DCFApixels.DragonECS
|
|||||||
for (int i = 0; i < cachedCount; i++) self[i].OnDel(entityID);
|
for (int i = 0; i < cachedCount; i++) self[i].OnDel(entityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,10 @@ namespace DCFApixels.DragonECS
|
|||||||
private bool[] _mapping;// index = entityID / value = itemIndex;/ value = 0 = no entityID
|
private bool[] _mapping;// index = entityID / value = itemIndex;/ value = 0 = no entityID
|
||||||
private int _count = 0;
|
private int _count = 0;
|
||||||
|
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
private List<IEcsPoolEventListener> _listeners = new List<IEcsPoolEventListener>();
|
private List<IEcsPoolEventListener> _listeners = new List<IEcsPoolEventListener>();
|
||||||
private int _listenersCachedCount = 0;
|
private int _listenersCachedCount = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
private T _fakeComponent;
|
private T _fakeComponent;
|
||||||
private EcsWorld.PoolsMediator _mediator;
|
private EcsWorld.PoolsMediator _mediator;
|
||||||
@ -86,7 +88,9 @@ namespace DCFApixels.DragonECS
|
|||||||
_count++;
|
_count++;
|
||||||
_mapping[entityID] = true;
|
_mapping[entityID] = true;
|
||||||
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnAdd(entityID, _listenersCachedCount);
|
_listeners.InvokeOnAdd(entityID, _listenersCachedCount);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
public void TryAdd(int entityID)
|
public void TryAdd(int entityID)
|
||||||
{
|
{
|
||||||
@ -108,7 +112,9 @@ namespace DCFApixels.DragonECS
|
|||||||
_mapping[entityID] = false;
|
_mapping[entityID] = false;
|
||||||
_count--;
|
_count--;
|
||||||
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
|
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void TryDel(int entityID)
|
public void TryDel(int entityID)
|
||||||
@ -166,7 +172,9 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
_mapping[entityID] = false;
|
_mapping[entityID] = false;
|
||||||
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
|
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -237,6 +245,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Listeners
|
#region Listeners
|
||||||
|
#if !DISABLE_POOLS_EVENTS
|
||||||
public void AddListener(IEcsPoolEventListener listener)
|
public void AddListener(IEcsPoolEventListener listener)
|
||||||
{
|
{
|
||||||
if (listener == null) { EcsPoolThrowHalper.ThrowNullListener(); }
|
if (listener == null) { EcsPoolThrowHalper.ThrowNullListener(); }
|
||||||
@ -251,6 +260,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_listenersCachedCount--;
|
_listenersCachedCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IEnumerator - IntelliSense hack
|
#region IEnumerator - IntelliSense hack
|
||||||
|
Loading…
Reference in New Issue
Block a user