diff --git a/src/DataInterfaces.cs b/src/DataInterfaces.cs index 3a46db5..fabac1f 100644 --- a/src/DataInterfaces.cs +++ b/src/DataInterfaces.cs @@ -11,63 +11,84 @@ namespace DCFApixels.DragonECS.Core void Init(ref T component, EcsWorld world); void OnDestroy(ref T component, EcsWorld world); } - public static class EcsWorldComponentHandler + public static class EcsWorldComponent where T : struct { - public static readonly IEcsWorldComponent instance; - public static readonly bool isHasHandler; - static EcsWorldComponentHandler() + public static readonly IEcsWorldComponent CustomHandler; + public static readonly bool IsCustom; + static EcsWorldComponent() { - T def = default; - if (def is IEcsWorldComponent intrf) + T raw = default; + if (raw is IEcsWorldComponent handler) { - isHasHandler = true; - instance = intrf; + IsCustom = true; + CustomHandler = handler; } else { - isHasHandler = false; - instance = new DummyHandler(); + IsCustom = false; + CustomHandler = new DummyHandler(); } } - private class DummyHandler : IEcsWorldComponent + private sealed class DummyHandler : IEcsWorldComponent { [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Init(ref T component, EcsWorld world) { } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void OnDestroy(ref T component, EcsWorld world) { } } } #endregion - #region IEcsComponentReset + #region IEcsComponentLifecycle public interface IEcsComponentLifecycle { - void Enable(ref T component); - void Disable(ref T component); + void OnAdd(ref T component, short worldID, int entityID); + void OnDel(ref T component, short worldID, int entityID); } - public static class EcsComponentLifecycleHandler + public static class EcsComponentLifecycle where T : struct { - public static readonly IEcsComponentLifecycle instance; - public static readonly bool isHasHandler; - static EcsComponentLifecycleHandler() + public static readonly IEcsComponentLifecycle CustomHandler; + public static readonly bool IsCustom; + static EcsComponentLifecycle() { - T def = default; - if (def is IEcsComponentLifecycle intrf) + T raw = default; + if (raw is IEcsComponentLifecycle handler) { - isHasHandler = true; - instance = intrf; + IsCustom = true; + CustomHandler = handler; } else { - isHasHandler = false; - instance = new DummyHandler(); + IsCustom = false; + CustomHandler = new DummyHandler(); + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void OnAdd(bool isCustom, IEcsComponentLifecycle custom, ref T component, short worldID, int entityID) + { + if (isCustom) + { + custom.OnAdd(ref component, worldID, entityID); + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void OnDel(bool isCustom, IEcsComponentLifecycle custom, ref T component, short worldID, int entityID) + { + if (isCustom) + { + custom.OnDel(ref component, worldID, entityID); + } + else + { + component = default; } } private sealed class DummyHandler : IEcsComponentLifecycle { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Enable(ref T component) { component = default; } + public void OnAdd(ref T component, short worldID, int entityID) { component = default; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Disable(ref T component) { component = default; } + public void OnDel(ref T component, short worldID, int entityID) { component = default; } } } #endregion @@ -77,22 +98,34 @@ namespace DCFApixels.DragonECS.Core { void Copy(ref T from, ref T to); } - public static class EcsComponentCopyHandler + public static class EcsComponentCopy where T : struct { - public static readonly IEcsComponentCopy instance; - public static readonly bool isHasHandler; - static EcsComponentCopyHandler() + public static readonly IEcsComponentCopy CustomHandler; + public static readonly bool IsCustom; + static EcsComponentCopy() { - T def = default; - if (def is IEcsComponentCopy intrf) + T raw = default; + if (raw is IEcsComponentCopy handler) { - isHasHandler = true; - instance = intrf; + IsCustom = true; + CustomHandler = handler; } else { - isHasHandler = false; - instance = new DummyHandler(); + IsCustom = false; + CustomHandler = new DummyHandler(); + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Copy(bool isCustom, IEcsComponentCopy custom, ref T from, ref T to) + { + if (isCustom) + { + custom.Copy(ref from, ref to); + } + else + { + to = from; } } private sealed class DummyHandler : IEcsComponentCopy @@ -102,4 +135,4 @@ namespace DCFApixels.DragonECS.Core } } #endregion -} +} \ No newline at end of file diff --git a/src/DebugUtils/EcsDebugUtility.cs b/src/DebugUtils/EcsDebugUtility.cs index 6a0f794..d30cd1f 100644 --- a/src/DebugUtils/EcsDebugUtility.cs +++ b/src/DebugUtils/EcsDebugUtility.cs @@ -285,7 +285,7 @@ namespace DCFApixels.DragonECS public static TypeMeta GetTypeMeta(object obj) { if (obj == null) { return TypeMeta.NullTypeMeta; } - return TypeMeta.Get(GetTypeMetaSource(obj).GetType()); + return TypeMeta.Get(Type.GetTypeHandle(GetTypeMetaSource(obj))); } public static TypeMeta GetTypeMeta() { @@ -295,6 +295,10 @@ namespace DCFApixels.DragonECS { return TypeMeta.Get(type); } + public static TypeMeta GetTypeMeta(RuntimeTypeHandle typeHandle) + { + return TypeMeta.Get(typeHandle); + } #endregion #region TypeMetaProvider diff --git a/src/DebugUtils/TypeMeta.cs b/src/DebugUtils/TypeMeta.cs index 0422993..c10ba97 100644 --- a/src/DebugUtils/TypeMeta.cs +++ b/src/DebugUtils/TypeMeta.cs @@ -46,7 +46,7 @@ namespace DCFApixels.DragonECS public static readonly TypeMeta NullTypeMeta; private static readonly object _lock = new object(); - private static readonly Dictionary _metaCache = new Dictionary(); + private static readonly Dictionary _metaCache = new Dictionary(); private static int _increment = 1; private readonly int _uniqueID; @@ -93,16 +93,17 @@ namespace DCFApixels.DragonECS _initFlags = InitFlag.All, }; - _metaCache.Add(typeof(void), NullTypeMeta); + _metaCache.Add(typeof(void).TypeHandle, NullTypeMeta); } - public static TypeMeta Get(Type type) + public static TypeMeta Get(Type type) { return Get(type.TypeHandle); } + public static TypeMeta Get(RuntimeTypeHandle typeHandle) { lock (_lock) //TODO посмотреть можно ли тут убрать лок { - if (_metaCache.TryGetValue(type, out TypeMeta result) == false) + if (_metaCache.TryGetValue(typeHandle, out TypeMeta result) == false) { - result = new TypeMeta(type); - _metaCache.Add(type, result); + result = new TypeMeta(Type.GetTypeFromHandle(typeHandle)); + _metaCache.Add(typeHandle, result); } return result; } @@ -375,7 +376,7 @@ namespace DCFApixels.DragonECS lock (_lock) { _metaCache.Clear(); - _metaCache.Add(typeof(void), NullTypeMeta); + _metaCache.Add(typeof(void).TypeHandle, NullTypeMeta); } } ITypeMeta ITypeMeta.BaseMeta @@ -395,7 +396,7 @@ namespace DCFApixels.DragonECS { if (IsHasCustomMeta(type)) { - meta = type.ToMeta(); + meta = type.GetMeta(); return true; } meta = null; @@ -469,15 +470,6 @@ namespace DCFApixels.DragonECS } #endregion - #region Obsolete - [Obsolete("Use TryGetCustomMeta(type)")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static bool IsHasMeta(Type type) - { - return IsHasCustomMeta(type); - } - #endregion - #region MetaGenerator private static class MetaGenerator { diff --git a/src/EcsMask.cs b/src/EcsMask.cs index 2aa5376..bec8575 100644 --- a/src/EcsMask.cs +++ b/src/EcsMask.cs @@ -34,6 +34,7 @@ namespace DCFApixels.DragonECS { public readonly int ID; public readonly short WorldID; + public readonly EcsWorld World; internal readonly EcsStaticMask _staticMask; internal readonly EcsMaskChunck[] _incChunckMasks; @@ -51,11 +52,6 @@ namespace DCFApixels.DragonECS private EcsMaskIterator _iterator; #region Properties - public EcsWorld World - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get { return EcsWorld.GetWorld(WorldID); } - } /// Sorted set excluding constraints. public ReadOnlySpan Incs { @@ -74,6 +70,25 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return _anys; } } + + /// Sorted set including constraints presented as global type codes. + public ReadOnlySpan IncTypeCodes + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return ToStatic().IncTypeCodes; } + } + /// Sorted set excluding constraints presented as global type codes. + public ReadOnlySpan ExcTypeCodes + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return ToStatic().ExcTypeCodes; } + } + /// Sorted set any constraints presented as global type codes. + public ReadOnlySpan AnyTypeCodes + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return ToStatic().AnyTypeCodes; } + } public EcsMaskFlags Flags { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -116,6 +131,7 @@ namespace DCFApixels.DragonECS _staticMask = staticMask; ID = id; WorldID = worldID; + World = EcsWorld.GetWorld(worldID); _flags = staticMask.Flags; EcsWorld world = EcsWorld.GetWorld(worldID); @@ -345,8 +361,6 @@ namespace DCFApixels.DragonECS internal EcsMask ConvertFromStatic(EcsStaticMask staticMask) { - - if (_staticMasks.TryGetValue(staticMask.ID, out EcsMask result) == false) { result = new EcsMask(staticMask, _staticMasks.Count, _world.ID); @@ -367,20 +381,42 @@ namespace DCFApixels.DragonECS _world = world; _builder = EcsStaticMask.New(); } - + public Builder Inc() { return this; } + public Builder Exc() { return this; } + public Builder Any() { return this; } public Builder Inc() { _builder.Inc(); return this; } public Builder Exc() { _builder.Exc(); return this; } public Builder Any() { _builder.Any(); return this; } public Builder Inc(Type type) { _builder.Inc(type); return this; } public Builder Exc(Type type) { _builder.Exc(type); return this; } public Builder Any(Type type) { _builder.Any(type); return this; } + public Builder Inc(params Type[] types) { _builder.Inc(types); return this; } + public Builder Exc(params Type[] types) { _builder.Exc(types); return this; } + public Builder Any(params Type[] types) { _builder.Any(types); return this; } + public Builder Inc(ReadOnlySpan types) { _builder.Inc(types); return this; } + public Builder Exc(ReadOnlySpan types) { _builder.Exc(types); return this; } + public Builder Any(ReadOnlySpan types) { _builder.Any(types); return this; } + public Builder Inc(IEnumerable types) { _builder.Inc(types); return this; } + public Builder Exc(IEnumerable types) { _builder.Exc(types); return this; } + public Builder Any(IEnumerable types) { _builder.Any(types); return this; } public Builder Inc(EcsTypeCode typeCode) { _builder.Inc(typeCode); return this; } public Builder Exc(EcsTypeCode typeCode) { _builder.Exc(typeCode); return this; } public Builder Any(EcsTypeCode typeCode) { _builder.Any(typeCode); return this; } + public Builder Inc(params EcsTypeCode[] typeCodes) { _builder.Inc(typeCodes); return this; } + public Builder Exc(params EcsTypeCode[] typeCodes) { _builder.Exc(typeCodes); return this; } + public Builder Any(params EcsTypeCode[] typeCodes) { _builder.Any(typeCodes); return this; } + public Builder Inc(ReadOnlySpan typeCodes) { _builder.Inc(typeCodes); return this; } + public Builder Exc(ReadOnlySpan typeCodes) { _builder.Exc(typeCodes); return this; } + public Builder Any(ReadOnlySpan typeCodes) { _builder.Any(typeCodes); return this; } + public Builder Inc(IEnumerable typeCodes) { _builder.Inc(typeCodes); return this; } + public Builder Exc(IEnumerable typeCodes) { _builder.Exc(typeCodes); return this; } + public Builder Any(IEnumerable typeCodes) { _builder.Any(typeCodes); return this; } + public Builder Combine(EcsMask mask) { _builder.Combine(mask._staticMask); return this; } public Builder Except(EcsMask mask) { _builder.Except(mask._staticMask); return this; } public EcsMask Build() { return _world.Get().ConvertFromStatic(_builder.Build()); } + public static implicit operator EcsMask(Builder a) { return a.Build(); } } #endregion diff --git a/src/EcsStaticMask.cs b/src/EcsStaticMask.cs index b34bb38..967376d 100644 --- a/src/EcsStaticMask.cs +++ b/src/EcsStaticMask.cs @@ -65,7 +65,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return _excs; } } - /// Sorted set excluding constraints presented as global type codes. + /// Sorted set any constraints presented as global type codes. public ReadOnlySpan AnyTypeCodes { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -109,9 +109,15 @@ namespace DCFApixels.DragonECS public static Builder Inc(Type type) { return Builder.New().Inc(type); } public static Builder Exc(Type type) { return Builder.New().Exc(type); } public static Builder Any(Type type) { return Builder.New().Any(type); } + public static Builder Inc(params Type[] types) { return Builder.New().Inc(types); } + public static Builder Exc(params Type[] types) { return Builder.New().Exc(types); } + public static Builder Any(params Type[] types) { return Builder.New().Any(types); } public static Builder Inc(EcsTypeCode typeCode) { return Builder.New().Inc(typeCode); } public static Builder Exc(EcsTypeCode typeCode) { return Builder.New().Exc(typeCode); } public static Builder Any(EcsTypeCode typeCode) { return Builder.New().Any(typeCode); } + public static Builder Inc(params EcsTypeCode[] typeCodes) { return Builder.New().Inc(typeCodes); } + public static Builder Exc(params EcsTypeCode[] typeCodes) { return Builder.New().Exc(typeCodes); } + public static Builder Any(params EcsTypeCode[] typeCodes) { return Builder.New().Any(typeCodes); } private static EcsStaticMask CreateMask(Key key) { if (_ids.TryGetValue(key, out EcsStaticMask result) == false) @@ -305,12 +311,24 @@ namespace DCFApixels.DragonECS #endregion #region Inc/Exc/Combine/Except + public Builder Inc() { return this; } + public Builder Exc() { return this; } + public Builder Any() { return this; } public Builder Inc() { return Inc(EcsTypeCodeManager.Get()); } public Builder Exc() { return Exc(EcsTypeCodeManager.Get()); } public Builder Any() { return Any(EcsTypeCodeManager.Get()); } public Builder Inc(Type type) { return Inc(EcsTypeCodeManager.Get(type)); } public Builder Exc(Type type) { return Exc(EcsTypeCodeManager.Get(type)); } public Builder Any(Type type) { return Any(EcsTypeCodeManager.Get(type)); } + public Builder Inc(params Type[] types) { foreach (var type in types) { Inc(type); } return this; } + public Builder Exc(params Type[] types) { foreach (var type in types) { Exc(type); } return this; } + public Builder Any(params Type[] types) { foreach (var type in types) { Any(type); } return this; } + public Builder Inc(ReadOnlySpan types) { foreach (var type in types) { Inc(type); } return this; } + public Builder Exc(ReadOnlySpan types) { foreach (var type in types) { Exc(type); } return this; } + public Builder Any(ReadOnlySpan types) { foreach (var type in types) { Any(type); } return this; } + public Builder Inc(IEnumerable types) { foreach (var type in types) { Inc(type); } return this; } + public Builder Exc(IEnumerable types) { foreach (var type in types) { Exc(type); } return this; } + public Builder Any(IEnumerable types) { foreach (var type in types) { Any(type); } return this; } public Builder Inc(EcsTypeCode typeCode) { if (_version != _builder._version) { Throw.CantReuseBuilder(); } @@ -329,6 +347,15 @@ namespace DCFApixels.DragonECS _builder.Any(typeCode); return this; } + public Builder Inc(params EcsTypeCode[] typeCodes) { foreach (var typeCode in typeCodes) { Inc(typeCode); } return this; } + public Builder Exc(params EcsTypeCode[] typeCodes) { foreach (var typeCode in typeCodes) { Exc(typeCode); } return this; } + public Builder Any(params EcsTypeCode[] typeCodes) { foreach (var typeCode in typeCodes) { Any(typeCode); } return this; } + public Builder Inc(ReadOnlySpan typeCodes) { foreach (var typeCode in typeCodes) { Inc(typeCode); } return this; } + public Builder Exc(ReadOnlySpan typeCodes) { foreach (var typeCode in typeCodes) { Exc(typeCode); } return this; } + public Builder Any(ReadOnlySpan typeCodes) { foreach (var typeCode in typeCodes) { Any(typeCode); } return this; } + public Builder Inc(IEnumerable typeCodes) { foreach (var typeCode in typeCodes) { Inc(typeCode); } return this; } + public Builder Exc(IEnumerable typeCodes) { foreach (var typeCode in typeCodes) { Exc(typeCode); } return this; } + public Builder Any(IEnumerable typeCodes) { foreach (var typeCode in typeCodes) { Any(typeCode); } return this; } public Builder Combine(EcsStaticMask mask) { if (_version != _builder._version) { Throw.CantReuseBuilder(); } @@ -354,6 +381,7 @@ namespace DCFApixels.DragonECS return result; } } + public static implicit operator EcsStaticMask(Builder a) { return a.Build(); } public void Cancel() { if (_version != _builder._version) { Throw.CantReuseBuilder(); } diff --git a/src/EcsWorld.static.cs b/src/EcsWorld.static.cs index 91699e1..b53904a 100644 --- a/src/EcsWorld.static.cs +++ b/src/EcsWorld.static.cs @@ -26,7 +26,6 @@ namespace DCFApixels.DragonECS private static EcsWorld[] _worlds = Array.Empty(); private static readonly IdDispenser _worldIdDispenser = new IdDispenser(4, 0, n => Array.Resize(ref _worlds, n)); - private static StructList _allWorldComponentPools = new StructList(64); private static readonly object _worldLock = new object(); private StructList _worldComponentPools; @@ -145,7 +144,7 @@ namespace DCFApixels.DragonECS private static short _count; private static short[] _recycledItems = new short[4]; private static short _recycledItemsCount; - private static readonly IEcsWorldComponent _interface = EcsWorldComponentHandler.instance; + private static readonly IEcsWorldComponent _interface = EcsWorldComponent.CustomHandler; private static readonly Abstract _controller = new Abstract(); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -321,27 +320,5 @@ namespace DCFApixels.DragonECS } } #endregion - - #region Obsolete - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Use EcsWorld.ID")] - public short id - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get { return ID; } - } - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("The GetPoolInstance(int componentTypeID) method will be removed in future updates, use FindPoolInstance(Type componentType)")] - public IEcsPool GetPoolInstance(int componentTypeID) - { - return FindPoolInstance(componentTypeID); - } - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("The GetPoolInstance(Type componentType) method will be removed in future updates, use FindPoolInstance(Type componentType)")] - public IEcsPool GetPoolInstance(Type componentType) - { - return FindPoolInstance(componentType); - } - #endregion } } \ No newline at end of file diff --git a/src/Pools/EcsPool.cs b/src/Pools/EcsPool.cs index 943d6c7..b63ea99 100644 --- a/src/Pools/EcsPool.cs +++ b/src/Pools/EcsPool.cs @@ -35,7 +35,8 @@ namespace DCFApixels.DragonECS public sealed class EcsPool : IEcsPoolImplementation, IEcsStructPool, IEnumerable //IEnumerable - IntelliSense hack where T : struct, IEcsComponent { - private EcsWorld _source; + private short _worldID; + private EcsWorld _world; private int _componentTypeID; private EcsMaskChunck _maskBit; @@ -45,10 +46,10 @@ namespace DCFApixels.DragonECS private int[] _recycledItems; private int _recycledItemsCount = 0; - private readonly IEcsComponentLifecycle _componentLifecycleHandler = EcsComponentLifecycleHandler.instance; - private readonly bool _isHasComponentLifecycleHandler = EcsComponentLifecycleHandler.isHasHandler; - private readonly IEcsComponentCopy _componentCopyHandler = EcsComponentCopyHandler.instance; - private readonly bool _isHasComponentCopyHandler = EcsComponentCopyHandler.isHasHandler; + private readonly IEcsComponentLifecycle _customLifecycle = EcsComponentLifecycle.CustomHandler; + private readonly bool _isCustomLifecycle = EcsComponentLifecycle.IsCustom; + private readonly IEcsComponentCopy _customCopy = EcsComponentCopy.CustomHandler; + private readonly bool _isCustomCopy = EcsComponentCopy.IsCustom; #if !DRAGONECS_DISABLE_POOLS_EVENTS private StructList _listeners = new StructList(2); @@ -77,7 +78,7 @@ namespace DCFApixels.DragonECS } public EcsWorld World { - get { return _source; } + get { return _world; } } public bool IsReadOnly { @@ -104,7 +105,8 @@ namespace DCFApixels.DragonECS } void IEcsPoolImplementation.OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID) { - _source = world; + _world = world; + _worldID = world.ID; _mediator = mediator; _componentTypeID = componentTypeID; _maskBit = EcsMaskChunck.FromID(componentTypeID); @@ -128,8 +130,8 @@ namespace DCFApixels.DragonECS { ref int itemIndex = ref _mapping[entityID]; #if DEBUG - if (entityID == EcsConsts.NULL_ENTITY_ID) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_source, entityID); } - if (_source.IsUsed(entityID) == false) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_source, entityID); } + if (entityID == EcsConsts.NULL_ENTITY_ID) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_world, entityID); } + if (_world.IsUsed(entityID) == false) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_world, entityID); } if (itemIndex > 0) { EcsPoolThrowHelper.ThrowAlreadyHasComponent(entityID); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } #elif DRAGONECS_STABILITY_MODE @@ -151,7 +153,7 @@ namespace DCFApixels.DragonECS } _mediator.RegisterComponent(entityID, _componentTypeID, _maskBit); ref T result = ref _items[itemIndex]; - EnableComponent(ref result); + EcsComponentLifecycle.OnAdd( _isCustomLifecycle, _customLifecycle, ref result, _worldID, entityID); #if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnAddAndGet(entityID, _listenersCachedCount); #endif @@ -179,7 +181,7 @@ namespace DCFApixels.DragonECS public ref T TryAddOrGet(int entityID) { #if DEBUG - if (entityID == EcsConsts.NULL_ENTITY_ID) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_source, entityID); } + if (entityID == EcsConsts.NULL_ENTITY_ID) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_world, entityID); } #endif ref int itemIndex = ref _mapping[entityID]; if (itemIndex <= 0) @@ -203,7 +205,7 @@ namespace DCFApixels.DragonECS } } _mediator.RegisterComponent(entityID, _componentTypeID, _maskBit); - EnableComponent(ref _items[itemIndex]); + EcsComponentLifecycle.OnAdd( _isCustomLifecycle, _customLifecycle, ref _items[itemIndex], _worldID, entityID); #if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnAdd(entityID, _listenersCachedCount); #endif @@ -222,14 +224,14 @@ namespace DCFApixels.DragonECS { ref int itemIndex = ref _mapping[entityID]; #if DEBUG - if (entityID == EcsConsts.NULL_ENTITY_ID) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_source, entityID); } + if (entityID == EcsConsts.NULL_ENTITY_ID) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_world, entityID); } if (itemIndex <= 0) { EcsPoolThrowHelper.ThrowNotHaveComponent(entityID); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } #elif DRAGONECS_STABILITY_MODE if (itemIndex <= 0) { return; } if (_isLocked) { return; } #endif - DisableComponent(ref _items[itemIndex]); + EcsComponentLifecycle.OnDel( _isCustomLifecycle, _customLifecycle, ref _items[itemIndex], _worldID, entityID); if (_recycledItemsCount >= _recycledItems.Length) { Array.Resize(ref _recycledItems, ArrayUtility.NextPow2Safe(_recycledItemsCount)); @@ -256,7 +258,7 @@ namespace DCFApixels.DragonECS #elif DRAGONECS_STABILITY_MODE if (!Has(fromEntityID)) { return; } #endif - CopyComponent(ref Get(fromEntityID), ref TryAddOrGet(toEntityID)); + EcsComponentCopy.Copy(_isCustomCopy, _customCopy, ref Get(fromEntityID), ref TryAddOrGet(toEntityID)); } public void Copy(int fromEntityID, EcsWorld toWorld, int toEntityID) { @@ -265,7 +267,7 @@ namespace DCFApixels.DragonECS #elif DRAGONECS_STABILITY_MODE if (!Has(fromEntityID)) { return; } #endif - CopyComponent(ref Get(fromEntityID), ref toWorld.GetPool().TryAddOrGet(toEntityID)); + EcsComponentCopy.Copy(_isCustomCopy, _customCopy, ref Get(fromEntityID), ref toWorld.GetPool().TryAddOrGet(toEntityID)); } public void ClearAll() @@ -277,11 +279,11 @@ namespace DCFApixels.DragonECS #endif _recycledItemsCount = 0; // , Del if (_itemsCount <= 0) { return; } - var span = _source.Where(out SingleAspect _); + var span = _world.Where(out SingleAspect _); foreach (var entityID in span) { ref int itemIndex = ref _mapping[entityID]; - DisableComponent(ref _items[itemIndex]); + EcsComponentLifecycle.OnDel(_isCustomLifecycle, _customLifecycle, ref _items[itemIndex], _worldID, entityID); itemIndex = 0; _mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit); #if !DRAGONECS_DISABLE_POOLS_EVENTS @@ -345,45 +347,6 @@ namespace DCFApixels.DragonECS #endif #endregion - #region Enable/Disable/Copy - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void EnableComponent(ref T component) - { - if (_isHasComponentLifecycleHandler) - { - _componentLifecycleHandler.Enable(ref component); - } - else - { - component = default; - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DisableComponent(ref T component) - { - if (_isHasComponentLifecycleHandler) - { - _componentLifecycleHandler.Disable(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 IEnumerable.GetEnumerator() { throw new NotImplementedException(); } IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); } @@ -484,7 +447,6 @@ namespace DCFApixels.DragonECS #endregion } - public static class EcsPoolExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -518,29 +480,5 @@ namespace DCFApixels.DragonECS { return self.AnyPool>(); } - - #region Obsolete - [Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Inc) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsPool Include(this EcsAspect.Builder self) where TComponent : struct, IEcsComponent - { - return self.IncludePool>(); - } - [Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Exc) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsPool Exclude(this EcsAspect.Builder self) where TComponent : struct, IEcsComponent - { - return self.ExcludePool>(); - } - [Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Opt) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsPool Optional(this EcsAspect.Builder self) where TComponent : struct, IEcsComponent - { - return self.OptionalPool>(); - } - #endregion } -} +} \ No newline at end of file diff --git a/src/Pools/EcsTagPool.cs b/src/Pools/EcsTagPool.cs index 536fe9c..203293c 100644 --- a/src/Pools/EcsTagPool.cs +++ b/src/Pools/EcsTagPool.cs @@ -35,7 +35,7 @@ namespace DCFApixels.DragonECS public sealed class EcsTagPool : IEcsPoolImplementation, IEcsStructPool, IEnumerable //IEnumerable - IntelliSense hack where T : struct, IEcsTagComponent { - private EcsWorld _source; + private EcsWorld _world; private int _componentTypeID; private EcsMaskChunck _maskBit; @@ -78,7 +78,7 @@ namespace DCFApixels.DragonECS } public EcsWorld World { - get { return _source; } + get { return _world; } } public bool IsReadOnly { @@ -102,7 +102,7 @@ namespace DCFApixels.DragonECS } void IEcsPoolImplementation.OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID) { - _source = world; + _world = world; _mediator = mediator; _componentTypeID = componentTypeID; _maskBit = EcsMaskChunck.FromID(componentTypeID); @@ -116,7 +116,7 @@ namespace DCFApixels.DragonECS public void Add(int entityID) { #if DEBUG - if (_source.IsUsed(entityID) == false) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_source, entityID); } + if (_world.IsUsed(entityID) == false) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_world, entityID); } if (Has(entityID)) { EcsPoolThrowHelper.ThrowAlreadyHasComponent(entityID); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } #elif DRAGONECS_STABILITY_MODE @@ -216,7 +216,7 @@ namespace DCFApixels.DragonECS if (_isLocked) { return; } #endif if (_count <= 0) { return; } - var span = _source.Where(out SingleTagAspect _); + var span = _world.Where(out SingleTagAspect _); _count = 0; foreach (var entityID in span) { @@ -407,7 +407,6 @@ namespace DCFApixels.DragonECS public static implicit operator ReadonlyEcsTagPool(EcsWorld.GetPoolInstanceMarker a) { return a.GetInstance>(); } #endregion } - public static class EcsTagPoolExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -441,68 +440,5 @@ namespace DCFApixels.DragonECS { return self.OptionalPool>(); } - - #region Obsolete - [Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Inc) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsTagPool Include(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent - { - return self.IncludePool>(); - } - [Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Exc) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsTagPool Exclude(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent - { - return self.ExcludePool>(); - } - [Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Opt) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsTagPool Optional(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent - { - return self.OptionalPool>(); - } - - //--------------------------------------------------- - - [Obsolete("Use " + nameof(EcsWorld) + "." + nameof(GetPool) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsTagPool GetTagPool(this EcsWorld self) where TTagComponent : struct, IEcsTagComponent - { - return self.GetPoolInstance>(); - } - [Obsolete("Use " + nameof(EcsWorld) + "." + nameof(GetPoolUnchecked) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsTagPool GetTagPoolUnchecked(this EcsWorld self) where TTagComponent : struct, IEcsTagComponent - { - return self.GetPoolInstanceUnchecked>(); - } - - [Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Inc) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsTagPool IncludeTag(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent - { - return self.IncludePool>(); - } - [Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Exc) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsTagPool ExcludeTag(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent - { - return self.ExcludePool>(); - } - [Obsolete("Use " + nameof(EcsAspect) + "." + nameof(EcsAspect.Builder) + "." + nameof(Opt) + "()")] - [EditorBrowsable(EditorBrowsableState.Never)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EcsTagPool OptionalTag(this EcsAspect.Builder self) where TTagComponent : struct, IEcsTagComponent - { - return self.OptionalPool>(); - } - #endregion } -} +} \ No newline at end of file