mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
simple refactoring
This commit is contained in:
parent
4b0d188955
commit
e7c623daf8
@ -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<T>(out string name) => TryGetCustomName(type: typeof(T), out name);
|
||||
|
@ -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();
|
||||
|
@ -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<TInterface>)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<TInterface> _targetsSealed;
|
||||
@ -333,7 +333,7 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
public static IEnumerable<Type> GetEcsProcessInterfaces(this Type self)
|
||||
{
|
||||
return self.GetInterfaces().Where(o=> o.IsEcsProcessInterface());
|
||||
return self.GetInterfaces().Where(o => o.IsEcsProcessInterface());
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -1,7 +1,4 @@
|
||||
using DCFApixels.DragonECS.Utils;
|
||||
using System;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public abstract partial class EcsWorld
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -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<Type, HybridMapping> _hybridMapping = new Dictionary<Type, HybridMapping>();
|
||||
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<IEcsHybridPoolInternal> _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<Type> _hybridComponents = new HashSet<Type>();
|
||||
@ -346,17 +346,17 @@ namespace DCFApixels.DragonECS
|
||||
_source = source;
|
||||
_type = type;
|
||||
_relatedPools = new List<IEcsHybridPoolInternal>();
|
||||
_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;
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
|
Loading…
Reference in New Issue
Block a user