mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
update data interfaces
This commit is contained in:
parent
7b2c64274a
commit
79452349c2
@ -17,10 +17,12 @@ namespace DCFApixels.DragonECS
|
||||
T def = default;
|
||||
if (def is IEcsWorldComponent<T> intrf)
|
||||
{
|
||||
isHasHandler = true;
|
||||
instance = intrf;
|
||||
}
|
||||
else
|
||||
{
|
||||
isHasHandler = false;
|
||||
instance = new DummyHandler();
|
||||
}
|
||||
}
|
||||
@ -47,10 +49,12 @@ namespace DCFApixels.DragonECS
|
||||
T def = default;
|
||||
if (def is IEcsComponentReset<T> intrf)
|
||||
{
|
||||
isHasHandler = true;
|
||||
instance = intrf;
|
||||
}
|
||||
else
|
||||
{
|
||||
isHasHandler = false;
|
||||
instance = new DummyHandler();
|
||||
}
|
||||
}
|
||||
@ -76,10 +80,12 @@ namespace DCFApixels.DragonECS
|
||||
T def = default;
|
||||
if (def is IEcsComponentCopy<T> intrf)
|
||||
{
|
||||
isHasHandler = true;
|
||||
instance = intrf;
|
||||
}
|
||||
else
|
||||
{
|
||||
isHasHandler = false;
|
||||
instance = new DummyHandler();
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,9 @@ namespace DCFApixels.DragonECS
|
||||
private int _recycledItemsCount;
|
||||
|
||||
private IEcsComponentReset<T> _componentResetHandler = EcsComponentResetHandler<T>.instance;
|
||||
private bool _isHasComponentResetHandler = EcsComponentResetHandler<T>.isHasHandler;
|
||||
private IEcsComponentCopy<T> _componentCopyHandler = EcsComponentCopyHandler<T>.instance;
|
||||
private bool _isHasComponentCopyHandler = EcsComponentCopyHandler<T>.isHasHandler;
|
||||
|
||||
private List<IEcsPoolEventListener> _listeners = new List<IEcsPoolEventListener>();
|
||||
|
||||
@ -55,7 +57,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
||||
_listeners.InvokeOnAddAndGet(entityID);
|
||||
_componentResetHandler.Reset(ref _items[itemIndex]);
|
||||
ResetComponent(ref _items[itemIndex]);
|
||||
return ref _items[itemIndex];
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -95,7 +97,7 @@ namespace DCFApixels.DragonECS
|
||||
_listeners.InvokeOnAdd(entityID);
|
||||
}
|
||||
_listeners.InvokeOnGet(entityID);
|
||||
_componentResetHandler.Reset(ref _items[itemIndex]);
|
||||
ResetComponent(ref _items[itemIndex]);
|
||||
return ref _items[itemIndex];
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -109,9 +111,11 @@ namespace DCFApixels.DragonECS
|
||||
if (!Has(entityID)) EcsPoolThrowHalper.ThrowNotHaveComponent<T>(entityID);
|
||||
#endif
|
||||
ref int itemIndex = ref _mapping[entityID];
|
||||
_componentResetHandler.Reset(ref _items[itemIndex]);
|
||||
ResetComponent(ref _items[itemIndex]);
|
||||
if (_recycledItemsCount >= _recycledItems.Length)
|
||||
{
|
||||
Array.Resize(ref _recycledItems, _recycledItems.Length << 1);
|
||||
}
|
||||
_recycledItems[_recycledItemsCount++] = itemIndex;
|
||||
_mapping[entityID] = 0;
|
||||
_itemsCount--;
|
||||
@ -127,14 +131,14 @@ namespace DCFApixels.DragonECS
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (!Has(fromEntityID)) EcsPoolThrowHalper.ThrowNotHaveComponent<T>(fromEntityID);
|
||||
#endif
|
||||
_componentCopyHandler.Copy(ref Get(fromEntityID), ref TryAddOrGet(toEntityID));
|
||||
CopyComponent(ref Get(fromEntityID), ref TryAddOrGet(toEntityID));
|
||||
}
|
||||
public void Copy(int fromEntityID, EcsWorld toWorld, int toEntityID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (!Has(fromEntityID)) EcsPoolThrowHalper.ThrowNotHaveComponent<T>(fromEntityID);
|
||||
#endif
|
||||
_componentCopyHandler.Copy(ref Get(fromEntityID), ref toWorld.GetPool<T>().TryAddOrGet(toEntityID));
|
||||
CopyComponent(ref Get(fromEntityID), ref toWorld.GetPool<T>().TryAddOrGet(toEntityID));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -187,6 +191,33 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Reset/Copy
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ResetComponent(ref T component)
|
||||
{
|
||||
if (_isHasComponentResetHandler)
|
||||
{
|
||||
_componentResetHandler.Reset(ref component);
|
||||
}
|
||||
else
|
||||
{
|
||||
component = default;
|
||||
}
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void CopyComponent(ref T from, ref T to)
|
||||
{
|
||||
if (_isHasComponentCopyHandler)
|
||||
{
|
||||
_componentCopyHandler.Copy(ref from, ref to);
|
||||
}
|
||||
else
|
||||
{
|
||||
to = from;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IEnumerator - IntelliSense hack
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => throw new NotImplementedException();
|
||||
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
|
||||
|
Loading…
Reference in New Issue
Block a user