From e7c623daf81488f863653905dfbc83199fe922f4 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 20 Dec 2023 23:21:10 +0800 Subject: [PATCH] simple refactoring --- src/Debug/EcsDebugUtility.cs | 4 ++-- src/EcsAspect.cs | 4 ++-- src/EcsRunner.cs | 8 ++++---- src/EcsWorld.cache.cs | 5 +---- src/EcsWorld.cs | 6 +++--- src/Pools/EcsHybridPool.cs | 16 ++++++++-------- src/Pools/EcsPool.cs | 1 - 7 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/Debug/EcsDebugUtility.cs b/src/Debug/EcsDebugUtility.cs index 4777e50..7e41fad 100644 --- a/src/Debug/EcsDebugUtility.cs +++ b/src/Debug/EcsDebugUtility.cs @@ -71,8 +71,8 @@ namespace DCFApixels.DragonECS public static string GetName(Type type, int maxGenericDepth = 2) => type.TryGetCustomAttribute(out MetaNameAttribute atr) ? atr.name : GetGenericTypeName(type, maxGenericDepth); public static bool TryGetCustomName(object obj, out string name) { - return obj is IEcsDebugMetaProvider intr ? - TryGetCustomName(intr.DebugMetaSource, out name) : + return obj is IEcsDebugMetaProvider intr ? + TryGetCustomName(intr.DebugMetaSource, out name) : TryGetCustomName(type: obj.GetType(), out name); } public static bool TryGetCustomName(out string name) => TryGetCustomName(type: typeof(T), out name); diff --git a/src/EcsAspect.cs b/src/EcsAspect.cs index ebfbaa3..bea4d3e 100644 --- a/src/EcsAspect.cs +++ b/src/EcsAspect.cs @@ -143,7 +143,7 @@ namespace DCFApixels.DragonECS foreach (var id in maskInc) { var bit = EcsMaskBit.FromID(id); - if(!r.TryAdd(bit.chankIndex, bit.mask)) + if (!r.TryAdd(bit.chankIndex, bit.mask)) r[bit.chankIndex] = r[bit.chankIndex] | bit.mask; } EcsMaskBit[] incMasks = r.Select(o => new EcsMaskBit(o.Key, o.Value)).ToArray(); @@ -155,7 +155,7 @@ namespace DCFApixels.DragonECS r[bit.chankIndex] = r[bit.chankIndex] | bit.mask; } EcsMaskBit[] excMasks = r.Select(o => new EcsMaskBit(o.Key, o.Value)).ToArray(); - + var inc = maskInc.ToArray(); Array.Sort(inc); var exc = maskExc.ToArray(); diff --git a/src/EcsRunner.cs b/src/EcsRunner.cs index 89008d6..b0d4470 100644 --- a/src/EcsRunner.cs +++ b/src/EcsRunner.cs @@ -162,7 +162,7 @@ namespace DCFApixels.DragonECS private static TInterface Instantiate(EcsPipeline source, TInterface[] targets, bool isHasFilter, object filter) { - if(_subclass == null) + if (_subclass == null) { Type interfaceType = typeof(TInterface); if (interfaceType.TryGetCustomAttribute(out BindWithEcsRunnerAttribute atr)) @@ -181,7 +181,7 @@ namespace DCFApixels.DragonECS throw new EcsFrameworkException("Процесс не связан с раннером, используйте атрибуут BindWithEcsRunner(Type runnerType)"); } } - + var instance = (EcsRunner)Activator.CreateInstance(_subclass); return (TInterface)(IEcsProcess)instance.Set(source, targets, isHasFilter, filter); } @@ -194,7 +194,7 @@ namespace DCFApixels.DragonECS return Instantiate(source, FilterSystems(source.AllSystems, filter), true, filter); } #endregion - + private EcsPipeline _source; protected TInterface[] targets; private ReadOnlyCollection _targetsSealed; @@ -333,7 +333,7 @@ namespace DCFApixels.DragonECS public static IEnumerable GetEcsProcessInterfaces(this Type self) { - return self.GetInterfaces().Where(o=> o.IsEcsProcessInterface()); + return self.GetInterfaces().Where(o => o.IsEcsProcessInterface()); } #endregion diff --git a/src/EcsWorld.cache.cs b/src/EcsWorld.cache.cs index 487bc86..8729c4b 100644 --- a/src/EcsWorld.cache.cs +++ b/src/EcsWorld.cache.cs @@ -1,7 +1,4 @@ -using DCFApixels.DragonECS.Utils; -using System; - -namespace DCFApixels.DragonECS +namespace DCFApixels.DragonECS { public abstract partial class EcsWorld { diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index c15d3ff..021ccbf 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -146,7 +146,7 @@ namespace DCFApixels.DragonECS #region Entity public int NewEntity() { - if(_freeSpace <= 1 && _delEntBufferCount > _delEntBufferMinCount) + if (_freeSpace <= 1 && _delEntBufferCount > _delEntBufferMinCount) ReleaseDelEntityBuffer(); int entityID = _entityDispenser.GetFree(); @@ -236,7 +236,7 @@ namespace DCFApixels.DragonECS { foreach (var pool in _pools) { - if (pool.Has(fromEntityID)) + if (pool.Has(fromEntityID)) pool.Copy(fromEntityID, toEntityID); } } @@ -285,7 +285,7 @@ namespace DCFApixels.DragonECS var count = --_componentCounts[entityID]; _entitiesComponentMasks[entityID][maskBit.chankIndex] &= ~maskBit.mask; - if (count == 0 && _allEntites.Has(entityID)) + if (count == 0 && _allEntites.Has(entityID)) DelEntity(entityID); #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS if (count < 0) Throw.World_InvalidIncrementComponentsBalance(); diff --git a/src/Pools/EcsHybridPool.cs b/src/Pools/EcsHybridPool.cs index 4f9d93f..e48ecda 100644 --- a/src/Pools/EcsHybridPool.cs +++ b/src/Pools/EcsHybridPool.cs @@ -70,7 +70,7 @@ namespace DCFApixels.DragonECS } _mediator.RegisterComponent(entityID, _componentTypeID, _maskBit); _listeners.InvokeOnAdd(entityID); - if(isMain) + if (isMain) component.OnAddToPool(_source.GetEntityLong(entityID)); _items[itemIndex] = component; _entities[itemIndex] = entityID; @@ -84,7 +84,7 @@ namespace DCFApixels.DragonECS } public void Set(int entityID, T component) { - if(Has(entityID)) + if (Has(entityID)) Del(entityID); Add(entityID, component); } @@ -121,7 +121,7 @@ namespace DCFApixels.DragonECS #endif ref int itemIndex = ref _mapping[entityID]; T component = _items[itemIndex]; - if(isMain) + if (isMain) component.OnDelFromPool(_source.GetEntityLong(entityID)); if (_recycledItemsCount >= _recycledItems.Length) Array.Resize(ref _recycledItems, _recycledItems.Length << 1); @@ -296,7 +296,7 @@ namespace DCFApixels.DragonECS private Dictionary _hybridMapping = new Dictionary(); internal HybridMapping GetHybridMapping(Type type) { - if(!_hybridMapping.TryGetValue(type, out HybridMapping mapping)) + if (!_hybridMapping.TryGetValue(type, out HybridMapping mapping)) { mapping = new HybridMapping(this, type); _hybridMapping.Add(type, mapping); @@ -314,7 +314,7 @@ namespace DCFApixels.DragonECS private IEcsHybridPoolInternal _targetTypePool; private List _relatedPools; - private static Type hybridPoolType = typeof(EcsHybridPool<>); + private static Type hybridPoolType = typeof(EcsHybridPool<>); private static MethodInfo getHybridPoolMethod = typeof(EcsHybridPoolExtensions).GetMethod($"{nameof(EcsHybridPoolExtensions.GetPool)}", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); private static HashSet _hybridComponents = new HashSet(); @@ -346,17 +346,17 @@ namespace DCFApixels.DragonECS _source = source; _type = type; _relatedPools = new List(); - _sourceForReflection = new object[]{ source }; + _sourceForReflection = new object[] { source }; _targetTypePool = CreateHybridPool(type); foreach (var item in type.GetInterfaces()) { - if(IsEcsHybridComponentType(item)) + if (IsEcsHybridComponentType(item)) { _relatedPools.Add(CreateHybridPool(item)); } } Type baseType = type.BaseType; - while(baseType != typeof(object) && IsEcsHybridComponentType(baseType)) + while (baseType != typeof(object) && IsEcsHybridComponentType(baseType)) { _relatedPools.Add(CreateHybridPool(baseType)); baseType = baseType.BaseType; diff --git a/src/Pools/EcsPool.cs b/src/Pools/EcsPool.cs index 73fabc8..315422b 100644 --- a/src/Pools/EcsPool.cs +++ b/src/Pools/EcsPool.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Reflection; using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS